Skip to content

Instantly share code, notes, and snippets.

View jpanganiban's full-sized avatar

Jesse Panganiban jpanganiban

View GitHub Profile
@jpanganiban
jpanganiban / gist:3826675
Created October 3, 2012 12:26
Scale an image by max_width and/or max_height using Wand
from wand.image import Image
def scale_image(filename, max_width=0, max_height=0, replace=False):
"""Resize an image by filename using wand (Imagemagick)
Returns tuple of filename, width and height."""
# Get filename and file format unsafely.
fname, fmat = filename.split('.')
# Create or use current filename
@jpanganiban
jpanganiban / gist:3826762
Created October 3, 2012 12:55
Unleash the Cracken
import requests
from bs4 import BeautifulSoup
url = 'http://polli.me/events.php?eid=%s&iids=%s'
while True:
response = requests.get('http://polli.me/events.php?ec=605061973')
soup = BeautifulSoup(response.text)
@jpanganiban
jpanganiban / gist:3844261
Created October 6, 2012 07:05
Pygame + OpenCV Real-time Face Detection
#!/usr/bin/env python
from pygame import camera
import pygame
import time
import cv
import os
# Recognition
@jpanganiban
jpanganiban / class.js
Created November 13, 2012 15:41
Backbone.js inspired Class
(function() {
/*
* Class: Javascript Baseclass. Inspired by Underscore.js and Backbone.js
*
* NOTE: Hard dependency on Underscore.js
*
*/
// Safely import underscore
var _ = this._;
@jpanganiban
jpanganiban / asyncnode.js
Created November 24, 2012 17:04
A short demonstration on asynchronous processing with node.
/*
* A short demonstration on asynchronous processing with node.
*/
// Asynchronous adding method
var add = function(a, b, timeout, callback) {
setTimeout(function() {
callback(a + b);
}, timeout * 1000); // Sleeps for <timeout> miliseconds.
};
@jpanganiban
jpanganiban / reactor.py
Created December 6, 2012 01:45
A Very Simple Reactor Pattern Implementation in Python (with Gevent)
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all() # Patch everything
import gevent
import time
class Hub(object):
"""A simple reactor hub... In async!"""
test2sdflk
@jpanganiban
jpanganiban / windmovehooks.el
Last active August 29, 2015 14:13
Emacs Windmove Hooks
(defcustom windmove-pre-move-hook nil
"Hook run before windmove select is triggered."
:group 'windmove
:type 'hook)
(defcustom windmove-post-move-hook nil
"Hook run after windmove select is triggered."
:group 'windmove
:type 'hook)
@jpanganiban
jpanganiban / app.py
Last active August 29, 2015 14:17
MVC pattern.
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/<user_id>/posts')
def api_posts(user_id):
"""Displays a page that returns all the posts created by this user."""