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
class Protocol | |
attr_reader :name, :ancestors | |
def initialize(name, ancestors, block) | |
@name = name | |
@ancestors = ancestors | |
@methods = [] | |
instance_exec(&block) | |
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
// ---- | |
// Sass (v3.2.19) | |
// Compass (v0.12.6) | |
// ---- | |
$price_classes: (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pc, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) | |
$price_small: ((0px -122px, 20px, 42px, -5px), (-44px -122px, 13px, 42px, -7px), (-85px -122px, 14px, 42px, -6px), (-129px -122px, 20px, 42px, -6px), (-174px -122px, 20px, 42px, -11px), (-222px -122px, 18px, 42px, -8px), (-269px -122px, 19px, 42px, -9px), (-311px -122px, 16px, 42px, -12px), (-358px -122px, 14px, 42px, -7px), (-404px -122px, 15px, 42px, -6px), (-453px -127px, 1px, 42px, -1px), (-4px -179px, 9px, 42px, -8px), (-38px -179px, 9px, 42px, -11px), (-79px -179px, 8px, 42px, -8px), (-117px -179px, 10px, 42px, -10px), (-164px -179px, 9px, 42px, -8px), (-214px -179px, 6px, 42px, -6px), (-261px -179px, 6px, 42px, -6px), (-308px -179px, 4px, 42px, -5px), (-355px -179px, 7px, 42px, -6px), (-400px -179px, 7px, 42px, -5px)) | |
$price_big: ((0px 0px, 30px, 61px, -5px), (-49px 0px, 32px, 61px, -7px), (-89px 0px, 44px, 61px, -7px), (-138px 0px, 40px, 61p |
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
require 'pp' | |
dict = Hash.new(0) | |
File.open(ARGV[0], 'r') do |src| | |
while line = src.gets | |
line.strip.scan(/\w+/) { |word| dict[word] += 1 } | |
end | |
end | |
pp dict |
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
class Promise | |
class << self | |
alias :make :new | |
end | |
def initialize(block) | |
@result = [] | |
@thread = Thread.new(@result) do |result| | |
result[0] = block.call | |
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
[package] | |
name = "wc" | |
version = "0.0.1" | |
authors = ["stefano"] | |
[dependencies] | |
regex = "0.1.12" | |
regex_macros = "0.1.6" |
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
module ComputedAttributes | |
module ClassMethods | |
def compute(name, components, &block) | |
getter = -> do | |
value = instance_variable_get("@_#{name}") | |
unless value | |
value = instance_exec(&block) | |
instance_variable_set("@_#{name}", value) | |
end | |
value |
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
require 'pp' | |
dice = [0, 0, 1, 2, 3, 4] | |
throws = dice.product(dice, dice, dice, dice) | |
counts = throws.inject(Hash.new(0)) { |t, p| t[p.inject(&:+)] += 1; t } | |
pp counts.map { |(k, v)| [k, (v.fdiv(throws.length) * 100).round(3)] } |
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
#![allow(dead_code)] | |
use std::thread; | |
use std::sync::mpsc::{sync_channel, SyncSender, Receiver}; | |
use std::collections::HashMap; | |
struct Port { | |
rx: Receiver<i32>, | |
tx: SyncSender<i32> | |
} |
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
module XssSanitizer | |
extend ActiveSupport::Concern | |
class Scrubber < Loofah::Scrubber | |
ALLOWED_TAGS = %w( | |
strong span em b u i a | |
h1 h2 h3 | |
div p ul ol li blockquote br | |
) |
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
require "thread" | |
module Synchronizable | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
base.send(:extend, ClassMethods) | |
end | |
module ClassMethods | |
def synchronized(meth) |
OlderNewer