View generating_bytecode.rb
def cancel
authorize OrderIssue
order_issue = OrderIssue.find(params[:id])
order_issue.cancel!
render_results(:results => order_issue,
:status => :ok,
:serializer => OrderIssueSerializer)
end
code = File.read(__FILE__).lines[0...__LINE__-1].join
View sql_injection_and_parameterizing_queries.rb
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.logger = Logger.new $stdout
ActiveSupport::LogSubscriber.colorize_logging = false
ActiveRecord::Schema.define do
create_table(:users) { |t| t.string :name }
end
# Create some users
User = Class.new ActiveRecord::Base
View rule_n.rb
require 'graphics'
require 'set'
class RuleN < Graphics::Simulation
def initialize(pixel_size, w, h)
self.pixel_size = pixel_size
self.rule_index = 30
self.needs_draw = true
self.cursor_pixel_offset = 0
self.initial_pixel_offsets = Set[0]
View ruby_parsing_and_vm.rb
code = <<-RUBY
class A
def whatevz
if 1
2
else
3
end
end
end
View 3d_cubes.rb
# Video is @ https://vimeo.com/222905527
# The math is prob wrong, but it's close enough to actually render them in 3D.
# It's just me trying to think through what should make sense based on how
# people describe things, and then trying to work out what the correct math
# is to pull it off, but obv I'm not quite there.
require 'graphics'
require 'matrix'
def √ n
View understanding_computation_ch2.rb
require 'pp'
class Machine < Struct.new(:sexp, :env)
def run
evaluations = []
sexp, env = self.sexp, self.env
loop do
puts "{#{env.map { |k, v| "#{k}: #{v}" }.join(", ")}}", sexp
evaluations << [sexp, env]
break unless sexp.evaluatable?
View 0.md

This is now hosted here, and there is a video here.

View f.sh
#!/usr/bin/env bash
man ls | col -b | ruby -ane '
BEGIN { valid = [] }
END { puts [*?a..?z, *?A..?Z, *?0..?9] - valid }
$F[0] =~ /^-(\S)$/ && valid << $1
'
View example_active_record.rb
require 'active_record'
require 'logger'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.logger = Logger.new $stdout
ActiveSupport::LogSubscriber.colorize_logging = false
# Migrations
ActiveRecord::Schema.define do
View lambda-calc.js
(TO_I => (n0 => (n1 => (n2 => (n3 =>
(IF => (FALSE => (TRUE => (TO_BOOL =>
(IS_EMPTY => (CDR => (CAR => (CONS => (EMPTY_LIST =>
(y => (reduce => (PRINT =>
// This program is the lambda calculus translation of:
// [1, 2, 1, 3].forEach(n => console.log(n))
(list =>
reduce((n => _ => PRINT(TO_I(n))))
(list)
(n1))