Skip to content

Instantly share code, notes, and snippets.

View thehenster's full-sized avatar

Henry thehenster

  • https://char.gy
  • London
View GitHub Profile
@thehenster
thehenster / config.ru
Created October 30, 2019 22:39
Rackup file for dynamic requests, then static files, then not found
require 'rack'
require 'rack/static'
class App
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
@thehenster
thehenster / time_travel_in_console.rb
Created November 28, 2017 17:55
Time travel in console
[1] pry(main)> require "active_support/testing/time_helpers"
=> true
[2] pry(main)> include ActiveSupport::Testing::TimeHelpers
=> Object
[3] pry(main)> travel_to("1969-01-01".to_time){ puts Time.current }
1969-01-01 00:00:00 +0100
@charset "utf-8";
@import "normalize";
html {
font-size: 62.5%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
@thehenster
thehenster / netcat-listen-on-port.sh
Last active December 8, 2015 14:40
The nc in Ubuntu doesn't have the same arguments as the normal one
# in normal nc
nc -l -p 8888
# in bsd nc
nc -l 0.0.0.0 8888
# throw in a -k to keep listening to subsequent requests
@thehenster
thehenster / scripttag.html
Last active November 17, 2015 09:10
script tag in gist
<script>alert('hello');</script>
@thehenster
thehenster / recipe_form.rb
Last active November 16, 2015 16:18
Pattern for Form Objects in Rails
class RecipeForm
ATTRIBUTES = [:name, :cooking_time_minutes]
attr_reader :recipe
attr_accessor *ATTRIBUTES
def initialize(recipe)
@recipe = recipe
end
@thehenster
thehenster / simple_rdoc.rb
Last active April 2, 2020 13:29
A very simple custom RDoc generator
# RDoc can use a custom generator but it isn't that well documentated. Here is a
# sample custom generator to get you going.
#
# Ruby comes with an `rdoc` executable but most of us generate our docs via Rake. To
# use your custom generator with Rake do something like the following in your Rakefile..
#
# require 'rdoc/task'
# require 'simple_rdoc'
#
# RDoc::Task.new('simple_doc') do |i|
@thehenster
thehenster / capybara-cheatsheet.rb
Created March 6, 2015 11:14
Capybara Cheatsheet
# A Capybara Cheatsheet
# In rails 3
Post.select(:id, :created_at).count #=> SELECT COUNT(*) FROM posts
# In rails 4
Post.select(:id, :created_at).count #=> SELECT COUNT(id, created_at) FROM posts ... bang
Post.select(:id, :created_at).count(:all) #=> SELECT COUNT(*) FROM posts
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord'