Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
@mark
mark / pair.shard.rb
Last active August 29, 2015 14:01
Enumerator # pair
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
(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))))
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
@mark
mark / priority_n.rb
Created December 7, 2013 04:44
Priority/n generator
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
@mark
mark / bash.shard.rb
Created October 24, 2013 04:20
Bash output helpers (stupid early)
module Bash
def self.clear
print "\e[H\e[2J"
end
end
@mark
mark / memstats.rb
Created October 18, 2013 15:52 — forked from kenn/memstats.rb
#!/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
@mark
mark / object_count_change.shard.rb
Created October 15, 2013 19:29
A method for tracking the change in counts of objects in ObjectSpace
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
@mark
mark / bindings.rb
Created October 13, 2013 22:23
Unification in Ruby
require 'set'
class Bindings
################
# #
# Declarations #
# #
################
@mark
mark / sinatra.shard.rb
Last active December 25, 2015 08:19
Running a sinatra app from a shard...
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...
@mark
mark / basic.shard.rb
Created October 12, 2013 02:58 — forked from shard-test/basic.shard.rb
Shard: sample shard
class Greeter
def initialize(who)
@who = who
end
def greet
puts "Hello, #{ @who }!"
end