Skip to content

Instantly share code, notes, and snippets.

Josh Cheek JoshCheek

View GitHub Profile
@JoshCheek
JoshCheek / why_i_chose_fish_over_bash_for_students.md
Last active Dec 28, 2019
Why I Chose Fish Over Bash For Students
View why_i_chose_fish_over_bash_for_students.md

Why I chose Fish over Bash for students

I'm currently the lead instructor at Code Platoon and an instructor/developer at the Turing School of Software and Design.

I've been advocating the Fish shell and when the choice is up to me, I choose that for my students. Enough people ask about the decision, particularly in relation to the preinstalled Bash shell, that I figured it's worth laying out my reasoning.

TL;DR

View timing_grape_api.rb
require 'grape'
require 'logger'
require 'json'
class MyApi < Grape::API
version 'v1', :using => :path
format :json
desc "Returns first / last name"
get '/:first/:last' do
@JoshCheek
JoshCheek / trunk_based_development
Last active Dec 3, 2019
Trunk Based Development
View trunk_based_development
Trunk Based Development
=======================
Disclaimer:
I've never done this on a deployed flagship app at a job.
Words:
Continuous integration: all code is merged frequently (perhaps several times per day to once every few days)
Continuous delivery: the integrated code is delivered (tested and deployable)
Continuous deployment: the deliverable code is deployed (shipped)
Release: feature is available to users
@JoshCheek
JoshCheek / lonpos.rb
Last active Dec 1, 2019
Lonpos Pyramid
View lonpos.rb
class Piece
def self.from_strs(*strs, **opts)
new strs.map { |s| s.chars.map { |c| c == "*" } }, **opts
end
attr_reader :rows, :graphic
def initialize(rows, graphic:)
@graphic, @rows = graphic, rows.map do |row|
row.map { |cell| cell == true ? graphic : (cell || nil) }
@JoshCheek
JoshCheek / budding-of-the-brood.js
Last active Nov 23, 2019
Budding of the Brood
View budding-of-the-brood.js
// "Budding of the Brood" by Josh Cheek (@josh_cheek on the twitter)
// Paste it into here: https://hydra-editor.glitch.me
// Or you can watch me run it here: https://vimeo.com/346283798
// And some explanatino of how it works here: https://vimeo.com/346242814
// Great explanation of the math here: https://www.youtube.com/watch?v=r6sGWTCMz2k
document.getElementsByClassName('console')[0].style.display = 'none'
function getPoint(time, getX) {
time = (time*5) % points.length
const [x1, y1] = points[Math.floor(time)]
@JoshCheek
JoshCheek / scrape_sigs
Last active Nov 23, 2019
My hydra signature scraping script
View scrape_sigs
#!/usr/bin/env bash
node -e 'console.log(JSON.stringify(require("./src/composable-glsl-functions.js")))' \
| ruby -r json -e '
puts JSON.parse($stdin.read, symbolize_names: true)
.map { |name, defn| {**defn, name: name} }
.group_by { |defn| defn[:type] }
.sort
.each { |cat, defns| defns.sort_by! { |defn| defn[:name] } }
.map { |category, defns|
defns.zip([category]).map.with_index { |(defn,category),i|
@JoshCheek
JoshCheek / pg_cursor_example.rb
Created Oct 6, 2017
PostgreSQL cursor example
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
@JoshCheek
JoshCheek / dot_is_for_minitest.rb
Created Sep 25, 2019
Experiment that adds `.is` (like the old RSpec `.should`) to Minitest
View dot_is_for_minitest.rb
require 'minitest/autorun'
module DotIs
# Track the current test so that we can run assertions in its context
def self.current_test=(test)
Thread.current[:dot_is_current_test] = test
end
def self.current_test
Thread.current.fetch :dot_is_current_test
@JoshCheek
JoshCheek / metaprogrammed_active_record_clone.rb
Created Sep 24, 2019
Metaprogrammed ActiveRecord "clone" (just a fun morning experiment)
View metaprogrammed_active_record_clone.rb
class Query
def initialize(table, db)
@db, @table, @cols, @rest = db, table.downcase, '*', ''
end
def method_missing(clause, *args)
clause == :select \
? @cols = args.join(', ') \
: @rest << ' ' << [clause, *args].join(' ')
self
end
@JoshCheek
JoshCheek / lambda-calc.js
Created Sep 23, 2019
lambda calc translation
View lambda-calc.js
($true => $false => $if => y => succ => zero => toJs =>
(one => two => three => add => nil => cons =>
(multiply => map => reduce =>
console.log(reduce(arr => n => [...arr, toJs(n)])(
// Translation of this program into lambda calculus
// https://dev.to/laurieontech/human-readable-javascript-337o
//
// const arr = [1,2,3]
// const timesTwoPlusIndex = (el, index) => (el*2) + index
You can’t perform that action at this time.