Skip to content

Instantly share code, notes, and snippets.

class _Main {
static function main(args:string[]): void {
var v = JSON.parse('["a", "b", "c"]');
var i: int;
i = (v as Array.<int>)[0];
log i;
}
}
/* Smooth scrolling
Changes links that link to other parts of this page to scroll
smoothly to those links rather than jump to them directly, which
can be a little disorienting.
sil, http://www.kryogenix.org/
v1.0 2003-11-11
v1.1 2005-06-16 wrap it up in an object
*/
var check = function(digits) {
var make_equations = function(digits, strict) {
var numbers = digits.length;
var equations = {};
var current = [];
var make_recursive = function(num_list, nums, operations) {
if(num_list.length == 0 && operations == 0) {
equations[current.join("")] = true;
return;
package com.example.hellogl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
@tkihira
tkihira / gist:3035490
Created July 2, 2012 20:26
convert SJIS to UTF-8 using AJAX and ecl.js
<!doctype html>
<html><head><title>escape sample</title></head>
// http://www.vector.co.jp/soft/other/java/se342855.html
<script src="ecl.js"></script>
<script>
onload = function() {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType('text/plain; charset=x-user-defined'); // binary
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) { // DONE
@tkihira
tkihira / gist:3014700
Created June 28, 2012 23:28
mkdir, rmdir and copyDir(deep-copy a directory) in node.js
var mkdir = function(dir) {
// making directory without exception if exists
try {
fs.mkdirSync(dir, 0755);
} catch(e) {
if(e.code != "EEXIST") {
throw e;
}
}
};
@tkihira
tkihira / gist:2779981
Created May 24, 2012 07:08
VM sample
while(offset >= 0) {
switch(offset) {
case 0: // "PUSH 10"
stack.push(10);
case 2: // "PUSH 8"
stack.push(8);
case 4: // "LESS"
var a = stack.pop();
var b = stack.pop();
stack.push((a < b)? 1: 0);
@tkihira
tkihira / gist:2367067
Created April 12, 2012 13:02
rmdir recursively in node.js
var fs = require("fs");
var path = require("path");
var rmdir = function(dir) {
var list = fs.readdirSync(dir);
for(var i = 0; i < list.length; i++) {
var filename = path.join(dir, list[i]);
var stat = fs.statSync(filename);
if(filename == "." || filename == "..") {
@tkihira
tkihira / gist:2292457
Created April 3, 2012 14:32
Chrome's bug code
var canvas = document.createElement("canvas");
canvas.width = canvas.height = 300;
document.body.appendChild(canvas);
var ctx = canvas.getContext("2d");
var m = document.createElement("canvas");
m.width = m.height = 100;
var mctx = m.getContext("2d");
mctx.fillStyle = "#f00";
mctx.fillRect(0, 0, 100, 100);
@tkihira
tkihira / gist:2250405
Created March 30, 2012 09:46
for..in hack
var o = {a: 0, b: 1, c: 2, d: 3};
var a = []; var i = 0;
for(a[i++] in o);