Skip to content

Instantly share code, notes, and snippets.

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

Serhii Potapov greyblake

🇺🇦
#StandWithUkraine
View GitHub Profile
@greyblake
greyblake / json_benchmark.rb
Created September 19, 2014 08:50
JSON backends comparison
#
# 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'
@greyblake
greyblake / method_visibility_declaration_proposal.rb
Last active August 29, 2015 14:15
Method visibility declaration
# 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
@greyblake
greyblake / rubocop-detect.sh
Created March 19, 2015 14:35
rubocop-detect
# 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"
# 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 {
use std::ops::Mul;
#[derive(Debug)]
struct Vector {
x : f64,
y : f64
}
impl<'a> Mul<f64> for &'a Vector {
type Output = Vector;
#[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;
}