notes

bash work notes by month

1
2
3
notes() {
subl ~/work/notes/$(date +%B)
}

documentation tools

ascii flow charting
obviously draw.io
jazzy ios

vi

w - jump by start of words (punctuation considered words)
W - jump by words (spaces separate words)
e - jump to end of words (punctuation considered words)
E - jump to end of words (no punctuation)

global find and replace
:%s/foo/bar/g

Linux

Grep

File pattern searcher
grep -E === egrep
grep -F === fgrep

basic usage
grep [options] [pattern] [file]

common options
-B lines before context
-A lines after after context
-C lines around context (-A num and -B num)
-e regex pattern

egrep is regex-ish grep
fgrep interprets pattern a a set of fixed strings separated by new lines
e.g. grep -F -f user_list.txt /etc/group

src

Find

find [directory] -name Filename -type f
find [directory] -name ".txt"
find . -name Notes -type d
find ./Documents ./Downloads -name 30.csv

1
2
3
4
5
6
7
8
9
+---------+ +-----+ +----+
|notes.txt|+----->|inode|+---->|data|
+---------+ +-----+ +----+
^
|
+
+-----------+
|symlink.txt|
+-----------+

Hardlink points to inode
Symlink points to hardlink

Sockets and ports

Ports are like the…port
Socket is like the dock number
One socket is used to listen for incoming connections. When something comes through, a new socket is created to handle the new request, mapped to the same port. The original socket waits for more requests.

host name

/etc/hostname
/etc/hosts

mv multi

mv -t DESTINATION file1 file2

messaging

w or who to display logged in users

broadcast to everyone

wall [message] to broadcast the message
might use -n to omit senders info

broadcast to terminal

echo “Lunch” > /dev/pts/1

open running chat

write [username] [TTY] e.g. write dev pts/0

src src

sed

pm2 logs 0 | sed -n '/key/p'
src

multi-key
sed -EN '/key1|key2/p'

sed -n -e '/pattern1/p' for linux?

reload term

source .bashrc
(run)

bash

sleep 5
!! - entire previous command
!$ - last
!^ - first
!:3 third
!* all

date +"%B" to get date

psql size

SELECT pg_size_pretty(pg_database_size(‘torque-converter’)) As fulldbsize;

general tools

tldr

‘Simplified and community-driven man pages’
npm install -g tldr

exa

‘exa is a modern replacement for ls.’
brew install exa

spectacle

window management
https://www.spectacleapp.com

pullit

‘Display and pull branches from GitHub pull requests.’
npm install -g pullit

init github api in index.js with an api token to use with private repos

1
2
3
4
this.github.authenticate({
type: 'token',
token: 'TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN'
})

markdown here

https://markdown-here.com/

octotree

https://github.com/buunguyen/octotree

nimbus products

https://nimbusweb.me/

art pip

art-pip

notes

kill mongo stuffs

db.currentOp()
db.currentOp( { "$ownOps": true } ) - only your own ops?
db.killOp([the_opid])

curl time

-w %{time_connect}:%{time_starttransfer}:%{time_total}
-w '\ntime_connect: %{time_connect} time_starttransfer: %{time_starttransfer} time_total: %{time_total} size_download: %{size_download}\n'

curl follow 302

curl -b cookies.txt with -L or --location-trusted
This will retain the cookies from the redirect and send them back on the GET

nodemon --exec for compiling and/or linting

nodemon --exec 'javac SomeClass.java && java SomeClass' ./SomeClass

jq

jq '.data.key.term.otherKey'
https://github.com/stedolan/jq/

create mongo time stamp from 1hr ago in bash

printf 'ObjectId("%x0000000000000000")\n' $(date -v-60M -u +%s)

bash time stamp

SECONDS=0
do some work
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."

node memory testing

kill -s SIGUSR1 node_pid

https://codefresh.io/blog/debug_node_in_docker/

git

looking at tags

git describe --tags

set the author

git commit --author="John Doe <john@doe.com>" -m "<the usual commit message>"
src

cleaning up branches

git branch -d [name] - to delete
git branch --merged - to see whats been merged

1
2
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do echo $branch; done # to see what will be deleted
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -d $branch; done # to delete

git diff

filter new files:
git diff origin/base origin/head --diff-filter=M

find and replace

osx:
find . -type f -name '*.csv' -exec sed -i '' "s/find/replace/g" {} \;
linux:
find . -type f -name '*.csv' -exec sed -i "s/{find}/{replace}/g" {} \;

push pop dirs

pushd
popd
dirs -l #list

look at docker logs command

docker logs

notes

more notes from the past few months:

shell notes

use cmd+i to set the ‘badge’ to something useful

exit all ssh sessions

~.

src

vi

vi find

/string Search forward for string
?string Search back for string
n Search for next instance of string
N Search for previous instance of string

vi delete all lines

:1,$d
src

vi line moving

Therefore, dd p / dd k P are common commands to move a line one down / up.

src

yy to yank
p to paste after
P to paste before
u to undo

comment out in vim

ctrl+v to enter visual block
x to delete selection
shift+I to enter edit mode on multiple lines

src

misc

:w [filename]

curl proxy

