Skip to content

Instantly share code, notes, and snippets.

View hkwid's full-sized avatar
😎
gemma

hkawaida hkwid

😎
gemma
View GitHub Profile
@hkwid
hkwid / ticktack.js
Last active January 22, 2016 10:03
ticktack alternately display 'tick' and 'tack'
var i = 0;
function ticktack() {
console.log('ticktack'.substr((i % 2) * 4, 4));
i++;
}
ticktack();
ticktack();
ticktack();
ticktack();
@hkwid
hkwid / numFilter.js
Last active January 20, 2016 20:56
Regular Expressions some examples
// put some number
var a = 200000;
[a].toString().replace(/(\d)(?=(\d{3})+$)/g , '$1,');
// -> 200,000
@hkwid
hkwid / express_mime.js
Created January 13, 2016 20:35
express mime
file_response = function( req, res ){
var deploied_file = ('any_file');
if( path.existsSync( deploied_file ) && fs.statSync( deploied_file ).isFile() ){
var type = mime.types[
path.extname( deploied_file ).substr(1)
];
// when file is .txt add charset=utf-8
type = [
type,
'charset=' + mime.charsets.lookup( type )
@hkwid
hkwid / 0_reuse_code.js
Created January 13, 2016 20:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hkwid
hkwid / regexFilter.js
Created January 7, 2016 14:25
angularjs/regexFilter.js
angular.module('app')
.filter('regex', function() {
return function(input, field, regex) {
var pattern = new RegExp(regex);
var out = [];
for (var i = 0; i < input.length; i++){
if(pattern.test(input[i][field]))
out.push(input[i]);
}
return out;
@hkwid
hkwid / leftpadFilter.js
Created January 7, 2016 14:14
leftpadFilter.js
angular.module('app')
.filter('leftpad', function () {
return function (input, length) {
return ('00000000000000000000' + String(input)).slice(-length);
};
});
@hkwid
hkwid / percentageFilter.js
Created January 7, 2016 14:12
angularjs/percentageFilter.js
angular.module('app')
.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
@hkwid
hkwid / abbreviateFilter.js
Created January 7, 2016 14:11
angularjs/abbreviateFiler.js
angular.module('app')
.filter('abbreviate', function () {
return function (text, length, end) {
if (isNaN(length)) length = 20;
if (typeof end === 'undefined')
end = "...";
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
@hkwid
hkwid / tickFilter.js
Last active January 7, 2016 14:23
angularjs/tickFilter.js
angular.module('app')
.filter('tick', function () {
var map = {
'0': '×',
'1': '○'
};
return function(input) {
if (typeof input == 'undefined'){
return '';
@hkwid
hkwid / sendReport.js
Created January 4, 2016 20:25
google_app_script/sendReport.js
function sendReport() {
MailApp.sendEmail(
"[email protected]",
"title",
"body"
);
}