Skip to content

Instantly share code, notes, and snippets.

@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')
@parameme
parameme / serializable_sha1_using_ffi.rb
Created April 2, 2012 04:22
Quick and dirty way to serialize and restore ruby Digest::SHA1 using FFI
require 'ffi'
require 'digest'
# Thanks to all ruby hackers everywhere who have donated their knowledge to the commons!
# With thanks to @judofyr for ffi/"evil.rb" - https://gist.github.com/2238438
class Object
def memory_location
object_id * 2
end
@stevenklise
stevenklise / app.rb
Created April 18, 2013 19:34
Using `irb` to connect to a Sinatra app or DataMapper connection
# require basic libraries
source 'https://rubygems.org'
require 'rubygems'
require 'sinatra'
require 'data_mapper'
# require DataMapper adapter, in this case we'll use Postgres
require 'dm-postgres-adapter'
DataMapper.setup(:default, ENV['DATABASE_URL'])
@dashed
dashed / github-pandoc.css
Created September 26, 2013 13:42
GitHub-like CSS for pandoc standalone HTML files (perfect for HTML5 output). Based on Marked.app's GitHub CSS. Added normalize.css (v2.1.3) in the prior to GitHub css.
/*! normalize.css v2.1.3 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 8/9.
*/
@gabrieltaylor
gabrieltaylor / sinatra-trailing-slash.md
Last active October 2, 2018 15:52
Rewrite trailing slash in Sinatra

To avoid receiving an error when you attempt to access one of your routes and accidentally leave a trailing slash on the URL, you can use Rack::Rewrite to redirect the browser to the same URL without the trailing slash.

First add the gem to your Gemfile

gem 'rack-rewrite', '~> 1.5.0'

Run bundle install

@JoshCheek
JoshCheek / rack_test_example.rb
Created July 21, 2014 21:35
example of how to use rack test with minitest
require 'sinatra/base'
require 'minitest/autorun'
require 'minitest/spec'
require "rack/test"
require 'nokogiri'
class MyApp < Sinatra::Base
enable :inline_templates
get '/users/:id' do
@victorwhy
victorwhy / gist:45bb5637cd3e7e879ace
Last active February 21, 2023 11:17
How Sinatra routes PUT/PATCH and DELETE

HTML and Sinatra really only support the GET and the POST methods. In order to be able to use the PUT and DELETE methods in Sinatra, you kind of have to "trick" the form to go to the right place. Then you can name the routes the proper way - otherwise you can only really work with GET and POST.

I used the Craiglist Jr challenge for some examples. Let's look at a quick example of a POST form/method/route- in this case, we're creating a new Craigslist article:

POST form and corresponding route:

<form action="/article/new" method="post">
  --------------------------------
  YOUR FORM FIELDS HERE
@davidcelis
davidcelis / metronome.rb
Last active March 6, 2020 10:19
A simple metronome in Ruby
class Metronome
def self.start(bpm: 120)
loop do
print "\a"
sleep (60 / bpm.to_f)
end
rescue Interrupt
puts "Exiting."
end
end
@gokulkrishh
gokulkrishh / media-query.css
Last active June 16, 2025 23:09
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
/* CSS */