Skip to content

Instantly share code, notes, and snippets.

@emctoo
emctoo / 0_reuse_code.js
Created August 8, 2014 12:39
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@emctoo
emctoo / gist:aa974f0e1eaa551e0ef8
Last active February 21, 2017 09:10
怎样伪装HTTP协议中的ip地址?

伪装HTTP请求中的IP地址

问题

我们需要做一次测试,由A向B发送HTTP请求,要求这些请求的IP地址是不同的,A会检查HTTP响应以判断是否正确。 问题是逐步明确的。

最初的测试只是要求一个IP发送,很简单,我写了一个Python的脚本,使用urllib库完成了所有的事情。能够值得 一提的是,urllib自己处理了302的跳转,这个出乎我的预料,这个还需要读文档。

但是一到多个IP地址的时候,问题就不那么容易了。

@emctoo
emctoo / the-little-schemer.scm
Created August 27, 2012 07:14
the little schemer practice
;
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
; consist of atoms
(define (lat? l)
(cond
((null? l) #f)
((atom? (car l)) (lat? (cdr l)))
(else #f)))
@emctoo
emctoo / main.cpp
Created July 6, 2012 08:55
example of vector and lambda
int foo(void) {
using namespace std;
std::vector<int> vi(10);
std::vector<int>::iterator iter;
for_each(vi.begin(), vi.end(), [](int &val){ val = rand() % 100; });
for_each(vi.begin(), vi.end(), [](int val) { std::cout << val << ", "; });
cout << endl;
do {
iter = max_element(vi.begin(), vi.end());
@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
@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 / 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 / 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 / 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 / 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