Skip to content

Instantly share code, notes, and snippets.

@ccorcos
ccorcos / okcancel.js
Created April 21, 2014 03:06
ok cancel events for meteor
////////// Helpers for in-place editing //////////
// Returns an event map that handles the "escape" and "return" keys and
// "blur" events on a text input (given by selector) and interprets them
// as "ok" or "cancel".
okCancelEvents = function(selector, callbacks) {
var ok = callbacks.ok || function() {};
var cancel = callbacks.cancel || function() {};
var events = {};
events['keyup ' + selector + ', keydown ' + selector] =
@ccorcos
ccorcos / newNode.js
Created April 21, 2014 03:10
ok cancel event
Session.setDefault("parents", [])
Session.setDefault("children", [])
Template.main.rendered = function() {
// autoupdate the parents and children
Deps.autorun(function() {
nodeId = Session.get("editNode");
if (nodeId) {
parents = parentsOf(nodeId)
children = childrenOf(nodeId)
@ccorcos
ccorcos / completely.js
Created April 21, 2014 04:24
complete.ly (js) customized for semantic-ui
/**
* complete.ly 1.0.0
* MIT Licensing
* Copyright (c) 2013 Lorenzo Puccetti
*
* This Software shall be used for doing good things, not bad things.
*
**/
completely = function completely(container, config) {
config = config || {};
@ccorcos
ccorcos / gist:11132188
Created April 21, 2014 04:24
how to use hotkeys.js
$('body').hotKey({
key: 's',
modifier: 'cmd'
}, saveNote)
$('body').hotKey({
key: 'esc',
}, cancelNote)
@ccorcos
ccorcos / gist:11196516
Created April 22, 2014 22:25
Some convenient helpers for interacting via the commandline in python
def wait(msg=''):
print msg
a = raw_input("press <enter> to continue...")
def yesno(msg):
print msg
a = raw_input('y/n: ')
if a == 'y':
return True
@ccorcos
ccorcos / gist:11197543
Created April 22, 2014 23:10
Python NumPy: pretty print multidimensional ndarray
from pylab import *
from pprint import pprint
def arrayToList(arr):
if type(arr) == type(array([])):
return arrayToList(arr.tolist())
elif type(arr) == type([]):
return [arrayToList(a) for a in arr]
else:
@ccorcos
ccorcos / matrixAnnoyance.py
Created April 22, 2014 23:43
Python NumPy: this function takes a list of matrices and converts it into a 2D matrix filling in zeros where no matrix is specified
from pylab import *
from pprint import pprint
def arrayToList(arr):
if type(arr) == type(array([])):
return arrayToList(arr.tolist())
elif type(arr) == type([]):
return [arrayToList(a) for a in arr]
else:
@ccorcos
ccorcos / git.txt
Created May 1, 2014 22:08
fix gitignore my clearing git cache
When you're gitignore is not working as it should, clear the cache and re-commit the files. All thanks to this amazing answer:
http://stackoverflow.com/questions/11451535/gitignore-not-working
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
@ccorcos
ccorcos / bash_profile
Created May 31, 2014 23:20
My custom terminal settings
export PS1='\[\033[31m\]$ \[\033[32m\]'
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
@ccorcos
ccorcos / parallel.py
Created June 7, 2014 02:39
parallel processing in python
from multiprocessing import Pool
def f(x):
print x
return x**2
if __name__ == '__main__':
# 8 processors
p = Pool(8)
a = range(100)