Skip to content

Instantly share code, notes, and snippets.

View greyblake's full-sized avatar
🇺🇦
#StandWithUkraine

Serhii Potapov greyblake

🇺🇦
#StandWithUkraine
View GitHub Profile
# Override some stuff to detect FacotoryGirl usage out of `it`
module RSpec
module Core
class ExampleGroup
class << self
# redefine to do nothing
def it(*args)
end
class SocialNotifier
include Celluloid
attr_reader :status
def intialize(&block)
@block = block
end
def run
@greyblake
greyblake / show_page.rb
Created November 21, 2013 19:22
My tiny useful method for Capybara webkit driver to see screenshot in one command when I debug
def show_page
filename = "/tmp/shot.png"
driver = page.driver
driver.save_screenshot(filename)
system "eog #{filename}"
end
# 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
#
fn main() {
let funcs = [
("+", sum as fn(f64, f64) -> f64),
("-", sub),
("*", mult),
("/", div),
("^", pow)
];
for &(name, func) in funcs.iter() {
fn main() {
let v1 = vec![4, 8, 12, 16];
let v2 = mult(&v1, 10);
pv("v1", &v1);
pv("v2", &v2);
println!("");
println!("{}", v1[2]);
trait HasArea {
fn area(&self) -> f64;
}
struct Cyrcle {
radius : f64,
}
impl HasArea for Cyrcle {
#[derive(Debug)]
struct Point {
x : f64,
}
trait Add {
fn add(&self, &Self) -> Self;
}
#[derive(Debug)]
struct Point {
x : f64,
}
trait Math : {
fn sub(&self, &Self) -> Self;
fn add(&self, &Self) -> Self;
}
use std::ops::Mul;
#[derive(Debug)]
struct Vector {
x : f64,
y : f64
}
impl<'a> Mul<f64> for &'a Vector {
type Output = Vector;