Skip to content

Instantly share code, notes, and snippets.

@philoye
philoye / heartbeat.rb
Created August 11, 2014 00:49
Simple rack middleware to provide a health monitor for rails app using sidekiq, memcache, and activerecord.
module Rack
class Heartbeat
def initialize(app)
@app = app
end
def call(env)
if env['PATH_INFO'] == "/pulse"
@messages = []
@hopsoft
hopsoft / db.rake
Last active February 5, 2025 13:23
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@juliocesar
juliocesar / gist:11162250
Last active August 29, 2015 14:00
Macbook Pro (Retina, mid 2012)

15" Macbook Pro (Retina, mid 2012)

Yo!

I'm selling my Macbook Pro Retina (mid 2012). This machine has served me well in many battles. It has witnessed me unleash the fury of a thousand suns while building many Internets around the world.

The specs:

  • Display: 15" Retina display.
  • Processor: 4 cores 2.3GHz Intel Core i7.
@benhoskings
benhoskings / gist:8344953
Created January 10, 2014 00:46
Ben's guide to painless ruby switching with chruby
1) Latest brews.
$ brew update
2) Install packages.
$ brew install chruby ruby-install selecta
3) Load chruby when the shell inits.
echo >> ~/.zshrc
if [ -d /usr/local/opt/chruby ]; then
. /usr/local/opt/chruby/share/chruby/chruby.sh
@jvns
jvns / interview-questions.md
Last active April 17, 2025 16:25
A list of questions you could ask while interviewing

A lot of these are outright stolen from Edward O'Campo-Gooding's list of questions. I really like his list.

I'm having some trouble paring this down to a manageable list of questions -- I realistically want to know all of these things before starting to work at a company, but it's a lot to ask all at once. My current game plan is to pick 6 before an interview and ask those.

I'd love comments and suggestions about any of these.

I've found questions like "do you have smart people? Can I learn a lot at your company?" to be basically totally useless -- everybody will say "yeah, definitely!" and it's hard to learn anything from them. So I'm trying to make all of these questions pretty concrete -- if a team doesn't have an issue tracker, they don't have an issue tracker.

I'm also mostly not asking about principles, but the way things are -- not "do you think code review is important?", but "Does all code get reviewed?".

@sgerrand
sgerrand / roro.rb
Created November 12, 2013 11:25
An example using Minitest::Mock, using the version (4.7) available in the Ruby standard library.
class Roro
def initialize(host, speakers = [])
@host = host
@speakers = speakers
end
def start
@host.speak
end
end
@anotheruiguy
anotheruiguy / web-fonts-asset-pipeline.md
Last active April 12, 2025 18:16
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@blaix
blaix / service-objects.md
Created June 12, 2013 11:04
Martin Fowler on Service Objects via the Ruby Rogues Parley mailing list

On Tue, Mar 12, 2013 at 1:26 PM, Martin Fowler [email protected] wrote:

The term pops up in some different places, so it's hard to know what it means without some context. In PoEAA I use the pattern Service Layer to represent a domain-oriented layer of behaviors that provide an API for the domain layer. This may or may not sit on top of a Domain Model. In DDD Eric Evans uses the term Service Object to refer to objects that represent processes (as opposed to Entities and Values). DDD Service Objects are often useful to factor out behavior that would otherwise bloat Entities, it's also a useful step to patterns like Strategy and Command.

It sounds like the DDD sense is the sense I'm encountering most often. I really need to read that book.

The conceptual problem I run into in a lot of codebases is that rather than representing a process, the "service objects" represent "a thing that does the process". Which sounds like a nitpicky difference, but it seems to have a real impact on how people us

@toolmantim
toolmantim / development.rb
Last active December 13, 2015 18:48
Filtering asset requests from the development log using Rails 3.2
# Add the following configuration to your config/environments/development.rb file
#
# This will set the Rails to log to STDOUT (insetad of log/development.log) as well
# as tag all assets request log lines with [assets]
#
# You can then pipe it into grep to filter out the asset lines
#
# tail -f log/development.rb | grep -v '\[assets\]'
#
# If you log to STDOUT rather than log/development.rb then you can:
@wilkie
wilkie / experiment.rb
Created November 19, 2012 23:51
Code to produce a probability distribution of how likely a gender breakdown in conference speakers is, and also to experiment to produce the result
# This program will select at random a set of speakers and look at the gender breakdown given 20% women
total_speakers = 15
percentage_of_women = 0.25
hist, list, results = {}, [], []
(1000 * (1 - percentage_of_women)).floor.times{list << 0}
(1000 * percentage_of_women).floor.times{list << 1}