Login  

How To

Initialize source code files
cd /src
git init
.
Create a git repo
cd /git/app
git init --bare
.
Link the source with repo
cd /src
git remote add origin /git/app
.
Save to repo
cd /src
git add .
git commit -m "First Commit"
git push origin master
.
Serve a file over quick HTTP
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
.
Save CD for quick jump
function ccb ()
{
FOO=`pwd`;
echo >> ~/shortcuts.sh;
echo alias $1=\'pushd $FOO\' >> ~/shortcuts.sh;
echo >> ~/shortcuts.sh;
. ~/shortcuts.sh
}
.
Dashboard
To disable, run on terminal
defaults write com.apple.dashboard mcx-disabled -boolean YES
To enable
defaults write com.apple.dashboard mcx-disabled -boolean NO
To close the Dashboard after disabling
killall Dock
.
Clipboard
Paste to terminal
pbpaste

Copy from terminal
pbcopy

Turn RichText to PlainText
pbpaste | pbcopy
.
Spotlight Search
Disable
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Enable
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
.
Run the last command with sudo
sudo !!
.
SQL Join Types
natural inner: minimum rows [join by where]
left outer: equal [the type I use]
full outer: maximum [full join]
.
Usage
Start
gdb [executable without parameter]

Run
run [parameter list]

Re-run after re-compile
r

Exit
quit
.
Stack trace
Call stack
where

Show source around
list [line number]

Select to stack function
frame [frame number from 'where' command]
.
Break points
Break here
break

Break on line
break [line_number]

Delete this breakpoint
clear

Delete all breakporints
delete
.
Regular expression
sed -n 's/^\([a-z]*\)$/\1/p'
Note: plus + in regexp doesn't work, but star * does.
.
Bare
sed -n 's///p'
.
Regular expression
\(.*\)  --> \1
[a-z]\+
.
Persistent connection.
Add to ~/.ssh/config
Host habibur.com
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist yes
.
Password less login
On client
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub habibur.com

To revoke
vi ~/.ssh/authorized_keys
and delete the entry


On Mac/OSX
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
.
Execute a program as root
chown root filename
chmod 4555 filename
.
List all branches
git branch
.
Not greedy
sed -n 's/<.*>/\1/p'
.
Grep
sed -n '/search/p'
.
Largest tables
select table_name,data_length from information_schema.tables where table_schema = "my_database_name" order by 2;
.

Execution time: 0.03 render + 0.00 s transfer.