Skip to content

Instantly share code, notes, and snippets.

View mygoare's full-sized avatar
:octocat:

Gore mygoare

:octocat:
View GitHub Profile
@mygoare
mygoare / eventEmitter.js
Last active August 29, 2015 14:07
Nodejs events listen and emit
// Nodejs event listen and emit
// 不光nodejs, Javascript 本身就有 eventEmitter
var events = require('events');
var eventEmitter = new events.EventEmitter();
var ringBell = function()
{
console.log('ring ring ring');
@mygoare
mygoare / clone.js
Created August 27, 2014 03:39
clone object without reference
// clone object without reference
// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
function clone(obj) {
var copy;
// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;
// Handle Date
if (obj instanceof Date) {
@mygoare
mygoare / eventEmitter.js
Created July 31, 2014 04:03
javascript eventEmitter
var events = require('events');
function Door(colour) {
this.colour = colour;
events.EventEmitter.call(this);
this.open = function()
{
this.emit('open');
}
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
@mygoare
mygoare / detect-dom-changes.html
Created July 9, 2014 08:17
detect dom changes
<html>
<head>
<title>detect node insertion</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<style type="text/css">
@-webkit-keyframes nodeInserted
{
0% {width: 100px;}
@mygoare
mygoare / demo.js
Created June 20, 2014 03:55
click outside of div
$(document).mouseup(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
@mygoare
mygoare / router.js
Created May 9, 2014 09:26
Backbone router
var WorkspaceRouter = Backbone.Router.extend({
routes: {
"help": "help", // #help
"search/:query": "search", // #search/kiwis
"search/:query/p:page": "search" // #search/kiwis/p7
},
help : function () { },
search : function () { }
@mygoare
mygoare / jquery.plugin.js
Created May 9, 2014 08:34
jQuery Plugin snippet
(function($){
function Demo(props, settings)
{
this.demo = null;
if (typeof props == 'object')
{
settings = props;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<style type="text/css">
#line{
width: 700px;
margin: 20px 0;
height: 300px;
background: #eee;
@mygoare
mygoare / README.md
Created April 14, 2014 08:10 — forked from mbostock/.block
Learn to write d3 plugin

Designed by Stephen Few, a bullet chart “provides a rich display of data in a small space.” A variation on a bar chart, bullet charts compare a given quantitative measure (such as profit or revenue) against qualitative ranges (e.g., poor, satisfactory, good) and related markers (e.g., the same measure a year ago). Layout inspired by Stephen Few. Implementation based on work by Clint Ivy, Jamie Love of N-Squared Software and Jason Davies. The "update" button randomizes the values slightly to demonstrate transitions.