Skip to content

Instantly share code, notes, and snippets.

View kfitfk's full-sized avatar
😇

Hao Ye kfitfk

😇
View GitHub Profile
@kfitfk
kfitfk / rm_keys_redis.sh
Created November 28, 2013 03:13
Remove keys matching a pattern with redis
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
@kfitfk
kfitfk / base64.js
Created November 28, 2013 03:15
JS Base 64 encode/decode
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
@kfitfk
kfitfk / empty_mysql_table.sql
Created November 28, 2013 03:16
Empty a mysql table
CREATE TABLE cloned LIKE the_table_to_drop;
RENAME TABLE the_table_to_drop TO drop_me, cloned TO the_table_to_drop;
DROP TABLE drop_me;
@kfitfk
kfitfk / group_pinyin.js
Created November 28, 2013 03:16
group pinyin array
/** 把中文转换成拼音数组后,如果有多音字,枚举所有可能的组合
* 示例:
* [ [ 'a' ],
* [ 'b', 'c', 'd' ],
* [ 'e', 'f' ],
* [ 'g' ] ]
* 使用getResult方法将会返回:
* ["abeg", "abfg", "aceg", "acfg", "adeg", "adfg"]
*/
@kfitfk
kfitfk / git_history_email.sh
Created November 28, 2013 03:18
Change git commit email
git filter-branch -f --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "yehao" ];
then
GIT_COMMITTER_NAME="Lingzheng";
GIT_AUTHOR_NAME="Lingzheng";
GIT_COMMITTER_EMAIL="lingzheng.yh@taobao.com";
GIT_AUTHOR_EMAIL="lingzheng.yh@taobao.com";
git commit-tree "$@";
else
git commit-tree "$@";
@kfitfk
kfitfk / open_window.as
Last active August 29, 2015 14:05
Open Browser Window in ActionScript
function openWindow($url:String, $window:String = "_blank"):void {
var req:URLRequest = new URLRequest($url);
if (!ExternalInterface.available) {
navigateToURL(req, $window);
} else {
try {
var strUserAgent:String = String(ExternalInterface.call("function() {return navigator.userAgent;}")).toLowerCase();
if (strUserAgent.indexOf("firefox") != -1 || (strUserAgent.indexOf("msie") != -1 && uint(strUserAgent.substr(strUserAgent.indexOf("msie") + 5, 3)) >= 7)) {
ExternalInterface.call("function(url, target){window.open(url, target);return;}", req.url, $window);
@kfitfk
kfitfk / gist:d71409a715b880551470
Created April 16, 2015 09:25
Extract a .tar.gz file
tar -xvzf community_images.tar.gz
To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things.
f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
z: tells tar to decompress the archive using gzip
x: tar can collect files or extract them. x does the latter.
v: makes tar talk a lot. Verbose output shows you all the files being extracted.
mxmlc ./YOUR_MAIN_CLASS.as -l ./YOUR_MAIN_SWC.swc -static-link-runtime-shared-libraries=true -managers=flash.fonts.AFEFontManager -default-size=550,400 -debug=false -o OUTPUT_FILE_NAME.swf
@kfitfk
kfitfk / flex_embed_unicode_ranges.js
Created May 8, 2015 09:34
Generate the unicodeRanges property for Flex font embed
function flexEmbedCharUnicode(charCode) {
var leadingZeros = '';
for (var i = 0; i < 4 - charCode.length; i++) {
leadingZeros += '0';
}
return 'U+' + leadingZeros + charCode;
}
function flexEmbedUnicodeRanges(string) {
var unicodeRange = []
@kfitfk
kfitfk / ps_save_jpeg.jsx
Created July 23, 2015 06:49
A Photoshop script to automate save for web as JPEG. Save the file as using jsx extenstion. Then in Photoshop go to "File-Scripts-Browse..." to load the file. This script will overwrite the existing output file if it already exists.
// Utils
function trace() {
$.writeln.apply($, arguments);
}
// Construct the dialog layout
var layoutInfo = "dialog{\
text: 'Save for Web in JPEG',\
info: Panel {\
orientation: 'column',\