Skip to content

Instantly share code, notes, and snippets.

@maniartech
maniartech / README.md
Created November 25, 2012 17:22 — forked from gudbergur/README.md
watchjs - Watch Javascript/CoffeeScript files for changes, concatenate and uglify

watchjs - Watch Javascript/CoffeeScript files for changes, concatenate and uglify

Just a very simple Python script (that depends on Node executables :p) to concatenate JS/Coffeescript files and compress them. I run a Procfile with Foreman that runs this python script on the js/ directory in small projects + stylus on the .styl files. It's similar to some functionality of Brunch.io but where Brunch is not suited I needed a small wrapper to do this for me.

Usage:

chmod +x watchjs.py

./watchjs.py <directory> <output filename>

@maniartech
maniartech / README
Created November 10, 2012 16:45 — forked from joelambert/README
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php
@maniartech
maniartech / file_to_base64.py
Created November 10, 2012 15:15
A python function which converts file to base64 string.
def file_to_base64(file_path):
"""
A simple function which accepts the file_path and
converts and returns base64 string if specified file
exists. Returns blank string '' if file is not found.
"""
from os import path
if not path.exists(file_path):
return ''
return open(file_path, 'rb').read().encode('base64')
@maniartech
maniartech / date_utils.py
Created November 10, 2012 15:09
Contains useful datetime related functions...
import datetime as dt
from datetime import datetime
import pytz
def local_datetime(timezone = 'Asia/Calcutta'):
"""
Returns the local time based on provided timezone.
"""
utc = datetime.utcnow()
tz = pytz.timezone(timezone)
@maniartech
maniartech / call_counter.py
Created November 10, 2012 14:45
A python decorator that prints the number of time a function has been executed.
def counter(func):
"""
A decorator that prints the number of time a function has been executed.
"""
counter.count = 0
def wrapper(*args, **kwargs):
counter.count = counter.count + 1
res = func(*args, **kwargs)
print func.__name__, "has been used : ", counter.count, "X"
return res
@maniartech
maniartech / benchmark.py
Created November 10, 2012 14:43
A python decorator that prints the function execution duration useful for bench-marking.
def benchmark(func):
"""
A decorator that prints the function execution duration useful for bench-marking.
"""
import time
def wrapper(*args, **kwargs):
t = time.clock()
res = func(*args, **kwargs)
print func.__name__, time.clock()-t
return res