- if previously intstalled:
-pacman -U /var/cache/pacman/pkg/old-pkg-version
- if not previously installed:
- pacman -U https://archive.archlinux.org/packages/{some_letter}/some_pkg_name.tar.gz
- to temporarily ignore updates to a pkg that has been downgraded, add pkg to IgnorePkg section of /etc/pacman.conf
- if can't update b/c of pacman, run:
- pacman-key --refresh-keys
- pactree
for refs: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=837637 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=837637
To find the duration of all audio files in a directory,use this command:
soxi -D /path/to/files/* | awk 'a+=$1; END{print a}'
Was having issues getting sound to play on Debian10 (buster)
Fixed with 'sudo alsactl init'
help screen showed that alsactl init returns driver to a default state
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-2.html
important: need to install mod24_ssl, not mod_ssl
[ec2-user ~]$ cd /etc/pki/tls/certs sudo ./make-dummy-cert localhost.crt
in /etc/httpd/conf.d/ssl.conf, comment out SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
restart httpd sudo /etc/init.d/httpd restart
https://stackoverflow.com/questions/8686125/update-wordpress-theme-on-ec2 sudo chown -R apache:ec2-user path/to/wordpress or sudo chown -R apache:apache path/to/wordpress
aws logs commands:
breakdown:
commands:
get-log-events --{log group name} -{log stream name}
aws lambda invoke --invocation-type RequestResponse --function-name {fn_name} --region ca-central-1 --cli-binary-format raw-in-base64-out --payload fileb:///code/{fn_name}/payload.json response.json
NOTE: running through a docker container will fail silently on AWS side; hash returned is just the docker id
need to use use the aws cli to run 's3api delete-bucket-policy --bucket {bucket name}'
need to use access keys of root account
adapting example below, command will be:
docker run --rm -v $HOME/.aws:/root/.aws amazon/aws-cli s3api delete-bucket-policy --bucket {bucket name}
the xml syntax appears to be deprecated? Though I didn't see this mentioned anywhere.
using the cli put-bucket-cors command solved the issue
sudo docker run --rm -tiv $HOME/.aws:/root/.aws amazon/aws-cli s3api put-bucket-cors --bucket {bucket name} --cors-configuration file:///root/.aws/{config file name}.json
-specify date as month/day (e.g., 1/1 for jan 1)
- pkill compton && compton --config ~/.config/compton.conf -bc
- :update-cache
- can use -f flag if not co-operating
- ^C
django-admin startproject {proj name}
python manage.py startapp {app name}
python manage.py runserver
#thanks to https://github.com/mikesir87/aws-cli-docker
run container with those files
docker run --rm -v $HOME/.aws:/root/.aws amazon/aws-cli describe instances
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
- ^P ^Q
- docker prune (prune -a; for more deletion)
- WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
-
- or (according to my understanding of
http://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/),
a dangling image is an intermediate image that is no longer the parent
of any child image. e.g., if you build hello-world image with fedora,
and then later the fedora image gets updated, the intermediate OLD
fedora layer for the hello world image no longer points to any
child/final image. I think...
- sudo docker rmi $(sudo docker images -a --filter=dangling=true -q)
- where dangling = you've created a new build of an image, but it wasn't named
- see: https://stackoverflow.com/questions/45142528/docker-what-is-a-dangling-image-and-what-is-an-unused-image)
- is this deprecated by --remove-orphans?
- note: docker docs refer to these as both orphans and dangling
- https://forums.docker.com/t/how-do-i-remove-orphaned-images/1172
docker run -i -t {image name} /bin/bash
// i - interactive
// t - allocate a psuedo tty (from docker docs, not sure whta this means)
create - creates a container but does not start it
rename - allows the container to be renamed
run - creates and starts a container in one operation
rm - deletes a container
- shortcut to remove al docker containers:
- sudo docker rm $(sudo docker ps -a -q)
update - updates a container's resource limits
start - starts a container so it is running
stop - stops a running container
restart - stops and starts a container
pause - pauses a running container, "freezing" it in place
unpause - will unpause a running container
wait - blocks until running container stops
kill - sends a SIGKILL to a running container
attach - will connect to a running container
ps - shows running containers
logs - gets logs from container
inspect - looks at all the info on a container
events - gets events from container
port - shows public facing port of container
top - shows running processes in container
stats - shows containers' resource usage statistics
diff - shows changed files in the container's FS
images - shows all images
import - creates an image from a tarball
build - creates image from Dockerfile
-t - tag iamge
-f - specify dockerfile
- e.g., docker build -t ThisWillBeTheImageTag -f abnormDockerFileName .
commit - creates image from a container
rmi - removes an image.
load - loads an image from a tar archive
save - saves an image to a tar archive
history - shows history of an image
tag - tags an image to a name (local or registry)
- can use lightspark, available as standalone and broswer extensoin
* --noreplace stops re-installing of default packages
* --jobs=X to run parallel installs
* for full system/world update:
* sudo emerge --update --changed-use --deep --ask --with-bdeps=y @world
java -jar ~/source_packages/bfg-1.13.1.jar --strip-blobs-bigger-than 40M repo_name.git
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch unwanted_file_or_dir' --prune-empty
git show branch:filepath/filename
- e.g., git show master:README.md
- git pull --rebase <remote name> <branch name>
- git branch -m <oldname> <newname>
- can choose local or remote with:
- git checkout --theirs path/to/file.png, for remote
- or --ours, for local
- first, make needed changes, stage them with "git add file2" then run
- git commit --amend
- git reset
- git merge --abort
- git config diff.tool vimdiff
- also: Gdiffsplit (from fugitive)
- once split, :diffget and :diffput make editing a diff really easy
git grep {regex to search} $(git rev-list --all)
- echo RELOADAGENT | gpg-connect-agent
(mod+d to bring up dmenu) - i3-msg move container to workspace number 1 firefox
(mod+d to bring up dmenu) - i3-msg workspace number 1 firefox
- :Prettier
- %load_ext autoreload
- %autoreload 2
- the first command 'loads extension' autoreload, which is disabled by default
- '2' means reload everything; 0 means nothing; 1 is only for modules loaded via %aimport
- see: https://switowski.com/blog/ipython-autoreload
- jupyter labextension install @axlair/jupyterlab_vim
- using this specific repo/version because the newest (2020-09-30) version
of jupyterlab doesn't support newest version of the extension
- see: https://github.com/jwkvam/jupyterlab-vim/issues/118
pip install ipympl pip install nodejs jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter labextension install jupyter-matplotlib
to mount host dir and share files with guest
mount shared dir in guest:
sudo mount -t 9p -o trans=virtio,version=9p2000.L /hostshare /tmp/hostshare
cancel a compilation:
sudo dpkg -i filename.deb
xdotool key Caps_Lock
record webcam embedded in screen:
eliminate static from mic when recording:
- ctrl+atl+{f1-f7}
- OR alt+left or alt+right
- this latter works to get back to a running xorg session
if running 'sudo dpkg -i {filename}.deb' and hitting a missing dependency error, do the following to use 'fix-missing' functionality:
sudo apt-get update -f
long-form (apt-get update --fix-broken)
lxappearance is an easy gui tool
file -i {filename}
xdg-settings set default-web-browser firefox-esr.desktop
xdg-mime --help
to set default file manager:
NOTE: firefox cannot launch an external application like thunar/nautilus if it's running under firejail
\% for dates and such
start daemon on openRC
http interface
if not detecting usb printer, could be permissions/ownership issue (see https://wiki.gentoo.org/wiki/Printing#Configuration)
problem with printing pdfs with forms in evince (apparently in okular too)
- backup to a compressed image file:
- sudo dd if=/dev/sda conv=sync,noerror status=progress, bs=64k | gzip -c > /PATH/TO/DRIVE/backup_image.img.gz
- restore from image file:
- gunzip -c /PATH/TO/DRIVE/backup_image.img.gz | dd of=/dev/sda
- create it:
- nav to location where backup will store, eg /mnt/ultrabay_hdd,
(so as not to cause tar failure/warning)
- tar -cz /home/km | gpg -c -o home_dir_backup_DATE.tgz.gpg
- restore it:
- gpg -d home_dir_backup_DATE.tgz.gpg | tar -xz
column -s, -t < {filename}
- faillog -r -u <user>
- /var/log is main dir
- /var/log/syslog is main file
- use grc, the generic colouriser, to colourise log files, e.g.:
- sudo grc less /var/log/syslog
- imagemagick / ImageMagick
- provides the 'import' function:
- `import test.jpg` - click for window, drag for selection
- `import -window root screenshot.png` - full desktop, multiple monitors
- lsb_release -a
- cat /etc/issue.logo
- tips/portage output with the following appearance are often kernel options:
- CONFIG_SNG_HDA_PREALLOC_SIZE=64
- openssl rand -base64 14
- if terminal goes bananas, with a bunch of crazy characters, can use the
'reset' command to clear screen and reload. Sometimes helps on headless
machines.
- Ctrl-Q
- great information at https://nlug.ml1.co.uk/2013/02/gentoo-kernel-3-7-9-webcams-v4l-uvc-video-kernel-config/3965
- modules needed (for logitech c270, uvc-based cam):
- CONFIG_MEDIA_SUPPORT
- CONFIG_MEDIA_CAMERA_SUPPORT
- CONFIG_MEDIA_USB_SUPPORT
- CONFIG_USB_VIDEO_CLASS
- restart service
- disconnect from connection
- # systecmtl stop networking
- # rmmod brcmfmac
- # modprobe brcmfmac
- # systemctl start networking.service
- check dmesg logs for messages
- remove/re-add kernel module - # rmmod brcmfmac & # modprobe brcmfmac
- usermod -aG sudo km
$ id3convert -s {filename}
tag with 'T'
l to filter (i.e., set tag pattern)
';' performs action on all tagged messages
W clears flag (w sets)
enter flag to clear (here, O)
example: inbox full of read messages, just want to archive: commands: T ~O ; W O
taken from
https://brianbuccola.com/how-to-mark-all-emails-as-read-in-mutt/
ctrl-g
y
$
T
l
;
W (uppercase clears flags)
w (lowercase is to add flag)
Esc-e
D
s (for save)
? to choose mailbox
Ctrl-t (function is redraw-screen in index)
shutdown db service, start in safe mode, connect as root, change pw, restart $ sudo systemctl stop mariadb $ sudo mysqld_safe --skip-grant-tables --skip-networking & $ mysql -u root
mysql> use mysql; mysql> UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost'; mysql> flush privileges; mysql> quit
(alternate syntax for update command) mysql> update user set authentication_string=password('NEWPASSWORD') where user='root';
- /usr/bin/mysqladmin -u root -p shutdown
- mysqladmin binary may be elsewhere
- can always use 'kill -9'
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
- nvm install node
- nvm ls
- npm install -g pkg_name
- npm uninstall -g pkg_name
- npm search pkg_name
- npm ls (must be in dir where pkg installed)
- npm ls -g (list global packages)
- npm ls -gl (list global packages detail)
- npm update
- npm update -g (update global pkgs)
- npm run pkg_name
- pdfunite in the poppler library combines pdfs
- e.g., pdfunite input1.pdf input2.pdf inputn.pdf output.pdf
- cpdf (for coherent pdf)
- pdfshuffler
- create a pdf from html pages
- .e.g, wkhtmltopdf input.html output.pdf
- may need to use a particular header line to render some utf8 chars
- include this in the head section of the html:
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- and on command line, may need to specify: --encoding='utf-8'
- check syntax on that argument
- pdf studio and masterpdf
- sudo /etc/init.d/postgresql-10 start
- psql
- \quit
- pg_ctl -D /var/lib/postgres/data -l ~/logfile {start/stop}
- if server won't start, may need to run:
- sudo chown postgres: /run/postgresql
- createuser --interactive
- createdb myDatabaseName
- \password {username}
python3 -m http.server 1337
$ sudo apt update $ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
tar -xf Python-3.8.2.tar.xz cd Python-3.8.2 ./configure --enable-optimizations make -j 4 sudo make altinstall python3.8 --version
- python 3.6+
- python3 -m venv {env name}
- python 2.7
- virtualenv --python=/usr/bin/{version} {env name}
- after installing bpython in venv, needed to deactivate/reactivate the
venv for it to see pip3 installed pkgs within bpython... I dunno
- create, activate venv
- install kernel: ipython kernel install --user --name={venv name}
- select kernel in notebook/lab
- rails db:migrate:redo
1. rake db:reset (loads from schema.rb)
2. rake db:drop db:create db:migrate db:seed (loads from migrations)
1. clear cache - Rails.cache.clear
2. make sprocket concatenate css&js:
- in config/environments/development:
- config.assets.debug = false
3. precompile assets
- RAILS_ENV=development rails assets:precompile
- not sure what the diff between 2 and 3 is
- :Extract partial_name
- ctrl-l
- useful for pdf previews overlapping/cluttering
### - proc - reusable block
- e.g.,
```ruby
def run_two_procs(a, b)
a.call
b.call
end
proc1 = Proc.new do
puts "Hello from proc1"
end
proc2 = Proc.new { p "Hello from Proc2"}
end
run_two_procs proc1, proc2 #=> "Hello from proc1", \n "Hello from proc2"
# alternate ampersand syntax
x = [2,4,6]
double = Proc.new { |n| n*2}
dubbed = x.map(&double) #=> [4,8,12]
```
- remove nils from array
- example:
```ruby
[ "a", nil, "b", nil, "c", nil ].compact #=> [ "a", "b", "c" ]
```
- drop first n elements from array
- example:
```ruby
- a = [1, 2, 3, 4, 5, 0]
- a.drop(3) #=> [4, 5, 0]
```
- drop elements up to, but not including, the first element for which the
block retuns nil or false; then return array containing the remaining
elements
- example:
```ruby
-- a = [1, 2, 3, 4, 5, 0]
=> a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0]
```
- invoke block once for each element of self
- example:
```ruby
- ['a', 'b', 'c'].collect{|letter| letter.capitalize} #=> ["A", "B", "C"]
```
- or more compactly/elegantly:
```ruby
- ['a', 'b', 'c'].collect(&:capitalize) #=> ["A", "B", "C"]
```
- Invoke the block passing in successive elements from self, returning an
array containing those elements for which the block returns a true value
- example:
```ruby
- a = %w{ a b c d e f }
- a.select {|v| v =~ /[aeiou]/} #=> ["a", "e"]
```
- Returns a copy of str with the characters in from_str replaced by the corresponding characters in to_str.
- example:
```ruby
"hello".tr('el', 'ip') #=> "hippo"
def rot13(secret_messages)
secret_messages.map { |c| c.tr("a-z", "n-za-m") }
end
- What it does: Return a copy of a string with some characters replaced. The
method name, tr, is short for Translate, and similar to the tr utility in
Unix-like operating systems. In example 1, "e" is replaced by "i" (the value in the corresponding index of the second argument), and "l" is replaced by "p". Example 1:
```bash
"hello".tr('el', 'ip') #=> "hippo"
```
Example 2 is a bit more complex: here we use the tr method to implement a [ROT13
cipher](https://en.wikipedia.org/wiki/ROT13), which, for the uninitiated, is
a common cipher used to encrypt/scramble text. (protip: you can ROT13 encipher
text within vim by using the g? command. Try g?ap to scramble a paragraph).
Example 2:
```ruby
def rot13(secret_messages)
secret_messages.map { |c| c.tr("a-z", "n-za-m") }
end
```
- enum for range from start "upto" argument
- example
```ruby
4.upto(8) { |n| p n } #=>4, 5, 6, 7,8
```
##### blog post for [upto] method
What it does: Generate an Enum for a range, from start value (i.e., the object
*upto* is being called on), to end value. Example:
```ruby
4.upto(8) { |n| p n } #=> 4, 5, 6, 7,8
```
- TODO
#### block_given?
- useful to check whether block was passed to yield
- gem query --local
- ri {class/method/etc name}
- ri -i #=> interactive mode
rvm list (or ls) - show installed and selected
rvm install {version} - install new ruby
rvm gemset create {name} - create new gemset
rvm gemset delete {name} - delete gemset
rvm gemset list - list all gemsets
rvm use 2.5.0@{name} - use gemset
rvm 2.5.0 --default - set deafult ruby
specify ruby version and gemset whenever cd'ing into dir
- use rvm helper:
- rvm --ruby-version use 2.5.0@dotbox
- creates 2 files: .ruby-version and a .ruby-gemset
my fix - move or delete Gemfile.lock
in command, e.g., echo ${PWD##*/}
esc + . (zsh in viins)
alt + . (emacs binding)
~.
echo $(some command)
e.g., mysqldump __ __ __ $(date +"%F)
for i in {0..255} ; do printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i" if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then printf "\n"; fi done
whatis {command}
man -a {command}
will show all available man pages
-C [n] switch
e.g., grep -C 2 cool_phrase cool_file
^S / ^Q
xdg-open {link address} can be combined, e.g.: cat file | tail -n 1 | xargs xdg-open
^Z - suspend process
bg - continue running process in background
fg - foreground process
jobs - list all jobs
reptyr - utility to reparent a process 2 different methods to use:
- echo $0
su -
note that "su" or "su root", then trying 'usermod -aG sudo {username}' will fail, b/c $PATH is no longer defined, and shell can't find usermod command
su - {uname}
note the dash
column -t
fc = fix command:
e.g., fc 10 20 - this will allow you to edit and then run those 11 commands
xrandr --output LVDS1 --brightness 0.3
note: doesn't reduce battery usage; mainly useful for external monitor
- mv .zsh_history .zsh_history_bad
- strings .zsh_history_bad > .zsh_history
- fc -R .zsh_history
- fc -R = read history from file
- unset {VAR NAME}
- if trying to recursively put directory(ies), the dirs must already exist
on target
- good to know for sftp management of web hosts
- select * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'{table name here';
- -t
tmux set-option -ga terminal-overrides ",xterm-256color:Tc"
detach then reattach
leader-z (for zoom)
after closing windows, ending up with gaps, can use:
can specify individual windows, too
, - rename-window $ - rename-session d - detach from session & - kill window ! - break pane into its own window V - horizontal stack / vert split S - vertical stack /horizontal split q - show pane numbers space - next layout UDLR - move to pane, up/down/left/right
set -g window-style 'fg=black,bg=green'
set -g window-style default
prefix V / S
v for vert stack (i.e., horizont split) (prefix+S)
prefix-[ = enter movement/copy mode Space = start copy mode Enter = copy selection prefix-] = paste
prefix-t
show-options
g - show global settings
:resize-pane -[D,U,L,R] number_of_cells
e.g., resize-pane -D 10
note that M(eta) key is alt, by def(ault)
prefix M-1 = vertical split, all panes same width |-------|-------|-------| | | | | | 0 | 1 | 2 | | | | | |-------|-------|-------|
prefix M-2 = horizontal split, all panes same height |-----------------------| | 0 | |-----------------------| | 1 | |-----------------------| | 2 | |-----------------------|
prefix M-3 = horizontal split, main pane on top |-----------------------| | 0 | |-----------------------| | 1 | 2 | 3 | |-----------------------|
prefix M-4 = vertical split, main pane left |-------|-------| | | 1 | | 0 |-------| | | 2 | |-------|-------|
prefix M-5 = tile, new panes on bottom, same height before same width |-------|-------| | 0 | 1 | |-------|-------| | 2 | 3 | |-------|-------|
- truffle migrate --reset
- will reset a running blockchain
- migrate will run compile first (saving a step)
- after running this, may need to restart console session
etc
ensure :echo has('clipboard') returns 1
use "+yG (for example) to yank into + register
can paste normally from there
- save: mksession ~/session.vim
- reload: ~/session.vim
- open vim with session - vim -S ~/mysession.vim
- :ret aka :retab
-
- technically this is a shell / tty problem. Ctrl-S stops output, ^Q
restores it
- git config diff.tool vimdiff
- ^W }
- this will pop up the definition in a small-ish split
- g?
- ^n / ^ p
- like ^x- ^n/^p but faster if only grabbing from current buffer
- -8,-4co.
- :%bd|e#
- In file explorer (:Explore or :Sex or :Vex), D / R
- %
- d
- set textwidth=0 wrapmargin=0
- bufdo
- example: run a replace on all open buffers, and save files
bufdo %s/old/new/ge | update
- e, no error raised if pattern not found,
- update - save if file was changed
- put =range((11,15))
- could also pipe to seq, e.g., :r! seq 10
- 0
- ^
- Ctrl-a / Ctrl-x
- works anywhere on line (sometimes?)
- :version
- can use vim-nox (at least on debian)
- :scriptnames
- redir >buffername
- :command
- redir END
- e buffername
PlugInstall
:PlugClean
gx
f5 from ctrl-p mode
to align, use : in desired spot in header. e.g.,
| header left | header center | header right |
|-------------+:-------------------------:+-------------:|
| col left | col center very long text | col_right |
| left | center | right |
ctrl-f - from command mode q:, q/, q? - from normal mode
make commit = cc in Gstatus window
C-^
C-o - to enter single normal mode command
use pipe |
// !v execute("command in here | second command")
note backticks, parens, quotes and optional pipe
execute seems needed to run arbitrary commands, but maybe not
useful when ^M or other non LF eol chars show up in files
:w
open file with "vim -b filename"
:set noeol
save
or add to vimrc - :set nofixendofline
vim -o file1.ext file2.ext
use O (capital O) for vertical splits
Ctrl-w f
vim -u {filename}
vim -u NONE #don't load vimrc or plugins
vim -u NORC #load plugins but not vimrc
- vi your_filename
- esc
- :%!xxd - to view the hex strings
- then :%!xxd -r to return to normal editing.
- open new tab in background:
- modify plain json in settings, for "F", to include:
- "background": true
- install webp package
- dwebp file.webp -o file.png
uploading will initially fail, show an error message "Link you requested is no longer valid"
hide header
#main-header { display: none; }
#page-container { padding-top: 0px !important; margin-top: -1px !important; }
total time to restore from a backup - 20 mins (!!)
spin up instance (takes a few minutes to launch)
attach elastic IP to VM/instance
point DNS to elasticIP
ssh into bitnami instance, generate cert
install plugin UpdraftPlus
- xprop - get window manager class name
download from non-free debian archive, install with 'dpkg -i {fname}'