View ruby_poor_mans_monads.rb
# kinda library code
def pack(v)
[v]
end
class Array
def unpack
self[0]
end
View pack_string_in_number_and_back.rb
def string_to_number(str)
Integer('0b' + str.unpack('B*')[0])
end
def number_to_utf8_string(num)
str = [num.to_s(2)].pack('B*')
str.force_encoding(Encoding::UTF_8)
end
p string_to_number("мудак")
View resize.go
package main
import (
"fmt"
"github.com/nfnt/resize"
"image/jpeg"
"io"
"os"
)
View elixir_coin.md

ElixirCoin

Let's build a small distributed system to mine a new cryptocurrency and become millionaires in ElixirCoins!

An ElixirCoin is a {secret_string, positive_integer} pair for which the MD5 digest of the concatenation of the secret string with the given integer is a hash whose hexadecimal representation starts with at least 5 consecutive zeroes.

For instance:

  • {"foo", 123} is not an ElixirCoin because the MD5 hash of foo123 is ef238ea00a26528de40ff231e5a97f50
  • {"Serun+u", 1} is a valid ElixirCoin because the MD5 hash of Serun+u1 is 00000011f4de73238f12fb2c57d5dc56
View SignalOfRandomNum.elm
module SignalOfRandomNum where
import Graphics.Element as GE
import Time
import Random
import Maybe exposing (..)
randomIntSignal : Int -> Int -> Signal Time.Time -> Signal Int
randomIntSignal lo hi inputSignal =
let
View day1.elm
module Day1 where
import Graphics.Element as G
import String
import List
import Maybe exposing ( Maybe(..) )
instructions =
"(((())))()((((((((())()(()))(()((((()(()(((()((()((()(()()()()()))(((()(()((((((((((())(()()((())()(((())))()(()(()((()(()))(()()()()((()((()(((()()(((((((()()())()((((()()(((((()(())()(())((())()()))()(((((((())(()())(()(((())(()))((())))(()((()())))()())((((())))(()(((((()(())(((()()((()((()((((((((((())(()())))))()))())()()((((()()()()()()((((((())())(((()())()((()()(((()()()))(((((()))(((()(()()()(()(()(((())()))(()(((()((())()(()())())))((()()()(()()(((()))(((()((((()(((((()()(()())((()())())(()((((((()(()()))((((()))))())((())()()((()(()))))((((((((()))(()()(((())())(())()((()()()()((()((()((()()(((())))(()((())()((((((((()((()(()()(((())())())))(())())))()((((()))))))())))()()))()())((()())()((()()()))(()()(((()(())((((())())((((((((()()()()())))()()()((((()()))))))()((((()(((()))(()()())))((()()(((()))()()())())(((())((()()(())()()()(((())))))()())((()))()))((())()()())()())
View assets_in_phoenix.md

Instead of implementing its own asset pipeline Phoenix uses Brunch, a fast and developer-friendly asset build tool. Phoenix comes with a default configuration for Brunch and it will work out of the box, but it is very easy to bend it to our needs, add support for various script and style languages, like CoffeeScript, JSX, or LESS.

Brunch has a very good tutorial, but this short guide should be enough to get us started with asset management from the Phoenix perspective.

Installation

Brunch is a Node.js application. A newly generated Phoenix project contains package.json which lists packages for installation with npm, the Node Package Manager . If we agree to install dependencies when running mix phoenix.new, Phoenix will run npm for us. If we don't, or if we change package.json, we can always do this ourselves:

View expand.ex
defmodule UselessMacros do
defmacro bar(42) do
quote do
"the answer"
end
end
defmacro baz(42) do
quote do