Skip to content

Instantly share code, notes, and snippets.

View pragdave's full-sized avatar
🖍️
Alternating between Haskell and PDP-11 assembler

Dave Thomas pragdave

🖍️
Alternating between Haskell and PDP-11 assembler
View GitHub Profile
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
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
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
#
# 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
[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
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
provision_list:
############################################
"staging-apps+search":
############################################
env: staging
count: 1
roles:
master: yes # has all the background services (cron)
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.'
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.' }
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