This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
def slow(list1, list2) | |
count = 0 | |
list1.each do |n| | |
count += 1 if list2.include?(n) | |
end | |
count | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Foo do | |
defmacro foo(do: block) do | |
quote do | |
var!(foo, Foo) = "foo" | |
unquote(block) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MacroFun do | |
defmacro a(str, do: block) do | |
quote do | |
res = [a: unquote(str)] | |
unquote(block) | |
res | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def anagram?(s1, s2) | |
s1.downcase.chars.sort == s2.downcase.chars.sort | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |