Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nkohari's full-sized avatar

Nate Kohari nkohari

View GitHub Profile

Keybase proof

I hereby claim:

  • I am nkohari on github.
  • I am nkohari (https://keybase.io/nkohari) on keybase.
  • I have a public key whose fingerprint is 00CC 8303 9D13 2418 A583 C02C 1676 90F7 95B6 A091

To claim this, I am signing this object:

{
"name": "awesome-project",
"version": "0.0.1",
"description": "awesomeness",
"dependencies": {
...
},
"scripts": {
"prepublish": "for LINK in 'common' 'data' 'http'; do ln -snf `pwd`/src/$LINK ./node_modules/$LINK; done"
}
@nkohari
nkohari / Environment.coffee
Created June 23, 2014 00:39
Proof-of-concept of AngularJS-inspired dependency injection in React.js
Forge = require 'forge-di'
MonkeyPatcher = require './util/MonkeyPatcher'
Store = require './services/Store'
# Create the Forge and monkey-patch React.createClass() so it can inject dependencies.
forge = new Forge()
MonkeyPatcher.patchReact(forge)
# Register component bindings
forge.bind('store').to.type(Store)
### Keybase proof
I hereby claim:
* I am nkohari on github.
* I am nkohari (https://keybase.io/nkohari) on keybase.
* I have a public key whose fingerprint is 94D8 67EB C67D D304 10DE 5443 2594 E61F 2876 7B1E
To claim this, I am signing this object:
coffee> regex = /foo/g
/foo/g
coffee> str = 'fooz'
'fooz'
coffee> regex.test(str)
true
coffee> regex.test(str)
false
coffee> regex.test(str)
true
class Person {
constructor(public name : string) { }
}
class Employee extends Person {
constructor(name: string, public employer: Employer) {
super(name);
}
}
namespace = (ns) ->
scope = this
tokens = ns.split('.')
passed = []
for token in tokens
passed.push(token)
scope = scope[token] ?= { __namespace: passed.join('.') }
@nkohari
nkohari / removeMatchingClasses.js
Created October 28, 2010 03:04
Given a regex, will remove all CSS classes that match from an element.
jQuery.fn.extend({
removeMatchingClasses: function(pattern) {
return this.each(function() {
var element = jQuery(this);
var classes = element.attr("class").split(/\s+/);
jQuery.each(classes, function(idx, class) {
if (class.match(pattern)) element.removeClass(class);
});
return this;
});
(function($) {
$.fn.extend({
equals: function(match) {
if (!match || !match.length || this.length != match.length)
return false;
for (var idx = 0, len = match.length; idx < len; idx++) {
if (this[idx] != match[idx])
return false;
}
return true;
@nkohari
nkohari / linq.js
Created September 26, 2009 20:13
linq.js
/*
linq.js -- a simple LINQ implementation for javascript
Author: Nate Kohari <nate@enkari.com>
Copyright (C) 2009 Enkari, Ltd.
Released under the Apache 2.0 license (http://www.opensource.org/licenses/apache2.0.php)
*/
Array.prototype.all = function(func) {
var result = true;
this.iterate(function(item) {