initial commit

This commit is contained in:
Malin Freeborn
2020-01-02 01:04:35 +01:00
commit 6befc5d3c1
162 changed files with 19086 additions and 0 deletions

107
data/git.md Normal file
View File

@@ -0,0 +1,107 @@
# Basic Git
Move to the directory containing the project.
> git status
Add this folder (or just any dir)
> git add .
History:
> git log
# Commits
Add current changes to current config.
> git add .
Make a comment:
> git commit -m "Created service"
Type out a message:
> git commit
Push your stuff out:
> git push
Add a single line:
> git log --oneline
Get recent changes:
> git pull
# New Project
> git init
# New Machines
> git config --global user.email "malinfreeborn@tutamail.com"
> git config --global user.name "Malin Freeborn"
# Branches
To make a new branch, make sure you're up to date, then:
> git checkout -b [branchname]
Check otu all branches with
> git branch -a
Add the new branch to a git:
> git push origin [branchname]
# Tricks
## Delete All History
> git checkout --orphan temp
> git add -A
> git commit -am "release the commits!"
> git branch -D master
> git branch -m master
> git push -f origin master
Gitlab requires more changes, such as going to `settings > repository` and switching the main branch, then stripping protection.
# Subtree
The project has subdirectories sub-1,sub-2,sub-3. The first should be its own repository, but should also retain its own history.
First, we extract its history as an independent item, and make that into a seprate branch.
> git subtree split --prefix=sub-1 -b sub
If you want something a few directories deep, you can use `--prefix=sub-1/dir-2/dir-3
Then go and create a new git somewhere else:
> cd ..;mkdir sub-1;cd sub-1;git init --bare
Then go back to your initial git repo, and do the following:
git push ../subtest sub:master
Finally, you can clone this repo from your original.
> git clone ../subtest

42
data/sc-im.md Normal file
View File

@@ -0,0 +1,42 @@
# Basic Commands
> H = highest part
> L = lowest part
> gg = top
> g$ = most right.
> g0 = most left.
> \ = insert middle
> > = insert left
> < = insert right
gb4 = to to cell b4
> x = delete a cell
> aa = see all text in cells
> f = format cells so you can see it.
> fl = format wider right
> fh = format smaller left
> fj = decrease decimal value
> fk = increase decimal value
# Edit
> e = edit a number
> E = edit text
> dc = delete column
> yc = yank column
> dr = delete row
> p = literal paste
> Pc = paste mutatis mutandis
#Functions
> =@avg(B1:B4) = average B1 to B4
> =@max(B1:B4) = maximum of those numbers
> =@min(B1:B8) = minimumof those numbers

10
data/sdcv.md Normal file
View File

@@ -0,0 +1,10 @@
# Install new dictionaries
If the path doesn't exist then:
> sudo mkdir -p /usr/share/stardict/dic
Then move the dictionaries there.

1009
data/sql/person.sql Normal file

File diff suppressed because it is too large Load Diff

354
data/sql/postgresql.md Normal file
View File

@@ -0,0 +1,354 @@
# Setup
Install postgres and start it as a service, then start with:
> psql
## Make a database as the new user postgres
> sudo su postgres
> [postgres] echo $HOME
> [postgres]
> [postgres] CREATE DATABASE dvdrental;
## Sample Data
Get sample data.
> wget http://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip
And then get the pdf mapping the sample data:
> wget http://www.postgresqltutorial.com/wp-content/uploads/2018/03/printable-postgresql-sample-database-diagram.pdf
Unzip and load sample data:
> unzip dvdrental.zip
> sudo su postgres
> [postgres] $ pg_restore -U postgres -d dvdrental dvdrental.tar
> [postgres]
# Commands
## Basics
List available databases.
> \l
You'll see a list of available databases like:
`dnd`
`dvdrentals`
Then you can connect to one:
> \c dvdrental
And have a look at what tables it has:
> \d dvdrental
If it has tables such as `language`, `film_actor` and `inventory`, you can see the table's settings with:
> \dt film_actor
And pull back the entire table:
> SELECT * from film_actor;
## Various
Connect to 231.13.48.38 with user 'bob', port 1234, database 'X'
> psql -h 231.13.48.38 -p1234 -U bob X
# Setup Yourself
Make database "test" and connect to it.
> CREATE DATABASE test;
> \l test
Delete database 'dogs':
> DROP DATABASE dogs;
Making a table has a basic form of:
`CREATE TABLE table_name (`
then [ column name ] + [data type ] ... (and possibly data constraints)
`)`
|Data Types | Meaning | Constraints |
|:----|:----|:----|
| BIGSERIAL | A number incrementing by one each entry | 'NOT NULL PRIMARY KEY (so it's used for relational reference) |
| int | integer | (50) limits the table to 50, e.g. `int(50)`|
| VARCHAR | any characters | limit, e.g.`VARCHAR(70)`|
| TIMESTAMP | time | |
| date | date | |
| text | text? | |
| tsquery | text search query | |
| money | money | |
| json | textual JSON data | |
| cidr | ipv4 or 6 address | |
| macaddr | mac address | |
E.g.
```
CREATE TABLE character (
id int,
str int(1),
dex int(1),
spd int(1),
int int(1),
wts int(1),
cha int(1));
```
See your table:
> \d
Look at what columns you have there:
> \d character
But this allows for empty characters, so...
```
CREATE TABLE person (
id BIGSERIAL NOT NULL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
gender VARCHAR(7) NOT NULL,
date_of_birth DATE NOT NULL,
);
```
Delete with
> DROP TABLE person;
## Inserting Data
```
INSERT INTO person (
first_name,
last_name,
gender,
date_of_birth)
VALUES ('Hugi','Smith','DWARF', date '200-01-12');
```
## Selecting Data
You can also mass select by choosing to insert a file. Download example data [here](https://mockaroo.com/).
> \i /home/ghost/file.sql
Various querries:
> SELECT * FROM person;
> SELECT * FROM person ORDER BY id DESC;
> SELECT * FROM person
## Offset, Fetch and Limit
'Limit' is not official, but was accepted later:
> SELECT * FROM person ORDER BY country ASC LIMIT 10;
The official way to make a limit is 'FIRST 5 ROWS ONLY:
> SELECT * FROM person OFFSET 5 FETCH FIRST 5 ROWS ONLY;
> SELECT * FROM person where gender = 'Male' AND ( country_of_birth = 'Poland' OR country_of_birth = 'China');
Miss out the first 5 result with 'OFFSET 5'.
> SELECT p\* FROM PERSON WHERE gender = 'Female' AND country_of_birth = 'Kosovo' OFFSET 5;
> SELECT * FROM person OFFSET 5 FETCH FIRST 7 ROW ONLY;
## Advanced Selection
This query takes a lot of typing:
> SELECT * FROM person WHERE country_of_birth = 'China'
> OR country_of_birth = 'Kosovo'
> OR country_of_birth = 'Brazil';
You can write the same thing with less typing:
> SELECT *
> FROM person
> WHERE country_of_birth in ('China','Kosovo','Brazil');
> SELECT * FROM person
> WHERE date_of_birth
BETWEEN DATE '2018-04-10' AND '2019-01-01'
> ORDER BY date_of_birth;
### Rough Search
Similar words - we can find emails ending in '.com'.
> SELECT * FROM person
> WHERE email LIKE '%.com';
Or any gmail address:
> SELECT * FROM person
> WHERE email LIKE '%@gmail.%';
Or particular characters, where three precede 'gmail.com' and it's case insensitive:
> SELECT * FROM person
> WHERE email iLIKE '\_\_\_@gmail.com';
### Groups and Aggregates
Select all countries as a complete mess:
> SELECT country_of_birth FROM person;
Select countries with proper grouping:
> SELECT country_of_birth FROM person GROUP BY country_of_birth;
Select countries and count instances:
> SELECT country_of_birth, COUNT(\*) FROM person GROUP BY country_of_birth ORDER BY country_of_birth;
Also select a minimum number with 'having'. What you have must be before 'order by'.
> SELECT country_of_birth, COUNT(\*) FROM person GROUP BY country_of_birth HAVING COUNT(\*) > 5;
> SELECT country_of_birth, COUNT(\*) FROM person GROUP BY country_of_birth HAVING COUNT(\*) >= 10;
Other aggregates include 'max', 'min'.
Select most expensive car:
> SELECT MAX(price) FROM car;
> SELECT MIN(price) FROM car;
> SELECT AVG(price) FROM car;
We can stick items together for better grouping:
> SELECT make, model, MAX(price) FROM car GROPU BY make, model;
Select all fields from table 'car', and add a column containing another price, discounted to 90%, rounded to two decimal places.
> SELECT id,make,model,price,ROUND(price * .9, 2) from car;
Same thing, but take 10% of the price from the price.
> SELECT id,make,model,price,ROUND(price - (price * .1), 2) from car;
## Comparison
> SELECT 10 + 2^2;
> SELECT 10! * 2 - 3;
... et c.
This returns false:
> SELECT 1 = 1;
These return false:
> SELECT 2<1;
Or '1 is not equal to 1':
> SELECT 1<>1;
And with strings, 'G is not the same as g':
> SELECT 'G'<>'g';
### Car Disconts
You want to show the discounts on various cars. You check which columns are available and select all of them:
> \d car
> SELECT id,make,model,price FROM car;
## Aliases
You can change what a column name appears as with:
> select price AS original_price from car;
# Null Values
## Coalesce
You can input a series of entries, requesting the first one which is present. Here we input three entries which are 'null', and a third which is '2', so '2' is selected:
> SELECT COALESCE(null, null, 2) AS number;
When selecting column 'email' from table 'person', you can input the string 'Email not provided' if there is no email provided:
> SELECT COALESCE(email, 'Email not provided') from person;
## Nullif
Normally, devision by 0 produces an error:
> SELECT 10/ 0;
But 10 divided by 'null' produces only 'null', which is not an error.
The 'nullif' statement takes two numbers, and returns 'null' iff the numbers are the same as each other.
> select nullif(0,0)
> select nullif(10,10)
# Date
Select date:
> SELECT NOW()::DATE;
> SELECT NOW()::TIME;
or just:
> SELECT NOW();
More [here](postgresql.org/docs/11/datatype-datetime.html).
2h23m

90
data/sql/sql.md Normal file
View File

@@ -0,0 +1,90 @@
MySQL, Aurora and the Maria Database work similarly, and mostly with the same commands.
MySQL requires 160 Megs of disk space.
The ontological layers go:
> Database > table > record > field
The record is a line containing multiple fields. The table contains multiple records.
## Database: RPGs
### Table: D&D
#### Columns:
| id | name | year | edition | stars |
|:--:|:-------------------|:-----|:--------|:------|
| 1 | Dungeons & Dragons | 1975 | 1 | 1 |
| 2 | Dungeons & Dragons | 1980 | 2 | 1 |
| 3 | Advanced Dungeons & Dragons | 1985 | 1 | 1 |
# Getting started
> sudo apt-get install mysql-server
You'll be asked for a password.
Log in with:
> mysql -u root -p
The -u requests a user, while -p tells it to prompt for a password.
List all databases:
> show databases;
Make a new database;
> create database creatures;
Start work on the new database:
> use creatures;
> create table stats (Strength VARCHAR(2), Speed VARCHAR(2), Dexterity(2));
This creatures a row called 'stats' within the 'creature'table' with a number of variables, all of type VARCHAR (a variable length character string).
Now you can insert data (which would normally be provided by a user via php or some-such).
> insert into stats (Strength,Speed,Dexterity) values (-1,0,+1)
Now have a look at the info:
> select * from stats
The old way to delete info by selection was:
> delete * from stats where Charisma='0'
...but now it's:
> delete from stats where Charisma='0'
Update a thing:
> update stats
> set Speed='-1',Charisma='-2'
> where Strength=0;
Leaving out the specifier 'where' means you're updating the entire database.
Control order with
> SELECT * FROM stats ORDER BY Strength;
Or for descending order, suffix 'DESC'.
> select * from stats ORDER by Date DESC;
# Resources
Try more at [w3schools](http://www.w3schools.com/sql/sql_groupby.asp).

6
data/sql/tricks.md Normal file
View File

@@ -0,0 +1,6 @@
# Find data from any table
> pg_dump --data-only --inserts -U postgres your-db-name > a.tmp
> grep 'my string' a.tmp

40
data/suitecrm/suitecrm.sh Normal file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
[ ! -z $1 ] && sudo apt-get install -y virtualbox-guest-additions-iso
sudo apt-get -y install wget php php-{pear,cgi,common,curl,mbstring,gd,mysql,gettext,bcmath,imap,json,xml,fpm}
clear
echo 'The correct version of php should be 7.2.8 or greater.'
echo "The current version is $(php -v | grep PHP)"
sleep 5
sudo sh -c 'printf "upload_max_filesize = 20M\nmax_execution_time = 120\n" >> /etc/php.ini'
sudo apt-get install -y nginx
# Installing mariadb server
## uninstall any old versions first
## install software-properties-common if missing
sudo apt-get install -y software-properties-common
# then get the keys to the server
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu $(lsb_release -cs) main"
sudo apt -y update && sudo apt -y install mariadb-server mariadb-client
# Enter a password for the database, or if you did not get a prompt, run:
sudo mysql_secure_installation
# Then just accept defaults

30
data/taskwarrior/.no Normal file
View File

@@ -0,0 +1,30 @@
setting up with:
- data at /var/taskd
- user: root
- host=localhost
- port=53589
- Organization=Andonome
- Name="Malin Freeborn"
## Next
Copy files to ~/.task
/usr/share/doc/taskd/pki/{ca.cert.pem,Malin_Freeborn.cert.pem,Malin_Freeborn.key.pem}
And run these commands:
```
Malin Freeborn must run these commands:
task config taskd.server localhost:53589
task config taskd.credentials 'Andonome/Malin Freeborn/36faa2a9-de12-4410-99d5-0bcaa5a4887a'
task config taskd.certificate ~/.task/Malin_Freeborn.cert.pem
task config taskd.key ~/.task/Malin_Freeborn.key.pem
task config taskd.ca ~/.task/ca.cert.pem
task config taskd.trust strict
task config taskd.ciphers NORMAL
```

View File

@@ -0,0 +1,57 @@
#!/bin/bash
export TASKDDATA=/var/lib/taskd
echo Change CN to hostname
sleep 2
sudo vim /usr/share/doc/taskd/pki/vars
cd /usr/share/doc/taskd/pki/
sudo ./generate
mkdir -p $TASKDDATA
cp *.pem $TASKDDATA
chown -R root /var/lib/taskd
sudo cp *pem $TASKDDATA
chown -R taskd:taskd $TASKDDATA
taskd config "$user".cert=/var/lib/taskd/client.cert.pem
taskd config "$user".key=/var/lib/taskd/client.key.pem
taskd config "$(hostname)".cert=/var/lib/taskd/server.cert.pem
taskd config "$(hostname)".key=/var/lib/taskd/server.key.pem
taskd config "$(hostname)".crl=/var/lib/taskd/server.crl.pem
taskd config ca.cert=/var/lib/taskd/ca.cert.pem
taskd config --force server $(hostname):53589
systemctl start taskd
echo name a group
read group
echo name user
read user
taskd add org $group
taskd add user $group $user
./generate.client $user
echo "
taskd.server=alfred:port
taskd.credentials=$group/$user/key
taskd.certificate=~/.task/'$user'.cert.pem
taskd.key=~/.task/'$user'.key.pem
taskd.ca=~/.task/ca.cert.pem" >> /var/lib/taskd/config
tar cf $user.tar "$user"* ca.cert.pem

34
data/taskwarrior/task.md Normal file
View File

@@ -0,0 +1,34 @@
# Contexts
Set three contexts by their tags:
> task context define work +sa or +hr
> task context define study +ed or +void or +rat
> task context define home -sa -hr -ed -void -rat
Change to the first context.
> task context work
Then stop.
> task context none
# Review
View list of tasks completed in the last week:
> task end.after:today-1wk completed
# Timewarrior
> timew start ed 'learn timewarrior'
> timew stop
> timew summary
> timew tags

178
data/taskwarrior/taskd.md Normal file
View File

@@ -0,0 +1,178 @@
Switch to root to make things easier.
> yay -S
> export TASKDDATA=/var/lib/taskd
Edit `/usr/share/doc/taskd/pki/vars` so that ``CN'' = the hostname (IP is fine).
> cd /usr/share/doc/taskd/pki
Execute the `generate` file to generate a selfsigned certificate for the server. These will be \*.pem-files. Copy all \*.pem-files to /var/lib/taskd.
Make sure a copy of ca.cert.pem remains to generate user-certificates later.
# Taskd Configurations
> taskd config --force client.cert $TASKDDATA/client.cert.pem
> taskd config --force client.key $TASKDDATA/client.key.pem
> taskd config --force server.cert $TASKDDATA/server.cert.pem
> taskd config --force server.key $TASKDDATA/server.key.pem
> taskd config --force server.crl $TASKDDATA/server.crl.pem
> taskd config --force ca.cert $TASKDDATA/ca.cert.pem
# Change Taskd Log Location
The default is /tmp/log, which obviously you don't want.
> touch /var/log/taskd.log
> chown taskd:taskd /var/log/taskd.log
> taskd config --force log /var/log/taskd.log
Finally, set up the servername - the same one as in the certificates. Mine is ``testarch''.
> taskd config --force server testarch:9001
# Adding users
Let's add the group ``home'', then the user ``ghost'', will go in that group.
> taskd add org home
> taskd add user home ghost
`3f9e6154-25cb-4e45-88bb-45e98feef904`
> taskd add user home alfred
`4fbb319c-c493-437a-ab7a-028f5b75e522`
The user then gets a key.
Finally, make sure that taskd can read its own data>
> chown -R taskd:taskd /var/lib/taskd/orgs
... or perhaps the entire directory of /var/lib/taskd/.
Then it's back to /usr/share/doc/taskd/pki
Generate some userfiles:
> ./generate.client ghost
> ./generate.client alfred
The bob and ghost \*pem files have to be added to the given users' home directories.
# Setting up Users
> sudo apt-get install taskwarrior taskd
> task
Then move the \*pem files into the .task directory of the user.
Don't forget to add the ca.key.pem from `/usr/share/doc/taskd/pki`!
# Attempt 2
Well, none of that worked.
New info from [taskwarrior](https://gitpitch.com/GothenburgBitFactory/taskserver-setup#/1/4)
Default port = 53589
starting with
> taskd init
> taskd config server localhost:53589
View supported settings with `taskdrc`.
!!! Start with taskdctl start
Do a non-daemon version with
> taskd server --data $TASKDDATA --daemon
# Systemd Unit file
This needs to be edited for "$TASKDDATA", "$TASKDUSER", and "$TASKDGROUP".
---
Unit]
Description=Secure server providing multi-user, multi-client access to Taskwarrior data
Requires=network.target
After=network.target
Documentation=http://taskwarrior.org/docs/#taskd
[Service]
ExecStart=/usr/local/bin/taskd server --data $TASKDDATA
Type=simple
User=$TASKDUSER
Group=$TASKDGROUP
WorkingDirectory=$TASKDDATA
PrivateTmp=true
InaccessibleDirectories=/home /root /boot /opt /mnt /media
ReadOnlyDirectories=/etc /usr
[Install]
WantedBy=multi-user.target
---
Enable all this by copying the file to `/etc/systemd/system`, reload daemon, then start it.
Key for ghost:
29bd8a06-2cc0-4163-905d-6216257a3031
e29bffe0-72d8-45f2-b1f9-f29397cfab16
# Different:
$ task config taskd.certificate -- ~/.task/first_last.cert.pem
$ task config taskd.key -- ~/.task/first_last.key.pem
$ task config taskd.ca -- ~/.task/ca.cert.pem
# Trust
For troubleshooting we can set:
> taskd.trust=ignore [hostname]
> taskd.trust=allow all
> taskd.trust=strict
# User Defines Attributes - UDA
Each UDA has two to four attributes: type (numeric or string) and label are necessary:
> task config uda.THING.type {numeric,string}
> task config uda.THING.label Thg
Constrain these attributes to a comma-delineated set with:
> task config uda.THING.values brown,orange,green
You can also show how important the Attribute makes something:
> urgency.uda.THING.coefficient=2.8
# Aliases
Alias `delete' to `rm' with:
task config alias.rm delete

