Skip to content

Instantly share code, notes, and snippets.

View tadeck's full-sized avatar

Tom Jaskowski tadeck

View GitHub Profile
@oinopion
oinopion / deco.py
Last active December 2, 2016 08:08
Use contextmanager to create a decorator
# Read docs here: https://docs.python.org/3/library/contextlib.html
>>> from contextlib import contextmanager
>>>
>>>
>>> @contextmanager
... def deco_and_cm():
... print('Hello')
... yield
... print('Goodbye')
...
#import necessary libraries
import cv2
import numpy as np
#capture video from the webcam
cap = cv2.VideoCapture(0)
#load the face finder
face_cascade = cv2.CascadeClassifier('/home/sm/Desktop/haarcascade_frontalface_default.xml')
@tadeck
tadeck / explicit_checker.py
Created August 9, 2013 19:08
Decorator allowing function to receive information on the parameters that were passed to it during call, regardless of whether they were positional or keyword-based.
from functools import partial, wraps
def explicit_checker(func=None, names_arg='explicit_params'):
"""Decorator of function, allowing the function to receive names of attributes
that were explicitly set (either positionally or as keyword arguments). The
explicitly set arguments are received as set assigned to some keyword argument
at function call (default name is "explicit_params").
Example usage:
@ndarville
ndarville / business-models.md
Last active February 27, 2025 10:00
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@tadeck
tadeck / pip_upgrade_all.py
Created October 11, 2012 10:25
pip upgrade all Python modules
"""
Script for upgrading all modules using pip command-line tool.
Source: http://stackoverflow.com/a/5839291/548696
"""
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
@skyl
skyl / kwacros.py
Created February 1, 2012 05:03
Django Template macros with args and kwargs
#
# templatetags/kwacros.py - Support for macros in Django templates
#
# Based on snippet by
# Author: Michal Ludvig <[email protected]>
# http://www.logix.cz/michal
#
# modified for args and kwargs by Skylar Saveland http://skyl.org
#
@atesgoral
atesgoral / LICENSE.txt
Last active January 26, 2017 18:11 — forked from 140bytes/LICENSE.txt
Date formatter that uses human-readable date instance getters instead of cryptic Y/M/D etc. tokens
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Ates Goral <http://magnetiq.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@io41
io41 / paginated_collection.js
Created February 22, 2011 10:10 — forked from zerowidth/paginated_collection.js
Pagination with Backbone.js
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
typeof(options) != 'undefined' || (options = {});
this.page = 1;
typeof(this.perPage) != 'undefined' || (this.perPage = 10);
},
fetch: function(options) {