Skip to content

Instantly share code, notes, and snippets.

View nickmcdonnough's full-sized avatar

Nick McDonnough nickmcdonnough

  • Perchwell
  • Austin, TX
View GitHub Profile
defmodule Example do
def start_tasks do
ids = [1,2,3,4,5]
tasks = Enum.map(ids, fn x -> Task.async(fn -> Job.start(x) end) end)
tasks |> Enum.map(fn x -> Task.await(x, 10_000) end)
end
end
defmodule Job do
def start(arg) do
@nickmcdonnough
nickmcdonnough / shunting_yard.rb
Created February 8, 2017 19:50
shunting-yard algorithm implementation in ruby
class MathParser
attr_reader :expression, :output, :operators, :postfix
PRECEDENCE = {
'^' => 3,
'*' => 2,
'/' => 2,
'+' => 1,
'-' => 1
}
@nickmcdonnough
nickmcdonnough / wtf.rb
Created March 16, 2016 18:24
banging my head against a wall
class Person
include ActiveModel::Serialization
attr_accessor :name
def attributes
{ 'name' => nil }
end
end
@nickmcdonnough
nickmcdonnough / meetup.clj
Created July 1, 2015 14:41
A better solution for the Meetup challenge on exercism.io
(ns meetup)
(def weekdays ["sunday" "monday" "tuesday" "wednesday"
"thursday" "friday" "saturday"])
(def month-max {1 31, 2 28, 3 31,
4 30, 5 31, 6 30,
7 31, 8 31, 9 30,
10 31, 11 30, 12 31})
@nickmcdonnough
nickmcdonnough / push2github.rb
Created April 21, 2015 15:28
First iteration of script to push student branches to github for self assessments. It's painfully slow and will be rewritten in AWK over the weekend.
#!/usr/bin/env ruby
#
# Create a new repo on the makersquare org.
# The name should be something like:
# MKSXX-self-assessments-week-X
#
# Usage:
# ./push2github.rb Week\ 00/ mks16
#
# This will read all student names from a
@nickmcdonnough
nickmcdonnough / binary_search.rb
Created April 18, 2015 13:36
Ruby Binary Search
def b_search coll, n
min = 0
max = coll.length - 1
while min < max do
mid = (min + max) / 2
item = coll[mid]
if item > n
max = mid - 1
@nickmcdonnough
nickmcdonnough / reductions.rb
Last active August 29, 2015 14:19
A Ruby version of Clojure's function `reductions`.
class Array
def reductions arg=nil, &block
s = arg ? 0 : 1
r = arg ? [arg] : [self.first]
self[s..-1].each do |x|
r << block.call(r.last, x)
end
r
@nickmcdonnough
nickmcdonnough / core.clj
Created April 14, 2015 00:49
Austin Clojure Meetup Refactor Fun
(ns dataprep.core
(:require [clojure.java.io :as io]
[clojure.string :as s]
[clojure.data.csv :as csv]
[semantic-csv.core :as sc]
[clj-http.lite.client :as http]))
(defn split-point [address]
"Takes the :Address value from a record and splits it up. Returns a map
Array.prototype.flatten = function () {
return this.reduce(function (a, b) {
if (Array.isArray(a)) {
return a.concat(b);
} else {
return [a].concat(b)
}
})
}

Recent improvements to the ClojureScript compiler have greatly simplified setting up development versus production outputs.

This example uses Figwheel as something that you want to exclude for production, but the pattern is general.

With this simple setup you only need one html file/view and it will work for developement and production.