Skip to content

Instantly share code, notes, and snippets.

@mrluanma
mrluanma / http_range.py
Created July 26, 2011 14:58
HTTP Range header 的用法, 也就是传说中的断点续传, Python httplib2 示例.
1. 首先验证 web server 支持断点续传:
(django13)[www@mail ~]$ curl -i http://127.0.0.1/123.txt
HTTP/1.1 200 OK
Server: nginx/0.8.54
Date: Tue, 26 Jul 2011 14:41:53 GMT
Content-Type: text/plain
Content-Length: 10
Last-Modified: Tue, 26 Jul 2011 14:32:35 GMT
Connection: keep-alive
@wardbekker
wardbekker / .erlang
Created August 8, 2011 06:41
Autoloading of modules
%% autoload all modules that are in the code:path() and reside in the user directory
%% put in ~/.erlang
[code:ensure_loaded(list_to_atom(filename:rootname(filename:basename(F))))
|| P <- lists:filter(fun(Path) -> string:str(Path, os:getenv("USER")) > 0 end, code:get_path()), F <- filelib:wildcard(P ++ "/*.beam")].
@klange
klange / image-to-ansi.py
Created January 27, 2012 06:29 — forked from MicahElliott/colortrans.py
Convert images to ANSI escape sequences
#! /usr/bin/env python
""" Convert an image (argv[1]) to an ANSI text string (xterm-256color)
Original readme from colortrans.py follows:
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
@codysoyland
codysoyland / virtualenv-auto-activate.sh
Created March 25, 2012 18:34
virtualenv-auto-activate
#!/bin/bash
# virtualenv-auto-activate.sh
#
# Installation:
# Add this line to your .bashrc or .bash-profile:
#
# source /path/to/virtualenv-auto-activate.sh
#
# Go to your project folder, run "virtualenv .venv", so your project folder
# has a .venv folder at the top level, next to your version control directory.
@koostudios
koostudios / main.coffee
Created May 5, 2012 08:32
BrowserID: Logging in with BrowserID, Passport and NodeJS
# Variables
exp = require 'express'
app = exp.createServer()
pass = require 'passport'
BrowserID = require('passport-browserid').Strategy
# Passport Serialize and Deserialize Functions
pass.serializeUser (user, done) ->
done null, user.email
@minikomi
minikomi / server.go
Created June 13, 2012 08:33
random go from golang
package main
import (
"fmt"
"net/http"
)
func broadcaster(in chan chan string, out chan chan string, listen chan string) {
chans := map[chan string]bool{}
for {
@mike-zhang
mike-zhang / udpProxyServer.cpp
Created October 14, 2012 15:32
a simple udp proxy server (cpp code)
/*
File : udpProxyServer.cpp
Author : Mike
E-Mail : [email protected]
*/
#include <cstdlib>
#include <cstddef>
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
@philipcristiano
philipcristiano / faces_example.py
Created June 18, 2013 14:10
Resize and crop an image based on OpenCV detected faces
import sys
from PIL import Image, ImageDraw
try:
import cv
except ImportError:
print 'Could not import cv, trying opencv'
import opencv.cv as cv
# Installing OpenCV python libs on mac to work with virtualenv
# OpenCV 2.4.3
# Python 2.7.3 installed with brew
# assuming you have virtualenv, pip, and python installed via brew
# assuming $WORKON_HOME is set to something like ~/.virtualenvs
# using homebrew - make sure we're current
brew update
import cv2
import cv2.cv as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
flags=cv.CV_HAAR_SCALE_IMAGE):
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,