Skip to content

Instantly share code, notes, and snippets.

@robmckinnon
robmckinnon / application.ex
Created April 10, 2018 22:16
Add GenServer implementation to supervision tree in application.ex
defmodule NodeProcess.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
children = [
@robmckinnon
robmckinnon / wrapper.sh
Created April 10, 2018 21:59
Elixir 1.6 Port documentation recommends the use of a process wrapper script to prevent zombie processes.
#!/bin/sh
"$@" &
pid=$!
while read line ; do
echo line
done
kill -KILL $pid
@robmckinnon
robmckinnon / server.ex
Last active March 19, 2024 11:20
A GenServer implementation that starts a Node.js server process using Elixir ports.
defmodule NodeProcess.Server do
@moduledoc """
A GenServer implementation that starts a Node.js server process using Elixir ports.
"""
# Elixir automatically defines callbacks not overriden
use GenServer
@doc """
Called when application started via application.ex.
# Ambient Experiment
# Coded by Darin Wilson
#
# The piece consists of three long loops, each of which
# plays one of two randomly selected pitches. Each note
# has different attack, release and sleep values, so that
# they move in and out of phase with each other. This can
# play for quite awhile without repeating itself :)
{
"swagger": "2.0",
"info": {
"title": "Account and Transaction API Specification",
"description": "Swagger for Account and Transaction API Specification",
"termsOfService": "https://www.openbanking.org.uk/terms",
"contact": {
"name": "Service Desk",
"email": "ServiceDesk@openbanking.org.uk"
},
@robmckinnon
robmckinnon / register-country-and-territory-list.rb
Created December 8, 2016 11:06
Get sorted list of territory and country names excluding those with end_dates using Open Register Ruby client
require 'openregister-ruby'
c = OpenRegister.register('country', :beta)._all_records +
OpenRegister.register('territory', :alpha)._all_records
c.select{|x| x.end_date.blank?}.map(&:name).sort
@robmckinnon
robmckinnon / register-diagram.rb
Last active November 21, 2016 13:24
ruby script to generate digram of register links
require 'graph' # gem 'graph'
require 'openregister-ruby' # gem 'openregister-ruby', git: 'https://github.com/robmckinnon/openregister-ruby.git', branch: 'record-versions'
r = OpenRegister.register 'school-eng', :alpha
digraph do
rotate
node_attribs << rectangle
r._fields.each do |f|
if f.register.present?
@robmckinnon
robmckinnon / elixir_stream.sh
Last active September 23, 2016 11:27
Different behaviour of Elixir `IO.stream` vs `Stream.map` vs 'File.stream!'
mix run -e 'stream = "x\ny" |> String.split() |> Stream.map(& &1);
IO.puts inspect stream |> Enum.at(0);
IO.puts inspect stream |> Enum.at(0);'
"x"
"x"
(echo x && echo y) | mix run -e 'stream = IO.stream(:stdio, :line);
IO.puts inspect stream |> Enum.at(0);
IO.puts inspect stream |> Enum.at(0);'
"x\n"
@robmckinnon
robmckinnon / gist:73ffb1ea3db15cd73f0d1cc3dd60a00d
Created August 23, 2016 15:25
Finding an address from UPRN
gem install base32-crockford
irb
require 'base32/crockford'
Base32::Crockford.encode(10033530330)
=> "9B0Q1ET"
exit
cd address-data/data/address
grep 9B0Q1ET *.tsv
TQ258.tsv:2003-04-27T00:00:00Z 9B0Q1ET 8400765 GROUND FLOOR AND FIRST FLOOR [-0.1364013,51.5173220] 2015-04-20
@robmckinnon
robmckinnon / download_discovery_registers.rb
Created July 29, 2016 15:16
Download discovery registers as TSV
`mkdir data`
%w[uk
street
school
school-type
school-tag
school-phase
school-gender
school-federation
school-admissions-policy