Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Coleman penguincoder

View GitHub Profile
View keybase.md

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:

@penguincoder
penguincoder / Dockerfile
Created Jul 2, 2018
reimplement Ruby's native `.to_i`
View Dockerfile
FROM ruby:2.5-alpine
COPY convert.rb /
RUN chmod 700 /convert.rb
CMD /convert.rb
View Dockerfile
FROM ruby:2.5-alpine
COPY coin.rb /
RUN chmod 700 /coin.rb
CMD /coin.rb
@penguincoder
penguincoder / Dockerfile
Created Jun 12, 2018
Even Fibonacci Numbers
View Dockerfile
FROM ruby:2.5.1-alpine3.7
COPY fib.rb /
RUN chmod 750 /fib.rb
CMD [ "/fib.rb" ]
@penguincoder
penguincoder / redis_mutex.rb
Last active Aug 29, 2015
A Redis-backed mutex that uses Lua transactions
View redis_mutex.rb
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"
##
View american_date_monkey_patch.rb
#
# © 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
View pg2mysql.rb
#!/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.
#
View vigenere.rb
#!/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:
You can’t perform that action at this time.