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 / orgmode-python-matplotlib.txt
Last active February 9, 2021 15:08
Plot in Orgmode with matplotlib in python code block
#+NAME: experiments
| k | Trial 1 | Trial 2 | Trial 3 | Trial 4 | Trial 5 |
| 5 | 0.357094 | 0.332661 | 0.28434 | 0.320276 | 0.288069 |
| 10 | 0.403938 | 0.389808 | 0.36694 | 0.372952 | 0.357887 |
| 25 | 0.443313 | 0.441736 | 0.42937 | 0.425222 | 0.418354 |
| 50 | 0.471826 | 0.458904 | 0.45862 | 0.443338 | 0.445892 |
| 75 | 0.472505 | 0.473701 | 0.48072 | 0.452730 | 0.461352 |
| 100 | 0.473184 | 0.481455 | 0.49159 | 0.462386 | 0.476871 |
#+BEGIN_SRC python :results file :exports results :var data=experiments
@penghou620
penghou620 / org-insert-clipboard-image
Last active February 20, 2019 21:52
Insert screenshot/image from clipboard to orgmode
;; Purpose:
;; Insert a image or a screenshot from the clipboard into a Org file.
;;
;; Requirements:
;; brew install pngpaste
;;
;; How to use:
;; 1. Copy the following code into your spacemacs init.el file. Put it inside the `dotspacemacs/user-init` function.
;; 1. Create a directory "attachments" in the same directory as your Org file.
;; 2. After you take a screenshot and the screenshot is in the clipboard, go back to your Org file and type `, i p` in sequence.
@penghou620
penghou620 / pdfmod.py
Created April 17, 2018 16:41 — forked from jrsmith3/pdfmod.py
Convert specified pages from a PDF to png
"""
This script was used to create the figures for http://jrsmith3.github.io/sample-logs-the-secret-to-managing-multi-person-projects.html from a PDF file containing some old CMU sample logs.
"""
import PyPDF2
from wand.image import Image
import io
import os
@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.

@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": "example.webhook@mandrillapp.com",
"sender": "example.sender@mandrillapp.com",
"tags": [
"webhook-example"
$ ipython
In [1]: %load_ext line_profiler
In [2]: import train
In [3]: %lprun -m pricing.transforms.lane_profitability -s -r train.main()

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

@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/
@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 / 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();