Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@gshutler
gshutler / update-rbenv-rubygems.sh
Created June 9, 2015 14:24
Update Rubygems for all rbenv rubies
#! /usr/bin/env bash
set -e
eval "$(rbenv init -)"
for version in `rbenv whence gem`; do
rbenv shell "$version"
echo "Updating rubygems for $version"
gem update --system --no-document --quiet
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@hpjaj
hpjaj / gist:ef5ba70a938a963332d0
Created April 2, 2015 16:41
RSpec - List of available Expectation Matchers - from Lynda.com course 'RSpec Testing Framework with Ruby'
## From Lynda.com course 'RSpec Testing Framework with Ruby'
describe 'Expectation Matchers' do
describe 'equivalence matchers' do
it 'will match loose equality with #eq' do
a = "2 cats"
b = "2 cats"
expect(a).to eq(b)
@iamatypeofwalrus
iamatypeofwalrus / generate_ctags.md
Last active February 11, 2019 10:17
Generate ctags for Atom (or for any other reason) on Mac os X

Why?

Atom can automagically picks up any tags file in your current directory which enables you to:

  • shift+cmd+r search for any function in your project
  • alt+cmd+down GoTo a function declaration

How

Get brew if you don't already have it. Then:

brew install ctags

@pixeltrix
pixeltrix / message_encryptor.rb
Created January 26, 2015 00:56
Action Mailer interceptor for encrypting emails using S/MIME
require 'openssl'
class MessageEncryptor
class << self
include OpenSSL
def delivering_email(message)
encrypted_message = sign_and_encrypt(message.encoded, message.to)
overwrite_body(message, encrypted_message)
overwrite_headers(message, encrypted_message)
@BattleBrisket
BattleBrisket / WEBrick default address binding.md
Last active September 9, 2015 10:33
Revert WEBrick bind address in Rails 4

Rails changed the default behavior for WEBrick somewhere around version 4. Instead of binding to 0.0.0.0, it will now default to localhost.

This makes life difficult when you're running Rails inside a VM like Vagrant, mostly because it won't work. ;)

Fortunately, you can force Rails back into the old universal address with the following snippet

# config/boot.rb

# ... end of existing file
@eliotsykes
eliotsykes / todo.js
Last active January 28, 2020 04:32
JSON API with jQuery AJAX and Rails
// Wrap in anonymous function to avoid adding variables to global scope needlessly.
(function($) { // $ is jQuery
function addTodoToDOM(data) { // 'data' is object built from response JSON
// id will be needed when adding delete functionality dynamically.
// var todoId = data.todo.id;
// Add HTML for new todo to document
var tableRow = '<tr><td>' + data.todo.description + '</td></tr>';
@eliotsykes
eliotsykes / capybara_finder_options_cheatsheet.md
Last active February 18, 2016 15:57
Capybara Finder Options Cheatsheet

Capybara Options Hash (options) for all, find:

  • text (String, Regexp) — Only find elements which contain this text or match this regexp
  • visible (Boolean, Symbol) — Only find elements with the specified visibility:
    • true - only finds visible elements.
    • false - finds invisible and visible elements.
    • :all - same as false; finds visible and invisible elements.
    • :hidden - only finds invisible elements.
    • :visible - same as true; only finds visible elements.
  • count (Integer) — Exact number of matches that are expected to be found
@leonelgalan
leonelgalan / README.md
Created November 17, 2014 21:39
Using stackprof and rspec (Rails)
  1. Existing rspec-stackprof is "empty"
  2. stackprof is written as a replacement for perftools.rb
  3. Added an environment variable to conditionally run the profiler, it slows down test runtime by a couple of seconds for me.
  4. Just add stackprof.rb to your spec/support folder, which is loaded on rails_helper.rb
@eliotsykes
eliotsykes / rails-dev-box-postgresql-HOWTO.md
Last active August 29, 2015 14:07
How to setup rails-dev-box & PostgreSQL

SSH to the vagrant OS command line.

Terminal $> vagrant ssh

Login to postgres database as vagrant user with the psql client:

vagrant@rails-dev-box: psql -U vagrant postgres