Skip to content

Instantly share code, notes, and snippets.

Josh Cheek JoshCheek

Block or report user

Report or block JoshCheek

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
View duo_lingo_clone.rb
#!/usr/bin/env ruby
require 'readline'
# copied from https://www.vistawide.com/spanish/top_100_spanish_words.htm
list = <<~WORDS
el / la (def. art.) the
de (prep.) of, from
que (conj.) that, which
y (conj.) and
a (prep.) to, at
@JoshCheek
JoshCheek / readline_insta_closes_in_worker_thread.js
Created Jun 9, 2019
Readline instacloses in worker thread
View readline_insta_closes_in_worker_thread.js
const readline = require('readline')
const { Worker, isMainThread } = require('worker_threads')
if(isMainThread)
new Promise((resolve, reject) => {
const worker = new Worker(__filename, {})
worker.on('message', message => console.log(message))
worker.on('error', err => reject)
worker.on('exit', resolve)
})
@JoshCheek
JoshCheek / you_spin_me_right_round.sh
Last active Jun 8, 2019
You spin me right round (iterations)
View you_spin_me_right_round.sh
# Tweet: https://twitter.com/josh_cheek/status/1137422115181871104
# Video: https://vimeo.com/341108197
# 1
node -e h=$LINES,w=$COLUMNS,p=process,t=0,T=6.28,s='""
p.stdin.setRawMode(1).on("data",k=>k[0]-3?s+=k:p.exit())
setInterval(()=>{++t;p.stdout.write(`\x1b[2J`)
l=s.length+5
r=l/T
x=i=>Math.round(Math.cos(T*(i-t)/l)*r*2+r*2)+1
@JoshCheek
JoshCheek / v0.rb
Last active May 25, 2019
Tweetable Mandelbrot Set
View v0.rb
# The first version was one I made in 2017 for Graphics,
# it has much better resolution but isn't animated:
# https://twitter.com/josh_cheek/status/846199094519443456
# https://gist.github.com/JoshCheek/dbb07c35e46d45f57c33579e03095f1c
@JoshCheek
JoshCheek / abandon_all_hope_ye_who_enter_here.md
Last active May 30, 2019
Evil Ruby: Turning procs into first class functions
View abandon_all_hope_ye_who_enter_here.md
  • To read the original tweet and comments, click here.
  • For my followup abomination, click here
  • If you're thinking about treating this as anything other than art, read there 👇

DISCLAIMER:

THIS IS ART, DON'T ACTUALLY DO THIS IN ANY CODE THAT YOU CARE ABOUT!

☠️ This is not a place of honor ☠️

@JoshCheek
JoshCheek / list.c
Last active May 19, 2019
Writing Ruby Like C (fun video of the process here: https://vimeo.com/336921852)
View list.c
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list {
char* data;
struct list* successor;
} List;
@JoshCheek
JoshCheek / progression_of_terminal_drawer.sh
Created May 14, 2019
Progression of "Terminal Drawer"
View progression_of_terminal_drawer.sh
require 'benchmark'
RUBY_VERSION # => "2.6.0"
n = 10_000
# arbitrarily sized callstack
def call_at_depth(n, &b)
n.zero? ? b.() : call_at_depth(n-1,&b)
end
ary = []
@JoshCheek
JoshCheek / mouse_reporting.sh
Last active May 17, 2019
Mouse reporting in the terminal
View mouse_reporting.sh
# https://gist.github.com/JoshCheek/8c4ee41ddfd305fdb628f5feabb515ce
ruby -rio/console -e '
# 1003 = report all mouse events,
# 1006 = in SGR format (CSI "<" button ";" Cx ";" Cy {"M","m"})
print "\e[?1006h\e[?1003h\e[?25l"
at_exit do
print "\e[?1006l\e[?1003l\e[?25h"
end
loop do
str = $stdin.raw { $stdin.readpartial 1000 }
@JoshCheek
JoshCheek / hydra_custom_glsl.js
Last active May 14, 2019
hydra sketch with custom glsl (against hydra-synth dev branch)
View hydra_custom_glsl.js
synth.setFunction('josh', { type: 'src', inputs: [], glsl: `
float josh_circle(vec2 st, float cr, float cx, float cy) {
float dx = cx-st.x, dy = cy-st.y;
float z = cr*cr - dx*dx - dy*dy;
return (z < 0.) ? 0. : sqrt(z)/cr;
}
vec4 josh(vec2 st){
float z = josh_circle(st, .35, .5, .5);
z = z-josh_circle(st, .25, .5, .5)+josh_circle(st, 0.2, 0.5, 0.5)*0.75;
for(int i = 0; i < 10; i+=1) {
View state_machine.rb
require 'json'
# these were actually in a namespace, but whatever
StateMachineError = Class.new StandardError
class InvalidStateMachine < StateMachineError
def self.check(seen, known)
return if known.include? seen
raise new(seen, known)
end
You can’t perform that action at this time.