Skip to content

Instantly share code, notes, and snippets.

View kfitfk's full-sized avatar
😇

Hao Ye kfitfk

😇
View GitHub Profile
@kfitfk
kfitfk / canvas_to_img.js
Last active August 30, 2023 06:15
Save canvas drawing to local image
function saveCanvas(canvas) {
var image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream'); // here is the most important part because if you dont replace you will get a DOM 18 exception.
window.location.href = image; // it will save locally
}
function openInNewWindow(canvas) {
// works in Firefox
window.open(canvas.toDataURL("image/png"), '_blank');
}
@kfitfk
kfitfk / img_to_base64.js
Created May 5, 2016 03:39
Convert an image to base64 encoding
/**
* Convert an image to a base64 encoded value
* @param {string} url - The url of the image which has correct Access-Control-Allow-Origin response header
* @param {function} callback - callback with one parameter containing the base64 encoded value
* @param {string} [outputFormat] - image/png or image/jpeg or image/webp(Chrome)
*/
function convertImgToBase64(url, callback, outputFormat){
var img = new Image()
img.crossOrigin = 'Anonymous'
img.onload = function() {
@kfitfk
kfitfk / rgb_to_lab.js
Created March 18, 2016 07:17
Convert RGB color to CIE LAB color
function rgbToXyz(r, g, b) {
r /= 255
g /= 255
b /= 255
if (r > 0.04045) r = Math.pow(((r + 0.055) / 1.055), 2.4)
else r = r / 12.92
if (g > 0.04045) g = Math.pow(((g + 0.055) / 1.055), 2.4)
else g = g / 12.92
@kfitfk
kfitfk / bin_cue_to_iso.md
Created November 9, 2015 05:23
Convert bin+cue to iso on Mac OS X
  1. install bchunk (use homebrew);
  2. bchunk a.bin a.cue output
@kfitfk
kfitfk / gb2312_characters.txt
Created September 22, 2015 01:49
The GB2312 characters.
 、。・ˉˇ¨〃々―~∥…‘’“”〔〕〈〉《》「」『』〖〗【】±×÷∶∧∨∑∏∪∩∈∷√⊥∥∠⌒⊙∫∮≡≌≈∽∝≠≮≯≤≥∞∵∴♂♀°′″℃$¤¢£‰§№☆★○●◎◇◆□■△▲※→←↑↓〓⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ!"#¥%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} ̄ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяāáǎàēéěèīíǐìōóǒòūúǔùǖǘǚǜüêㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦㄧㄨㄩ─━│┃┄┅┆┇┈┉┊┋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛├┝┞┟┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯┰┱┲┳┴┵┶┷┸┹┺┻┼┽┾┿╀╁╂╃╄╅╆╇╈╉╊╋啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨安俺按暗岸胺案肮昂盎凹敖熬翱袄傲奥懊澳芭捌扒叭吧笆八疤巴拔跋靶把耙坝霸罢爸白柏百摆佰败拜稗斑班搬扳般颁板版扮拌伴瓣半办绊邦帮梆榜膀绑棒磅蚌镑傍谤苞胞包褒剥薄雹保堡饱宝抱报暴豹鲍爆杯碑悲卑北辈背贝钡倍狈备惫焙被奔苯本笨崩绷甭泵蹦迸逼鼻比鄙笔彼碧蓖蔽毕毙毖币庇痹闭敝弊必辟壁臂避陛鞭边编贬扁便变卞辨辩辫遍标彪膘表鳖憋别瘪彬斌濒滨宾摈兵冰柄丙秉饼炳病并玻菠播拨钵波博勃搏铂箔伯帛舶脖膊渤泊驳捕卜哺补埠不布步簿部怖擦猜裁材才财睬踩采彩菜蔡餐参蚕残惭惨灿苍舱仓沧藏操糙槽曹草厕策侧册测层蹭插叉茬茶查碴搽察岔差诧拆柴豺搀掺蝉馋谗缠铲产阐颤昌猖场尝常长偿肠厂敞畅唱倡超抄钞朝嘲潮巢吵炒车扯撤掣彻澈郴臣辰尘晨忱沉陈趁衬撑称城橙成呈乘程惩澄诚承逞骋秤吃痴持匙池迟弛驰耻
@kfitfk
kfitfk / unicode_range_to_characters.js
Created September 15, 2015 10:20
Converts a Unicode range to the actual characters.
/**
* Convert a Unicode range to the actual characters.
* The Unicode range is in this form - ['U+0020', 'U+0041-005A']
* @param {array} range - An array containing strings of Unicode range.
* @returns {array} - An array containing the actual characters.
*/
function charactersFromUnicodeRange(ranges) {
var output = [];
ranges.forEach(function(range) {
@kfitfk
kfitfk / most_used_simplified_chinese_unicode_range.txt
Created September 15, 2015 09:27
This unicode range includes most used Chinese characters, including uppercase and lowercase letters, numerals and punctuations, and simplified Chinese Level 1 characters.
U+0020,U+0041-005A,U+0061-007A,U+0030-0039,U+002E,U+0020-002F,U+003A-0040,U+005B-0060,U+007B-007E,U+4E00-4E01,U+4E03,U+4E07-4E0E,U+4E10-4E11,U+4E13-4E16,U+4E18-4E1E,U+4E22,U+4E24-4E25,U+4E27-4E28,U+4E2A-4E2D,U+4E30,U+4E32,U+4E34,U+4E36,U+4E38-4E3B,U+4E3D-4E3F,U+4E43,U+4E45,U+4E47-4E49,U+4E4B-4E50,U+4E52-4E54,U+4E56,U+4E58-4E59,U+4E5C-4E61,U+4E66,U+4E69,U+4E70-4E71,U+4E73,U+4E7E,U+4E86,U+4E88-4E89,U+4E8B-4E8F,U+4E91-4E95,U+4E98,U+4E9A-4E9B,U+4E9F-4EA2,U+4EA4-4EA9,U+4EAB-4EAE,U+4EB2-4EB3,U+4EB5,U+4EBA-4EBB,U+4EBF-4EC7,U+4EC9-4ECB,U+4ECD-4ECE,U+4ED1,U+4ED3-4ED9,U+4EDD-4EDF,U+4EE1,U+4EE3-4EE5,U+4EE8,U+4EEA-4EEC,U+4EF0,U+4EF2-4EF3,U+4EF5-4EF7,U+4EFB,U+4EFD,U+4EFF,U+4F01,U+4F09-4F0A,U+4F0D-4F11,U+4F17-4F1B,U+4F1E-4F20,U+4F22,U+4F24-4F27,U+4F2A-4F2B,U+4F2F-4F30,U+4F32,U+4F34,U+4F36,U+4F38,U+4F3A,U+4F3C-4F3D,U+4F43,U+4F46,U+4F4D-4F51,U+4F53,U+4F55,U+4F57-4F60,U+4F63-4F65,U+4F67,U+4F69,U+4F6C,U+4F6F-4F70,U+4F73-4F74,U+4F76,U+4F7B-4F7C,U+4F7E-4F7F,U+4F83-4F84,U+4F88-4F89,U+4F8B,U+4F8D,U+4F8F,U+4F91,U+4F94,U+4F97,U+4F9B
@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',\
@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 = []
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