Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
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.
package main
import (
"fmt"
)
type Objs []Obj
type Obj interface{ GetType() string }
type IntObj struct{ Int int }
type StrObj struct{ Str string }
@JoshCheek
JoshCheek / hooks.rb
Created August 24, 2012 12:56
Creates before/after hooks for methods
# a response to www.ruby-forum.com/topic/4405076
module Hook
def before(meth_name, &callback)
add_hook :before, meth_name, &callback
end
def after(meth_name, &callback)
add_hook :after, meth_name, &callback
end
@JoshCheek
JoshCheek / test.cpp
Created January 17, 2023 03:29
c++ value/pointer/reference example
#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";
print_by_value(message);
@JoshCheek
JoshCheek / btd6_survey_responses.txt
Last active December 22, 2022 19:07
BTD6 are you better than the youtubers survey
quiz video: https://www.youtube.com/watch?v=nacAv7XMOIE
solution video: https://www.youtube.com/watch?v=lbyRTowoQDE
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
JoshCheek / btd6-thoughts-on-v34.0-update-notes.md
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
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).
# I submitted a bug report https://github.com/rails/rails/issues/34244
# 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
JoshCheek / split_path_slashes_but_not_url_slashes.rb
Last active November 22, 2022 14:38
Split slashes in paths, but not URLs
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 "http://example.com"
# 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
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)
#!/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
@JoshCheek
JoshCheek / semicolon-at-the-beginning.js
Created November 15, 2022 13:48
Example of putting the semicolon at the beginning of the line in JS
// https://twitter.com/josh_cheek/status/1592514535789060101
console.log(1)
// this line will "continue" the previous one so
// it gets a semicolon to stop it from doing that
// JS would otherwise consider it a function call,
// ie `console.log("hello")(function() { ... })
;(function() {
console.log(2)
@JoshCheek
JoshCheek / whydoesntgowork.go
Last active November 10, 2022 02:55
whydoesntgowork.go
package main
import ("fmt")
// Real A (I cannot change this)
type RealA struct{}
func NewRealA() *RealA { return &RealA{} }
func (a *RealA) M() string { return "real a" }
// Fake A (I can change this)
type FakeA struct{}