Skip to content

Instantly share code, notes, and snippets.

View penghou620's full-sized avatar

Peng Hou penghou620

  • LoadSmart Inc.
  • New York
View GitHub Profile
@penghou620
penghou620 / ToDo
Last active August 29, 2015 14:15
ToDo
- [ ] Release
- [ ] driver email [#128](https://github.com/loadsmart/server/issues/218)
@penghou620
penghou620 / AWK Snippet
Created February 24, 2015 15:22
AWK Snippet
awk -F\t 'NR!=1 {printf "%s\t%s\t%s\t%s\n", $1,$2,$3,$16}' OFS="\t" 1.txt | node piping.js &> /tmp/r1.txt
machine:
node:
version: 0.10.35
dependencies:
pre:
- sudo apt-get install -y libpoppler-glib-dev libpoppler-glib8 libcairo2-dev libcairo2
- sudo apt-get install -y libpq-dev
database:
override:
- psql -c 'create database test;' -U postgres
@penghou620
penghou620 / close_db_connections
Created August 3, 2015 19:47
[Postgres] Close database connections
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND pid <> pg_backend_pid();
@penghou620
penghou620 / tmux-kill-sessions.sh
Created January 6, 2016 18:21
Tmux kill un-attached sessions
tmux ls | grep --invert-match 'attached' | awk '{print $1}' | grep -oh '[0-9]\{1,\}' | xargs -n 1 -I {} tmux kill-session -t {}
@penghou620
penghou620 / ssh-config-github-multiple-deploy-keys
Created January 21, 2016 14:48
Using multiple github deploy keys from a Jenkins instance
# When using a CI server, like Jenkins, in conjunction with github, you may wish to use
# multiple deploy keys (github-speak for an rsa key pair that has been assigned to a single
# repo, rather than a user) to allow Jenkins to pull code from the github repositories
# In the example here, where three repos are used, the idea is to take advantage of ssh's config mechanism
# For use with Jenkins, do the following:
# login to your CI Server
sudo su jenkins
cd ~/.ssh/

If you import live data into Google Docs spreadsheets using the importdata function and you want to force a refresh at a certain interval, but you also want to ensure that some cache-busting goes on, append a querystring that's the epoch time value that the refresh occurs, so for a sheet that should grab new data every hour you could force an update like this:

importData("http://example.com/data.csv?" & hour(googleclock()) & ")")

But the url requested looks like this: http://example.com/data.csv?11 if the refresh happened at 11am. The next day at 11, the url will be the same, so there's a chance you may get cached data. To get around this, use an epoch time-based refresh. The formula:

=((date(year(googleclock()),month(googleclock()),day(googleclock())) & " " & time(hour(googleclock()), 0, 0)) - DATE( 1970;1;1))*86400

gives you the epoch timestamp for the time at the current hour. If you wanted the timest

$ ipython
In [1]: %load_ext line_profiler
In [2]: import train
In [3]: %lprun -m pricing.transforms.lane_profitability -s -r train.main()
@penghou620
penghou620 / gist:d537cbc27eac715a1442c3bce4a1dbaa
Created September 25, 2017 16:30 — forked from ramonsmits/gist:7563502
Example of Mandrill webhook JSON data.
[
{
"event": "send",
"msg": {
"ts": 1365109999,
"subject": "This an example webhook message",
"email": "[email protected]",
"sender": "[email protected]",
"tags": [
"webhook-example"
@penghou620
penghou620 / multiple-deploy-keys-multiple-private-repos-github-ssh-config.md
Created November 29, 2017 22:15 — forked from gubatron/multiple-deploy-keys-multiple-private-repos-github-ssh-config.md
How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

Let's say alice is a github.com user, with 2 or more private repositories repoN. For this example we'll work with just two repositories named repo1 and repo2

https://github.com/alice/repo1

https://github.com/alice/repo2

You need to be to pull from these repositories without entering a passwords probably on a server, or on multiple servers. You want to perform git pull origin master for example, and you want this to happen without asking for a password.