Skip to content

Instantly share code, notes, and snippets.

View JoshuaChi's full-sized avatar

Joshua Chi JoshuaChi

View GitHub Profile
@JoshuaChi
JoshuaChi / postgres-cheatsheet.md
Created August 23, 2017 09:17 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@JoshuaChi
JoshuaChi / consist_hash.java
Created June 1, 2017 14:20 — forked from bcambel/consist_hash.java
Consistent Hash Java implementation
import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;
public class ConsistentHash<T> {
private final HashFunction hashFunction;
private final int numberOfReplicas;
private final SortedMap<Integer, T> circle = new TreeMap<Integer, T>();
@JoshuaChi
JoshuaChi / LeastConnectionBalancer.java
Created April 9, 2017 08:18
Zookeeper::LeastConnectionBalancer
public class LeastConnectionBalancer implements Balancer {
private CuratorFramework zkClient;
public LeastConnectionBalancer(CuratorFramework zkClient){
this.zkClient = zkClient;
}
@Override
public String select() throws Exception {
@JoshuaChi
JoshuaChi / RoundRobinBalancer.java
Created April 9, 2017 08:17
Zookeeper::RoundRobinBalancer
public class RoundRobinBalancer implements Balancer {
private CuratorFramework zkClient;
public RoundRobinBalancer(CuratorFramework zkClient){
this.zkClient = zkClient;
}
@Override
public String select() throws Exception {
@JoshuaChi
JoshuaChi / gist:82acf99323dfd49af7929c0c218fe4ff
Created December 31, 2016 07:55 — forked from kaiwren/gist:1283905
Steve Yegge's SOA post
From: https://raw.github.com/gist/933cc4f7df97d553ed89/24386c6a79bb4b31fb818b70b34c5eab7f12e1ff/gistfile1.txt
Stevey's Google Platforms Rant
I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.
I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various effort
@JoshuaChi
JoshuaChi / multi-process
Created January 2, 2016 09:35
Shell Multi Process
#!/bin/bash
set -m # Enable Job Control
WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
for i in `seq 8`; do # start 8 jobs in parallel(e.g. 8 cores)
//sh example.sh
done
@JoshuaChi
JoshuaChi / GetCsvDataFromYahoo.java
Created March 19, 2015 14:25
GetCsvDataFromYahoo
package finance.datainit.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@JoshuaChi
JoshuaChi / default.conf
Last active August 29, 2015 14:14 — forked from cbmd/default.conf
server {
index index.php;
set $basepath "/var/www";
set $domain $host;
# check one name domain for simple application
if ($domain ~ "^(.[^.]*)\.dev$") {
set $domain $1;
set $rootpath "${domain}";

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin

Steps to install PIL

$ sudo apt-get install python-imaging
$ sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/

$ pip install PIL