Skip to content

Instantly share code, notes, and snippets.

View MarchLiu's full-sized avatar

Mars Liu MarchLiu

View GitHub Profile
@MarchLiu
MarchLiu / http request use put method
Created July 28, 2013 17:17
how to put a http request in python code
import urllib2
opener = urllib2.build_opener(urllib2.HTTPHandler)
with open("/storage/pic/logo.png") as f:
data=f.read()
request = urllib2.Request("http://localhost:8080/logo.png", data=data)
request.add_header("Content-Type", "image/png")
request.get_method = lambda:"PUT"
url = opener.open(request)
@MarchLiu
MarchLiu / gist:8afa138de6485f8041cc
Created May 26, 2015 05:49
expected `core::iter::Map<&mut &core::iter::Iterator<Item=A>, F>`, found `core::iter::Map<&mut core::iter::Iterator<Item=A>, F>`
use std::vec::Vec;
use std::iter::{Iterator, Map};
pub trait Functor<A, B, F: FnMut(&A) -> B> {
type Output;
fn fmap(&self, f: F ) -> <Self as Functor<A, B, F>>::Output;
}
pub trait FunctorMut<A, B, F: FnMut(&A) -> B> {
type Output;
@MarchLiu
MarchLiu / gist:6401a95252c5d809776e
Created June 12, 2015 08:05
this is a part of the state and either parsec
pub trait BinComb<L, R, T> {
type S;
fn left(&self)->&mut Parsec<L, Self::S>;
fn right(&self)->&mut Parsec<R, Self::S>;
}
pub struct Either<R, S>{
x: Parsec<R, S>,
y: Parsec<R, S>,
}
//either parsec
pub fn either<T, R>(x: Parsec<T, R>, y: Parsec<T, R>)->Either<T, R> {
Either{
x: x,
y: y,
}
}
impl<'a, T, R> FnOnce<(&'a mut VecState<T>, )> for Either<T, R> {
type Output = Status<R>;
@MarchLiu
MarchLiu / gist:787e85cc5515894d2fd5
Last active August 29, 2015 14:24
sep and sep1
var sep = function(s, p) {
var fun = function(state){
return choice(sep1(s, p), [])
};
parsec(fun);
return fun;
};
sep.prototype = parsec;
var sep1 = function(s, p) {
package main
import (
"fmt"
"github.com/Dwarfartisan/pgears"
"time" )
var Engine *pgears.Engine
type Usertbl struct{
Name string `field:"name" pk:"true"`
Signup_date time.Time `field:"signup_date"`
}
@MarchLiu
MarchLiu / sample.clj
Created April 4, 2016 06:54
模拟 haskell do 环境的 clojure 宏
;; parsec.clj
(defmacro =>>
"Threads the state through the parsers. Inserts state as the
parameter in the first parser. If there are more parsers,
inserts the first residue as the second state in second parser, etc.
If a parser throw exception, throw it and exit, else return all bind result
as a dictionay and residue data.
"
[data & forms]
(loop [data (list (list return {}) data), forms forms]
@MarchLiu
MarchLiu / elements.json
Created July 4, 2016 13:02
Euclid's Elements relations. Each json item for each element.
{"name":"C.N.1","description":"Things which are equal to the same thing are also equal to one another.","references":[]}
{"name":"C.N.2","description":"If equals be added to equals, the wholes are equal.","references":[]}
{"name":"C.N.3","description":"If equals be subtracted from equals, the remainders are equal.","references":[]}
{"name":"C.N.4","description":"Things which coincide with one another are equal to one another.","references":[]}
{"name":"C.N.5","description":"The whole is greater than the part.","references":[]}
{"name":"Def.1.1","description":"A point is that which has no part.","references":[]}
{"name":"Def.1.10","description":"When a straight line set up on a straight line makes the adjacent angles equal to one another, each of the equal angles is right, and the straight line standing on the other is called a perpendicular to that on which it stands.","references":[]}
{"name":"Def.1.11","description":"An obtuse angle is an angle greater than a right angle.","references":[]}
{"name":"Def.1.12