-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoftenforgotten
More file actions
438 lines (356 loc) · 16.3 KB
/
Copy pathoftenforgotten
File metadata and controls
438 lines (356 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#--------------Linux--------------------
# Find
find . #searches in current directory
find . -maxdepth 1 -type f #Finds all files in the current directory but NOT subdirectories
# Sed
grep vs sed #Cut which lines you want vs Cut out things from the line
sed -E # regexes
-n # Do not print the input by default.
/p # print only if a replacement was done.
# Grep
grep vs sed #Cut which lines you want vs Cut out things from the line
grep -wl -E [regex] *.tex #Grep for the specified expression in all tex files
grep -iwl -E [regex] *.tex #Grep for the specified expression in all tex files, case insensitive
grep -i #grep case insensitive
# Ripgrep
-F # raw string literal
-S # smart case search
-l # show filenames only
--type cpp #Only C++ files
# Jobs
kill (jobs -p) # kill running jobs
# Pr
pr -Tm [file1] [file2] # Output both files in two columns
# Paste
paste file{1,2} | column -s $'\t' -tn # output both files in two columns
# Tar
tar -xzvf # Extract a file
tar -tvf # List the files in a tar.gz archive. z is optional.
-x # Extract
-c # Compress
-z # Gzip
-j # bzip2
-v # Visual, i.e. show your work
-f # File. Not strictly needed, but meh
-t # List files
# mpv keybindings
j/J # cycle through subtitles
\# # cycle through audio tracks
LEFT # Left arrow moves backwards 5 seconds.
UP # Up key moves back by 1 min
[ # decrease playback speed by 10%
{ # halve playback speed
<Backspace> # restore playback speed
<Space> # Pause
q # quit
/ and * # Decrease / increase volume
9 and 0 # Decrease / increase volume
m # mute
f # full screen
o # Show progression bar
l # adjust A-B loop points
L # toggle infinite loop
r/R # adjust subtitles positions
s # take a screenshot
v # Toggle subtitle
< # Go backwards in playlist
. # Step forward one frame
F9 # show audio/sub streams
i # show info
mpv --audio-device=help # Find all audio devices
# In case cannot detect headphones, use this:
mpv --audio-device='pulse/alsa_output.usb-0b0e_Jabra_Link_370_745C4BA6557C011200-00.analog-stereo' 'https://www.youtube.com/playlist?list=PLnif93tJftftkzehpooEI-WrldifzoNgB' --no-video
mpv --audio-device='pulse/alsa_output.usb-0b0e_Jabra_Link_370_745C4BA6557C011200-00.analog-stereo' --ytdl-raw-options=write-sub=,write-auto-sub=,sub-lang=en <youtube-link>
# Rsync
# For full system backup
rsync -aAXH --info=progress2 --exclude={".cache/*",".choosenim/*","node_modules/*","Downloads/SageMath","Downloads/ubuntu-18.04.1-desktop-amd64.iso",".ccache/*",".vim/*",".dotnet/*",".config/Code/*",".nuget/*","ionide/*",".rustup/*",".local/*",".dbus/*"} /home /media/HDD/linux_partition_backup/
## Explanation: -aAX means archive mode
## NO SPACES in between the commas!
# Sort
sort #sorts any stdin that you want
sort -u #sorts without duplicates
sort -bgr #sort according to numerics, in reverse order (most to least impt), ignoring leading blanks
# Combos
find -type f -path "*/hw*/*/cpp" #Searches everything with a subdirectory hw and is a cpp file
find . -type f -name "*.cpp" -exec grep "vector< *vector< *TableEntry *> *> *\w*;" {} \; | grep -v iter | sed "s/.*([^;]*);/\1/
find -L . -type f -path "*/LATEST/*.cpp" -exec grep "vector *< *vector< *TableEntry *> *>" {} \; | wc -l # -L follows links, -exec tells you to execute the instruction afterwards
find -L . -type f -path "*.txt" -exec grep "vector *< *vector< *TableEntry *> *>" {} \; | grep -v "&" | grep -v '=' | grep -v "::" | sed "s/\(vector.*vector.*TableEntry.*>\) *\([^;]*\);/\2/" #This \( \) creates a group, which you can then refer to later using \1 or \2. The ^ in the square brackets means to ignore any item in the group.
find -L . -type f -path "*.txt" -exec grep "vector *< *vector< *TableEntry *> *>" {} \; | grep -v "&" | grep -v '=' | grep -v "::" | sed "s/\(vector.*vector.*TableEntry.*>\) *\([^;, ]*\);.*/\2/" | sed "s/^\s//" | sort | uniq -c | sort -rn | head
# Image magick compression
convert -sampling-factor 4:2:0 -strip -quality 30% [source.jpg] [result.jpg]
~/.scripts/shrink-jpg.sh [inputfile] # Implements the above
# PDF
~/.scripts/shrinkpdf.sh [inputfile] [outputfile]
# stat
stat -c '%y' <filename> # Last modified time of a file
# du
du -h <filename> # size of a particular file
du -sh * | sort -hr # size of all files in a directory
ncdu # Ncurses based du
# -------------Fish shell----------------------
history # Command history
history search <stuff> # Command history
set # set a variable. Possibilities are:
-U # Universal. Done only once. Don't put in config
-x # export this variable
-l # Local, to block scope
-g # Global scope
<blank> # If nothing, variables are function scoped
test # tests the given expression
-lt/ge # <, >= operators
-n # tests if a string is nonzero
# -------------gdb----------------------
gdb --tui [file] #gdb has a tui mode; and in this mode.
C-s #enters single key mode
list #Shows the current source code
disable [breakpt] #Disables the specified breakpoint by index
x/32w # Show memory at location for 32 words
# -------------Assembly / Object files----------------------
g++ -g -S -masm=intel -fverbose-asm [file].cpp -o [file].s #generate readable assembly
objdump -Mintel -x [file].o # dump an object file (simple)
objdump -C -Mintel -x [file].o # dump an object file with demangling for C++
# Find dependencies of a binary
ldd <binary> # To recursively find deps
readelf -d <binary> | grep NEEDED # Read header
strace -e -trace=open,openat <binary> # Run the program and log the dlopen syscalls
# Graphics
xrandr --output eDP-1 --auto --panning 2560x1440 --scale 1.25x1.25 #scaling issues in Linux
xset dpms 0 0 1200 # sets the screen timeout to 1200 seconds (20 min)
xset q # Shows the current xset settings
# Keyboard
xev -event keyboard #Show keys pressed on the keyboard
# Devices & ISOs
sudo mount /location/of/device /location/of/mount/point #Mount a device
lsblk #Shows the location of devices and their mount points
lsusb #Shows the output of the USB devices list
sha256sum -c [SHA256SUM file] --ignore-missing # If the SHA256SUM file contains the name of your file
sudo dd if=/path/to/file of=/dev/sda status=progress oflag=sync #Burn ISO to USB
sudo mount /dev/sda1 /media/HDD # Mount HDD
# Bluetooth
bluetoothctl #Runs the CLI for bluetooth
power on
agent on
scan on
pair [DEVICE MAC ADDRESS]
connect [DEVICE MAC ADDRESS]
connect F4:4E:FD:E0:EF:56 #Bluetooth speaker
74:5C:4B:5E:62:B3 # Jabra evolve 75
# Apt
apt install --only-upgrade <package-name>
# Where things are
/etc/default/tlp #TLP config files
/etc/default/grub #Grub config files
/var/log/apt/history.log #Contains the data from apt installs
# Misc Terminal
ln -s [Place the link points to] [URL of link] #Creates a Symbolic link in Ubuntu
<C-z> #Stops any running process (but does not kill!)
<C-l> #Clear the page
<C-a> #Go to start of line
<C-e> #Go to end of line
bg #If there is a stopped procedure, run any stopped procedure in the background
cut #cut the lines vertically
cut -d ')' -f 2 #Cut the lines that have a ) char, print the second one
<<EOF #Read in a file until EOF is written in text
head * #Prints the head of everything in the directory
2>&1 #Redirects standard error to standard output
command > out 2>eror #Redirects stdout to one file and stderr to another
command >out 2>&1 #Redirects stderr to stdout and then redirect stdout to a file
command &> out
utime="$( TIMEFORMAT=%plR;time ./test a 1000 2>&1 1>/dev/null )" #Timing a program to stdout
command > /dev/null 2>&1 & # Run command in background, with no output
# For fun (6)
sl
apt moo
telnet towel.blinkenlights.nl
traceroute -m 254 -q1 obiwan.scrye.net
aptitude -v moo
# Android with jmtpfs
jmptfs ~/mnt # mount device
fusermount -u ~/mnt #unmount device
# ncmpcpp
u # Reload database
#------------------------------------APPLICATIONS-------------------------------
#--------------Python------------------
{:02d}.format() #Formats a number into two digits
break #Breaks out of a FOR loop (not if)
# Python Virtualenvironments
. venv/bin/activate #Activates the virtual environment
deactivate #Deactivates the current virtual environment
pip freeze > requirements.txt #Saves the virtual environment
pip install -r requirements.txt #install from requirements
# -------------Vim----------------------
# vim Commands
di( #in Vim, di( means delete in ()
dt( #In Vim, dt( means delete to (
"a"ap #The command pastes the register in a as literal text
]s #Navigate around in spellcheck
zg #Add a word to spellfile
:set ff=unix #this command sets converts the CRLF endings to LF endings for .gitconfig files
vim -o[N] Open N windows (default: one for each file)
vim -O[N] Like -o but split vertically
:s/[PAT_1]/\r/g #Replace all of PAT_1 with a newline
:%normal f;D #In every line, go to the first semicolon and delete everything after
@: # Repeat the last command line change
. # Repeat the last action
% # On the command line, this refers to the current file
set columns=120 # set window size for writing
# vim plugins: Git-fugitive
:Gdiff #Starts up the merge window
:diffget //2 #From the merge window, gets the buffer from the target
:diffget //3 #From the merge window, gets the buffer from the merge
:diffupdate #Updates the merge window
:Glog # See the diff of the last commit
# vim plugins: ctags
ctags -R * #Create the ctags file
<C-]> #Jump to tag under cursor
<C-W> <C-]> #Open definition in horizontal split
<C-t> #Go back up the stack
:ts #List all definitions of the last tag
:tags #All tags
# -------------Git----------------------
HEAD #refers to the current node you are in
HEAD^ #goes back one node
Git show #Shows the last commit
Git diff [FILENAME] #tells you the difference between files
git diff [FILENAME] [commit hash] #tells you the difference between files
Types of git resets:
git reset --soft: #The staged snapshot and working directory are not altered in any way.
git reset --mixed: #The staged snapshot is updated to match the specified commit, but the working directory is not affected. This is the default option.
git reset --hard #The staged snapshot and the working directory are both updated to match the specified commit.
git revert #undoes changes by creating a new commit
git reflog #shows all commits, even deleted ones
git rm --cached <filename> #Removes a file from your staging area
git stash #Stashes the current working directory and reverts to HEAD
git stash pop #Retrieves the last stash and pops it.
git merge <branch ahead> <branch to be merged into> #If one br is specified, it merges into the current working branch by default.
git clean -ndfx #Remove all untracked files and directories (remove n to do it for real)
## Git log
-p # Show all files
-3 # Show all files changed, in last 3 commits
--stat # summarize changes
--since # show changes sinec a date
--since 2.weeks # show changes since two weeks ago
--since "5 days ago" # show changes since 5 days ago
-S <string> # show patches only related to function_name
gitk # graphical viewer for git log history
# ----------Virtualbox------------------
sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) share ~/host #How to mount the shared folder
# --------Betterlockscreen--------------
betterlockscreen -u [FILE] #The default setting is enough for me
betterlockscreen -l dimblur #To lock the screen
# ----------------Tmux------------------
<C-a>n #Switch to next pane
<C-a>[0-9] #Switch to numbered pane
<CR>~. # Exit and kill SSH (ssh) session
# ---------------Github----------------
 #Embed images in Github
``` # Code block
# 2 spaces needed after blockquotes
- [x] #This is a complete item
- [ ] #This is an incomplete item
# ---------------Ranger----------------
<F7> #Make new directory
zh #Show hidden files
o #Sort
cw #Rename file
r #Open with
uv # Unmark all files
# -------------C++----------------------
constructor: vector v(SIZE, DEFAULT);
##Regex
+ #One or more matches
[^;, ] #Ignore all of semicolon, comma, whitespace
##ssh
The SSH config file allows you to input several names "Host name" for your files
ssh-agent #A client that allows you to add ssh keys
ssh-add #The interface to add ssh keys
##Makefiles
make by default runs the first rule it finds. So, ideally you want make all to be the first rule (by tradition)
.PHONY declares which rules don't actually make a file, and so the compiler won't check for whether clean is up to date or not, it'll just run the command no matter what
## Ubuntu
layout.css.devPixelsPerPx #1.5 for laptop, 1 for normal
GRUB_DEFAULT=saved;GRUB_SAVEDEFAULT=true #/etc/default/grub changes to make it save last boot (see next line)
sudo update-grub #Updates grub
sudo tlp start #Updates TLP
nmtui #TUI interface for connecting to the internet
nmcli device wifi connect [SSID-NAME] password [WIRELESS-PASSWORD] #CLI to connect to the internet
sudo dpkg -i /path/todebfile; sudo apt install -f; #Install deb file
journalctl -b # Read boot log messages
## Timezone / timedatectl
sudo dpkg-reconfigure tzdata #interactive tool
sudo timedatectl set-timezone <timezone> #CLI tool
sudo timedatectl set-ntp on # set this to off and on to restart NTP
sudo journalctl -f -eu systemd-timesyncd # See timesyncd messages, including timeout
#i3 Hacks (that work but aren't pretty)
sudo echo "export GDK_SCALE=2" >> /etc/default/i3_scale.sh; sudo systemctl restart #For i3, Run this when running out on the laptop. It scales GDK_SCALE by 2, which means apps work better.
$mod+Shift+Space # Toggle floating mode
## Firefox
http://detectportal.firefox.com/success.txt #Login to wifi
## Youtube-dl
youtube-dl https://www.youtube.com/watch?v=0VtmmVQrNcY -o '%(title)s.%(ext)s' -x --audio-format mp3 -i
# -x --audio-format mp3 // extracts the mp3 file out. requires ffmpee
# --postprocessor-args '-threads 3' //Use more threads
# --playlist-start 3 //starts the playlist at 3.
# -i //ignore errors
# -o %%(playlist)s/%%(playlist_index)s - %%(title)s.%%(ext)s // syntax for playlists
# -o %%(title)s.%%(ext)s // syntax for normal files
## pdftk
pdftk microsoft-job-offer-letter.pdf cat 3-11 output job-letter.pdf # Crop pages from a PDF document
pdftk [first_file.pdf] [second_file.pdf] cat output [output.pdf] # Merge any number of files
## Latex
\setlength{\parindent}{0pt} # no indents in paragraph
# Panserver - view markdown in the browser
## this opens a server in the current directory
## Opened it on port 10190 to avoid clashes
python3 ~/panserver/panserver.py > /dev/null 2>&1 &
# Changing DNS
## It is probably most effective to edit it on the router
Manual setup > Change DNS server # D-Link router
nmtui > Edit > TT > IPv4 (Auto) > (add your dns here) && ignore-auto-dns # Linux
Settings > Wifi > TT > Advanced > IP > Static > DNS 1/2 # Android
# DNS servers
8.8.8.8 - Google
1.1.1.1 - Cloudflare
208.67.222.222 - OpenDNS 1
208.67.220.220 - OpenDNS 2
# Querying the DNS server of a website
dig +short [website]
hosts [website]
nslookup [website]
#--------------Windows------------------
# Where to find things
The Windows Path is in C:\Users\Thomas\AppData\Local
##Powershell
Get-ChildItem . | Foreach-Object {
echo $_.Name
echo $_.BaseName //Name without extension
echo $_.Extension //extension only
}
Get-ChildItem . | Foreach-Object {
$bn = $_.BaseName
ffmpeg -i $_.Name -vn -ab 192k "$bn.mp3"
}
mklink /H [Link] [Target] #Symbolic Link - Windows command prompt (NOT POWERSHELL) Note that link is the link itself, target is the place where the actual file lives
#---------------Clojure ----------------------
## Java:
if (b) {
return true;
}
(do-stuff here)
return false;
## Clojure:
(or b (do-stuff here))
## Java:
if (!b1) {
return false;
}
if (!b2) {
return false;
}
(do-stuff here)
return true;
## Clojure:
(and b1 b2
(do
(do-stuff here)
true))