Skip to content

Instantly share code, notes, and snippets.

@kyletolle
kyletolle / gist:9939366
Created April 2, 2014 17:51
RubyProf outline
RubyProf.start
# Code to profile...
result = RubyProf.stop
# Print a graph to an HTML file, sorted by time spend in children.
File.open('profile_output.html', 'w') do |file|
printer = RubyProf::GraphHtmlPrinter.new result
printer.print(file, sort_method: :children_time)
irb(main):002:0> require 'bigdecimal'
=> true
irb(main):003:0> v = BigDecimal("7.1762")
=> #<BigDecimal:7f8905213dc0,'0.71762E1',18(18)>
irb(main):004:0> v.truncate(2).to_s('F')
=> "7.17"
irb(main):005:0> w = BigDecimal("4.2")
=> #<BigDecimal:7f890522c5f0,'0.42E1',18(18)>
irb(main):006:0> w.truncate(2).to_s('F')
=> "4.2"
@mikepack
mikepack / 1_inheritance.rb
Last active August 29, 2015 14:07
5 Composition Techniques
class Animal
def run
puts 'running'
end
end
Animal.new.run #=> running
class Wolf < Animal
def follow_pack
@searls
searls / gist:a644a89017022912b2c6
Last active August 29, 2015 14:11
Some thoughts on small teams and headquarters HQs

This is a simple little note I wrote down when talking to another company owner on the topic of moving a fully distributed team (with some folks in the same city) to a mostly-distributed team with an HQ office in a single city. It's not necessarily useful as general advice beyond that

why thoughtful physical location matters

I often advise clients that are actively focused on improving their teams to either embrace a fully-distributed team or a fully-colocated one, and to avoid other permutations of organization. Patterns that I see a lot:

  • small satellite offices off a large HQ
  • a handful of remote folk off a large HQ
  • n similarly-sized engineering offices
@otaviomedeiros
otaviomedeiros / alias_matcher.rb
Created March 1, 2012 16:18
RSpec matcher for alias_method
# RSpec matcher for alias_method.
# https://gist.github.com/1950961
# Usage:
#
# describe User do
# it { should alias_from(:username).to(:email) }
# end
RSpec::Matchers.define :alias_from do |alias_method|
@satlavida
satlavida / nested.coffee
Created February 5, 2012 14:12
Nested classes in CoffeeScript
class AlertMyFriends
class AlertMyFriends::Show
constructor: ->
alert "Hello Friends"
amf = new AlertMyFriends
al = new amf.Show()
@infotroph
infotroph / pandoc-word-sectionbreak.hs
Last active June 6, 2018 05:42
Pandoc filter: convert horizontal rules into section breaks for Word output
#!/usr/bin/env runhaskell
{-
Pandoc filter to replace horizontal rules with hard section breaks when output is in Word format.
Credits: This is a very lightly adapted version of a `\newpage` filter
previously described on pandoc-discuss:
https://groups.google.com/forum/#!topic/pandoc-discuss/FzLrhk0vVbU
describe Item do
describe "total" do
before do
@item = Item.new
@item.stub!(:calculate_total => 123)
end
it "returns the calculated total" do
@item.total.should == 123
end
[aaron@TC omglolwut (master)]$ cat lib/tasks/disable_autoload_during_migrations.rake
task :disable_autoload do
ActiveSupport::Dependencies.class_eval do
extend Module.new {
def load_file(path, const_paths = loadable_constants_for_path(path))
return if path.starts_with? File.join(Rails.application.root, 'app', 'models')
super
end
}
end
#!/bin/bash
# Install sleepwatcher
cd /tmp
curl -O http://www.bernhard-baehr.de/sleepwatcher_2.2.tgz
tar -zxvf sleepwatcher_2.2.tgz
cd sleepwatcher_2.2
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
sudo cp sleepwatcher /usr/local/sbin
sudo cp sleepwatcher.8 /usr/local/share/man/man8
sudo cp config/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents