Skip to content

Instantly share code, notes, and snippets.

View longlho's full-sized avatar

Long Ho longlho

View GitHub Profile
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
# Install git to get statsd
sudo apt-get install git
@longlho
longlho / gist:5286735
Last active December 15, 2015 16:09 — forked from chalmerj/gist:1492154
graphite start/stop
#! /bin/sh
### BEGIN INIT INFO
# Provides: gunicorn-graphite
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $nginx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: gunicorn + nginx ubuntu init script
# Description: gunicorn + nginx ubuntu init script
## {{{ http://code.activestate.com/recipes/576694/ (r9)
import collections
class OrderedSet(collections.MutableSet):
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
@longlho
longlho / keybase.md
Created March 4, 2014 20:00
Keybase.md

Keybase proof

I hereby claim:

  • I am longlho on github.
  • I am lh (https://keybase.io/lh) on keybase.
  • I have a public key whose fingerprint is 3E71 7EF0 92AB 94DB 2713 0E79 4F91 72E2 70C1 3BE8

To claim this, I am signing this object:

@longlho
longlho / getElementsByClassName-polyfill.js
Created September 5, 2014 01:38
getElementsByClassName Polyfill for IE8
(function () {
if (!document.getElementsByClassName) {
window.Element.prototype.getElementsByClassName = document.constructor.prototype.getElementsByClassName = function (classNames) {
classNames || (classNames = '*');
classNames = classNames.split(' ').join('.');
if (classNames !== '*') {
classNames = '.' + classNames;
}
@longlho
longlho / kittens_script.js
Last active August 29, 2015 14:24
Kittens scripts
(function () {
var res = window.gamePage.resPool.resources;
function findRes (type) {
return res.filter(function (r) {
return r.name === type;
})[0];
}
function setRes (type, amt) {
@longlho
longlho / ioslocaleidentifiers.csv
Last active January 6, 2017 18:07 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)
@longlho
longlho / test.js
Created February 23, 2017 16:32
intl tree-shaking
// lib.js
import formatRelative from 'intl-relativeformat'
export function foo () {
formatRelative()
}
export function bar () {}
// main.js
@longlho
longlho / compile-css.ts
Created August 13, 2017 18:57
Extract CSS type definitions
import * as postcss from 'postcss'
import { basename, resolve, join } from 'path'
import { outputFileSync } from 'fs-extra'
import { sync as globSync } from 'glob'
import { readFileSync } from 'fs'
import { watch as chokidarWatch } from 'chokidar'
const { NODE_ENV } = process.env
// Change CSS glob pattern
@longlho
longlho / css-modules.tsx
Created March 21, 2018 23:12
css-modules
import * as styles from 'foo.css'
type CssMap = typeof styles
export const legacyCss: CssMap = {
container: 'mc-foo',
content: 'mc-content'
}
export interface Props {
css: CssMap