41
data/taskwarrior/taskd.sh Normal file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
export TASKDDATA=/var/lib/taskd
sudo mkdir -p $TASKDDATA
sudo chown taskd:$(whoami) $TASKDDATA
sudo chmod 775 $TASKDDATA
cp -r /usr/share/doc/taskd/pki/ $TASKDDATA
cd $TASKDDATA/pki
sed -i s/localhost/$(hostname -f)/ vars
./generate
cp client.cert.pem $TASKDDATA
cp client.key.pem $TASKDDATA
cp server.cert.pem $TASKDDATA
cp server.key.pem $TASKDDATA
cp server.crl.pem $TASKDDATA
cp ca.cert.pem $TASKDDATA
taskd config --force client.cert $TASKDDATA/client.cert.pem
taskd config --force client.key $TASKDDATA/client.key.pem
taskd config --force server.cert $TASKDDATA/server.cert.pem
taskd config --force server.key $TASKDDATA/server.key.pem
taskd config --force server.crl $TASKDDATA/server.crl.pem
taskd config --force ca.cert $TASKDDATA/ca.cert.pem
cd $TASKDDATA/..
taskd config --force log $PWD/taskd.log
taskd config --force pid.file $PWD/taskd.pid
taskd config --force server $(hostname -f):53589
taskd add org public
# 1515de89-cc81-4af6-a6a4-41c1430620b0
journalctl -u taskd

