Skip to content

Instantly share code, notes, and snippets.

@tomdalling
tomdalling / benchmarks.txt
Created June 13, 2017 00:07
Benchmarking input validation
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 16:07
Pluggable/composable coercion upcoming in RSchema v3
# 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 12:26
A simple Sinatra app that demonstrates basic authentication
#!/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 April 11, 2016 07:28
Cells Erbse automatic escaping
require 'cell'
class AppCell < Cell::ViewModel
include ::Cell::Erb
def show
render
end
def template_options_for(*args)
@tomdalling
tomdalling / fragment-shader.txt
Created November 26, 2014 06:08
tomdalling.com OpenGL article 2 modified to use two textures
#version 150
uniform sampler2D tex;
uniform sampler2D tex2;
in vec2 fragTexCoord;
out vec4 finalColor;
void main() {
OPERATORS = ['+', '-']
ROUNDS = 2
MAX_NUMBER = 9
puts 'What is your name?'
name = gets.chomp
puts "Welcome to Arithmetic Tutor, #{name}!"
results = (1..ROUNDS).map do
left = rand(MAX_NUMBER + 1)
@tomdalling
tomdalling / PlayerController_States.h
Created March 20, 2013 02:01
Some code from a state machine for Oddworld-style platform movement.
//
// Copyright 2012. All rights reserved.
//
static const int StandingHeight = 2;
static const int CrouchingHeight = 1;
class State {
public:
#!/bin/bash
# Copyright (C) 2013 Thomas Dalling
# Copyright (C) 2013 Marshall Levin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do