Skip to content

Instantly share code, notes, and snippets.

View rayyee's full-sized avatar
🌴
On vacation

Ray Yee rayyee

🌴
On vacation
View GitHub Profile
@rayyee
rayyee / ReadUtfBytes.as
Created February 11, 2014 14:07
Read utf string from bytes file.
/**
* 从未知编码的二进制流中读取文本
* @param ba
* @param len 读取长度,默认为-1,则读取至文件尾
* @return
*/
public static function readString(ba:ByteArray,len:int = -1):String
{
if ((len != -1 && len > ba.bytesAvailable) || (len == -1)) len = ba.bytesAvailable;
var encode:String = 'gb2312';
@rayyee
rayyee / AsPrototype.as
Created February 11, 2014 14:13
as3 prototype test.
//给数组原型增加一个获取随机数组元素的方法:randomItem
Array.prototype.getRandomItem = function(): *
{
return this[Math.floor(Math.random() * this.length)];
};
//这里设置这个方法不可被(for...in、foreach...in)枚举,非常重要!
Array.prototype.setPropertyIsEnumerable('getRandomItem', false);
var arr:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* User: Ray Yee
* Date: 14-3-6
* All rights reserved.
*/
package
{
import flash.filters.ColorMatrixFilter;
public class ColorMatrixUtility
{
"selector": "source.jsfl",
"cmd": ["Flash" ,"$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)"
}
/**
* Copyright (c) 2013 Amos Laber
*
* 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 the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@rayyee
rayyee / Color.as
Created June 4, 2014 05:57
Color.as
/**
* Add alpha to RGB color
* @param rgb
* @param a
* @return
*/
public static function addAlpha( rgb:uint, a:uint = 0xFF ):uint
{
return (a << 24) | rgb;
}
// =================================================================================================
//
// based on starling.text.TextField
// modified to use text layout framework engine for rendering text
//
// =================================================================================================
package starling.extensions
{
import flash.display.BitmapData;
package starling.extensions.DistanceFieldFont
{
import flash.geom.Rectangle;
import flash.utils.Dictionary;
import starling.display.Image;
import starling.text.BitmapChar;
import starling.textures.Texture;
import starling.textures.TextureSmoothing;
import starling.utils.HAlign;
@rayyee
rayyee / Gaussian.as
Created July 22, 2014 11:44
正态分布随机数
public const c0:Number = 2.515517;
public const c1:Number = 0.802853;
public const c2:Number = 0.010328;
public const d1:Number = 1.432788;
public const d2:Number = 0.189269;
public const d3:Number = 0.001308;
/**
* 正态分布的随机数.a控制波形的顶点,b控制波形的扁度
* @param a 如a是0即,随机出0的机率会大到-1,1,-2,2,然后递减
* @param b 如b是2即,随机出>-2和<2之间的数字机率最大(注意这里的b 是方差,等于标准差的平方)
@rayyee
rayyee / Crawler.java
Created July 30, 2014 07:08
简单的爬虫
package com.rayyee;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.File;