Skip to content

Instantly share code, notes, and snippets.

View tundal45's full-sized avatar
👻
there is more to life than coding

Ashish Dixit tundal45

👻
there is more to life than coding
View GitHub Profile
###
# This is a demonstration of using SQLite3's Virtual File System API in Ruby.
#
# == Synopsis
#
# This program will store its SQLite database after the __END__ line.
#
# === In Detail
#
# SQLite3 uses the DATABase class as a proxy for our IO object. Upon
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@mattyoho
mattyoho / module_overrides.rb
Created December 9, 2010 02:57
Defining methods in an included module inside your class allows modification by modules later.
class Dog
module InstanceMethods
def bark
"Arf arf!"
end
end
include InstanceMethods
end
dog = Dog.new
@patmaddox
patmaddox / 1_before.rb
Created March 7, 2011 07:03
Wondering what people think. Gratuitous refactoring, or marvelous use of Ruby?
module API
class Version1 < Grape::API
version 'v1'
resource :hotels do
get '/' do
if [:latlng, :query].all? {|key| params[key].blank? }
error! 'Please pass in latlng|query'
end
@michaelfeathers
michaelfeathers / methodshark.rb
Created March 9, 2011 15:58
Output the complexity trend of an individual method across its history
#!/usr/bin/env ruby
# Print the complexity over time for a Ruby method in a
# git repository.
#
# Requires: >= bash ?.?
# >= git 1.7.1
# >= ruby 1.9.2
# >= flog 2.5.0
#
require 'net/http'
require 'json'
###
# Stupid simple class for uploading to imgur.
#
# client = Imgur2.new 'my imgur key'
# p File.open(ARGV[0], 'rb') { |f|
# client.upload f
# }
@shinzui
shinzui / tmux.conf
Created March 12, 2011 01:08 — forked from bryanl/tmux.conf
tmux.conf
# ~/.tmux.conf
#
# See the following files:
#
# /opt/local/share/doc/tmux/t-williams.conf
# /opt/local/share/doc/tmux/screen-keys.conf
# /opt/local/share/doc/tmux/vim-keys.conf
#
# URLs to read:
#
require 'sass'
module Sass::Script::Functions
def svg_circle(radius, color, circle_type)
img = if circle_type.value == "disc"
%Q{<circle cx="#{radius.value}" cy="#{radius.value}" r="#{radius.value}"
stroke-width="0" fill="#{color}"/>}
else
%Q{<circle cx="#{radius.value}" cy="#{radius.value}" r="#{radius.value}"
stroke="#{color}" stroke-width="1" fill="white"/>}

Polymorphism

Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:

  • A Person
  • A Company
  • A PhoneNumber that can connect to a Person or a Company

At the Database Level

@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:29
Focus on specific specs in RSpec
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# and then use the :focus tag in your specs
it "does something awesome", :focus do