Skip to content

Instantly share code, notes, and snippets.

View nicholasjhenry's full-sized avatar

Nicholas Henry nicholasjhenry

View GitHub Profile
describe "My page" do
it "lists the item" do
item = create_item
within item_row(item) do
expect(page).to mention_item(item)
end
end
private
@kommen
kommen / mp3_info.ex
Created May 8, 2016 18:28
Compute MP3 variable bitrate file duration with Elixir
defmodule Mp3Info do
def duration(data) do
compute_duration(data, 0, 0)
end
defp compute_duration(data, offset, duration) when byte_size(data) > offset do
case decode_header_at_offset(offset, data) do
{:ok, length, {samplerate, samples}} ->
compute_duration(data, offset + length, duration + (samples / samplerate))
@rlivsey
rlivsey / test_channel.ex
Last active July 22, 2016 10:30
Subscribing to events from a Phoenix.Channel in 1.2.0-rc.0
defmodule MyApp.TestChannel do
use MyApp.Web, :channel
require Logger
intercept ["some-event"]
def join("test:lobby", _, socket) do
# subscribe to a topic
subscribe socket, "some-topic"
@jamesladd
jamesladd / ansi_v1.rb
Last active August 29, 2015 14:15
Original ansi.rb requiring more than 12 test to prove to_ansi method works as expected vs new version requiring 3 tests to prove to_ansi method works as expected.
# - ORIGINAL - Requires 12 test cases the provide to_ansi does what it should
# 1. Test empty commands map returns ""
# 2. 11 Tests to test each if/elsif.
#
class Clear; end
class HideCursor; end
class ShowCursor; end
class SetPos < Value.new(:row, :column); end
class FG < Value.new(:red, :green, :blue); end

In order to become a permanent member of the RMU community and move on to take additional courses, each student must pass an entrance exam and then go on to successfully complete their core skills course. The entrance exam is mainly used for ensuring that the people joining the program are diligent workers who have sufficient background knowledge to do well in our core skills course. The core skills course itself though, is something I think is something genuinely unique that you can’t find anywhere outside of RMU.

Each core course starts with roughly 15 students submitting a proposal for a personal project to work on during their session. This can be anything Ruby related, but typically involves the student building an open source application or library that scratches a particular itch of theirs. This is the first learning opportunity of the course, as it filters out those who can’t think of anything to work on. There isn’t a list of suggested projects to pick from, students need to come up with an idea the

@jefffis
jefffis / gist:806f4082eb00004cf191
Created October 22, 2014 17:44
Responsive email template -- works in Outlook, Gmail, pretty much everywhere but Lotus Notes. Also, works great on mobile in Gmail =)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Single-Column Responsive Email Template</title>
@mikepack
mikepack / 1_inheritance.rb
Last active August 29, 2015 14:07
5 Composition Techniques
class Animal
def run
puts 'running'
end
end
Animal.new.run #=> running
class Wolf < Animal
def follow_pack
require "erb"
require "pathname"
DOT_TEMPLATE=<<-END
digraph {
size="20,20";
overlap=false;
sep=0.4;
graph [fontname=Helvetica,fontsize=10];
node [fontname=Helvetica,fontsize=10];
@rosenfeld
rosenfeld / application_controller.rb
Created July 18, 2014 11:47
Supporting automatic return from render/redirect/head in Rails
# Please don't comment in this gist since I'm not notified by any comments here:
# https://github.com/isaacs/github/issues/21
# This is the discussion to comment on: http://blog.arkency.com/2014/07/4-ways-to-early-return-from-a-rails-controller/
class ApplicationController < ActionController::Base
# ...
around_action :catch_halt
def render(*args)