This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# user system total real | |
# json_gem 1.970000 0.000000 1.970000 ( 1.969385) | |
# yajl 2.090000 0.000000 2.090000 ( 2.096399) | |
# oj 1.240000 0.000000 1.240000 ( 1.234021) | |
# json_pure 23.400000 0.000000 23.400000 ( 23.432088) | |
# | |
require 'benchmark' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Since ruby 2.1, method definition returns a name of a method as a symbol. | |
# Example: | |
def aaa; end # => :aaa | |
# How we do it currently | |
class SomeClass | |
def pub_meth | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Finds ruby files that was changed in HEAD against passed branch | |
# and run rubocop with them. It's supposed to help to detect | |
# rubocop offenses introduced by YOU. | |
# | |
# Examle: | |
# rubocop-detect develop | |
function rubocop-detect(){ | |
local branch=${1:-master} | |
echo -e "\e[1mCOMPARING:\e[0m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Benchmark of djb2, sdbm and lose lose hashing algorithms | |
# Algorithm descriptions: http://www.cse.yorku.ca/~oz/hash.html | |
# Output | |
# | |
# ===== djb2 ===== | |
# Values: 5000000 | |
# Collisions: 2988 | |
# Time: 0.76589 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let funcs = [ | |
("+", sum as fn(f64, f64) -> f64), | |
("-", sub), | |
("*", mult), | |
("/", div), | |
("^", pow) | |
]; | |
for &(name, func) in funcs.iter() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let v1 = vec![4, 8, 12, 16]; | |
let v2 = mult(&v1, 10); | |
pv("v1", &v1); | |
pv("v2", &v2); | |
println!(""); | |
println!("{}", v1[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait HasArea { | |
fn area(&self) -> f64; | |
} | |
struct Cyrcle { | |
radius : f64, | |
} | |
impl HasArea for Cyrcle { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Mul; | |
#[derive(Debug)] | |
struct Vector { | |
x : f64, | |
y : f64 | |
} | |
impl<'a> Mul<f64> for &'a Vector { | |
type Output = Vector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Point { | |
x : f64, | |
} | |
trait Add { | |
fn add(&self, &Self) -> Self; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Point { | |
x : f64, | |
} | |
trait Math : { | |
fn sub(&self, &Self) -> Self; | |
fn add(&self, &Self) -> Self; | |
} |