Skip to content

Instantly share code, notes, and snippets.

View minodisk's full-sized avatar

Daisuke Mino minodisk

  • Knowledge Work
  • Tokyo, Japan
  • 16:33 (UTC +09:00)
  • X @minodisk
View GitHub Profile
@minodisk
minodisk / gist:964198
Created May 10, 2011 09:49
Add style with JavaScript.
var style = document.createElement('style');
style.appendChild(document.createTextNode('#sample { background-color: #FF0000; }'));
document.documentElement.appendChild(style);
window.addEventListener('DOMContentLoaded', function () {
document.head.appendChild(style);
}, false);
> require('fs').statSync('/usr')
{ dev: 234881026,
ino: 369622,
mode: 16877,
nlink: 14,
uid: 0,
gid: 0,
rdev: 0,
size: 476,
blksize: 4096,
@minodisk
minodisk / gist:1136327
Created August 10, 2011 07:54
Get server time with AJAX
$(function () {
$.ajax({
type: 'GET',
cache: false,
url: location.href,
complete: function (req, textStatus) {
var dateString = req.getResponseHeader('Date');
if (dateString.indexOf('GMT') === -1) {
dateString += ' GMT';
}
@minodisk
minodisk / gist:1158984
Created August 20, 2011 11:27
XMLリテラルでCDATA
var text:String = 'abc0123456789';
var a:XML = <a><![CDATA[{text}]]></a>;
trace(a.toXMLString()); // <a><![CDATA[{text}]]></a>;
var b:XML = <b>{'<![CDATA[' + text + ']]>'}</b>;
trace(b.toXMLString()); // <b>&lt;![CDATA[abc0123456789]]&gt;</b>
var c:XML = <c>{new XML('<![CDATA[' + text + ']]>')}</c>;
trace(c.toXMLString()); // <c><![CDATA[abc0123456789]]></c>
@minodisk
minodisk / gist:1160416
Created August 21, 2011 10:02
BitmapDataを綺麗にリサイズ
public function resizeLowQuality(src:BitmapData, width:Number, height:Number):BitmapData {
var matrix:Matrix = new Matrix();
matrix.scale(width / src.width, height / src.height);
var dst:BitmapData = new BitmapData(width, height, true, 0);
dst.draw(src, matrix, null, null, null, true);
return dst;
}
public function resizeHighQuality(src:BitmapData, width:Number, height:Number):BitmapData {
var bitmap:Bitmap = new Bitmap(src, 'auto', true);
@minodisk
minodisk / gist:1169805
Created August 25, 2011 02:18
コンパイラオプションをASファイルに書く
/**
* @mxmlc -load-config+=obj\{PROJECT_NAME}Config.xml -debug=true -incremental=true -benchmark=false -static-link-runtime-shared-libraries=true -o bin/{FILE_NAME}.swf
*/
@minodisk
minodisk / gist:1172887
Created August 26, 2011 07:17
SWFWheelでブラウザのスクロールを止める
import org.libspark.ui.SWFWheel;
SWFWheel.initialize(stage);
SWFWheel.browserScroll = false;
@minodisk
minodisk / print.as
Created August 29, 2011 13:58
状況によってtraceを出力するかどうかを切り分ける
package {
public function print(...texts):void {
if (printable) {
trace.apply(null, texts);
}
}
}
@minodisk
minodisk / install.sh
Created September 8, 2011 03:41
Nodeでproxy
npm install http-proxy
@minodisk
minodisk / progressiveplayer.as
Created September 16, 2011 05:40
NetStream.Seek.Notify で再生時間が期待した値で取得できない件
var connection:NetConnection = new NetConnection();
connection.connect(null);
var stream:NetStream = new NetStream(connection);
stream.client = {};
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
stream.play('example.f4v');
setTimeout(function ():void {
stream.seek(100);
}, 5000);