Skip to content

Instantly share code, notes, and snippets.

View CatTail's full-sized avatar

Chiyu Zhong CatTail

View GitHub Profile
@CatTail
CatTail / dont-starve.py
Created April 11, 2016 03:17
Decode(encode) don't starve saved file
# see http://forums.kleientertainment.com/topic/33321-how-to-get-decoded-save-game-files/
from base64 import b64decode
from sys import argv
from os import path
if __name__ == '__main__':
if len(argv)>1:
try: open(path.join(path.dirname(path.realpath(argv[0])),'my_output_file.txt'),'w').write(b64decode(open(argv[1], 'rb').read()[11:])[16:].decode('zlib'))
except Exception, e: print(e)
function getScript(src, func) {
var script = document.createElement('script');
script.async = "async";
script.src = src;
if (func) {
script.onload = func;
}
document.getElementsByTagName("head")[0].appendChild( script );
}
@CatTail
CatTail / memoize.js
Last active December 15, 2015 07:07
It's hard to write a common memoize function in javascript
/**
* NOTE:
* 1. alter return value will affect internal cache
* 2. `uniq` implementation may cause memory leak. try WeakMap?
*/
/**
* @return {string} unique arguments identifier
*/
function uniq() {
@CatTail
CatTail / input.json
Last active March 22, 2018 06:20
JSON to Graphql schema generator
{"title":"A New Hope","episode_id":4,"opening_crawl":"It is a period of civil war.\r\nRebel spaceships, striking\r\nfrom a hidden base, have won\r\ntheir first victory against\r\nthe evil Galactic Empire.\r\n\r\nDuring the battle, Rebel\r\nspies managed to steal secret\r\nplans to the Empire's\r\nultimate weapon, the DEATH\r\nSTAR, an armored space\r\nstation with enough power\r\nto destroy an entire planet.\r\n\r\nPursued by the Empire's\r\nsinister agents, Princess\r\nLeia races home aboard her\r\nstarship, custodian of the\r\nstolen plans that can save her\r\npeople and restore\r\nfreedom to the galaxy....","director":"George Lucas","producer":"Gary Kurtz, Rick McCallum","release_date":"1977-05-25","characters":["http://swapi.co/api/people/1/","http://swapi.co/api/people/2/","http://swapi.co/api/people/3/","http://swapi.co/api/people/4/","http://swapi.co/api/people/5/","http://swapi.co/api/people/6/","http://swapi.co/api/people/7/","http://swapi.co/api/people/8/","http://swapi.co/api/people/9/","http://swa
@CatTail
CatTail / 00-helloworld.js
Last active October 21, 2015 08:47
log-starter-kit examples
#! /usr/bin/env node
'use strict';
var app = require('koa')();
var port = 8080;
app.use(function* () {
console.log(this.url);
this.status = 200;
this.body = 'Hello World!';
});
@CatTail
CatTail / project.clj
Last active September 22, 2015 10:25
Clojure script and https://github.com/omcljs/om/ tryout
(defproject vote "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2755"]
[figwheel "0.2.2-SNAPSHOT"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
@CatTail
CatTail / group.py
Created September 17, 2015 03:30
Parse url and group them by path
import sys
import urlparse
import operator
"""
Parse url and group them by path
"""
filename = sys.argv[1]
if not filename:
print "Usage group.py <file path>"
@CatTail
CatTail / decorate.js
Created September 10, 2015 10:19
Simple decorate function
function decorate(decorator, decorated, context) {
return function() {
decorated.apply(context, decorator.apply(this, arguments));
};
}
@CatTail
CatTail / switch.sh
Created August 7, 2015 06:50
Switch two file
#! /bin/bash
TMPFILE="$1-${RANDOM}.bak"
mv $1 $TMPFILE
mv $2 $1
mv $TMPFILE $2