Skip to content

Instantly share code, notes, and snippets.

View KelseyDH's full-sized avatar

Kelsey Hannan KelseyDH

  • Australia
View GitHub Profile
@KelseyDH
KelseyDH / twitterblue-nerd.js
Last active November 10, 2022 05:47 — forked from busybox11/twitterblue-nerd.js
create a safe path for using this script
// ==UserScript==
// @name @chaoticvibing Twitter Blue Nerd - twitter.com
// @namespace Violentmonkey Scripts
// @match *://*.twitter.com/*
// @grant none
// @version 1.2.0
// @author @chaoticvibing - GH @busybox11
// @description 11/9/2022, 11:45:28 PM
// @updateURL https://gist.githubusercontent.com/KelseyDH/7478e6fea882a5a685ededdebf0d51ea/raw/76eedc195d471add755e84c71bf92126908b1629/twitterblue-nerd.js
// @downloadURL https://gist.githubusercontent.com/KelseyDH/7478e6fea882a5a685ededdebf0d51ea/raw/76eedc195d471add755e84c71bf92126908b1629/twitterblue-nerd.js
@KelseyDH
KelseyDH / README.md
Created May 19, 2021 03:06 — forked from tombigel/README.md
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)

How to Change Open Files Limit on OS X and macOS

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

To check the current limits on your Mac OS X system, run:

@KelseyDH
KelseyDH / local-dnsserver.md
Created February 4, 2020 20:30 — forked from nsbingham/local-dnsserver.md
Testing a CNAME

Setting up a local DNS server with bind on OSX Mavericks

This is really just an approach for locally testing DNS changes, which can easily be done with a HOSTS file if the change involves an IP address, but gets a bit trickier when things like CNAMEs are involved. This is only meant to test locally off a single machine.

  1. Install bind using homebrew

    brew install bind

  2. Follow the installation steps to start up bind

@KelseyDH
KelseyDH / osx_setup.sh
Created January 14, 2020 19:30 — forked from dannysmith/osx_setup.sh
Sensible defaults for New Mac
#!/usr/bin/env bash
# ~/.osx — http://mths.be/osx
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `.osx` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# app/domain/null_account.rb
class NullAccount
def id
raise "You are calling id on an account that doesn't exist. Make sure the user you're working with has accounts first before trying to call them."
end
def available_balance
Money.new(available_balance_cents, available_balance_currency)
end
class User < ApplicationRecord
def savings_account
self.accounts.where(savings: true).first || NullAccount.new
end
def chequing_account
self.accounts.where(chequing: true).first || NullAccount.new
end
# .present?
if user.savings_account.present?
user.savings_account.available_balance_cents
else
0
end
# .try
user.try(:savings_account).(:available_balance_cents) || 0
@KelseyDH
KelseyDH / null_object_example.rb
Created August 23, 2019 09:59
Using Null Object pattern in Ruby on Rails apps
# E.g. for a banking app where users might not have bank accounts yet.
# Not having accounts could mean lots of code like this:
if user.savings_account.present?
user.savings_account.available_balance_cents
end
# But with the NullObject pattern I can confidently call:
user.savings_account.available_balance_cents
@KelseyDH
KelseyDH / service_object.rb
Created January 27, 2018 08:26
How to write a Rails Service Object with logging
# # A Plain Old Ruby Object (poro) with Rails logger support:
class ServiceObject
def initialize(foo)
@logger = Logger.new(STDOUT)
@foo = foo
end
def call
do_something
end
@KelseyDH
KelseyDH / thread_safe.rb
Created July 18, 2017 22:30 — forked from mikbe/thread_safe.rb
Stops collisions but it's ugly
require 'thread'
module ThreadSafe
def self.included(base)
base.extend(ThreadSafeClassMethods)
base.threadsafe_class_mutex = Mutex.new
end
module ThreadSafeClassMethods