156
data/taskwarrior/timew.md Normal file
View File

@@ -0,0 +1,156 @@
# Setup
Below commands mostly deal with timew alone. With taskwarrior installed as well, `locate on-modify-time`, then add it to ~/.task/hooks and make it executable.
#Summaries
Try:
> timew summary :yesterday
You can also use :week, :lastweek, :month, :quarter, :year, or a range such as:
> timew summary today to tomorrow
> timew today - tomorrow
> 2018-10-15T06:00 - 2018-10-17T06:00
Each of these can gain with the :ids tag.
# Basics
> timew start
> timew stop
> timew continue
> timew summary
> timew tags
And add ids with:
> timew summary :ids
> timew track 10am - 1pm timewarrior
> timew track 1pm for 2h walk
# Adjusting Timewarrior
First get ids.
> timew summary :ids
Then if we're looking at task @2:
> timew move @2 12:00
> timew lengthen @2 3mins
> time shorten @2 40mins
# Forgetting
> timew start 1h ago @4
Or if your action actually had a break:
> timew split @8
Or maybe not?
> timew join @4 @8
> timew @8 delete
Start at previous time
> timew start 3pm 'Read chapter 12'
> timew start 90mins ago 'Read chapter 12'
Cancel currently tracked time.
> timew cancel
# Backdated tracking
> timew untag @3
# Hints
* :quit - for automation
* :yes
* :color
* :fill - expand the time to fill out available time
* :adjust - automatically correct overlaps
* :ids - show id numbers
# Times
* :yesterday
* :day
* :week
* :month
* :quarter
* :lastweek
* :lastmonth
* :lastquarter
* :lastyear
# Mistakes
task end.after:2015-05-01 and end.before:2015-05-31 completed
task end.after:today-1wk completed
# Errors with Python3
Replace
`os.system('timew start ' + combined + ' :yes')`
with:
`os.system('timew start ' + combined.decode() + ' :yes')`
and
`os.system('timew stop ' + combined + ' :yes')`
with:
`os.system('timew stop ' + combined.decode() + ' :yes')`
# Fixing Errors
> curl -O https://taskwarrior.org/download/timew-dbcorrection.py
> python timew-dbcorrections.py

12
data/w3m.md Normal file
View File

@@ -0,0 +1,12 @@
Ctrl+u to go to new url.
tab between fields.
B to go back.
o for the love of options.
T for a new tab.
'{' and '}' to change tabs.
'H' for help.