Skip to content

Instantly share code, notes, and snippets.

-- tagsoup 0.13.1 package, ghc 7.8.2
*Main> :m +Text.HTML.TagSoup
*Main Text.HTML.TagSoup> :t renderOptions { optEscape = id, optMinimize = const True, optRawTag = const True }
<interactive>:1:1:
No instance for (Text.StringLike.StringLike t0)
arising from a use of ‘renderOptions’
The type variable ‘t0’ is ambiguous
Note: there are several potential instances:
instance Text.StringLike.StringLike
@nagisa
nagisa / output
Last active August 29, 2015 14:11
Rust being slower when optimised?
$ rustc slower.rs --test -C no-stack-check -O
$ ./slower --bench
running 1 test
test bench_stdrng_u64 ... bench: 187 ns/iter (+/- 14) = 42 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
$ rustc slower.rs --test -C no-stack-check
$ ./slower --bench
src/net.rs:99:34: 99:53 error: type `&net::Host` does not implement any method in scope named `update_tables`
src/net.rs:99 self.update_tables(c, p);
^~~~~~~~~~~~~~~~~~~
src/net.rs:99:34: 99:53 note: found defined static methods, maybe a `self` is missing?
src/net.rs:157:5: 159:6 note: candidate #1 is defined in an impl for the type `net::Host`
src/net.rs:157 fn update_tables(source: IP, packet: &RIPv1Packet) {
src/net.rs:158
src/net.rs:159 }
enum B {}
impl B {
fn bb() -> i32 { 0 }
}
fn main() {
match 0 {
B::bb => {}
}
trait Monoid<T> {
let zero : T;
// Arbitrary 2 argument functions may be used as binary operators
let `+` : T → T → T;
}
@nagisa
nagisa / gist:1152069
Created August 17, 2011 17:22
Split by sentence
#settings
DESCRIPTION_LEN = 5
DESCRIPTION_SPLITTER = r'(?<=[.?!。!?])\s+'
#Modelis
def get_description(self, splitter = re.compile(settings.DESCRIPTION_SPLITTER)):
if self.short_content:
return self.short_content
else:
return ' '.join(splitter.split(self.content, settings.DESCRIPTION_LEN)[:-1])
@nagisa
nagisa / gist:1170125
Created August 25, 2011 06:59
Benchmarking JavaScript
start = new Date();
for(i=0; i<1000000; i++){String(Math.floor(Math.random()*1000000))};
console.log(new Date()-start)
>> 2054
start = new Date();
for(i=0; i<1000000; i++){String(~~(Math.random()*1000000))};
console.log(new Date()-start)
>> 1752
@nagisa
nagisa / cookie.py
Created August 28, 2011 14:18
Cookie
body{background:#ffffff;color:#111111;}
h1,h2,h3,h4,h5,h6{color:#222222;}
.content{box-shadow:0 0 5px #111111;-moz-box-shadow:0 0 5px #111111;-webkit-box-shadow:0 0 5px #111111;border:#000 solid;border-width:0 1px;}
#logo{background:url("http://kazlauskas.me/m/image/logo.svg") 100%;height:100px;}
>> stash.set('a', function(){return true;})
<< 1
>> stash.add('a', 'adding string') //It shouldn't replace old value.
<< 1
>> stash.get('a') //Unexpected value, we would expect old function.
<< "adding string"
//For people who may want replace action, they could use stash.cut(); and stash.set(); again.