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
angular.module('utils.watcher_hider', []) | |
.service 'WatcherHider', ['$log', ($log)-> | |
($scope)-> | |
@scope = $scope | |
# Don't try this at home kids... | |
listeners = [] | |
watches = [] | |
@$watch = (name_or_fn, watcher_fn)=> |
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
module ElmDemo where | |
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Color exposing (..) | |
import Time | |
import Text | |
import Window | |
-- MODEL |
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
module ElmDemoRefactored where | |
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Color exposing (..) | |
import Time | |
import Text | |
import Window | |
-- MODEL |
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
module ElmDemo where | |
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Color exposing (..) | |
import Time | |
import Text | |
import Window | |
-- MODEL |
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
# Lets create a bartender in the same way you would in a imperative language. | |
defmodule Bartender do | |
def serve(user, drink) do | |
if user.age >= 21 do | |
IO.puts "The bartender slides #{user.name} a #{drink}." | |
else | |
IO.puts "Sorry #{user.name}, you'll have to wait #{21 - user.age} more year(s)." | |
end | |
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
# Assuming we have some code like this | |
defmodule Processor do | |
# A lot of code uses the following format, and its a good way to write code | |
# However, when we have potential failures at each step things get complicated | |
def process(user, meta) do | |
user | |
|> verify_authenticity(meta[:credentials]) | |
|> process_payment(meta[:charges]) | |
|> issue_resource | |
|> generate_response |
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
# prices = [11, 7, 5, 8, 10, 9] | |
# => 5 | |
# ALGO 1: BRUTE FORCE | |
# for each map to profit, find biggest number | |
# 11 => [-4, -6, -3, -1, -2] | |
# 7 => [-2, 1, 3, 2] | |
# 5 => [3, 5, 4] | |
# 8 => [2, 1] | |
# 10 => [-1] | |
# |
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
{} + "" == "()" // true | |
pow(2, 31).intValue + 1 > 0 // false | |
Set(1,2,3).sameElements(Set(3,2,1)) // false | |
Some(null).get // No exception :(, Some(null) should result in a None IMO | |
// Option objects might be null!!! | |
def safeOption(shouldBeSafe : Option[String]) : String = { |
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
# machine 1 | |
# start up with `iex --name m1@127.0.0.1 --cookie greeter` | |
# This isn't really necessary but it won't hurt anything | |
Node.connect :"m1@127.0.0.1" | |
# All `Node.connect/1` calls can go to the same machine and every machine | |
# in the cluster will automatically be connected. | |
# machine 2 | |
# start up with `iex --name m2@127.0.0.1 --cookie greeter` |
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
# Take all numbers from 0 to 50 million and sum every number from 0 to that number and sum those numbers | |
:timer.tc fn -> | |
1..50_000_000 | |
|> Enum.map(& Enum.sum(0..&1)) | |
|> Enum.sum() | |
end | |
# Takes almost 2 minutes to run and returns the value 20,833,345,833,335,000,000 | |
# => {108521694, 20833334583333350000000} | |
# Using task async stream, this can be done concurrently easily by just |
OlderNewer