Skip to content

Instantly share code, notes, and snippets.

@g-i-o-
g-i-o- / script.py
Last active January 20, 2019 03:33
Preparing a bunch of AngularJS modules for webpack
import os
import os.path
import re
import ast
def parse_angular_file(file):
with open(file, 'r') as finp:
contents = finp.read()
matches = re.findall('angular.module\w*\(([^)]+)\)', contents)
if matches:
@g-i-o-
g-i-o- / gist:c8e58235b9b40b9bfb5e2c5d229e4beb
Created October 10, 2018 19:51
Icons supported by Native Base
- ios-add
- ios-add-circle
- ios-add-circle-outline
- ios-add-outline
- ios-alarm
- ios-alarm-outline
- ios-albums
- ios-albums-outline
- ios-alert
@g-i-o-
g-i-o- / getCallStack.js
Created August 18, 2016 15:30
Returns the call stack of the function calling this function.
/** Returns the call stack of the function calling this function.
* @return {Array} of function calls up to the function calling this function
*/
function getCallStack(){
try{
throw new Error('! ... Snake!, SNAKE!!!');
} catch(e){
return (e.stack || '').split('\n').filter(function(_){
return /^\s*at\s+.+/.test(_);
}).map(function(_){
@g-i-o-
g-i-o- / serialize-promised-fn.js
Created August 18, 2016 15:15
Serializing promise returning functions: because sometimes you need to process each call one at a time.
angular.module('service.serialize-promised-fn', [
])
/** serializePromisedFn function decorator.
* Decorates a promise-returning function so that
* concurrent calls occur in a serialized manner,
* that is, each call takes turn in a queue and gets
* processed one at a time, in call order.
*/
.service('serializePromisedFn', function($q){
return function serializePromisedFn(fn){
@g-i-o-
g-i-o- / git-on
Last active May 6, 2016 13:53
git-on :: for performing stuff on ther branches without all the (manual) switcharoo.
#!/bin/bash
if [ "$2" != "do" ]; then
echo "Runs a git command on the given branch and returns to this one."
echo "Usage:"
echo " git on [branch] do [normal git command] [arg1] ..."
exit
fi
tbranch="$1"
@g-i-o-
g-i-o- / gist:9e622b9e2a169d8d9419
Created April 21, 2015 00:38
handy dandy pip sh scripts
# Check if you have the required python libraries
cat ./requirements.txt | while read i; do q=`echo $i | cut -d = -f 1`; p=`pip freeze | grep $q`; echo "$i -> $p"; done
# Install the ones you dont
cat ./requirements.txt | while read i; do q=`echo $i | cut -d = -f 1`; p=`pip freeze | grep $q`; if [ "$p" = "" ]; then echo $i; pip install $i; fi; done
@g-i-o-
g-i-o- / angular-konami.js
Created December 10, 2014 18:15
angular module for the konami code
angular.module('angular-konami', [])
.run(function($rootScope){
var code = [38,38,40,40,37,39,37,39,65,66,13];
var stack = [];
$(document).keydown(function(evt){
console.log(evt.which);
stack.push(evt.which);
if(stack.length > code.length){
stack.shift();
} else if(stack.length == code.length){
@g-i-o-
g-i-o- / sample_median.py
Created December 5, 2013 07:03
So... you have an unsorted array of numbers and need a approximation to the median, but you don't want to waste a lot space nor sort the array, not even partially...
def sample_median(X):
"Returns an aproximate for the sample median for the array X"
n, xmax, xmin = 0, 0, 0
for x in X: # O(x)
if n:
xmax = max(x, xmax)
xmin = min(x, xmin)
else:
xmax = xmin = x