Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Panganiban jpanganiban

View GitHub Profile
@jpanganiban
jpanganiban / app.py
Last active Aug 29, 2015
MVC pattern.
View app.py
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."""
@jpanganiban
jpanganiban / windmovehooks.el
Last active Aug 29, 2015
Emacs Windmove Hooks
View windmovehooks.el
(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 / reactor.py
Created Dec 6, 2012
A Very Simple Reactor Pattern Implementation in Python (with Gevent)
View reactor.py
#!/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!"""
@jpanganiban
jpanganiban / asyncnode.js
Created Nov 24, 2012
A short demonstration on asynchronous processing with node.
View asyncnode.js
/*
* 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 / class.js
Created Nov 13, 2012
Backbone.js inspired Class
View class.js
(function() {
/*
* Class: Javascript Baseclass. Inspired by Underscore.js and Backbone.js
*
* NOTE: Hard dependency on Underscore.js
*
*/
// Safely import underscore
var _ = this._;
@jpanganiban
jpanganiban / gist:3844261
Created Oct 6, 2012
Pygame + OpenCV Real-time Face Detection
View gist:3844261
#!/usr/bin/env python
from pygame import camera
import pygame
import time
import cv
import os
# Recognition
@jpanganiban
jpanganiban / gist:3826762
Created Oct 3, 2012
Unleash the Cracken
View gist:3826762
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:3826675
Created Oct 3, 2012
Scale an image by max_width and/or max_height using Wand
View gist:3826675
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