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
@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:6f8f8f2f235a2293fe62
Last active August 29, 2015 14:26
Installing MUQ on OS X
brew install boost --c++11
brew tap homebrew/science
brew install eigen flann hdf5 sundials gcc
cd /tmp
git clone https://bitbucket.org/mituq/muq
cd muq/MUQ/build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/muq ..
make && make install
@cjbottaro
cjbottaro / gist:a966008af75fbbd874e1
Created June 8, 2015 21:04
Chef bootstrap error
Connecting to 10.1.13.242
10.1.13.242 Installing Chef Client...
10.1.13.242 --2015-06-08 20:51:43-- https://www.opscode.com/chef/install.sh
10.1.13.242 Resolving www.opscode.com (www.opscode.com)... 184.106.28.91
10.1.13.242 Connecting to www.opscode.com (www.opscode.com)|184.106.28.91|:443... connected.
10.1.13.242 HTTP request sent, awaiting response... 504 Gateway Time-out
10.1.13.242 2015-06-08 20:53:44 ERROR 504: Gateway Time-out.
10.1.13.242
10.1.13.242 Starting first Chef Client run...
10.1.13.242 bash: line 88: chef-client: command not found
@cjbottaro
cjbottaro / gist:cc5d7d3ae4329e35d7f9
Created April 27, 2015 20:34
log_lock_waits output (partial)
[scholarship_app_development] STATEMENT: UPDATE applications SET updated_at = '2015-04-27 20:25:35 +0000' WHERE id = 455423
[scholarship_app_development] LOG: process 97776 still waiting for ExclusiveLock on tuple (408,65) of relation 5436886 of database 5158717 after 1000.090 ms
[scholarship_app_development] STATEMENT: UPDATE applications SET updated_at = '2015-04-27 20:25:29 +0000' WHERE id = 455423
[scholarship_app_development] LOG: process 96629 still waiting for ExclusiveLock on tuple (408,65) of relation 5436886 of database 5158717 after 1000.175 ms
[scholarship_app_development] STATEMENT: UPDATE applications SET updated_at = '2015-04-27 20:25:22 +0000' WHERE id = 455423
[scholarship_app_development] LOG: process 97110 still waiting for ExclusiveLock on tuple (408,65) of relation 5436886 of database 5158717 after 1001.027 ms
[scholarship_app_development] STATEMENT: UPDATE applications SET updated_at = '2015-04-27 20:25:32 +0000' WHERE id = 455423
[scholarship_app_development] LOG: process 96891
# General structure of a recursive function
def f
if condition
# Base case. Stops the loop
else
# Recursive case. Continues loop.
end
end
# Addition implemented with normal iteration.
@cjbottaro
cjbottaro / gist:19b5919cca4cdbec5830
Last active August 29, 2015 14:14
Anagram detector in Ruby
def anagram?(s1, s2)
s1.downcase.chars.sort == s2.downcase.chars.sort
end
@cjbottaro
cjbottaro / gist:2bfd0e8582d9ee2e083c
Created August 12, 2014 17:15
Keep track of parent thread when spawning new thread
class Thread
def self.spawn(*args, &block)
new(Thread.current, *args) do |*args|
Thread.current[:parent] = args.first
block.call(*args[1..-1])
end
end
singleton_class.class_eval{ private :new }