This file contains 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 Reflect do | |
use Application.Behaviour | |
def run do | |
path = :code.lib_dir(:elixir, :ebin) | |
load_modules_in(path) | |
modules = for {name,_} <- :code.all_loaded, | |
Regex.match?(~r/^[A-Z]/, atom_to_binary(name)), | |
do: name |
This file contains 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 Bitmap do | |
defstruct value: 0 | |
defimpl Access do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
end | |
end |
This file contains 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 Bitmap do | |
defstruct value: 0 | |
end | |
defimpl Access, for: Bitmap do | |
use Bitwise | |
def access(%Bitmap{value: value}, bit) do | |
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1 | |
end |
This file contains 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
# | |
# Given a list, return a new list with all occurrences of consecutive | |
# duplicated elements replaced by `{element, count}` | |
# | |
# compress [ 1,2,2,3,4,4,4,5,6,6] | |
# → [1, {2, 2}, 3, {4, 3}, 5, {6, 2}] | |
# | |
# This version uses the head of the result to give the effect of lookahead |
This file contains 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
[elixir/Book] svn commit -m 'prep for 0.15' [Book:158836] | |
Sending Changes.pml | |
Sending Enumeration.pml | |
Sending Introduction.pml | |
Sending Nodes.pml | |
Sending OTP-applications.pml | |
Sending OTP-servers.pml | |
Sending OTP-supervisors.pml | |
Sending Project.pml | |
Sending Protocols.pml |
This file contains 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
Card = Struct.new(:rank, :suit) | |
dealer = Fiber.new do | |
ranks = (1..13).to_a | |
suits = [:club, :diamond, :heart, :spade] | |
pack = ranks.product(suits).map {|card| Card.new(*card)} | |
all_cards = pack*7 | |
cards = [] | |
loop do | |
cards = all_cards.shuffle if cards.size < 2*52 | |
Fiber.yield cards.pop |
This file contains 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
provision_list: | |
############################################ | |
"staging-apps+search": | |
############################################ | |
env: staging | |
count: 1 | |
roles: | |
master: yes # has all the background services (cron) |
This file contains 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
validates_presence_of :title, :description, :image_url | |
validates_numericality_of :price, :greater_than => 0 | |
validates_uniqueness_of :title | |
validates_format_of :image_url, | |
:with => %r{\.(gif|jpg|png)$}i, | |
:message => 'must be a URL for GIF, JPG or PNG image.' |
This file contains 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
validates :title, :description, :image_url, :presence => true | |
validates :price, :numericality => { :greater_than => 0 } | |
validates :title, :uniqueness => true | |
validates :image_url, | |
:format => { :with => %r{\.(gif|jpg|png)$}i, | |
:message => 'must be a URL for GIF, JPG or PNG image.' } |
This file contains 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
Stephenson, G. R. (1967). Cultural acquisition of a specific learned response among rhesus monkeys. In: Starek, D., Schneider, R., and Kuhn, H. J. (eds.), Progress in Primatology, Stuttgart: Fischer, pp. 279-288. | |
mentioned in: Galef, B. G., Jr. (1976). Social Transmission of Acquired Behavior: A Discussion of Tradition and Social Learning in Vertebrates. In: Rosenblatt, J.S., Hinde, R.A., Shaw, E. and Beer, C. (eds.), Advances in the study of behavior, Vol. 6, New York: Academic Press, pp. 87-88: | |
[...] Stephenson (1967) trained adult male and female rhesus monkeys to avoid manipulating an object and then placed individual naïve animals in a cage with a trained individual of the same age and sex and the object in question. In on case, a trained male actually pulled his naïve partner away from the previously punished manipulandum during their period of interaction, whereas the other two trained males exhibited what were described as "threat facial expressions while in a fear posture" when a naïve animal appro |
OlderNewer