Skip to content

Instantly share code, notes, and snippets.

View djanowski's full-sized avatar

Damian Janowski djanowski

View GitHub Profile
function useMatchMedia(query) {
const mediaQuery = useMemo(() => window.matchMedia(query), [ query ]);
const [ matches, setMatches ] = useState(mediaQuery.matches);
useEffect(() => {
function onChange({ matches: newMatches }) {
setMatches(newMatches);
}
if (mediaQuery.addEventListener)
# Removing old Rubies in preparation for RVM
/usr/bin/gem list | awk '{ print $1 }' | xargs /usr/bin/gem uninstall -a --install-dir=/Library/Ruby/Gems/1.8 --bindir=/usr/bin
/usr/bin/gem list | awk '{ print $1 }' | xargs /usr/bin/gem uninstall -a --install-dir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 --bindir=/usr/bin
/opt/local/bin/gem list | awk '{ print $1 }' | xargs /opt/local/bin/gem uninstall -a
for file in $(find /usr/bin -type f); do (head -n1 $file | grep '^#.*ruby' > /dev/null) && echo $file && rm $file; done
port installed | ack '^(j?ruby|rb\-)' | awk '{ print $1, $2 }' | xargs port uninstall
@djanowski
djanowski / gist:742381
Created December 15, 2010 18:25
Super wget
$ cd doc
$ wget --mirror --no-host-directories --adjust-extension --convert-links --page-requisites -e robots=off --span-hosts --domains heroku.com,googleapis.com http://redis-io.heroku.com
@djanowski
djanowski / throttle_async.js
Created February 1, 2019 16:49
Throttle an async (promise-returning) function in JavaScript/Node.js
// Throttles an async function.
function throttleAsync(fn, wait) {
let lastRun = 0;
let currentRun = null;
async function throttled(...args) {
if (currentRun)
return currentRun;
const currentWait = lastRun + wait - Date.now();
@djanowski
djanowski / each_async_update.js
Created November 29, 2017 15:28
Concurrently transform a MongoDB cursor into a stream of bulk MongoDB updates.
// Concurrently transform a MongoDB cursor into a stream of bulk MongoDB updates.
//
// Usage:
//
// const users = db.collection('users');
// const usersToUpdate = users.find({ email: null });
//
// await eachAsyncUpdate(users, usersToUpdate, async function(user) {
// const userEmail = await findUserEmail(user);
//
@djanowski
djanowski / timezones.txt
Created November 29, 2017 14:49
Good-enough default IANA time zones by US state
AL America/Chicago
AK America/Anchorage
AS Pacific/Samoa
AZ America/Denver
AR America/Chicago
CA America/Los_Angeles
CO America/Denver
CT America/New_York
DE America/New_York
DC America/New_York
require 'rubygems'
require "sinatra"
enable :sessions
#use Rack::Session::Cookie
#use Rack::Session::Pool
get '/' do
if session[:username]
"hi, #{session[:username]}"
#!/usr/bin/env bash
# Monitors your tree and runs tests when anything changes.
#
# `make`, `yarn test`, etc. automatically detected.
#
# $ autotest
#
# Run a specific command on changes:
#
#!/usr/bin/env bash
# Monitors your tree and runs tests when anything changes.
#
# `make`, `yarn test`, etc. automatically detected.
#
# $ autotest
#
# Run a specific command on changes:
#
#!/usr/bin/env bash
# Monitors your tree and runs tests when anything changes.
#
# `make`, `yarn test`, etc. automatically detected.
#
# $ autotest
#
# Run a specific command on changes:
#