Skip to content

Instantly share code, notes, and snippets.

Tom Dalling tomdalling

Block or report user

Report or block tomdalling

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomdalling
tomdalling / guide.md
Last active Feb 3, 2019
Tom's Narrow Guide to Melbourne
View guide.md

Tom's Narrow Guide to Melbourne

Places I like, for RubyConf AU attendees.

Coffee + Brunch Spots

  • Queen Victoria Markets
  • Degraves St
  • St Ali (South Melbourne, just outside the CBD. Must try the bottled iced lattes.)
  • Auction Rooms (North Melbourne, just outside the CBD)
@tomdalling
tomdalling / rspec_output.md
Created Jan 20, 2019
Mutant RSpec error output
View rspec_output.md

When I do puts method_name inside #respond_to_missing?, it outputs begin, so it looks like it's treating self as if it were a Range.

This is the RSpec output:

An error occurred while loading ./spec/value_semantics_spec.rb.
Failure/Error: first_letter = method_name[self]

SystemStackError:
  stack level too deep
@tomdalling
tomdalling / article.md
Last active Apr 18, 2018
jekyll-include_snippet gem usage behind article: https://www.rubypigeon.com/posts/super-secret-methods/
View article.md
title layout date snippet_source
Super Secret Methods
post
2017-07-16
code/super_secret_methods.rb

Here is a quirk of the Ruby language that I discovered a few weeks ago.

Method names can not contain a period character.

@tomdalling
tomdalling / notes.md
Created Mar 13, 2018
value object stuff
View notes.md

I like the idea of providing an RSpec shared example to test all these behaviours.

For the constructor, I would change "consider using keywords" to "should use keywords". Keywords should be the default, unless the order is really obvious.

Re: "Value construction options could be provided by keyword arguments." I would probably prefer value contruction options to be in separate class methods, instead of #new.

Re: caching. I would be hesitant to do this at the global level (e.g. stored in the class).

@tomdalling
tomdalling / after.rb
Last active Jul 7, 2019
Refactoring a controller action
View after.rb
class CommentsController
def create
result = CreateComment.call(params, @user)
if result.ok?
render :partial => "comments/postedreply", :layout => false,
:content_type => "text/html", :locals => { :comment => result.value }
else
case result.error.name
when :story_not_found
render :plain => "can't find story", :status => 400
@tomdalling
tomdalling / benchmarks.txt
Created Jun 13, 2017
Benchmarking input validation
View benchmarks.txt
Using Ruby 2.4.1
Code being benchmarked: https://github.com/tomdalling/rschema/blob/62da91a8c6e9b4795affe6824e23f27e713a1214/benchmarks/input_validation.rb
Warming up --------------------------------------
RSchema 3.1.1 1.640k i/100ms
(coerced) 673.000 i/100ms
(built + coerced) 142.000 i/100ms
ActiveModel 5.1.1 103.000 i/100ms
dry-validation 0.10.7
759.000 i/100ms
@tomdalling
tomdalling / rschema_pluggable_coercion.rb
Last active May 7, 2017
Pluggable/composable coercion upcoming in RSchema v3
View rschema_pluggable_coercion.rb
# params usually come in as strings, regardless of the actual type they are
params = {
'fruit' => 'banana',
'harvested_at' => '2017-05-08T01:46:16+10:00',
'unwanted_framework_crap' => 'DHH',
}
# you can declare what the types are _supposed_ to be with a schema
schema = RSchema.define {{
fruit: _Symbol,
@tomdalling
tomdalling / simple_authentication.rb
Created May 23, 2016
A simple Sinatra app that demonstrates basic authentication
View simple_authentication.rb
#!/user/bin/env ruby
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4'
gem 'bcrypt', '~> 3.1'
end
require 'sinatra/base'
@tomdalling
tomdalling / app_cell.rb
Last active Apr 11, 2016
Cells Erbse automatic escaping
View app_cell.rb
require 'cell'
class AppCell < Cell::ViewModel
include ::Cell::Erb
def show
render
end
def template_options_for(*args)
@tomdalling
tomdalling / fragment-shader.txt
Created Nov 26, 2014
tomdalling.com OpenGL article 2 modified to use two textures
View fragment-shader.txt
#version 150
uniform sampler2D tex;
uniform sampler2D tex2;
in vec2 fragTexCoord;
out vec4 finalColor;
void main() {
You can’t perform that action at this time.