This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg_notify' | |
class ChatController < ApplicationController | |
include Tubesock::Hijack | |
@@notifier = PGNotify.new 'chat' | |
def chat | |
hijack do |websocket| | |
websocket.onopen do | |
@@notifier.subscribe websocket do |payload| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>Flame Graph of Page</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task 'assets:precompile' => 'environment' do | |
# See https://github.com/rails/sprockets-rails/issues/49 | |
# | |
# Sprockets no longer creates undigested assets, so we have to | |
# emulate the old behavior to keep vendored JS libraries happy | |
# | |
# For the record, | |
# Digested: 4-star-de4f1f10cb13e222111c8afe0b516131.jpg | |
# Undigested: 4-star.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When you have really complex scenarios you have to test, your tests can become very long | |
# and duplicative. Here's a simple way to prevent that: | |
describe SomeController do | |
def scenario_setup | |
post :foo | |
expect(controller.current_user).to be_a User | |
# some more complex stuff that takes a lot of space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def at(time) | |
original = Time.now | |
allow(Time).to receive(:now) { time } | |
yield | |
ensure | |
allow(Time).to receive(:now) { original } | |
end | |
at 12.hours.from_now do | |
# your test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child < ActiveRecord::Base | |
belongs_to :parent | |
INHERITABLE_SETTINGS = %i[foo bar baz] | |
INHERITABLE_SETTINGS.each do |attr| | |
define_method attr do | |
value = read_attribute(attr) | |
default = default_setting(attr) | |
inherited = inherited_setting(attr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup | |
class User | |
def name; 'Bob'; end | |
end | |
class Object | |
def wrap(method, &block) | |
prepend Module.new { define_method method, &block } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: &default | |
adapter: postgresql | |
database: app_development | |
connect_retry_timeout: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# SEE YOU SPACE COWBOY by DANIEL REHN (danielrehn.com) | |
# Displays a timeless message in your terminal with cosmic color effects | |
# Usage: add `ruby ~/seeyouspacecowboy.rb; sleep 2` to .bash_logout (or similar) in your home directory | |
# (adjust the sleep variable to display the message for more seconds) | |
class String | |
def colorize(color_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class SomethingYouDontControl | |
# def! :something_you_expect_not_to_exist do |arg| | |
# arg + 1 | |
# end | |
# end | |
# | |
# I wanted to provide built-in memoization, but it's not currenlty possible | |
# while preserving strict argument checking. https://bugs.ruby-lang.org/issues/9777 | |
# | |
module Kernel |