Skip to content

Instantly share code, notes, and snippets.

@penguincoder
penguincoder / bootstrap.sh
Last active April 9, 2024 15:25
A shell script to bootstrap your machine with nix, direnv, and devenv.
#!/usr/bin/env bash
#
# Copyright (c) 2024 Andrew Coleman <penguincoder@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

Keybase proof

I hereby claim:

  • I am penguincoder on github.
  • I am penguincoder (https://keybase.io/penguincoder) on keybase.
  • I have a public key ASD7uK4ULWqyNQbV6YHMzdX7NG_brCLKqqkPx79pPb8DHQo

To claim this, I am signing this object:

#
# &copy; 2009 Andrew Coleman
# Released under MIT license.
# http://www.opensource.org/licenses/mit-license.php
#
# total hack to allow american style date parsing.
# does not allow european-ish date parsing, sorry.
#
module AmericanDateMonkeyPatch
def to_date
#!/usr/bin/env ruby
##
# A pure ruby version of a Vigenere cipher engine. Encodes, decodes and guesses
# keys.
#
class Vigenere
##
# Encodes a plaintext string into a enciphered code. Strips all
# nonalphanumeric characters from input. Takes the following keys:
#!/usr/bin/env ruby
##
# Andrew Coleman <mercury at penguincoder dot org>
# Released under the GPLv2 http://gnu.org
# General purpose tranlator for pgsql -> mysql. Best used with Rails-like data.
#
# Use: pg_dump -DOx [dbname] > outputfile
# to get a proper dump for this program.
#
@penguincoder
penguincoder / redis_mutex.rb
Last active August 29, 2015 14:11
A Redis-backed mutex that uses Lua transactions
require 'digest/md5'
require 'redis'
class RedisMutex
MutexTimeout = Class.new(StandardError)
LUA_ACQUIRE = "return redis.call('SET', KEYS[1], ARGV[2], 'NX', 'EX', ARGV[1]) and redis.call('expire', KEYS[1], ARGV[1]) and 1 or 0"
LUA_RELEASE = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"
##