Skip to content

Instantly share code, notes, and snippets.

JoshCheek / authenticated_field.go
Last active March 16, 2023 23:03
Example of how we can prob use resolvers in graphql-go so that you only need to be authenticated if you are asking for fields that require it.
View authenticated_field.go
package main
import (
gql ""
JoshCheek /
Last active March 7, 2023 10:06
A program that is both a palindrome and a quine, made with hearts for Joe

A program that is a palindrome (if you reverse its source code, you get the same program) and is a quine (if you run it, it prints out its own source code). Verify like this:

ruby palindrome_quine.rb | tee output
diff palindrome_quine.rb output # the output is the same as the source program
ruby -e 'puts $' < palindrome_quine.rb > reversed
diff palindrome_quine.rb reversed # the reversed program is the same as the source program
JoshCheek / golang_type_system_failing_me.go
Created February 24, 2023 08:44
Golang's type system failing me, tests passed the values, but prod passed pointers to them, the type system didn't care, but staging broke b/c of a type error.
View golang_type_system_failing_me.go
package main
import (
type Objs []Obj
type Obj interface{ GetType() string }
type IntObj struct{ Int int }
type StrObj struct{ Str string }
JoshCheek / hooks.rb
Created August 24, 2012 12:56
Creates before/after hooks for methods
View hooks.rb
# a response to
module Hook
def before(meth_name, &callback)
add_hook :before, meth_name, &callback
def after(meth_name, &callback)
add_hook :after, meth_name, &callback
JoshCheek / test.cpp
Created January 17, 2023 03:29
c++ value/pointer/reference example
View test.cpp
#include <iostream>
using namespace std;
void print_by_value(string message) { cout << message << endl; }
void print_by_pointer(string *message) { cout << *message << endl; }
void print_by_reference(string &message) { cout << message << endl; }
int main() {
string message = "whatever";
JoshCheek / btd6_survey_responses.txt
Last active December 22, 2022 19:07
BTD6 are you better than the youtubers survey
View btd6_survey_responses.txt
quiz video:
solution video:
1. dies (WRONG)
lvl1 Sauda tends to leak on like... r4 or something, and that's a bad position for her
2. dies (WRONG)
I don't think they'll be able to take the ceramics at the end
3. wins (RIGHT)
quincy is good under alchemy, the cannon is good cleanup
4. wins (WRONG)
JoshCheek /
Created December 7, 2022 01:52
Thoughts on BTD6 v34.0 Update Notes

BTD6 v34.0 update notes

"New Boss Bloon: Dreadbloon!"

I guess I need to get into bosses, b/c they do make sense for me in CT, but outside of CT, god, they're so fkn tedious. I'm basically indifferent.

Team banners 9 and 10

Sweet, lets hold off and get one of these since none of the other teams will have them... unless they suck, in which case screw that.

JoshCheek / api_only_rails_example.rb
Last active December 6, 2022 18:46
How to configure API only Rails (esp how to deal with param parsing).
View api_only_rails_example.rb
# I submitted a bug report
# b/c Rails was not honouring my `rescue_from` block which was causing my API to
# be inconsistent. I was told this is expected behaviour. I think it's probably
# fine for an HTML app where you control the form inputs. But for an API app,
# the API is public facing and very important, so Rails shouldn't have its own
# special errors that bypass my app's configuration and make my API inconsistent.
# Decided it shouldn't be too difficult to handle this myself. So, here is my
# solution. It contains most of the important lessons I've learned about how to
# get a Rails API app setup. It removes Rails' params parsing and adds its own.
JoshCheek / split_path_slashes_but_not_url_slashes.rb
Last active November 22, 2022 14:38
Split slashes in paths, but not URLs
View split_path_slashes_but_not_url_slashes.rb
def split_path(path)
slash = Regexp.escape File::SEPARATOR
match = path.match(%r~ # regex that is delimited by tildes so I can use slashes, quotes, backticks, etc in the comments
( # capture whatever the path_slash group matches
(?<path_slash> # a named group that matches slashes in paths, but not urls, eg will not match ""
# don't match first slash in "://"
(?: # don't capture this group
(?<!:) # not preceeded by ":"
(?!#{slash}#{slash}) # not succeeded by "//" (we haven't matched the slash yet, so it's in front of the cursor)
JoshCheek / golang-test-wrapper
Last active November 22, 2022 11:44
Golang test runner (not very mature, prob lots of cases I don't yet know about, that it doesn't handle correctly yet)
View golang-test-wrapper
#!/usr/bin/env ruby
require 'json'
require 'time'
require 'pp'
# Run from the root of the app
Dir.chdir File.dirname __dir__
# Find package information for handling args
ROOT_PACKAGE = File.foreach("go.mod").first.split.last