Skip to content

Instantly share code, notes, and snippets.

View MachinesAreUs's full-sized avatar

Agustín Ramos MachinesAreUs

View GitHub Profile
@MachinesAreUs
MachinesAreUs / zurg.ex
Last active October 13, 2015 21:25
Solution to "Escape from Zurg" in Elixir
defmodule Zurg do
import Enum
@toys %{buzz: 5, woody: 10, rex: 20, hamm: 25}
def solve() do
initial_state
|> complete_sequences
|> pick_fastest
end
@MachinesAreUs
MachinesAreUs / tshirts.ex
Created September 17, 2015 04:16
Erlang Factory t-shirts
alias ErlangFactory.MexicoCity2015.Repo
Repo.all Attendee
|> share
|> learn
|> make_friends
|> have_mezcal
|> have_fun
@MachinesAreUs
MachinesAreUs / basic_stats.sh
Created August 13, 2015 20:30
Calculate basic statistics from a numeric input stream
# Requires pythonpy
cat numbers | py --ji -l 'min(l), max(l), numpy.median(l), numpy.mean(l)'
@MachinesAreUs
MachinesAreUs / crawl_elixir_doc.sh
Created July 21, 2015 21:44
Crawl Elixir doc to get some stats
base_url="http://elixir-lang.org/docs/stable/elixir/"
curl "${base_url}/modules_list.html" > modules.html
grep '<a href' modules.html | grep -v '#' | \
awk '{print $2}' | sed -e 's/href=\"//g' -e 's/\.html\".*//g' | \
tail +3 > modules.txt
for m in `cat modules.txt`; do
curl "${base_url}/${m}.html" > "${m}.html";
@MachinesAreUs
MachinesAreUs / detect_duplicates.rb
Last active November 11, 2015 20:19
Detect similar strings from a list in a file. using the Fuzzy Match gem
#!/usr/bin/env ruby
require 'ostruct'
require 'fuzzy_match'
file_name = ARGV[0] || 'names.txt'
threshold = ARGV[1].to_i || 0.7
strs = File.readlines(file_name).collect {|s| s.strip }
matches = strs.collect{|s|
@MachinesAreUs
MachinesAreUs / Groovy Hack for Jenkins
Created May 20, 2015 15:00
Example of how to pass parameters from one job to the next via a file and groovy magic
build_number = build.buildVariableResolver.resolve('PARENT_BUILD_NUMBER')
compile_job = build.buildVariableResolver.resolve('COMPILE_JOB_NAME')
println("Build number: ${build_number}")
println("Compile job: ${compile_job}")
PackagePath = "C:\\Jenkins\\jobs\\"
RutaLog = "$PackagePath\\$compile_job\\builds\\$build_number\\log"
println("Ruta log: ${RutaLog}")
file = new File(args[0])
board = [][]
file.eachWithIndex {obj, i ->
if (i == 0) {
(rows, columns) = obj.split(" ")*.toInteger()
} else {
board << ([0] << obj.collect{ it == '*'?'*':0 } << [0]).flatten()
}
}
@MachinesAreUs
MachinesAreUs / koch2.elm
Last active August 29, 2015 13:56
Implementation of Koch's curve as an L-system
import Window
import Graphics.Collage
middle (x,y) (x',y') = ((x + x') / 2, (y + y') / 2)
distance (x,y) (x',y') = sqrt <| (x' - x) ^ 2 + (y' - y) ^ 2
trisect (x,y) (x',y') =
let (dx, dy) = ((x' - x) / 3, (y' - y) / 3)
in ((x + dx, y + dy), (x + 2 * dx, y + 2 * dy))
@MachinesAreUs
MachinesAreUs / ColorfulCircles.elm
Last active January 4, 2016 04:39
Randomly placed colorful circles.
import Window
import Graphics.Collage
import Random
import Text
import Signal
radius = 30
lineWidth = 3
bubbleAlpha = 0.4
@MachinesAreUs
MachinesAreUs / ColorCirclesRandomNums.elm
Last active January 4, 2016 01:49
Colorful circles with random numbers on them.
import Window
import Random
import Text
radius = 30
lineWidth = 3
bubbleAlpha = 0.4
-- Util