Skip to content

Instantly share code, notes, and snippets.

View YanhaoYang's full-sized avatar

Yanhao Yang YanhaoYang

  • Berlin, Germany
View GitHub Profile
--colour
-I app
@YanhaoYang
YanhaoYang / .gitconfig-for-diffmerge
Last active October 29, 2020 05:18
Using DiffMerge as your Git visual merge and diff tool on Mac
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
trustExitCode = true
@YanhaoYang
YanhaoYang / sym_equal_definition
Created January 9, 2013 08:55
For Symbols, `==` is exactly same as `===`
// string.c in ruby-1.9.3-p125 src
7896 rb_define_method(rb_cSymbol, "==", sym_equal, 1);
7897 rb_define_method(rb_cSymbol, "===", sym_equal, 1);
7395 static VALUE
7396 sym_equal(VALUE sym1, VALUE sym2)
7397 {
7398 if (sym1 == sym2) return Qtrue;
7399 return Qfalse;
@YanhaoYang
YanhaoYang / .inputrc
Created January 15, 2013 14:13
Let ctrl+left to go back one word in iTerm2, and ctrl+right to go forward one word. See http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2
"\e[1;5D": backward-word
"\e[1;5C": forward-word
@YanhaoYang
YanhaoYang / install-postgis.sh
Last active December 15, 2015 10:59
Commands for installing postgis copied from How to compile PostGIS 2.0.1 on Ubuntu Server 12.04 (http://blog.mackerron.com/2012/06/01/postgis-2-ubuntu-12-04/)
sudo /etc/init.d/postgresql stop
# PostGIS 1.5.2 and its dependencies were installed already, so I
# removed them
sudo aptitude remove postgis postgresql-9.1-postgis \
libgdal1-dev libgdal1-1.7.0 gdal-bin python-gdal \
libspatialite2 libspatialite3 libgeos-dev libgeos-c1
# install any missing prerequisites
sudo aptitude install build-essential checkinstall postgresql \
@YanhaoYang
YanhaoYang / Differences between Ruby 1.8 and 1.9.md
Created October 15, 2013 02:43
Differences between Ruby 1.8 and 1.9

Date.parse

1.8.7: parse(str='-4712-01-01', comp=false, sg=ITALY)
1.9.3: parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=ITALY]])

Note: the default values of comp are different.

Enumerator#next

@YanhaoYang
YanhaoYang / shared-memory.txt
Last active December 31, 2015 17:19
Increase shared memory in Linux
# 16 GB shared memory
$ sysctl -w kernel.shmmax=17179869184
# A page is almost always 4096 bytes except in unusual kernel configurations with "huge pages" (use getconf PAGE_SIZE to verify).
$ sysctl -w kernel.shmall=4194304
To preserve the settings between reboots, in /etc/sysctl.conf:
kernel.shmmax=17179869184
kernel.shmall=4194304
@YanhaoYang
YanhaoYang / postgresql-connections.md
Created December 18, 2013 09:36
PostgreSLQ connections
  • Show active connections

    • SELECT * FROM pg_stat_activity;
    • ps aux | grep postgres | wc -l (roughly, when you cannot connect to it)
  • Show @max_connections@

    • In psql: SHOW max_connections; (SHOW ALL;)
  • SQL: SELECT * FROM pg_settings WHERE name = 'max_connections';

@YanhaoYang
YanhaoYang / cron-job-for-low-battery
Created May 10, 2014 14:46
A cron job warning when battery is low
*/2 * * * * if [[ `pmset -g batt | awk -F'[^0-9]*' '{ print $3 }'` -lt 20 ]];then say "Battery low";fi