Skip to content

Instantly share code, notes, and snippets.

View cjbottaro's full-sized avatar

Christopher J. Bottaro cjbottaro

  • AcademicWorks, Inc
  • Austin, Tx
View GitHub Profile

Roger Zelazny. For a Breath I Tarry

They called him Frost. Of all things created of Solcom, Frost was the finest, the mightiest, the most difficult to understand.

This is why he bore a name, and why he was given dominion over half the Earth.

On the day of Frost's creation, Solcom had suffered a discontinuity of complementary functions, best described as madness. This was brought on by an unprecedented solar flareup which lasted for a little over thirty-six hours. It occurred during a vital phase of circuit-structuring, and when it was finished so was Frost.

Solcom was then in the unique position of having created a unique being during a period of temporary amnesia.

@cjbottaro
cjbottaro / .ex
Created January 17, 2016 00:18
Dynamically define function using module attribute as name
defmodule Definer do
defmacro define(do: block) do
quote bind_quoted: [block: Macro.escape(block)] do
func_name = @name |> String.to_atom |> Macro.var(__MODULE__)
def unquote(func_name) do
unquote(block)
end
end
end
end
@cjbottaro
cjbottaro / .ex
Last active January 16, 2016 19:29
Non-hurty, Ruby-like DSL in Elixir
##############
# Define DSL #
##############
defmodule Config.Dsl do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@cjbottaro
cjbottaro / .rb
Created January 14, 2016 20:45
Optimize lookups with Hash
require "benchmark"
def slow(list1, list2)
count = 0
list1.each do |n|
count += 1 if list2.include?(n)
end
count
end
@cjbottaro
cjbottaro / .ex
Created January 12, 2016 04:07
var!/2
defmodule Foo do
defmacro foo(do: block) do
quote do
var!(foo, Foo) = "foo"
unquote(block)
end
end
end
defmodule MacroFun do
defmacro a(str, do: block) do
quote do
{ :ok, var!(buffer, MacroFun) } = Agent.start_link fn -> [a: unquote(str)] end
unquote(block)
res = Agent.get var!(buffer, MacroFun), &(&1)
Agent.stop var!(buffer, MacroFun)
Enum.reverse res
end
defmodule MacroFun do
defmacro a(str, do: block) do
quote do
res = [a: unquote(str)]
unquote(block)
res
end
end
@cjbottaro
cjbottaro / gist:8378583
Created January 11, 2014 23:54
Climbing accident at Seismic on 2014-11-01
Climber was on Bird Dog, had the last bolt clipped and was trying to figure out how to clip the chains. He was experimenting with different beta and tried to go a little left, about 2-3 ft left of the bolt. He didn't like it, and started to down climb, lost his footing and fell. Since he was off to the left, he was pulled to the right when he fell, and rolled backwards off the right side of the ledge. He was pretty much upside side down when the rope caught and he slammed into the rock back first. Because it was a pendulum fall, he swayed back towards the left, and hit the back of his head on the rock below the ledge.
After examining his head, I decided he needed a few stitches, so we packed up our stuff and started to walk out. He complained of loss of vision, ringing ears and trouble standing, at which point he lay down and I called EMS.
He was taken to Brackenridge and released after 2 staples and a CAT scan. All is well, Dr's said he's fine and can continue climbing when the staples heal.
About
@cjbottaro
cjbottaro / gist:7162130
Created October 25, 2013 21:29
Like Python!
module Foo
extend(self)
def foo
"foo"
end
end
Foo.foo
# => "foo"
@cjbottaro
cjbottaro / gist:2937550
Created June 15, 2012 16:53
content for navbar
# app/views/layouts/application.html.erb
<% if content_for?(:navbar) %>
<%= yield(:navbar) %>
<% else %>
<%# default navbar %>
<section class="navbar"></section>
<% end %>
# app/views/blah/show.html.erb
<% content_for(:navbar) %>