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 Fizzbuzz do | |
| def fizzbuzzer(n) do | |
| case {rem(n, 3), rem(n, 5), n} do | |
| {0, 0, _} -> | |
| "FizzBuzz" | |
| {0, _, _} -> | |
| "Fizz" | |
| {_, 0, _} -> |
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 Async do | |
| def run do | |
| task1 = Task.async(fn -> :timer.sleep(10000); :slow end) | |
| task2 = Task.async(fn -> :timer.sleep(2000); :fail end) | |
| task3 = Task.async(fn -> :timer.sleep(1000); :fail end) | |
| await([task1, task2, task3]) | |
| 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 Sublist do | |
| @doc """ | |
| Returns whether the first list is a sublist or a superlist of the second list | |
| and if not whether it is equal or unequal to the second list. | |
| """ | |
| def compare(a, b) do | |
| task1 = Task.async(fn -> is_equal(a, b) end) | |
| task2 = Task.async(fn -> | |
| case is_equal(a, b) do | |
| :equal -> |
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 Parse do | |
| def brackets(map) do | |
| map | |
| |> Enum.map(fn({k,v})-> process(Atom.to_string(k), v) end) | |
| |> List.flatten | |
| |> URI.encode_query | |
| end | |
| def process(acc, v) when is_map(v) do |
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 Repo.Migrations.CreateProcedures do @doc """ | |
| Creates procedure to get and update a local_id number on SaaS apps where | |
| next local id is stored in the tenant table. | |
| Example trigger is given for the user table | |
| """ | |
| use Ecto.Migration | |
| def up do | |
| execute "CREATE OR REPLACE FUNCTION get_local_id(tenant_id integer) RETURNS integer AS $$ |
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 PlugJwt do | |
| @moduledoc """ | |
| A JWT Plug | |
| Usage: | |
| #When reading from joken config block | |
| plug PlugJwt | |
| #or the module that implements `Joken.Config` can be set explicitly |
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
| Vagrant.configure(2) do |config| | |
| config.vm.box = "ubuntu/trusty64" | |
| config.vm.network "forwarded_port", guest: 4000, host: 4000 | |
| config.vm.provision :shell, :inline => PROVISION | |
| end |
This file has been truncated, but you can view the full file.
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
| tariffs = [%{category: "Live horses, asses, mules and hinnies", hs_number: "010121", subcategory: "Horses", type: "Purebred breeding animals"}, %{category: "Live horses, asses, mules and hinnies", hs_number: "010129", subcategory: "Horses", type: "Other"}, %{category: "Live horses, asses, mules and hinnies", hs_number: "010190", subcategory: "Horses", type: "Imported for immediate slaughter"}, %{category: "Live bovine animals", hs_number: "010221", subcategory: "Cattle", type: "Purebred breeding animals"}, %{category: "Live bovine animals", hs_number: "010229", subcategory: "Cattle", type: "Other"}, %{category: "Live bovine animals", hs_number: "010231", subcategory: "Cattle", type: "Purebred breeding animals"}, %{category: "Live bovine animals", hs_number: "010239", subcategory: "Cattle", type: "Other"}, %{category: "Live swine", hs_number: "010391", subcategory: "Other", type: "Weighing less than 50 kg each"}, %{category: "Live swine", hs_number: "010392", subcategory: "Other", type: "Weighing 50 kg or more |
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
| on run {input, parameters} | |
| tell application "Finder" | |
| set dir_path to "\"" & (POSIX path of (input as string)) & "\"" | |
| -- display dialog dir_path | |
| end tell | |
| log dir_path | |
| CD_to(dir_path) | |
| end run | |
| on CD_to(theDir) |
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
| # rather than blindly overwriting key=>value pairs in the target | |
| # as #merge method, for each matching key found in the target, the | |
| # values are merged, meaning you can add to any level of the hash by | |
| # passing the full key=>value path to the value you wish to add to | |
| def cumulative_merge(target, hash) | |
| if target.keys.include? hash.keys.first | |
| Hash[hash.keys.first, cumulative_merge(target[hash.keys.first], hash[hash.keys.first])] | |
| else | |
| target.merge(hash) | |
| end |
OlderNewer