Skip to content

Instantly share code, notes, and snippets.

@emctoo
emctoo / gist:2627595
Created May 7, 2012 12:51
[OpenCV]operation
// create random Mat
int rows = 10, cols = 10;
cv::Mat m = cv::Mat::zeros(rows, cols, CV_32F);
cv::RNG(cv::getTickCount().fill(m, cv::RNG::UNIFORM, cv::Scalar(0), cv::Scalar(1));
// or you can use randu and randn. I prefer RNG, because I can set the seed.
randu(m, cv::Scalar(0), cv::Scalr(1));
// change one line
cv::mat row = m.row(0);
@emctoo
emctoo / foo.py
Created May 23, 2012 13:59
Windows 下用于自动化工作的Python脚本
#! /usr/bin/env python
import os, shutil
def remove_files_dirs(dir = '.'):
''' remove all files and dirs in cwd '''
print "Current work dir: " + os.getcwd()
judge = raw_input("remove all?[Y/n]")
if judge == 'n':
exit()
@emctoo
emctoo / random_int.hs
Created June 1, 2012 13:28
generate random int
module Main where
import qualified Random
main :: IO ()
main = do
a <- randInt 0 100
putStrLn $ show a
-- generate random number between [lo, hi]
@emctoo
emctoo / get_videos.py
Created June 2, 2012 03:27
Get the video url
# -*- coding = utf-8 -*-
import urllib, urllib2, sys
from BeautifulSoup import BeautifulSoup # for html
def fetch_url(link):
''' '''
f = urllib.urlopen(link)
contents = f.read()
f.close()
@emctoo
emctoo / gist:2882025
Created June 6, 2012 14:00
example of state monad
module Main where
import Control.Monad.State
type IntState = State Int
inc :: IntState ()
-- inc = get >>= put . (+1)
inc = do
v <- get
@emctoo
emctoo / RecursiveContents.hs
Created June 16, 2012 05:39
recursive list contents of a directory
-- from Real World Haskell, Chapter 9
module RecursiveContents (getRecursiveContents) where
import Control.Monad (forM)
import System.Directory (doesDirectoryExist, getDirectoryContents, getCurrentDirectory)
import System.FilePath ((</>))
getRecursiveContents :: FilePath -> IO [FilePath]
getRecursiveContents topdir = do
@emctoo
emctoo / guess.rb
Created June 20, 2012 13:41
try password(to be continued)
require "open-uri"
require "net/http"
Net::HTTP.version_1_2
uri = URI.parse("http://192.168.1.1")
http = Net::HTTP.new(uri.host, uri.port)
while true
@emctoo
emctoo / readCamera.py
Created June 28, 2012 02:16
read camera with OpenCV
#! /usr/bin/env python
import cv2
if __name__ == "__main__":
''' '''
camera = cv2.VideoCapture(0)
while True:
# cv2.VideoCapture return a tuple, (Bool, Numpy.ndarray)
_, im = camera.read()
@emctoo
emctoo / setup.py
Created June 28, 2012 03:11
to ext
from distutils.core import setup
import py2exe
setup(
options = {"py2exe": {"bundle_files": 1, "includes": "numpy"}},
console=["readCamera.py"],
zipfile = None,
)
@emctoo
emctoo / hello.cxx
Created July 3, 2012 14:16
Boost.Python example
// compile by: g++ hello.cxx -shared -fPIC -o hello.so -I/usr/include/python2.7 -lboost_python
#include <string>
#include <boost/python.hpp>
using std::string;
using namespace boost::python;
string hello() { return "Hello, world!"; }
// add a argument