Skip to content

Instantly share code, notes, and snippets.

ONE = 1
TWO = 2
def plus(a, b)
a + b
end
def minus(a, b)
a - b
end
@ubermajestix
ubermajestix / inspector.rb
Created September 5, 2012 20:35
Override inspect on ruby objects
# When an RSpec test like this fails,
#
# @my_array.should == [@some_model, @some_model2]
#
# RSpec will call inspect on each of the objects to "help" you figure out
# what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying
# to figure out why `@my_array` is not made up of `@some_model` and `@some_model2`.
#
# This little module and technique helps get around that. It will redefine `inspect`
# if you include it in your model object.
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@juanje
juanje / gist:3797297
Created September 28, 2012 00:38
Mount apt cache of a Vagrant box in the host to spin up the packages installation

This is a little trick I use to spin up the packages instalation on Debian/Ubuntu boxes in Vagrant.

I add a simple function that checks if a directory named something similar to ~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist.

def local_cache(basebox_name)
  cache_dir = Vagrant::Environment.new.home_path.join('cache', 'apt', basebox_name)
  partial_dir = cache_dir.join('partial')
  partial_dir.mkdir unless partial_dir.exist?
 cache_dir
@jc00ke
jc00ke / while_successful.rb
Created November 27, 2012 06:49
Run while exit status is 0
begin
system(%(rake spec))
end while $? == 0
@jc00ke
jc00ke / gist:4592719
Created January 22, 2013 07:08
video to gif
$ ffmpeg -i some.mov -pix_fmt rgb24 output.gif
$ convert -layers Optimize output.gif output_optimized.gif
class FooController < ApplicationController
#
# Each "------ N" is a step of refactoring. I start with 0 and go as far as I need to
# depending on the code smell. Each step makes the code easier to reuse outside the view,
# controller, etc.
# ------ 0. Code smell, ivar
def some_action
@calculated_data = Something.funky.that('isnt').abstracted('in a lower level')
end
@jdkanani
jdkanani / notepad.html
Last active April 6, 2024 17:09 — forked from jakeonrails/Ruby Notepad Bookmarklet
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" id="editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("editor");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
<!--
For other language: Instead of `ace/mode/ruby`, Use
Markdown -> `ace/mode/markdown`
Python -> `ace/mode/python`
C/C++ -> `ace/mode/c_cpp`
Javscript -> `ace/mode/javascript`
Java -> `ace/mode/java`
Scala- -> `ace/mode/scala`
@hgmnz
hgmnz / dblink-demo
Created March 6, 2013 16:33
How to move data from one postgres database to another using dblink. Useful for cherry-picking data from a remote database
@hakanensari
hakanensari / 1_create_products.rb
Created April 30, 2013 23:47
Sequel + uuid-ossp
Sequel.migration do
up do
run 'CREATE EXTENSION "uuid-ossp"'
create_table :products do
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true
end
end
end