View drawing_sandpiles.rb
# Video: https://t.co/FCdLtWceez
# Based on: https://www.youtube.com/watch?v=1MtEUErz7Gg
# This one is better than mine: http://people.reed.edu/~davidp/web_sandpiles/
require 'graphics'
class Sandpile < Graphics::Simulation
AVERAGE_HEIGHT = 2.1 # he mentioned this in the video
def initialize(n)
super 800, 800
View ruby_&&_is_control_flow.rb
# Note that we can use parentheses to group expressions together,
# we'll use this to make a "side-effect" of incrementing a number,
# and then return a boolean value (true / false)
i = 0
(i += 1; true) # => true
(i += 1; false) # => false
i # => 2
View ruby_&&_is_control_flow.rb
# Note that we can use parentheses to group expressions together,
# we'll use this to make a "side-effect" of incrementing a number,
# and then return a boolean value (true / false)
i = 0
(i += 1; true) # => true
(i += 1; false) # => false
i # => 2
View pg_collate_are_all_case_sensitive.rb
require 'pg'
# PG.connect(dbname: 'postgres').exec('drop database josh_testing')
# PG.connect(dbname: 'postgres').exec('create database josh_testing')
db = PG.connect(dbname: 'josh_testing')
def db.exec(*)
super.to_a
end
# Locale currently used for collation
db.exec "show lc_collate" # => [{"lc_collate"=>"en_US.UTF-8"}]
View pgvc_demo.sql
create or replace function short_hash(long_hash character(32))
returns character(10) as $$
select substring(long_hash, 0, 10)
$$ language sql; -- helper
-- pgvc "PostgreSQL Version Control"
-- it's like git for postgres!
-- some pre-existing work
select * from products;
View trey_typing.rb
module TreyTyping
def method_added(name)
m = instance_method(name)
file, line = m.source_location
types = RubyVM::InstructionSequence.disasm(m).lines.slice_before { |l| l['checkkeyword'] }.to_a.drop(1).map { |lines| Object.const_get lines[3].split.last[1..-1] }
return if file == __FILE__ && line == 1+__LINE__
define_method name do |*args, **kws|
kws.zip(types).each do |(name, value), type|
next if type === value
raise TypeError, "#{name} should be a #{type}"
View pg_backup_with_hstore.rb
require 'pg'
# PG.connect(dbname: 'postgres').exec('create database josh_testing')
db = PG.connect(dbname: 'josh_testing').tap { |db| db.exec 'begin' }
# Make the db a little nicer to work with for our experiment
def db.exec(*)
super.to_a
end
View lyrical_repetition.rb
# Based on https://colinmorris.github.io/SongSim/#/about/intro
# inspired by https://www.youtube.com/watch?v=HzzmqUoQobc
MAX_HEIGHT = 900
MIN_LUMINOSITY = 0.35 # b/c the background is black, making it difficult to see dark colours
REMOVE_STOPWORDS = false # cut down on size by removing spammy low-quality words
EXPLORE_MODE = true # add crosshairs and the current word
SONG =
# 'BAA_BAA_BLACK_SHEEP'
# 'CALL_ME_MAYBE'
# 'RUMOUR_HAS_IT'
View notes.md

Advance Object Model

Notes for Gamut "platform basics"

Structure

  • Objects
    • class
View pg_cursor_example.rb
require 'pg'
db = PG.connect dbname: 'postgres'
db.exec("DROP DATABASE IF EXISTS just_fkn_around;")
db.exec("CREATE DATABASE just_fkn_around;")
db = PG.connect dbname: 'just_fkn_around'
define_method(:sql) { |sql| db.exec(sql).to_a }
sql <<-SQL
-- some data to query