curl
Timing Details
time_namelookup: %{time_namelookup}n
time_connect: %{time_connect}n
time_appconnect: %{time_appconnect}n
time_pretransfer: %{time_pretransfer}n
time_redirect: %{time_redirect}n
time_starttransfer: %{time_starttransfer}n
----------n
time_total: %{time_total}n
curl -w "@curl-format.txt" -o /dev/null -s http://wordpress.com/
Angular
Directive isolated scope
app.directive('someDirective', function () {
return {
scope: {
oneWay: '@',
twoWay: '=',
expr: '&' // to evaluate in parent scope
}
};
});
npm
Version Ranges
Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4
Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.
History of published versions
npm view package # see time field
Ruby one-liner
Filter JSON objects stream
cat haystack.json | ruby -rjson -pe 'o = JSON.parse($_); next unless o["needle"]'
Systemd
Sample script
# /home/evgeniy/.config/systemd/user/parser.service
[Unit]
Description=Parser
[Service]
WorkingDirectory=/home/evgeniy/parser
ExecStart=/home/evgeniy/parser/bin/parser
[Install]
WantedBy=default.target
Sample timer
# /home/evgeniy/.config/systemd/user/parser.timer
[Unit]
Description=Parser task
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
Enable with
systemctl --user enable parser.timer
Start with
systemctl --user start parser-fetch-anns.timer
R...
Apt
List installed packages
dpkg --get-selections | grep -v deinstall
Which package provides Ruby
dpkg -S /usr/bin/ruby2.2
List all Ruby packages
apt-cache search ruby
Show package details
apt-cache show ruby2.2
apt-cache policy ruby2.2
Ubuntu
Sound Settings
gnome-control-center sound
Startup Applications
gnome-session-properties
Restore stock NVidia drivers
http://askubuntu.com/a/163808
https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/1166765/comments/9
http://www.webupd8.org/2012/10/how-to-reset-compiz-and-unity-in-ubuntu.html
Install binary NVidia drivers
https://askubuntu.com/questions/450046/black-screen-with-nvidia-drivers-on-ubuntu/450546#450546
Git
Diff, exclude noisy path
git diff master production -- !vendor
Rebase
so "--ours" means the anonymous one rebase is building while "--theirs" means "our branch being rebased"
the side reported as ours is the so-far rebased series, starting with
<upstream>
,
and theirs is the working branch.
In other words, the sides are swapped.
is "ours" always the upper of the two versions displayed?
Map Caps Lock to Control
Windows 8
Apply registry fix from http://johnhaller.com/useful-stuff/disable-caps-lock.
Ruby 2.1 CSV
Getting Array
CSV(ARGF, headers: [:col1, :col2], converters: :numeric).to_a.map(&:to_h)
Rails
Log ActiveRecord SQL in production (ala in dev)
ActiveRecord::Base.logger = Logger.new(STDOUT)
Golang
Parse JSON request
dec := json.NewDecoder(req.Body)
var target Target
if err := dec.Decode(&target); err != nil {
return err
}
Slicing
len(a[0:x]) # => x
Godep
Update all third-party packages this package depends on (DOES NOT include test dependencies)
go get github.com/dolzenko/deplist
go list -f '{{.ImportPath}}' ./... | xargs -n 1 deplist | grep -v P | sort -u | xargs go get -u -v
VIM
Copy, cut and paste
v
to select characters (V
to select whole lines).
d
to cut (or y
to copy).
P
to paste before the cursor, or p
to paste after.
Search and replace
:%s/foo/bar/g
.vimrc
set wildmenu
set wildmode=longest:full,full
Moving
C-o
jump to previous location
Buffers
:bn
next buffer
Scroll
^F ^B scroll page up, down
To comment out blocks in vim:
hit ctrl+v (visual block mode)
use the down arrow keys to select the lines you want (it won't highlight everything)
Shift+i (capital I)
insert...
Linux
Shutdown HDD
sudo hdparm -y /dev/sda
Open files
lsof -i -n
Format USB
sudo fdisk -l
sudo umount /dev/sdc4
sudo mkfs.vfat /dev/sdc4
Normalize line endings in projects
find . -type f \! -path \*/\.git/\* -exec dos2unix –quiet {} \;
Ruby 2.1 Exception Hierarchy
BasicObject
Exception
MonitorMixin::ConditionVariable::Timeout
NoMemoryError
ScriptError
LoadError
Gem::LoadError
NotImplementedError
SyntaxError
SecurityError
SignalException
Interrupt
StandardError
ArgumentError
Gem::Requirement::BadRequirementError
EncodingError
Encoding::CompatibilityError
Encoding::ConverterNotFoundError
Encoding::InvalidByteSequenceError
...
Tmux
Prefix +
d - detach
" - split
SPC - next layout
o - next pane
[ - copy mode
M-v - scroll up
C-v - scroll down
q - quit
tmux at - attach
Less
-S or --chop-long-lines
Causes lines longer than the screen width to be chopped (truncated) rather than wrapped. Also works after file is opened (`- S ENTER`)
-n or --line-numbers
Suppresses line numbers.
Key | Action |
---|---|
F | simulate tail -f |
= | file info |
&pattern | Display only lines which match the pattern |
! | Display only lines which do NOT match the pattern |
/pattern | Search forward for (N-th) matching line |
?pattern | Search backward for ... |
Aliasing et. al.
Shell: ln -s EXISTING NEW
Ruby: alias NEW EXISTING
Git: git branch NEW EXISTING
Ruby Benchmarking
require 'benchmark'
Benchmark.measure { }
=> [user, system, user+system, wall]