Skip to content

Instantly share code, notes, and snippets.

@roadmanfong
roadmanfong / gist:9ebf2fa756ed67a4c507
Last active August 29, 2015 14:08
deferred promise .then()
function fooA(){
console.log('exec fooA');
var dfd = new $.Deferred();
dfd.done(function() {
console.log('fooA Success');
})
.fail(function() {
console.log('fooA fail');
});
setTimeout(dfd.reject, 0);
@roadmanfong
roadmanfong / gist:19eac03312e037e4155f
Created October 29, 2014 09:48
node.js upload file
var formidable = require('formidable'),
http = require('http'),
util = require('util'),
fs = require('fs-extra');
http.createServer(function(req, res) {
/* Process the form uploads */
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
function remainFreqenceEqual(data, frequence){
console.log('remainFreqenceEqual');
frequence = frequence || 1;
return _.chain(data)
.reduce(function (acc, freq) {
console.log('acc');
console.log(acc);
acc[freq] = typeof acc[freq] == 'undefined' ? 1 : acc[freq]+1;
return acc;
@roadmanfong
roadmanfong / promiseWhile.js
Last active November 22, 2018 15:14
promiseWhile demo
function promiseWhile(condition, body) {
var dfd = $.Deferred();
function loop() {
if (!condition()) return dfd.resolve();
body.apply(this, arguments)
.done(loop)
.fail(dfd.reject);
}
//call loop async
@echo off
rem Based on a gist for adding sublime text 2:
rem https://gist.github.com/mrchief/5628677
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with ST3" /t REG_SZ /v "" /d "Open with ST3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with ST3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@echo off
rem Based on a gist for adding sublime text 2:
rem https://gist.github.com/mrchief/5628677
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with ST3" /t REG_SZ /v "" /d "Open with ST3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with ST3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@roadmanfong
roadmanfong / Package Control.sublime-settings
Created July 17, 2015 04:02
Package Control.sublime-settings
{
"in_process_packages":
[
],
"installed_packages":
[
"All Autocomplete",
"AutoFileName",
"Autoprefixer",
"Babel",
let tree = {
name: 'root',
children: [
{
name: 'a',
children: [
{ name: 'd' },
{ name: 'e' }
]
@roadmanfong
roadmanfong / app.js
Created October 5, 2016 07:53 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
0x277E034c59dDD2c56539459B0C566075685a681f