Skip to content

Instantly share code, notes, and snippets.

Erik Berlin sferik

Block or report user

Report or block sferik

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pmap.rb
def pmap(enum)
return to_enum(:pmap, enum) unless block_given?
enum.map { |e| Thread.new { yield e } }.map(&:value)
end
# Returns elements in order, as expected.
pmap(1..10) { |e| e } #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Returns elements in nondeterministic order on MRI >= 1.9.3.
# Works as expected on JRuby, Rubinius, and earlier versions of MRI.
View random_emoji.rb
#!/usr/bin/env ruby
EMOJIS = %w[#️⃣ 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ © ® 🌀 🌁 🌊 🌋 🌌 🌍 🌎 🌏 🌐 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 🌝 🌞 🌟 🌰 🌱 🌲 🌳 🌴 🌵 🌷 🌸 🌹 🌺 🌻 🌼 🌾 🌿 🍀 🍁 🍂 🍃 🍄 🎃 🎅 🎆 🎇 🎍 🎎 🎏 🎐 🎑 🎒 🎓 🎵 🎶 🏃 🐀 🐁 🐂 🐃 🐄 🐅 🐆 🐇 🐈 🐉 🐊 🐋 🐌 🐍 🐎 🐏 🐐 🐑 🐒 🐓 🐔 🐕 🐖 🐗 🐘 🐙 🐚 🐛 🐜 🐝 🐞 🐟 🐠 🐡 🐢 🐣 🐤 🐥 🐦 🐧 🐨 🐩 🐪 🐫 🐬 🐭 🐮 🐯 🐰 🐱 🐲 🐳 🐴 🐵 🐶 🐷 🐸 🐹 🐺 🐻 🐼 🐽 🐾 👀 👂 👃 👄 👅 👆 👇 👈 👉 👊 👋 👌 👍 👎 👏 👐 👣 👤 👥 👦 👧 👨 👩 👪 👫 👬 👭 👮 👯 👰 👱 👲 👳 👴 👵 👶 👷 👸 👹 👺 👻 👼 👽 👿 💀 💁 💂 💃 💅 💆 💇 💋 💌 💏 💐 💑 💓 💔 💕 💖 💗 💘 💙 💚 💛 💜 💝 💞 💢 💤 💥 💦 💧 💨 💩 💪 💫 💬 💭 🔥 😀 😁 😂 😃 😄 😅 😆 😇 😈 😉 😊 😋 😌 😍 😎 😏 😐 😑 😒 😓 😔 😕 😖 😗 😘 😙 😚 😛 😜 😝 😞 😟 😠 😡 😢 😣 😤 😥 😦 😧 😨 😩 😪 😫 😬 😭 😮 😯 😰 😱 😲 😳 😴 😵 😶 😷 😸 😹 😺 😻 😼 😽 😾 😿 🙀 🙅 🙆 🙇 🙈 🙉 🙊 🙋 🙌 🙍 🙎 🙏 🚶 🀄 🃏 🅰 🅱 🅾 🅿 🆎 🆑 🆒 🆓 🆔 🆕 🆖 🆗 🆘 🆙 🆚 🇨🇳 🇩🇪 🇪🇸 🇫🇷 🇬🇧 🇮🇹 🇯🇵 🇰🇷 🇷🇺 🇺🇸 🈁 🈂 🈚 🈯 🈲 🈳 🈴 🈵 🈶 🈷 🈸 🈹 🈺 🉐 🉑 🌂 🌃 🌄 🌅 🌆 🌇 🌈 🌉 🌽 🍅 🍆 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍔 🍕 🍖 🍗 🍘 🍙 🍚 🍛 🍜 🍝 🍞 🍟 🍠 🍡 🍢 🍣 🍤 🍥 🍦 🍧 🍨 🍩 🍪 🍫 🍬 🍭 🍮 🍯 🍰 🍱 🍲 🍳 🍴 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍼 🎀 🎁 🎂 🎄 🎈 🎉 🎊 🎋 🎌 🎠 🎡 🎢 🎣 🎤 🎥 🎦 🎧 🎨 🎩 🎪 🎫 🎬 🎭 🎮 🎯 🎰 🎱 🎲 🎳 🎴 🎷 🎸 🎹 🎺 🎻 🎼 🎽 🎾 🎿 🏀 🏁 🏂 🏄 🏆 🏇 🏈 🏉 🏊 🏠 🏡 🏢 🏣 🏤 🏥 🏦 🏧 🏨 🏩 🏪 🏫 🏬 🏭 🏯 🏰 👑 👒 👓 👔 👕 👖 👗 👘 👙 👚 👛 👜 👝 👞 👠 👡 👢 👾 💄
View ahoward.rb
require 'gems'
require 'nokogiri'
require 'octokit'
require 'open-uri'
doc = Nokogiri::HTML(open('https://rubygems.org/profiles/45069'))
repo_names = doc.search('.profile-list ol li a.profile-rubygem').map do |element|
gem = Gems.info(element.text.split(/\s+/)[1])
gem['info'].match('kicks the ass') && gem['homepage_uri'].match(%r{github\.com/ahoward/(\w*)})[1]
View and_or.rb
class BasicObject
def &&(other)
other
end
def ||(other)
self
end
end
View gist:7324739
# Node A:
# iex --sname "nodea"
Process.register self, :iex
# Blocking
receive do
{ :hello, pid } ->
IO.puts "Hello from #{inspect(pid)}"
end
View future.ex
defmodule Future do
def new(fun) do
fn(x) ->
spawn_link fn ->
value = try do
{ :ok, fun.(x) }
rescue
e -> { :error, e }
end
View classes.rb
graph = {}
ObjectSpace.each_object(Class) do |klass|
sup = klass.superclass and graph[klass] = sup
end
puts "digraph{"
graph.map do |key, value|
puts %("#{key}"\n"#{key}"->"#{value}")
end
puts"}"
View square.rb
class Square < Rectangle
def initialize(side)
@side = side
end
def height
@side
end
View 20130611021300_create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.timestamps
end
end
end
View search_results.csv
search_id rank property_id price
3 1 8011 3787
4 1 326 752
5 1 7973 780
5 2 87 13580
5 3 5265 19920
6 1 5981 8349
7 1 5814 6585
9 1 3942 14780
10 1 6925 11286
You can’t perform that action at this time.