Skip to content

Instantly share code, notes, and snippets.

@arches
arches / example.rb
Last active December 25, 2015 03:09
table_print for pure ruby objects
> my_array = [{server: "localhost", ip: "192.168.0.1"}, {server: "google dns", ip: "8.8.8.8"}]
> tp my_array
SERVER | IP
-----------|------------
localhost | 192.168.0.1
google dns | 8.8.8.8
# or with objects
> class ServerInfo
@arches
arches / kaboom.rb
Created October 4, 2013 15:08
so SOMETIMES you can return from inside a block...?
def foobar(&blk)
yield "bar" if blk
"foo"
end
> foobar
=> "foo"
> foobar {|x| puts x}
bar
=> "foo"
@arches
arches / 1 resources
Last active December 21, 2015 05:39
[DRAFT] Job posting for a mobile developer at Aisle50 in Chicago. We believe in diversity and are trying to construct a welcoming interview process for all. Please leave some feedback if you have any ideas how we can improve this posting! Is anything unclear? Unaddressed? Insensitive? Offputting? What else do you want to know about the company, …
I have found these resources particularly helpful in preparing this posting:
Hiring Engineers, a Process
http://hueniverse.com/2013/02/hiring-engineers-a-process/
Join the Lift Team
http://blog.lift.do/post/24988178079/join-the-lift-team
How Etsy Increased Diversity in Its Engineering Department: An Interview with Marc Hedlund
https://www.youtube.com/watch?v=0D66GVc7ztA
@arches
arches / Procfile
Last active February 16, 2021 10:44
A little hack to restart Heroku web dynos when they hit 1000MB of memory
monitor: bundle exec ruby monitor.rb
class Bob
def hey(message)
message ||= ""
message = Message.new(message)
case
when message.shouting?
"Woah, chill out!"
when message.question?
@arches
arches / gol.html
Created May 29, 2013 13:58
Doyle's Game of Conway's Life
<html>
<head>
<script type="text/javascript">
/*! jQuery v2.0.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-2.0.1.min.map
*/
(function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],f="2.0.1",p=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=f.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(
@arches
arches / scheduler.rake
Created May 12, 2013 22:11
rake task to ping a url
desc "Pings PING_URL to keep a dyno alive"
task :dyno_ping do
require "net/http"
if ENV['PING_URL']
puts "Pinging #{ENV['PING_URL']}"
uri = URI(ENV['PING_URL'])
Net::HTTP.get_response(uri)
end
end
@arches
arches / abstract.txt
Last active December 14, 2015 03:29
Concrete Metaprogramming
"Change it until it works" used to be how I approached
metaprogramming - the ruby equivalent of kicking the
tires until the car starts. In this talk we'll gingerly
lift the hood and take a look at what's under there.
We'll start with a high-level overview to get some
context but quickly move on to various ways of inspecting
and manipulating objects, classes, and the metaclass.
You'll leave with a set of tools and techniques to make
metaprogramming more tangible and explorable.
module Discountable
def to_discount_code
DiscountCode.find_by_code(self)
end
end
class DiscountCode < ActiveRecord::Base
def to_discount_code
self
end
@arches
arches / 1_order_collection_extension.rb
Created July 20, 2012 14:25
Write methods against a collection of ActiveRecord objects
module OrderCollectionExtension
def revenue
self.sum(:payment_total_in_cents)
end
end
Order.non_zero_price.extend(OrderCollectionExtension).revenue