Skip to content

Instantly share code, notes, and snippets.

View agius's full-sized avatar
🐐
goat rodeo

Andrew Evans agius

🐐
goat rodeo
View GitHub Profile
@agius
agius / json_diff.rb
Created May 8, 2012 00:52
Ruby JSON Diff
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
unless ARGV.count > 1
puts "Usage: json_diff.rb json_file_1.json json_file_2.json"
exit
end
def different?(a, b, bi_directional=true)
@agius
agius / keybase.md
Created October 20, 2017 17:26
Proof of identity on Keybase

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@agius
agius / key-value-api-elixir.md
Last active July 7, 2017 19:17
Learning Elixir: Key-Value Server
layout title
default
A stateful key/value server in Elixir

I wanted to make a simple key-value server in Elixir - json in, json out, GET, POST, with an in-memory map. The point is to reinvent the wheel, and learn me some Elixir. My questions were: a) how do I build this without Phoenix and b) how do I persist state between requests in a functional language?

Learning new stuff is always painful, so this was frustrating at points and harder than I expected. But I want to emphasize that I did get it working, and do understand a lot more about how Elixir does things - the community posts and extensive documentation were great, and I didn't have to bug anyone on StackOverflow or IRC or anything to figure all this out.

Here's what the learning & development process sounded like from inside my head.

@agius
agius / planckjs.rb
Created January 12, 2016 19:03
Scan your node_modules directory and report on how many Planck-scale JS libraries you have
=begin
PlanckJS - or: why the FUCK do you have 700+ dependencies?
Planck-scale libraries are not just microlibraries, they're even BETTER! They're so micro
they're beyond nanolibraries. They have _more boilerplate code than actual code!_ So composable.
Such Unix philosophy. Wow.
Back in my day, we called these things "functions" and put them in our code, rather than
descending into package-management hell with a broken tool like npm.
@agius
agius / find.rake
Created November 1, 2013 04:32
Find and replace rake task
namespace :find do
desc "Find and replace"
task :replace, :find, :replace do |t, args|
find = args[:find]
replace = args[:replace]
`egrep -lRZ "#{find}" --exclude-dir='.git' --exclude-dir='db' --exclude-dir='tmp' --exclude-dir='images' --exclude-dir='fonts' --exclude-dir='vendor' . | xargs -I {} sed -i '' -e 's/#{find}/#{replace}/g' {}`
end
end
@agius
agius / jekyll.rake
Created October 18, 2013 05:48
Generate static error pages and upload to S3
namespace :static do
desc "Generate and upload static pages"
task :generate do
`jekyll build -s jekyll -d jekyll/_site`
`cp -r jekyll/_site/* public/`
config = YAML.load(File.read(File.join(File.dirname(__FILE__), '..', '..', 'config', 'keys.yml')))
config = config['production']['amazon']
AWS.config(:access_key_id => config['key'], :secret_access_key => config['secret'])
s3 = AWS::S3.new
@agius
agius / blunder.rb
Created October 12, 2013 00:11
Centralized error reporting module - control what services you use and how you log errors in one place.
module Blunder
# Centralizes error reporting, so we don't get custom
# library names like BugSnag or Errplane all over our code
def self.oops(exception, custom_data = {})
raise if Rails.env == 'test'
exception = Exception.new(exception) unless exception.is_a?(Exception)
custom_data = custom_data.with_indifferent_access
Rails.logger.error("\n\nBlunder Exception: #{exception}")
Rails.logger.error("backtrace:#{exception.backtrace.take(20).join("\n")}\n\n") if exception.backtrace.present?
env = custom_data.delete(:env)
@agius
agius / hamlconvert.rb
Created August 20, 2013 04:53
Recursively browse directory and convert all .haml files to .erb via Herbalizer (https://github.com/danchoi/herbalizer)
#!/usr/bin/env ruby
require 'open3'
# things herbalizer hates:
# nested hashes: %div{data: {href: src }} -> %div{data: Hash[href: src] }
# comments in the first line
# blank first line
# ruby-style interpolation: Message to #{person} -> Message to \ = person
# ternary operators inside blocks: %div{href: one ? two : three } -> put on separate line
@agius
agius / bookmarklet_toolbar.js
Last active December 17, 2015 23:58
Prose Bookmarklet
s = document.createElement('script');
s.setAttribute('src','http://prose.atevans.com/bookmarklet.js');
document.head.appendChild(s);
@agius
agius / metroify.rb
Created May 20, 2013 14:10
An application_helper function to output stuff in a metro-like format for bootstrap.
def metroify(collection, partial, opts = {})
return "" unless collection.present?
output = ""
coll_copy = collection.dup
renderize = lambda do |obj, tile|
locals = {tile: tile}
locals = locals.merge(opts[:locals]) if opts[:locals]
render_opts = opts.dup.merge(partial: partial, object: obj, locals: locals)
render(render_opts).to_s