Skip to content

Instantly share code, notes, and snippets.

@joeylin
joeylin / promise.js
Last active December 28, 2015 13:38
Create your own promise
var util = require('util');
var events = require('events');
function Promise(done) {
Promise.super_.call(this);
this.results = null;
this.errors = null;
this.ended = false;
@joeylin
joeylin / ghostPlugin.js
Last active November 10, 2018 23:41 — forked from jgable/index.js
a ghost plugin example
var fs = require('fs'),
path = require('path'),
_ = require('underscore'),
when = require('when'),
express = require('express'),
GhostPlugin = require('../../../core/server/plugins/GhostPlugin'),
knex = require('../../../core/server/models/base').Knex,
KudosPlugin;
KudosPlugin = function (ghost) {
@joeylin
joeylin / QunitTemplate.js
Created November 22, 2013 08:16
a jQuery Quint test suit example
(function($) {
/*
======== A Handy Little QUnit Reference ========
http://api.qunitjs.com/
Test methods:
module(name, {[setup][ ,teardown]})
test(name, callback)
expect(numberOfAssertions)
stop(increment)
@joeylin
joeylin / angularPluginNote.js
Created November 24, 2013 14:22
some common codes used in every third part merged angular plugin
// Garbage collection
// below example
// change third plugin to angular service
// used in most station
scope.$on('$destroy', function() {
$modal.remove();
});
@joeylin
joeylin / keyEventDetect.js
Last active December 30, 2015 21:19
common process to key event
// key name
var key_names = {
32: 'SPACE',
13: 'ENTER',
9: 'TAB',
8: 'BACKSPACE',
16: 'SHIFT',
17: 'CTRL',
18: 'ALT',
20: 'CAPS_LOCK',
@joeylin
joeylin / lightJQ.html
Created January 6, 2014 03:34
a lightweight jquery plugin patterns
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
/*!
@joeylin
joeylin / HowToCode.js
Last active January 2, 2016 08:49
a complete jQuery Plugin patterns
// initialied plugin
$('.element').pluginName();
$('.element').pluginName({
skin:'your skin',
// config
.....
});
// callback method after initialied
$('.element').pluginName('disable'); // call disable method
@joeylin
joeylin / askPassword.js
Created February 8, 2014 07:44
nodejs input password in Terminal
function askPassword(callback) {
var stdin = process.openStdin(),
stdio = process.binding("stdio");
stdio.setRawMode();
console.log('Enter your password:');
var password = "";
stdin.on("data", function(c) {
c = c + "";
@joeylin
joeylin / copy.js
Last active August 29, 2015 13:56
nodejs file copy
var fs = require('fs'),
url = require('url'),
when = require('when'),
errors = require('../errorHandling'),
path = require('path'),
paths = require('./paths'),
appRoot = paths().appRoot,
configExample = paths().configExample,
configFile = process.env.GHOST_CONFIG || paths().config,
@joeylin
joeylin / angular-input-test.js
Created February 10, 2014 06:12
a test example of input directive in angular
'use strict';
describe('green.inputmask4angular', function () {
beforeEach(module('green.inputmask4angular'));
var $scope, $compile, elm,$timeout;
beforeEach(inject(function ($rootScope, _$compile_,_$timeout_) {
$scope = $rootScope;