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:
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. |
| # Your init script | |
| # | |
| # Atom will evaluate this file each time a new window is opened. It is run | |
| # after packages are loaded/activated and after the previous editor state | |
| # has been restored. | |
| # | |
| # An example hack to log to the console when each text editor is saved. | |
| # | |
| # atom.workspace.observeTextEditors (editor) -> | |
| # editor.onDidSave -> |
| class MyController < ApplicationController | |
| def create | |
| @model = Model.new(model_params) | |
| # we have to call this here, to populate | |
| # errors on any other fields that might | |
| # be invalid | |
| @model.valid? | |
| if @model.model_attr == 'invalid' && [email protected]_state(:dont_care) |
| #!/usr/bin/env ruby | |
| site 'http://community.opscode.com/api/v1' | |
| cookbook 'sprout-rbenv', | |
| :github => 'pivotal-sprout/sprout-rbenv' | |
| cookbook 'sprout-ruby', | |
| :github => 'pivotal-sprout/sprout-ruby' |
| Fetching repository, done. | |
| -----> Node.js app detected | |
| PRO TIP: Specify a node version in package.json | |
| See https://devcenter.heroku.com/articles/nodejs-support | |
| -----> Defaulting to latest stable node: 0.10.31 | |
| -----> Downloading and installing node | |
| -----> Exporting config vars to environment |
| var d = new Date(); | |
| var tz_offset = d.getTimezoneOffset(); // seconds, not ms, because Javascript | |
| var tz_select = $('#tz-select'); | |
| var abbr = tz_select.find("option[data-offset='" + tz_offset + "']").data('abbreviation'); |
| 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 |