Skip to content

Instantly share code, notes, and snippets.

Avatar

Jahyun Oh soharu

View GitHub Profile
View submit.py
#!/usr/bin/env python
import urllib, urllib2
import cookielib
import os
from contextlib import closing
import re
import getpass
import webbrowser
import sys
View json2cpp.py
#!/user/bin/env python
import json
import sys
from types import *
def cpp_type(value):
if type(value) is IntType:
return 'int'
elif type(value) is FloatType:
@soharu
soharu / gist:5096919
Last active Dec 14, 2015
va_list in Cocoa
View gist:5096919
- (void)setContentsWithFormat:(NSString *)formatString, ...
{
[contents autorelease];
va_list args;
va_start(args, formatString);
contents = [[NSString alloc] initWithFormat:formatString arguments:args];
va_end(args);
}
View suffix_array.cpp
// Suffix Array from JMBook
//
//
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
@soharu
soharu / gist:8281553
Last active Jan 2, 2016
Example of Constructor Overloading
View gist:8281553
function Set() {
this.values = {};
this.n = 0;
if (arguments.length == 1 && isArrayLike(arguments[0]))
this.add.apply(this, arguments[0]);
else if (arguments.length > 0)
this.add.apply(this, arguments);
}
@soharu
soharu / gist:8284174
Last active Jan 2, 2016
Factory function example
View gist:8284174
function inherit(p) {
if (p == null)
throw TypeError();
if (Object.create)
return Object.create(p);
var t = typeof p;
if (t !== "object" && t !== "function")
throw TypeError();
function f() {};
f.prototype = p;
@soharu
soharu / gist:8284255
Last active Jan 2, 2016
Constructor function example
View gist:8284255
function Range(from, to) {
this.from = from;
this.to = to;
}
Range.prototype = {
includes: function (x) {
return this.from <= x && x <= this.to;
},
foreach: function (f) {
@soharu
soharu / gist:8284890
Last active Jan 2, 2016
Example of constructor property
View gist:8284890
var F = function() {}; // This is a function object
var p = F.prototype; // This is the prototype object associated with it
var c = p.constructor; // This is the function associated with the prototype
c === F // => true, F.prototype.constructor === F fo any function
var o = new F(); // Create an object o of class F
o.constructor === F // => true, the constructor property specifies the class
@soharu
soharu / gist:8285049
Created Jan 6, 2014
Example of constructor property 2
View gist:8285049
function Range(from, to) {
this.from = from;
this.to = to;
}
Range.prototype.includes = function (x) {
return this.from <= x && x <= this.to;
};
Range.prototype.foreach = function (f) {
@soharu
soharu / gist:8285069
Created Jan 6, 2014
Example of constructor property 3
View gist:8285069
function Range(from, to) {
this.from = from;
this.to = to;
}
Range.prototype = {
constructor: Range,
includes: function (x) {
return this.from <= x && x <= this.to;
},