Skip to content

Instantly share code, notes, and snippets.

@wiky
wiky / events.js
Last active October 8, 2016 09:55
/**
* Custom Event
*
* @example
* <pre>
* function Foo() {}
* Foo.prototype.render = function() {
* this.trigger('rendered');
* };
* Events.mixin(Foo);
@wiky
wiky / promise.js
Last active February 1, 2016 11:00
function Promise() {
this._callbacks = [];
}
Promise.prototype.then = function(func, context) {
var p;
if (this._isdone) {
p = func.apply(context, this.result);
} else {
p = new Promise();
@wiky
wiky / 0_reuse_code.js
Last active August 29, 2015 14:21
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
@wiky
wiky / build
Created December 25, 2014 02:15
nw-gyp clean configure build --arch=x64 --target=0.10.5
@wiky
wiky / build.md
Created November 4, 2014 09:36
build nodegit for node-webkit
# Fetch this project.
git clone git://github.com/tbranyen/nodegit.git

# Enter the repository.
cd nodegit

# Installs the template engine, run the code generation script, and build.
npm install
@wiky
wiky / md5.js
Created October 28, 2014 11:23
md5
var crypto = require('crypto');
function md5 (text) {
return crypto.createHash('md5').update(text).digest('hex');
};
@wiky
wiky / app.js
Last active August 29, 2015 13:57
var fs = require('fs'),
path = require('path'),
TianmaCmd = require('./tianma-cmd'),
doc = window.document,
workdir = doc.getElementById('workdir'),
tianma = TianmaCmd();
workdir.addEventListener('change', function(evt) {
var dir = this.value,
configArr = [];
<html>
<head>
<title>tianmaGUI</title>
</head>
<body>
<script type="text/javascript">
document.write('node version:' + process.version);
</script>
</body>
</html>
var exec = require('child_process').exec,
path = require('path');
var TianmaCmd = function(tianma, cwd) {
this.tianma = tianma || path.join(__dirname, '../node_modules/tianma/bin/tianma');
this.cwd = cwd || path.join(__dirname, '../node_modules/tianma/deploy');
};
TianmaCmd.prototype = {
_exec: function(cmd, callback) {
(function() {
var cache = {};
this.tmpl = function(str, data) {
cache[str] = cache[str] ||
new Function('data', [
'var _p="";\nwith(arguments[0]||{}){\n_p+="',
str.replace(/"/g, '\\$&')
.replace(/[\r\n]/g, '')
.replace(/<%([^\w\s\}\)]*)\s*(.*?)\s*%>/g, function(match, mark, code) {
if (mark === '=') return '"+(' + code + ')+"';