Skip to content

Instantly share code, notes, and snippets.

View soharu's full-sized avatar

오자현 / Jahyun Oh soharu

View GitHub Profile
@soharu
soharu / gist:8284890
Last active January 2, 2016 09:39
Example of constructor property
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:8284255
Last active January 2, 2016 09:39
Constructor function example
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:8284174
Last active January 2, 2016 09:39
Factory function example
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:8281553
Last active January 2, 2016 09:09
Example of Constructor Overloading
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);
}
// Suffix Array from JMBook
//
//
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
@soharu
soharu / gist:5096919
Last active December 14, 2015 13:58
va_list in Cocoa
- (void)setContentsWithFormat:(NSString *)formatString, ...
{
[contents autorelease];
va_list args;
va_start(args, formatString);
contents = [[NSString alloc] initWithFormat:formatString arguments:args];
va_end(args);
}
@soharu
soharu / submit.py
Last active December 13, 2015 19:59 — forked from falsetru/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
#!/usr/bin/env python
import unittest
import os
import sys
r, s, m = 43, 22, 2**32
X = []
def setup(xs):
var input = [],
s2n = function (s) { return parseInt(s, 10) },
solve = function (r, c, candy_box) {
var result = 0;
for (var i = 0; i < r; i += 1) {
for (var j = 0; j < c; j += 1) {
if (candy_box[i][j] !== 'o')
continue;
if (j > 0 && j < c - 1 && candy_box[i][j - 1] === '>' && candy_box[i][j + 1] === '<') {
result += 1;
@soharu
soharu / gist:9760239
Created March 25, 2014 11:53
TAOCP 1.3.2 Exercise 5: silly
LOC #100
Main GETA $255,Silly
TRAP 0,Fputs,StdOut
TRAP 0,Halt,0
Silly BYTE 3+"pills"+6 % 3+'p','i','l','l','s'+6