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 Brainfuck do | |
# opcodes | |
@op_vinc "+" # increment value at memory address | |
@op_vdec "-" # decrement value at memory address | |
@op_pinc ">" # increment memory address | |
@op_pdec "<" # decrement memory address | |
@op_putc "." # output byte at memory address | |
@op_getc "," # input byte into memory address | |
@op_lbeg "[" # loop begin |
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 NumberParser do | |
import NimbleParsec | |
@moduledoc """ | |
In most European countries decimal separator is the , (comma) | |
This is a simple parser for numbers formatted that way | |
""" | |
nat = integer(min: 1) | |
sep = 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
if Meteor.client? | |
user = User.new('Admin') | |
puts user | |
puts user.admin? | |
puts "hello from client #{user.name}!" | |
end | |
if Meteor.server? | |
user = User.new('Massimo') | |
puts user |
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 App do | |
def bench do | |
:timer.tc(fn -> start() end) | |
end | |
defp start do | |
run() | |
wait() | |
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 A do | |
use GenServer | |
def start do | |
GenServer.start_link(__MODULE__, []) | |
end | |
def send_after(pid) do | |
1..10 | |
|> Enum.each(fn _ -> Process.send_after(pid, :message, 1_000) 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 Processes do | |
@compile :native | |
def create_and_forget do | |
1..1_000_000 | |
|> Enum.each(fn x -> | |
Task.async(fn -> x + 1 end) |> Task.await | |
end) | |
IO.puts("Maximum number of threads per process is = 1000000") |
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
{:ok, ips} = :inet.getif() | |
ips | |
|> Enum.map(fn {ip, _broadaddr, _mask} -> ip |> Tuple.to_list |> Enum.map_join(".", &to_string/1) end) | |
|> Enum.map(fn ip -> {ip, String.jaro_distance(ip, "192.168.99.100")} end) | |
|> Enum.sort(fn {_, score1}, {_, score2} -> score1 > score2 end) | |
|> List.first | |
|> elem(0) | |
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
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
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
git filter-branch --commit-filter ' | |
if [ "$GIT_AUTHOR_EMAIL" = "<email>" ]; | |
then | |
GIT_COMMITTER_EMAIL="<new-email>"; | |
GIT_AUTHOR_EMAIL="<new-email>"; | |
git commit-tree "$@"; | |
else | |
git commit-tree "$@"; | |
fi' HEAD |
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
<?php | |
// Takes the parameter value and validate it against a | |
// list of known validators and throws an exception if it doesn't | |
// | |
// params: | |
// mixed $value | |
// string $validator | |
// |
NewerOlder