This file contains hidden or 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 PairEnumerator | |
| def pair | |
| if block_given? | |
| if any? | |
| last_item = self.next | |
| each do |this_item| | |
| result = yield(last_item, this_item) | |
| last_item = this_item | |
| result |
This file contains hidden or 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
| (ns look-and-say) | |
| (defn- consecutive [string] | |
| (map first (re-seq #"(.)\1*" string))) | |
| (defn- say [chars] | |
| [(count chars) (first chars)]) | |
| (defn- get-next [string] | |
| (apply str (mapcat say (consecutive string)))) |
This file contains hidden or 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
| inputs = [[:sensor, "input1", 0], [:sensor, "input2", 1], [:sensor, "input3", 2], [:sensor, "input4", 3], [:sensor, "input5", 4], [:sensor, "input6", 5], [:sensor, "input7", 6], [:sensor, "input8", 7], [:sensor, "input9", 8], [:sensor, "input10", 9], [:sensor, "input11", 10], [:sensor, "input12", 11], [:sensor, "input13", 12], [:sensor, "input14", 13], [:sensor, "input15", 14], [:sensor, "input16", 15], [:sensor, "input17", 16], [:sensor, "input18", 17], [:sensor, "input19", 18], [:sensor, "input20", 19]] | |
| outputs = [[:effector, "output1", 0], [:effector, "output2", 39], [:effector, "output3", 40], [:effector, "output4", 41], [:effector, "output5", 42], [:effector, "output6", 43], [:effector, "output7", 44], [:effector, "output8", 45], [:effector, "output9", 46], [:effector, "output10", 47], [:effector, "output11", 48], [:effector, "output12", 49], [:effector, "output13", 50], [:effector, "output14", 51], [:effector, "output15", 52], [:effector, "output16", 53], [:effector, "output17", 54], [:effector, "outp |
This file contains hidden or 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
| def priority(n) | |
| WireMind::Circuits::Circuit.new.tap do |priority| | |
| # I/O | |
| inputs = (1..n).map { |idx| priority.input("input#{idx}") } | |
| outputs = (1..n).map { |idx| priority.output("output#{idx}") } | |
| # Nodes |
This file contains hidden or 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 Bash | |
| def self.clear | |
| print "\e[H\e[2J" | |
| end | |
| end |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| #------------------------------------------------------------------------------ | |
| # Aggregate Print useful information from /proc/[pid]/smaps | |
| # | |
| # pss - Roughly the amount of memory that is "really" being used by the pid | |
| # swap - Amount of swap this process is currently using | |
| # | |
| # Reference: | |
| # http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361 |
This file contains hidden or 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 Kernel | |
| def object_count_change(root = ActiveRecord::Base) | |
| before = Hash.new(0).tap { |hash| ObjectSpace.each_object(root) { |obj| hash[obj.class.to_s] += 1 } } | |
| yield | |
| after = Hash.new(0).tap { |hash| ObjectSpace.each_object(root) { |obj| hash[obj.class.to_s] += 1 } } | |
| Hash.new.tap do |change| | |
| all_keys = (before.keys + after.keys).uniq.sort | |
| all_keys.each { |key| change[key] = after[key] - before[key] } | |
| end |
This file contains hidden or 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 'set' | |
| class Bindings | |
| ################ | |
| # # | |
| # Declarations # | |
| # # | |
| ################ | |
This file contains hidden or 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 'sinatra' | |
| get '/hi' do | |
| "Hello World, brought to you by a shard!" | |
| end | |
| Sinatra::Application.run! # Because we're not running this file directly... |
This file contains hidden or 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 Greeter | |
| def initialize(who) | |
| @who = who | |
| end | |
| def greet | |
| puts "Hello, #{ @who }!" | |
| end |