Skip to content

Instantly share code, notes, and snippets.

View soharu's full-sized avatar

오자현 / Jahyun Oh soharu

View GitHub Profile
@soharu
soharu / args2.mms
Last active August 29, 2015 13:56
레지스터 $0에 저장된 명령행 인자 갯수를 이용한 명령행 인자 출력
cnt IS $0
argv IS $1
t IS $255
k GREG 0
LOC Data_Segment
GREG @
NewLn BYTE #a,0
LOC #100
Main SET k,0
Loop LDOU t,argv,k
@soharu
soharu / args.mms
Created February 11, 2014 12:16
명령행 인자를 출력하는 MMIX 코드
argv IS $1
t IS $255
k GREG 0
LOC Data_Segment
GREG @
NewLn BYTE #a,0
LOC #100
Main SET k,0
Loop LDOU t,argv,k
BZ t,Term
@soharu
soharu / gist:8285507
Created January 6, 2014 16:38
classof() function
function classof(o) {
if (o === null) return "Null";
if (o === undefined) return "Undefined";
return Object.prototype.toString.call(o).slice(8, -1);
}
@soharu
soharu / gist:8285069
Created January 6, 2014 16:11
Example of constructor property 3
function Range(from, to) {
this.from = from;
this.to = to;
}
Range.prototype = {
constructor: Range,
includes: function (x) {
return this.from <= x && x <= this.to;
},
@soharu
soharu / gist:8285049
Created January 6, 2014 16:09
Example of constructor property 2
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: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;