Skip to content

Instantly share code, notes, and snippets.

View mutoo's full-sized avatar

Lingjia Liu mutoo

View GitHub Profile
@mutoo
mutoo / bit_bitmask.h
Last active December 17, 2015 13:29
macro: bit and bit_mask
#define BIT(n) ((uint32_t)1 << (n))
#define BITMASK(n) (BIT(n) - 1)
// code from: spidermonkey.h
@mutoo
mutoo / custom_assert.h
Created May 21, 2013 02:07
snippet from <Writing Clean Code>
#ifdef DEBUG
void _Assert(char*, unsigned);
#define ASSERT(f) \
if(f) \
NULL; \
else \
_Assert(__FILE__, __LINE__)
#else
#define ASSERT(f) NULL
#endif
@mutoo
mutoo / requestAnimFrame.js
Created May 21, 2013 02:11
compatible requestAnimFrame
window.requestAnimFrame = window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback) {
window.setTimeout(callback, 1000 / 60); // fps:60
};
@mutoo
mutoo / domReady.js
Created May 21, 2013 02:16
compatible domReady
// initialize when DOM content is loaded
var domReady = function() {
var fns = [];
var init = function() {
if (!arguments.callee.done) { // run init functions once
arguments.callee.done = true;
for (var i = 0; i < fns.length; i++) {
fns[i]();
}
}
@mutoo
mutoo / dhcp2static.bat
Created May 21, 2013 05:05
a batchfile for switching dhcp to static
@echo off
cls
echo 开始获取动态IP :)
echo.
echo 正在设置自动获取IP地址...
netsh interface ip set address "本地连接" dhcp
echo 正在设置自动获取DNS...
netsh interface ip set dns "本地连接" dhcp
@mutoo
mutoo / hello_os.asm
Created May 21, 2013 05:13
the simplest operating system that only shows the words "Hello,OS!" on screen after computer startup
org 07c00h ; tell the complier put this code to 0x7c00
%endif
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ; call sub-func
jmp $ ; while(1); $ means current address;
DispStr:
mov ax, BootMessage
mov bp, ax
@mutoo
mutoo / tacoyaki_p.js
Created May 21, 2013 05:23
a javascript program to solve the tacoyaki+ game - http://www.gamedesign.jp/flash/tacoyaki_p/tacoyaki_p.html
var row,column;
row = column = 7; // setup the size of game
var map = [1,1,1,0,0,1,1]; // setup first column
for(i=row;i<row*column;i++)
map[i] = 0; // insure others tile are ZERO
display(map);
function tapByCoor(map,r,c){
index = r*column+c;
@mutoo
mutoo / circumcircle.js
Last active November 17, 2022 15:54
a very fast algorithm for getting the circumcircle from a triangle - http://www.exaflop.org/docs/cgafaq/cga1.html#Subject 1.04
function circumcircle(a, b, c) {
this.a = a
this.b = b
this.c = c
var A = b.x - a.x,
B = b.y - a.y,
C = c.x - a.x,
D = c.y - a.y,
E = A * (a.x + b.x) + B * (a.y + b.y),
@mutoo
mutoo / loadAndExecute.js
Created May 22, 2013 02:51
executing function after loading a extern script.
var load, execute, loadAndExecute;
load = function(a, b, c) {
var d;
d = document.createElement("script"), d.setAttribute("src", a), b != null && d.addEventListener("load", b), c != null && d.addEventListener("error", c), document.body.appendChild(d);
return d
}, execute = function(a) {
var b, c;
typeof a == "function" ? b = "(" + a + ")();" : b = a, c = document.createElement("script"), c.textContent = b, document.body.appendChild(c);
return c
}, loadAndExecute = function(a, b) {
@mutoo
mutoo / AVLTree.pde
Created May 24, 2013 06:35
play with intersections of lines (unfinish)
abstract class Node {
Node left;
Node right;
Object element;
int height;
private Node() {
}