Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
joshuaflanagan / meme.sh
Last active October 5, 2022 23:08 — forked from tzermias/meme.sh
Meme Generator using ImageMagick
#!/bin/bash
# meme.sh
# https://gist.github.com/joshuaflanagan/77f31411d137aec9b9c1b79b42d339f8
# Meme generator with ImageMagick
# https://www.it-cooking.com/technology/digital-image/image-processing/meme-generator-imagemagick/
usage() {
echo "Usage: $0 [ -t TOP_MSG ] [ -b BOTTOM_MSG ] [ -s FONTSIZE=80] [ -a TOP_FONTSIZE=80 ] [ -z BOTTOM_FONTSIZE=80 ] SRC DST"
@joshuaflanagan
joshuaflanagan / fish.rb
Last active January 13, 2016 23:50
Simplify working with UUID primary keys in Rails console
class ActiveRecord::Base
# Find a record by UUID primary key prefix
#
# Example:
# > User.fish "1245"
# # User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."id" BETWEEN '12450000000000000000000000000000' AND '1245ffffffffffffffffffffffffffff') LIMIT $1 [["LIMIT", 2]]
# => #<User id: "12451304-761d-4e1d-8281-40aa6213b633", name: "josh">
def self.fish(partial_id)
return find(partial_id) unless partial_id.is_a?(String)
scrubbed = partial_id.gsub(/[^a-fA-F0-9]/, "")
@joshuaflanagan
joshuaflanagan / big_decimal_marshal.rb
Created November 15, 2015 01:56
BigDecimal does not Marshal round trip in ruby 2.1/2.2 (did in 1.9.3)
# Ruby 2.1.2
2.1.2 :173 > x = BigDecimal.new(1.0, 1)
=> #<BigDecimal:7ffcee09bb98,'0.1E1',9(27)>
2.1.2 :174 > y = Marshal.load Marshal.dump x
=> #<BigDecimal:7ffcec5d9ee0,'0.1E1',9(18)>
2.1.2 :175 > x == y
=> true
2.1.2 :176 > Marshal.dump(x) == Marshal.dump(y)
=> false
def no_surprises!
ActiveRecord::Base.class_eval do
include SkipsValidations
include SkipsCallbacks
end
end
module SkipsValidations
def perform_validations(*)
true
@joshuaflanagan
joshuaflanagan / pngcheck.rb
Last active August 29, 2015 14:13
Parse PNG file
# http://www.w3.org/TR/PNG/#5DataRep
class PNGCheck
def initialize(path)
@path = path
end
def check_all!
expected_signature = [137, 80, 78, 71, 13, 10, 26, 10]
file.seek 0
signature_data = file.read(8)
@joshuaflanagan
joshuaflanagan / gist:523aeec5fceb3bc75691
Created December 17, 2014 01:46
Recover a branch when you know the SHA, but don't have it locally
http -v -a username:password POST https://api.github.com/repos/owner/repo/git/refs ref="refs/heads/recovered_branch" sha="290b2090a741d35edd67f15c74b2d43299df8995"
git fetch
git checkout recovered_branch
@joshuaflanagan
joshuaflanagan / gist:7495006
Created November 16, 2013 02:15
Postgres extensions on Amazon RDS
name | default_version | installed_version | comment
------------------------+-----------------+-------------------+---------------------------------------------------------------------
pg_buffercache | 1.0 | | examine the shared buffer cache
earthdistance | 1.0 | | calculate great-circle distances on the surface of the Earth
pg_freespacemap | 1.0 | | examine the free space map (FSM)
intagg | 1.0 | | integer aggregator and enumerator (obsolete)
plperl | 1.0 | | PL/Perl procedural language
sslinfo | 1.0 | | information about SSL certificates
btree_gist | 1.0 | | support for indexing common datatypes in GiST
fuzzystrmatch | 1.0
@joshuaflanagan
joshuaflanagan / pull_request_labels.user.js
Created February 2, 2013 19:53
UserScript to show Labels on Pull Requests
// ==UserScript==
// @name Pull Request Labels
// @namespace http://joshuaflanagan.com
// @include https://github.com/*/*/pulls
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==
$(function(){
var $pull_requests = $(".pulls-list .list-browser-item h3");
$pull_requests.each(function(){
@joshuaflanagan
joshuaflanagan / watch_git.rb
Created June 27, 2012 01:10
See what's going on in your .git folder when you perform git commands
# I used this to monitor changes to the .git folder during
# my Austin on Rails lightning talk on Understanding Git.
#
# I ignore any changes to the .git/logs folder, because they are
# noisy and don't add a lot to understanding.
# If you want "the whole truth", remove the :ignore parameter below.
#
# ruby listen.rb <path to .git folder>
#
# gem install listen # its the foundation of Guard
@joshuaflanagan
joshuaflanagan / delegate_eql.rb
Created May 5, 2012 22:13
DelegateClass instance doesn't eql? itself
require 'test/unit'
require 'delegate'
# These tests demonstrate some unexpected (to me)
# behavior of a class created by DelegateClass.
# An instance of a DelegateClass created class does not eql? itself.
#
# The WidgetTests all pass.
# The comparison and eql WidgetWrapperTests fail.
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]