Skip to content

Instantly share code, notes, and snippets.

View jerray's full-sized avatar
🤯

Jerray jerray

🤯
View GitHub Profile
@jerray
jerray / Keyremap4MacBook_private.xml
Created August 26, 2012 07:35
KeyRemap4MacBook的自定义键位映射
<?xml version="1.0"?>
<root>
<item>
<name>7lemon custom settings</name>
<!--
互换option键和command键(虚拟机和远程桌面除外)
外接键盘用。可配合"General"中的"Don't remap Apple's keyboards"使用
-->
<item>
<name>Swap Option_L and Command_L</name>
@jerray
jerray / pre-receive
Created February 26, 2014 02:08
php syntax check for git pre-receive hook
#! /bin/bash
errors_buffer=""
working_dir=""
function php_syntax_check() {
local errors=$(php -l $file 2>&1 | grep "Parse error")
if [ "$errors" != "" ]; then
if [ "$errors_buffer" != "" ]; then
errors_buffer="$errors_buffer\n$errors"
@jerray
jerray / background.coffee
Created September 21, 2014 11:27
A simple chrome message handler for chrome extensions
class BackgroundMessageHandler extends SimpleChromeMessageHandler
onHello: (name) ->
@send "reply", "OK, #{name}"
chrome.runtime.onConnect.addListener (port) ->
handler = new BackgroundMessageHandler(port)
@jerray
jerray / singleton.js
Created September 26, 2014 07:52
JavaScript Singleton
var Singleton = function() {
if (Singleton.prototype._instance) {
return Singleton.prototype._instance;
}
Singleton.prototype._instance = this;
};
var a = new Singleton;
var b = new Singleton;
function modify(modifiers) {
return through2.obj(function(file, encoding, done) {
var stream = this;
function applyModifiers(content) {
(typeof modifiers === 'function' ? [modifiers] : modifiers).forEach(function(modifier) {
content = modifier(content, file);
});

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

@jerray
jerray / 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
@jerray
jerray / javascript_resources.md
Last active August 29, 2015 14:21 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@jerray
jerray / luhn.js
Created January 30, 2016 08:07 — forked from ShirtlessKirk/luhn.js
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
function docker-cli
set vm $argv[1]
if test -s $vm
set vm "default"
end
set host (docker-machine url $vm)
if test -z $host
docker-machine ls
return 1