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 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 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 exposable.rb
require 'set'
module Lotus
module Action
module Exposable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
View stratus-customization.html
<script type="text/javascript">
$(document).ready(function(){
$.stratus({
auto_play: true,
download: false,
key: "Enter your Client ID here",
links: 'http://soundcloud.com/qotsa',
random: true
});
});
View stratus-installation.html
<script type="text/javascript">
$(document).ready(function(){
$.stratus({
key: "Enter your Client ID here",
links: "https://soundcloud.com/zedsdead/sets/somewhere-else-ep"
});
});
</script>
@sferik
sferik / 404_image_swap.js
Created Aug 11, 2009
JQuery code to swap out broken images with a replacement image.
View 404_image_swap.js
$(document).ready(function() {
$('img').error(function(){
$(this).attr('src', 'not_found.png');
});
});
View to_tags.rb
include Stemmable
class String
def to_tags
# lower case
# replace new lines, numbers, and puncuation with spaces
# break words on spaces
# get the word stem
# remove duplicates
# removed stems less than 3 letters
View classes.rb
#!/usr/bin/env ruby
nodes = []
edges = {}
ObjectSpace.each_object(Class) do |klass|
# Skip classes outside the global namespace
next if klass.to_s.include?(':')
# Skip classes like ARGF.class
next if klass.to_s.include?('.')
View winner.rb
require 'curb'
require 'json'
followers_response = Curl::Easy.http_get("http://twitter.com/followers/ids/perpetually.json")
followers = JSON.parse(followers_response.body_str)
winner_id = followers[rand(followers.length)]
users_response = Curl::Easy.http_get("http://twitter.com/users/show/#{winner_id}.json")
winner = JSON.parse(users_response.body_str)
puts "We have a winner!"
@sferik
sferik / config.rb
Created Nov 20, 2009 — forked from merbjedi/config.rb
MerbAdmin DSL
View config.rb
MerbAdmin.config User do
label "Users" # @model.pretty_name
list do
before do
puts "Called before list"
end
fields :name, :description # All columns
filters :publication_date, :retired # All booleans
You can’t perform that action at this time.