Skip to content

Instantly share code, notes, and snippets.

class Promise
@STATE_PENDING = 2
@STATE_RESOLVED = 1
@STATE_REJECTED = 0
constructor: ->
@_onResolved = null
@_onRejected = null
@_next = null
@_state = Promise.STATE_PENDING
@ukyo
ukyo / fileio.html
Last active December 16, 2015 20:39
<!doctype html>
<html>
<head>
<title>fileio</title>
</head>
<body>
<input type="file">
<script src="file.js"></script>
<script>
window.onload = function() {
aaaaa
test
@ukyo
ukyo / asmjs.md
Last active December 15, 2015 06:49

asm.jsとは

  • JSエンジンで事前コンパイルを行うためのJSサブセットの仕様
  • 書き方を工夫することによって型情報を与えたり、TypedArrayをメモリとして使ったり
  • 主に機械的にJSにコンパイルする何かを対象としている
  • もちろん、手でも書ける(大規模なのは現実的には無理かも)

試す

@ukyo
ukyo / file0.txt
Created March 18, 2013 14:15
再帰 with promise pattern ref: http://qiita.com/items/86ad078cd6d9e1bf0a3d
function fact(n) {
var d = $.Deferred();
setTimeout(function() {
function onResolved(result) {
d.resolve(result * n);
}
n > 1 ? fact(n - 1).then(onResolved) : d.resolve(n);
}, 100);
return d.promise();
}
@ukyo
ukyo / waitForAsyncProcesses.js
Last active December 14, 2015 20:39
http://www.slideshare.net/uupaa/flowjs のjQuery.Deferredの使い方はそもそもおかしい。
waitForAsyncProcesses().done(finishedCallback);
function waitForAsyncProcesses() {
var asyncFunc, A, B, C, D;
asyncFunc = function(ms) {
var dfd = $.Deferred();
setTimeout(dfd.resolve, ms);
return dfd.promise();
};
@ukyo
ukyo / file0.txt
Created March 6, 2013 17:13
jQueryでcheckboxでval()したい ref: http://qiita.com/items/0f0004c35a4d14c09d40
$('#checkbox').val();
@ukyo
ukyo / file0.xml
Created November 28, 2012 13:49
ライセンスのスニペット ref: http://qiita.com/items/96845cf3905b6bfa3e09
<snippet>
<content><![CDATA[
The MIT License
Copyright (c) ${1:year} ${2:author} <${3:hoge}@${4:gmail.com}>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
@ukyo
ukyo / TypedArray.hx
Created November 14, 2012 17:04
haxe typedarray extern
extern class ArrayBuffer
{
public function new(byteLength:Int):Void;
public var byteLength(default, null):Int;
public function slice(begin:Int, ?end:Int):ArrayBuffer;
}
extern private class ArrayBufferView
{
public var buffer(default, null):ArrayBuffer;