Skip to content

Instantly share code, notes, and snippets.

View sferik's full-sized avatar

Erik Berlin sferik

View GitHub Profile
@tomstuart
tomstuart / gist:4382332089a8402bf475
Created April 30, 2014 12:59
Person#age gives the wrong answer for a person who hasn’t had their birthday yet this year
require 'active_support/time'
require 'active_support/testing/time_helpers'
require 'rspec/expectations'
include ActiveSupport::Testing::TimeHelpers
include RSpec::Matchers
class Person < Struct.new(:birthday)
def age
Date.today.year - birthday.year
end
@georgeguimaraes
georgeguimaraes / and_begin_idiom.rb
Created September 1, 2010 17:11
And Begin Idiom to avoid if with assignments
# After reading this comment
# http://avdi.org/devblog/2010/08/02/using-and-and-or-in-ruby/#comment-1098 ,
#
# I became aware of a cool idiom for Ruby.
#
# I've seen this in a lot of cases:
if (variable = expression_or_method(options))
variable.calculate_something
do_other_stuff(variable)
@leemartin
leemartin / stratus-installation
Created March 1, 2012 04:02
Stratus Installation
<script type="text/javascript">
$(document).ready(function(){
$.stratus({
links: 'http://soundcloud.com/foofighters/sets/wasting-light'
});
});
</script>
@Indamix
Indamix / gist:2226290
Created March 28, 2012 13:44
css 3d bended shadow
.bended-shadow {position:relative}
.bended-shadow::before, .bended-shadow::after {
content: '';
position: absolute;
width: 60%;
height: 20px;
-webkit-box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
-ms-box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
@joshsusser
joshsusser / injections.rb
Created May 9, 2012 16:31
Challenge: implement enumerable methods using #inject instead of #each.
def collect(&block)
inject([]) { |memo, obj| memo << block.call(obj) }
end
def detect(&block)
inject(nil) { |memo, obj| memo ||= obj if block.call(obj) }
end
def reject(&block)
inject([]) { |memo, obj| block.call(obj) ? memo : memo << obj }
@mislav
mislav / geoip_service.rb
Created September 3, 2012 11:48
Simple GeoIP service class using freegeoip.net and Faraday
require 'faraday_middleware'
require 'hashie/mash'
# Public: GeoIP service using freegeoip.net
#
# See https://github.com/fiorix/freegeoip#readme
#
# Examples
#
# res = GeoipService.new.call '173.194.64.19'
Subject: [ruby-dev: 46350] RubySpec maintainer
From: Yukihiro Matsumoto <matz ruby.or.jp>
Date: Fri, 2 Nov 2012 10:43:12 +0900
Yukihiro Matsumoto is
Dis was've been on a grand scale and to Brian Ford at RubyConf.
It is not matter since it's always on it (truth is
Specification originally not good), so less contribution from Japan to RubySpec
Checking to what it is not, the distinction between behavior and specifications of chance
@stephencelis
stephencelis / emoji.txt
Created April 3, 2012 18:38
iOS 6 / Mountain Lion Emoji
2139 ℹ INFORMATION SOURCE
23EB ⏫ BLACK UP-POINTING DOUBLE TRIANGLE
23EC ⏬ BLACK DOWN-POINTING DOUBLE TRIANGLE
23F0 ⏰ ALARM CLOCK
23F3 ⏳ HOURGLASS WITH FLOWING SAND
26C5 ⛅ SUN BEHIND CLOUD
26D4 ⛔ NO ENTRY
2705 ✅ WHITE HEAVY CHECK MARK
2753 ❓ BLACK QUESTION MARK ORNAMENT
2757 ❗ HEAVY EXCLAMATION MARK SYMBOL
@JoshCheek
JoshCheek / png_dots.rb
Last active January 11, 2016 15:51
Freaky Dot Patterns, based on this video by Numberphile: https://www.youtube.com/watch?v=QAja2jp1VjE
# Pics at https://twitter.com/josh_cheek/status/681062928980783104
# Gif at https://twitter.com/josh_cheek/status/686465757476065280
# Based on https://www.youtube.com/watch?v=QAja2jp1VjE
require 'chunky_png'
require 'matrix'
include Math
def white
ChunkyPNG::Color.rgb(255, 255, 255)
end
@judofyr
judofyr / fizzbuzz.rb
Created August 1, 2012 21:37 — forked from JEG2/fizzbuzz.rb
Writing FizzBuzz with flip-flops
a=b=c=(1..100).each do |num|
print num, ?\r,
("Fizz" unless (a = !a) .. (a = !a)),
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
?\n
end