Skip to content

Instantly share code, notes, and snippets.

View ekhall's full-sized avatar

EK Hall ekhall

  • Personal
  • New York, USA
View GitHub Profile
@ekhall
ekhall / gist:6996849
Created October 15, 2013 18:58
This is sick...
--- ~ » irb
2.0.0p247 :001 > class MyClass
2.0.0p247 :002?> def initialize(val)
2.0.0p247 :003?> @x = val
2.0.0p247 :004?> end
2.0.0p247 :005?> def my_method
2.0.0p247 :006?> @x
2.0.0p247 :007?> end
2.0.0p247 :008?> end
=> nil
describe "PUT update" do
describe "with valid params" do
it "updates the requested article" do
article = Article.create! valid_attributes
Article.any_instance.should_receive(:update).with({ "these" => "params" })
put :update, {:id => article.to_param, :article => { "these" => "params" }}, valid_session
end
it "assigns the requested article as @article" do
article = Article.create! valid_attributes
➜ MgDB git:(abs-neo4j) ✗ pry
[1] pry(main)> require 'yaml'
=> true
[2] pry(main)> require './model/abstract_node'
=> true
[3] pry(main)> myhash = YAML.load(File.open('yaml-model/patient.yaml'))
=> {:model_name=>"Patient",
:properties=>[:mrn, :firstname, :surname, :dob, :gender]}
[4] pry(main)> Patient = Mgdb::NodeFactory.get_node_class(myhash)
=> Kernel::Patient
@ekhall
ekhall / gist:8566682
Last active January 4, 2016 04:09
Complex code smell?
describe 'Created Node Class' do
before(:all) do
@name = 'Patient'
@token = {model_name: @name, properties: [:first, :second]}
@klass = NodeFactory.get_node_class(@token)
end
it 'queries the graph and instantiates itself the correct number of times' do
iex> Stream.unfold({0,1}, fn {f1,f2} -> {f1, {f2, f1+f2}} end) |> Enum.take(15)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
@ekhall
ekhall / gist:9630990
Last active August 29, 2015 13:57
Understanding &Enum.reduce/3
iex(11)> Enum.reduce([1, 2, 3, 4, 5], 0, fn(x, acc) -> IO.puts "x: #{x} acc: #{acc}";x + acc end)
x: 1 acc: 0
x: 2 acc: 1
x: 3 acc: 3
x: 4 acc: 6
x: 5 acc: 10
15
iex(12)>
(ns patient.core
(:require [datomic.api :as d]))
(def conn nil)
(defn add-patient [patient-name]
@(d/transact conn [{:db/id (d/tempid :db.part/patient)
:patient/name patient-name}]))
(defn find-all-patients []
(defn wrap-dump [handler]
(let [out-writer (java.io.FileWriter. "output.html")]
(fn [request]
(binding [*out* out-writer] (prn request))
(let [response (handler request)]
(binding [*out* out-writer] (prn response))
response))))
(def app
(-> (wrap-simulated-methods routes)
Country,Dwellings without basic facilities,Housing expenditure,Rooms per person,Household net adjusted disposable income,Household net financial wealth,Employment rate,Job security,Long-term unemployment rate,Personal earnings,Quality of support network,Educational attainment,Student skills,Years in education,Air pollution,Water quality,Consultation on rule-making,Voter turnout,Life expectancy,Self-reported health,Life satisfaction,Assault rate,Homicide rate,Employees working very long hours,Time devoted to leisure and personal care
Australia,1.1,20,2.3,31197,38482,72,4.4,1.06,46585,93,74,514,18.8,13,93,10.5,93,82,85,7.4,2.1,0.8,14.23,14.41
Austria,1,21,1.6,29256,48125,73,3.4,1.07,43837,95,82,498,16.9,27,95,7.1,75,81.1,69,7.5,3.4,0.5,8.61,14.46
Belgium,1.9,20,2.3,27811,78368,62,4.5,3.37,47276,91,71,507,18.8,21,84,4.5,89,80.5,74,7.1,6.6,1.2,4.41,15.71
Canada,0.2,22,2.5,30212,63261,72,6.6,0.9,44017,94,89,522,17,15,90,10.5,61,81,88,7.6,1.3,1.7,3.98,14.25
Chile,9.4,19,1.3,13762,18141,62,4.7,2.01,15438,85,72,439,1
#lang racket
(struct student (name id# dorm))
(define bob (student 'Bob 1234 'dorm1))
(list bob) ; -> '(#<student>)
'(bob) ; -> '(bob)
; I thought these two ways of creating lists were equivalent?