Skip to content

Instantly share code, notes, and snippets.

View chunyan's full-sized avatar

Chunyan Song chunyan

  • Uber
  • San Francisco
View GitHub Profile
@chunyan
chunyan / gist:b426e4b696ff3e7b9afb
Created September 17, 2014 06:33
sed cheat sheet
-------------------------------------------------------------------------
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor) Dec. 29, 2005
Compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.5
Latest version of this file (in English) is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.pement.org/sed/sed1line.txt
This file will also available in other languages:
Chinese - http://sed.sourceforge.net/sed1line_zh-CN.html
@chunyan
chunyan / gist:df58588b099a49f233e5
Created September 17, 2014 06:32
awk cheat sheet
HANDY ONE-LINE SCRIPTS FOR AWK 30 April 2008
Compiled by Eric Pement - eric [at] pement.org version 0.27
Latest version of this file (in English) is usually at:
http://www.pement.org/awk/awk1line.txt
This file will also be available in other languages:
Chinese - http://ximix.org/translation/awk1line_zh-CN.txt
USAGE:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// Strategy pattern.
// The computer player's behavior/strategy can be replaced by inheriting from the interface below
// Also, the human player's behavior inherits from the same interface
// This also makes it easy to modify the game for 2 human players, 2 computer players etc.
interface MoveMethod
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// Strategy pattern.
// The computer player's behavior/strategy can be replaced by inheriting from the interface below
// Also, the human player's behavior inherits from the same interface
// This also makes it easy to modify the game for 2 human players, 2 computer players etc.
interface MoveMethod
@chunyan
chunyan / gist:9679846
Created March 21, 2014 05:02
out-of-network recommendation disappears in D2 page.
https://dev-api.gemshare.com/secure/questions/242/responses?token=07f87b6a92cb4dc98524174d511159eb
search for "Big Dog Surf Camp"
The recommender Nicki Storm is not in my network so her recommendation doesn't appear on the gem details page
{
"responses_yes": [
{
"relationship": {
"myself": false,
@chunyan
chunyan / gist:9676999
Last active August 29, 2015 13:57
D2 page as an asker
https://dev-api.gemshare.com/secure/questions/295/responses?token=07f87b6a92cb4dc98524174d511159eb
{
"responses_yes": [{
"relationship": {
"myself": false,
"via_text": null,
"direct": true,
"out_of_network": false
},
import math
import sys
import uuid
# this is taken from: https://gist.github.com/bhelx/778542
# modified to support long
class UrlShortener:
BASE = 62
UPPERCASE_OFFSET = 55
LOWERCASE_OFFSET = 61
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#