Skip to content

Instantly share code, notes, and snippets.

View bangedorrunt's full-sized avatar

bangedorrunt ヽ(ヅ)ノ bangedorrunt

View GitHub Profile
@bangedorrunt
bangedorrunt / asyncify_by_getify.js
Last active October 4, 2015 05:12
JavaScript Cookbook
// Copy from `You Don't Know JS: Async & Performance` book
// by Kyle Simpson
function asyncify(fn) {
var orig_fn = fn,
intv = setTimeout(function() {
intv = null;
if (fn) fn();
}, 0);
var Rx = require('rx');
function EventAggregator() {
this._subject = new Rx.Subject(); // Can be ReplaySubject too
}
EventAggregator.prototype.publish = function (type, data) {
this._subject.onNext( { type: type, data: data });
};
@bangedorrunt
bangedorrunt / init.coffee
Last active August 29, 2015 14:20
Custom Binding Key Map for Atom Editor
#
init.coffee
atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-proceeded-by-j': (e) ->
editor = @getModel()
pos = editor.getCursorBufferPosition()
range = [pos.traverse([0,-1]), pos]
lastChar = editor.getTextInBufferRange(range)
if lastChar != "j"
e.abortKeyBinding()
else
@bangedorrunt
bangedorrunt / decimal_to_binary.rb
Last active August 29, 2015 14:20 — forked from alexvbush/decimal_to_binary.rb
Convert Decial to Binary
def dec2bin(number)
number = Integer(number)
if(number == 0) then 0 end
ret_bin = ""
while(number != 0)
ret_bin = String(number % 2) + ret_bin
number = number / 2
end
ret_bin
class Spam:
def do_it(self, message):
print(message)
def do_it_without_self(message)
print(message)
spam = Spam()
bound_func = spam.do_it # Bound method object (automatically)
bound_func('yummy') # Same as spam.do_it('yummy')
@bangedorrunt
bangedorrunt / es5_observer_pattern.js
Last active August 29, 2015 14:21
Design Patterns for JavaScript and Ruby
function Event(sender) {
this._sender = sender;
this._listeners = [];
}
Event.prototype = {
attach: function(listener) {
this._listeners.push(listener);
},
notify: function(args) {
@bangedorrunt
bangedorrunt / build.sublime-build.json
Last active September 29, 2015 04:20
Sublime Text Config
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
@bangedorrunt
bangedorrunt / syntastic.vim
Created May 29, 2015 06:02
Vim Plugin Configs
"" SYNTASTIC CONFIG
"" ----------------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_aggregate_errors = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
@bangedorrunt
bangedorrunt / delegation.js
Last active August 29, 2015 14:25
Mixin Patterns
function delegate (receiver, methods, toProvider) {
methods.forEach(function (methodName) {
receiver[methodName] = function () {
return toProvider[methodName].apply(receiver, arguments);
};
});
return receiver;
}
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->