Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / hoge.jsx
Created September 27, 2012 10:43
shadowing
class Base {}
class Derived extends Base {}
class _Main {
function method2(obj : Base) : void {
if (obj instanceof Derived) {
var obj = obj as Derived;
funcA(obj);
}
else {
@nyuichi
nyuichi / list-monad.lisp
Created October 14, 2012 00:08
Monad framework for Common Lisp
;;; List Monad
(defmethod bind ((m list) f)
(apply #'append (mapcar f m)))
(defmethod fmap ((m list) f)
(mapcar f m))
@nyuichi
nyuichi / monad.lisp
Created October 15, 2012 15:07
Direct return extraction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun singlep (list)
(= (length list) 1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Core Primitives
(defparameter list nil)
(defparameter set nil)
(defun visit (node)
(unless (visitedp node)
(mark-visited node)
(loop for m in (connected-nodes node) do
(visit m))
(push node)))
@nyuichi
nyuichi / poke.js
Created October 28, 2012 08:51
poke function (facebook)
/*
* 1. Open facebook.com/pokes
* 2. Open developer console
* 3. input this function
* 4. Run 'poke()'
*/
function poke() {
var a = pagelet_pokes.lastChild.lastChild.firstChild.firstChild.lastChild.lastChild.firstChild.lastChild.lastChild.lastChild;
var e = document.createEvent("MouseEvents");
class Klass.<T> {
var a : T;
}
class _Main {
static function main(args : string[]) : void {
var klass = new Klass.<function(:number):number>;
}
}
@nyuichi
nyuichi / type_join_test.jsx
Created November 11, 2012 17:57
enhance type inference of conditional expression
class A {}
class B extends A {}
class C extends A {}
interface I {}
class X implements I {}
class Y implements I {}
class Z extends Y {}
class _Main {
@nyuichi
nyuichi / hakatashi.cpp
Created November 24, 2012 16:46
バグ入り
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int SIZE = 100001;
class mint;
mint multiply(mint &lhs, mint &rhs, int n);
class mint {
public:
(let* ((p1 b)
(v1 (v- a b))
(p2 d)
(v2 (v- c d)))
(with-vector (x1 y1 z1) v1
(with-vector (x2 y2 z2) v2
(with-vector (x3 y3 z3) (v- p1 p2)
(when (<= (abs (- (+ (* x1 y2 z3) (* x2 y3 z1) (* x3 y1 z2))
(+ (* x3 y2 z1) (* y3 z2 x1) (* z3 x2 y1))))
*vector3-acceptable-error-range*)
@nyuichi
nyuichi / slime-profile-report
Created December 11, 2012 13:43
decompose-interference
STL> (DECOMPOSE-INTERFERENCE dat)
seconds | gc | consed | calls | sec/call | name
---------------------------------------------------------------
5.775 | 0.327 | 1,214,028,864 | 660,262 | 0.000009 | CREATE-VECTOR3
0.218 | 0.000 | 3,373,952 | 63,762 | 0.000003 | MAKE-SEGMENT
0.011 | 0.000 | 1,080,752 | 21,254 | 0.000001 | GET-SEGMENTS
0.008 | 0.000 | 622,304 | 1,246 | 0.000006 | GET-NEIGHBOR-POINTS
0.005 | 0.000 | 65,536 | 1,246 | 0.000004 | GET-NEAREST-POINT
0.002 | 0.000 | 65,520 | 1,173 | 0.000002 | MIN/KEY
0.002 | 0.000 | 0 | 76 | 0.000025 | REGISTER-POINT