Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
JoshCheek / uninstall_snap_camera_mac_osx.sh
Last active Apr 9, 2021
How to uninstall Snap Camera on Mac OS X
View uninstall_snap_camera_mac_osx.sh
# 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\ Camera.app/
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
JoshCheek / blog_code_feedback.md
Last active Apr 2, 2021
Refactoring + code review of some code I saw in a blog
View blog_code_feedback.md
@JoshCheek
JoshCheek / syncing_promises.js
Created Apr 1, 2021
JS syncing promises code sample
View syncing_promises.js
# https://twitter.com/josh_cheek/status/1377767258601181189
node -e '
const sleep = n => new Promise(resolve => setTimeout(resolve, n))
!async function() {
const start = Date.now()
const val1 = sleep(1000).then(() => console.log({ line: 5, at: Date.now()-start }))
const val2 = sleep(1500).then(() => console.log({ line: 6, at: Date.now()-start }))
const val3 = sleep(500 ).then(() => console.log({ line: 7, at: Date.now()-start }))
await Promise.all([val1, val2, val3]) // <-- IS THERE ANYTHING BETTER THAN THIS YET?!?!!?!?
@JoshCheek
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
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 = str.lines.map do |line|
line.chomp.chars.map do |c|
color if c != " ".freeze
end
end
@JoshCheek
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
def self.call(outstream)
data = {
@JoshCheek
JoshCheek / linked_list.py
Last active Mar 19, 2021
linked list in Python
View linked_list.py
import functools
class LList:
@classmethod
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
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 `obj.call()`
# 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:
# https://github.com/JoshCheek/seeing_is_believing/blob/46d49a53a68ec22edd52322ad0f1192ef2d77f51/lib/seeing_is_believing/event_stream/producer.rb#L155
# So it should include this alias in the Safe refinements here:
# https://github.com/JoshCheek/seeing_is_believing/blob/46d49a53a68ec22edd52322ad0f1192ef2d77f51/lib/seeing_is_believing/safe.rb#L47-L51
module SeeingIsBelieving::Safe
refine String do
alias << <<
end
end