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:
#!/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) |
I hereby claim:
To claim this, I am signing this object:
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.
=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. |
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 |
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 |
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) |
#!/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 |
s = document.createElement('script'); | |
s.setAttribute('src','http://prose.atevans.com/bookmarklet.js'); | |
document.head.appendChild(s); |
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 |