-x, –proxy [protocol://][user:password@]proxyhost[:port]

find (and kill) that process

ps -A | less
ps -A | grep firefox
ps -feww | grep firefox

kill 31098
kill -15 (SIGTERM) 31098

webstorm

minimap
CodeGlance plug in

scratch page
shift + command + n

search everywhere
shift + shift + shift

aut0-format
⌥+⌘+L
option + command + L

cd back

cd -

protobuf

If you are running into an error with node-gyp regarding protobuf when running npm install:
brew install protobuf
brew install pkg-config

send output to file and console

tee it up!

color output

console.log('\x1b[36m%s\x1b[0m', 'I am cyan');
https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color

mongo

db.collection.find().limit(1).sort({$natural:-1})
.pretty() on json payloads to make them…pretty.
.explain('executionStats')
{$regex : ".*/route$"}

case insensitive

db.stuff.find( { foo: /^bar$/i } )
https://stackoverflow.com/questions/1863399/mongodb-is-it-possible-to-make-a-case-insensitive-query

kill mongo stuffs

db.currentOp()
db.currentOp( { "$ownOps": true } ) - only your own ops?
db.killOp([the_opid])
db.currentOp().inprog.length

and or

$and: [{expression 1}, {expression 2}]
$or: [{expression 1}, {expression 2}]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
db.collection.find({
"_id": {
$gt: ObjectId("5a3ad38c0000000000000000")
},
"name": "Joe",
$and: [
{"items": {
"$elemMatch": {
"fName": /Case/i
}
}},
{"items": {
"$elemMatch": {
"lname": /Jojo/i
}
}}
]
}).sort({$natural:-1})

Max query time:
.maxTimeMS()

remove env vars

unset <var>

grep

multiples
grep -e foo -e bar *.txt

extra spaces
-A after
-B before
-C both

srchttps://unix.stackexchange.com/questions/37313/how-do-i-grep-for-multiple-patterns)

pm2

watch

–watch [paths]
–ignore-watch
note: need to figure out how to correctly pass in ignored files

using config file is easier

node args

“node_args”: “–prof”

iterm

jump words

https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-backwards-words-in-iterm-2-on-os-x

config open location

https://apple.stackexchange.com/questions/148508/how-to-open-a-new-tab-in-iterm-in-the-same-folder-as-the-one-that-is-open

command overlord

command + shift + i = send command to all terminal windows

finding where something is aliased

which ls
ls: aliased to ls -G

grep -r 'ls -G' ~
src (2nd answer down)

to override
command ls

ping to get ip of url

windows ssh

eval ssh-agent -s
ssh-add -l
ssh-add .ssh/your_id #not the pub one

notes

notes from the past few months:

Terminal Copy

copy and paste pwd form command line:
pwd | pbcopy –> to copy current directory to clipboard
then cd $(pbpaste) –> to cd in different terminal

Copying when sshed in

commandThatMakesOutput | ssh (host name) pbcopy
need local ssh server though…

src

scroll up in terminal:

shit + fn up-key (page up)

webstorm

command 1 = project view
command 2 = favorites
command 3 = search thingy
esc = return to editor

Mongo - ‘the mongo shell speaks js’

decodeURIComponent(query that returns stringified stuff)

npm test

exit status 0 is added to the end of npm test calls

Use ; exit 0 to replicate this for other npm scripts.

source of info and link to code source

grep files with regex

grep -c -F /\**
grep ^\ *function

grep options
-c count
-F fixed string

control-R to search command history!!

Broken Git Fetch?

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

Running in background

node server.js > std.txt 2> err.txt &

src

Time stamp in name

$(date +%s)

What does /etc stand for?

http://www.aboutlinux.info/2007/03/what-does-etc-stands-for-in-linuxunix.html

JSON Funzies

json_pp
jq - jq 'if ._links.html then ._links.html.href else .errors[0].message end'

Shhh curl, shhh

-s flag prevents process display

src

PM2

delete - start with a set environment variables
pm2 delete 0
pm2 start app.json --only num2

clean logs
pm2 logs [--raw] 0

SSH

ssh-copy-id [username]@[addresss]

src

NPM

npm i -S -> save as dep - this is now the default behavior in npm@5
npm i -D -> save as dev dep
npm repo -> go to repo
npm run -> what can i run?

npm version [<newversion> | major | minor | patch ]

npm ls -g --depth=0 npm uninstall -g
list and uninstall globals

npm update -g
update globals - not sure if this is recommended

npm rb
rebuild after changing node version

src

git reset

git reset HEAD~

src

good ref for other things:
http://ohshitgit.com

vi

set number
:44
syntax off
x - to delete char under cursor

pasting
:set paste then i then :set nopaste
src

docker port publishing

docker run -d -p 127.0.0.1:80:8080 ubuntu bash

This binds port 8080 of the container to port 80 on 127.0.0.1 of the host machine.
A.k.a -p [host]:[container]. host:container, host:container got it.

notes

starting and stopping mongo

If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:
brew services list
To start mongodb:
brew services start mongodb
To stop mongodb if it’s already running:
brew services stop mongodb

src

yaml

Basically JSON

http://www.yaml.org/start.html

ESP8266

“It is sold as a wifi to serial module.”

nano

delete line:
control+c+k
control- will give you a line prompt
nano +[line #] filename to open at line

pi check disk space

df -Bg

hexo

hexo new [title]

hexo generate

hexo server

hexo deploy #sends /public to github

removing dups in history

add
HISTCONTROL=erasedups
in bash_profile/zshrc/etc

hello-blog

Well hello there. Nice to see you. Welcome to my alternative to bookmarks. This blog is also supported by the idea that if you have a question, so do ten of your classmates.

Inspired by http://kbeckmann.github.io/ who added the ws2801 module to nodemcu.