Skip to content

Instantly share code, notes, and snippets.

JoshCheek /
Last active Apr 9, 2021
How to uninstall Snap Camera on Mac OS X
# these are reconstructed from a shell session without runnig them, so make
# sure you check that it's a sane thing to do before running it, I make no
# guarantees of fitness, and accept no liability. Run at your own risk.
sudo launchctl remove com.snap.SnapCameraRemover
rm -r ~/Library/Caches/Snap/
rm -r ~/Library/Caches/com.snap.SnapCamera/
rm -r ~/Library/Preferences/Snap/
rm ~/Library/Preferences/com.snap.SnapCamera.plist
rm ~/Library/Preferences/com.snap.Snap\ Camera.plist
sudo rm -rf /Applications/Snap\
View TrixEditor.js
import React, { Component, Fragment } from 'react'
import PropTypes from 'prop-types'
const randomString = () =>
Math.random().toString(36).substring(2, 15)
export default class TrixEditor extends Component {
static propTypes = {
customRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
name: PropTypes.string,
JoshCheek /
Last active Apr 2, 2021
Refactoring + code review of some code I saw in a blog
JoshCheek / syncing_promises.js
Created Apr 1, 2021
JS syncing promises code sample
View syncing_promises.js
node -e '
const sleep = n => new Promise(resolve => setTimeout(resolve, n))
!async function() {
const start =
const val1 = sleep(1000).then(() => console.log({ line: 5, at: }))
const val2 = sleep(1500).then(() => console.log({ line: 6, at: }))
const val3 = sleep(500 ).then(() => console.log({ line: 7, at: }))
await Promise.all([val1, val2, val3]) // <-- IS THERE ANYTHING BETTER THAN THIS YET?!?!!?!?
JoshCheek / weak_memoization_through_rubys_weak_ref.rb
Last active Apr 1, 2021
Example of how you could use Ruby's WeakRef to perform weak memoization
View weak_memoization_through_rubys_weak_ref.rb
require 'weakref'
# This module allows methods to be memoized, but the memoized result can still be GC'd.
# So the object can live for a long time. Eg maybe it's created on server initialization
# and lasts for the lifetime of a server. If the calculated result is large,
# then memoizing it doesn't permanently allocate that memory.
module WeakMemo
def memoize(name)
method = instance_method name
ivar = :"@_memoized_#{name}"
JoshCheek / tetris
Last active Mar 28, 2021
CLI tetris
View tetris
#!/usr/bin/env ruby
require 'io/console'
class Grid
def self.from_str(str, color:)
rows = do |line| do |c|
color if c != " ".freeze
JoshCheek / show_unused.rb
Created Mar 24, 2021
Show unused / untested stuff in Rails
View show_unused.rb
require 'set'
# For answering questions:
# * What views exist that we didn't render?
# * What controller actions exist that we didn't hit?
# * What routes exist that we didn't request? / generate a link to?
# * What files exist that we never required
class ShowUnused
data = {
JoshCheek /
Last active Mar 19, 2021
linked list in Python
import functools
class LList:
def fromArray(cls, array):
return functools.reduce(lambda ll, val: ll.append(val), array, cls())
def __init__(self): self.isEmpty = True
def append(self, val): return LNode(val, self)
def __iter__(self): return self
JoshCheek / how_to_implement_service_objects.rb
Last active Mar 12, 2021
A myriad of ways to implement "service objects"
View how_to_implement_service_objects.rb
# Note1: all `...` below mean "etcetera", like psuedocode, not implying the new Ruby 3 syntax
# Note2: `obj.()` is syntactic sugar for ``
# Given an invocation like this:
OnboardOrganization.(arg1, arg2, ...)
# Here are some possible ways you could implement it:
# 1. If the definition fits in a s single method, you can toss it on a module
# You'd choose a module b/c you don't want a class here since you don't want to
View be_the_monkey_patch_you_wish_to_see_in_the_world.rb
# This fixes a bug that the code below triggered. SiB uses String#<< on this line:
# So it should include this alias in the Safe refinements here:
module SeeingIsBelieving::Safe
refine String do
alias << <<