Skip to content

Instantly share code, notes, and snippets.

View uolter's full-sized avatar

Walter Traspadini uolter

View GitHub Profile
@uolter
uolter / init_flaskapp.sh
Created November 9, 2012 13:53
flask project dir structure
#!/bin/bash
APP_NAME="${1}"
if [ "$APP_NAME" = "" ]; then
echo "you must provide an application name!! "
echo "usage: <this script> <app name>"
exit
fi
@uolter
uolter / flaskapp_init.py
Last active October 12, 2015 15:18
flask application basic setup (python flaskapp_init.py -a <myapp> )
#!/usr/local/bin/python
from optparse import OptionParser
import os
PATH_SEPARATOR = os.sep
html_layout = "<!DOCTYPE html>\n" \
"<html>\n" \
@uolter
uolter / jsonp.py
Created November 26, 2012 09:16
jsonp decorator for python
'''
Created on Nov 23, 2012
@author: uolter
'''
from functools import wraps
from flask import request, current_app
@uolter
uolter / vhost_dotcom2013
Created December 4, 2012 14:07
Rewrite rule based on cookie and matching URI for preview landing page
RewriteEngine on
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 5
# Check whether the cookie role exists and whether the url does not contain PRV.shtml
# if so it executes the rewrite rule
RewriteCond %{HTTP_COOKIE} role=(.*)
RewriteCond %{REQUEST_URI} !^.*_PRV.*
RewriteRule /art/(.*).shtml /art/$1_PRV.shtml [NC,QSA]
@uolter
uolter / gist:4258624
Created December 11, 2012 13:39
find and exclude svn directory
find . -type f | grep -v '\.svn' | xargs grep "img/add.png"
@uolter
uolter / gist:4258642
Created December 11, 2012 13:41
svn add new files only
svn st | grep ? | awk '{print $2}' | xargs svn add
@uolter
uolter / huffman.py
Created April 22, 2013 13:33
Huffman code with python
from collections import Counter
import heapq
class Node(object):
def __init__(self, pairs, frequency):
self.pairs = pairs
self.frequency = frequency
def __repr__(self):
return repr(self.pairs) + ", " + repr(self.frequency)
@uolter
uolter / collaborative_filtering.py
Created June 30, 2013 09:31
Simple collaborative filtering in python
import numpy as np
from scipy.optimize import fmin_cg
def cost(p, Y, R, alpha):
"""
Calculates collaborative filtering cost function.
Arguments
----------
@uolter
uolter / cdb.sh
Last active December 28, 2015 05:29
#!/bin/bash
# save this script in your bin directory source it.
# source cdb.sh
# (it would be nice to do that in your bash profile as well.)
# Then you can run the cdb function in every terminal and bookmark any path you like.s
function show_bookmark {
for f in `ls ~/.cd_bookmarks/`
do
@uolter
uolter / counting_string
Created November 26, 2013 15:01
Counting characters in a string putting them in a dictionary
import sys
import unittest
def count(text):
# if the text is None or empty do nothing
if text:
text = text.replace(' ', '')
else:
return None