Skip to content

Instantly share code, notes, and snippets.

View johnfn's full-sized avatar

Grant Mathews johnfn

View GitHub Profile
@johnfn
johnfn / gist:d7907fd100261beda045
Created January 4, 2015 08:03
Parsing javascript for docs and inserting them into Typescript definition files.
import re
CLASS_RE = r'(export )?class ([^\s]+)'
MODULE_RE = r'(declare )?module ([^\s]+)'
INTERFACE_RE = r'interface ([^\s]+)'
FUNCTION_RE = r'^\s*(static)?\s*([^\(]+)\('
PARAM_RE = r'^\s*(static)?\s*([^:^\(]+):'
DOCS_START = r'^\s*/\*\*\s*$'
DOCS_END = r'^\s*\*/\s*$'
CLOSE_BRACKET_RE = r'^\s*\};?\s*$'
@johnfn
johnfn / gist:b9afbaae3d05c63f3f6b
Last active August 29, 2015 14:16
JSON to Swift Mk. I
// JSON String -> Object
// Still TODO:
// 1. Nested JSON object parsing
// 2. String -> JSON data type
// Data structures to hold JSON
// Probably not necessary but they make the code nice and I wanted to learn about them
enum JSONItem {
case StringEntry(String, String)
@johnfn
johnfn / gist:d4b4f25e7caef6bd70b6
Last active August 29, 2015 14:16
c# to swift (written in python for obvious reasons)
# TODO
# * Parse out name of class
# * Parse nested objects
# * Since they are explicitly marked with ForeignKey("nameOfProperty"), this should be a single regex
# * test against different files
import re
filename = "DbPerson.cs"
test = "".join([line for line in open(filename)])
class DbPerson.cs {
var id: int
var email: string
var snippet: string
var bio: string
var created: DateTime
var firstname: string
var lastname: string
var birthdate: DateTime?
var gender: string
@johnfn
johnfn / gist:0d8d1bf7e4de78d0e4bc
Created June 21, 2015 03:14
TypeScript plugin freeze
DEBUG:TS:Body sequence#: 358
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 359
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 360
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 361
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 362
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 610
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 611
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 612
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 613
DEBUG:TS:Read body of length: 83
DEBUG:TS:Body sequence#: 614
// this is what the data looks like
interface Battle {
entries: number[];
host: string;
id: number;
major: boolean;
timestamp: string;
title: string;
}
@johnfn
johnfn / gist:2434a822f64d0bda2e47
Created June 28, 2015 23:27
Floodfill with LINQ
public List<List<Cell>> World; // 100x100 2d list of Struct
private void FloodFill()
{
var edge = new List<Cell> { World[0][0] };
var seen = new HashSet<Cell> { };
//while (edge.Count > 0)
for (var i = 0; i < 50; i++) // Just run 50 iterations
{
(defmacro simple [x] (eval x))
(let [y 5] (simple y))
>> can't eval locals
@johnfn
johnfn / gist:1177226
Created August 28, 2011 21:02
Ludum dare stat cruncher
# Copy (yes, literally copy as in copy and paste) all the data from the LD big stats page (http://www.ludumdare.com/compo/ludum-dare-20/?more=1)
# and put it into a file called "data" (quotes for clarity). Then run this file with python.
data = [l[:-1] for l in file("data")]
scores = {}
score_category = ""
categories = []
for line in data: