Skip to content

Instantly share code, notes, and snippets.

View myguidingstar-zz's full-sized avatar

Hoàng Minh Thắng myguidingstar-zz

View GitHub Profile
@myguidingstar-zz
myguidingstar-zz / convertCharset.cpp
Created April 10, 2012 02:56
convertCharset for BoGo
void simpleReplace(std::string& str, const std::string& oldStr, const std::string& newStr)
{
size_t pos = 0;
while((pos = str.find(oldStr, pos)) != std::string::npos)
{
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
}
@myguidingstar-zz
myguidingstar-zz / charset-helpers.sh
Created April 10, 2012 04:47
Generate charset-table (cpp vector) for all charsets
#!/bin/sh
convertibles=('À' 'Á' 'Ả' 'Ã' 'Ạ' 'Ằ' 'Ắ' 'Ẳ' 'Ẵ' 'Ặ' 'Ă' 'Ầ' 'Ấ' 'Ẩ' 'Ẫ' 'Ậ' 'Â' 'È' 'É' 'Ẻ' 'Ẽ' 'Ẹ' 'Ề' 'Ế' 'Ể' 'Ễ' 'Ệ' 'Ê' 'Ì' 'Í' 'Ỉ' 'Ĩ' 'Ị' 'Ò' 'Ó' 'Ỏ' 'Õ' 'Ọ' 'Ồ' 'Ố' 'Ổ' 'Ỗ' 'Ộ' 'Ô' 'Ờ' 'Ớ' 'Ở' 'Ỡ' 'Ợ' 'Ơ' 'Ù' 'Ú' 'Ủ' 'Ũ' 'Ụ' 'Ừ' 'Ứ' 'Ử' 'Ữ' 'Ự' 'Ư' 'Ỳ' 'Ý' 'Ỷ' 'Ỹ' 'Ỵ' 'Đ' 'à' 'á' 'ả' 'ã' 'ạ' 'ằ' 'ắ' 'ẳ' 'ẵ' 'ặ' 'ă' 'ầ' 'ấ' 'ẩ' 'ẫ' 'ậ' 'â' 'è' 'é' 'ẻ' 'ẽ' 'ẹ' 'ề' 'ế' 'ể' 'ễ' 'ệ' 'ê' 'ì' 'í' 'ỉ' 'ĩ' 'ị' 'ò' 'ó' 'ỏ' 'õ' 'ọ' 'ồ' 'ố' 'ổ' 'ỗ' 'ộ' 'ô' 'ờ' 'ớ' 'ở' 'ỡ' 'ợ' 'ơ' 'ù' 'ú' 'ủ' 'ũ' 'ụ' 'ừ' 'ứ' 'ử' 'ữ' 'ự' 'ư' 'ỳ' 'ý' 'ỷ' 'ỹ' 'ỵ' 'đ')
#Usage: convertTo charsetName id
function convertTo() {
printf "${convertibles[$2]}" | uvconv -f UTF-8 -t $1 | hexdump -e '1/1 "%02X"'
}
#Usage: makeTable charsetName
(defn fact [n]
(loop [n n x (dec n)]
(if (= 1 x)
n
(recur (* n x) (dec x)))))
(apply + (->> (bigint 100)
fact
str
(map #(Integer. (str %1)))))
@myguidingstar-zz
myguidingstar-zz / set-term-title.clj
Last active December 15, 2015 22:39
Clojure snippet to set the title of current terminal window.
(defn set-term-title
"Sets title of current terminal window."
[new-title]
(printf "%s]2;%s%s" (char 27) new-title (char 7))
(println))
@myguidingstar-zz
myguidingstar-zz / angular.min.js
Last active February 11, 2020 11:09
Custom radio and checkbox styles in angularjs http://plnkr.co/edit/gist:5469101?p=preview
/*
AngularJS v1.1.4
(c) 2010-2012 Google, Inc. http://angularjs.org
License: MIT
*/
(function(M,V,s){'use strict';function gc(){var b=M.angular;M.angular=hc;return b}function o(b,a,c){var d;if(b)if(I(b))for(d in b)d!="prototype"&&d!="length"&&d!="name"&&b.hasOwnProperty(d)&&a.call(c,b[d],d);else if(b.forEach&&b.forEach!==o)b.forEach(a,c);else if(!b||typeof b.length!=="number"?0:typeof b.hasOwnProperty!="function"&&typeof b.constructor!="function"||b instanceof P||ca&&b instanceof ca||Da.call(b)!=="[object Object]"||typeof b.callee==="function")for(d=0;d<b.length;d++)a.call(c,b[d],
d);else for(d in b)b.hasOwnProperty(d)&&a.call(c,b[d],d);return b}function rb(b){var a=[],c;for(c in b)b.hasOwnProperty(c)&&a.push(c);return a.sort()}function ic(b,a,c){for(var d=rb(b),e=0;e<d.length;e++)a.call(c,b[d[e]],d[e]);return d}function sb(b){return function(a,c){b(c,a)}}function Ea(){for(var b=Z.length,a;b;){b--;a=Z[b].charCodeAt(0);if(a==57)return Z[b]="A",Z.join("");if(a==90)Z[b]="0";else return Z[b]=String.fromCharCod
@myguidingstar-zz
myguidingstar-zz / index.html
Created April 26, 2013 18:21
Using ChlorineJS on Plunker. Sample compiling error http://plnkr.co/edit/gist:5469298?p=preview
<!DOCTYPE html>
<html>
<head>
<script src="http://cl2-plnkr.herokuapp.com/dev/script.cl2"></script>
</head>
<body>
<h1>Should yell at an unknown error while compiling!</h1>
</body>
@myguidingstar-zz
myguidingstar-zz / index.html
Created April 26, 2013 18:33
Using ChlorineJS on Plunker. Sample compiling error http://plnkr.co/edit/gist:5469390?p=preview
<!DOCTYPE html>
<html>
<head>
<script src="http://cl2-plnkr.herokuapp.com/dev/script.cl2"></script>
</head>
<body>
<h1>Should yell an "Error expanding macro"!</h1>
</body>
@myguidingstar-zz
myguidingstar-zz / index.html
Created April 26, 2013 18:37
Using ChlorineJS on Plunker. Sample timeout compiling error http://plnkr.co/edit/gist:5469423?p=preview
<!DOCTYPE html>
<html>
<head>
<script src="http://cl2-plnkr.herokuapp.com/dev/script.cl2"></script>
</head>
<body>
<h1>Should yell at timeout error while compiling!</h1>
</body>
@myguidingstar-zz
myguidingstar-zz / index.html
Last active December 16, 2015 17:19
Demo using ChlorineJS on plunker. Using [angular-cl2 "0.3.2"] http://plnkr.co/edit/gist:5469561?p=preview
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"></script>
<script src="http://angular-ui.github.com/bootstrap/ui-bootstrap-tpls-0.1.0-SNAPSHOT.js"></script>
<script src="http://cl2-plnkr.herokuapp.com/dev/prelude.js"></script>
<script src="http://cl2-plnkr.herokuapp.com/dev/script.cl2"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>