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
6c f0 9f 8d ad 70 => | |
01101100 11110000 10011111 10001101 10101101 01110000 |
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
f0 9f 8d ad => | |
11110000 10011111 10001101 10101101 => | |
-----xxx --xxxxxx --xxxxxx --xxxxxx => | |
000 011111 001101 101101 => | |
┕━━━━━━━━━ 0x1f36d ━━━━━━━━━━┙ |
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 MyBinParser1 do | |
def valid?(<<length::2, data::binary>>), | |
do: byte_size(data) >= length | |
def valid?(_), do: false | |
end | |
defmodule MyBinParser2 do | |
def valid?(<<length::2, _data::binary-size(length), _rest::binary>>), | |
do: true |
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
iex> a_very_large_binary = :binary.copy("x", 1000) | |
...> <<_first_three_bytes::binary-3, rest::binary>> = a_very_large_binary | |
...> byte_size(rest) | |
997 | |
...> :binary.referenced_byte_size(rest) | |
1000 |
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 IEEE_754 do | |
def friction_to_mantissa(""), do: 0 | |
def friction_to_mantissa(<<n::1, rest::bits>>), | |
do: n + friction_to_mantissa(rest) * 0.5 | |
end | |
iex> mantissa = IEEE_754.friction_to_mantissa(<<1::1, friction::bits>>) | |
...> :math.pow(-1, sign) * mantissa * :math.pow(2, exponent - 1023) | |
3.14 |
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 RenderingDemo do | |
@behaviour Ratatouille.App | |
import Ratatouille.View | |
def init(_context) do | |
"Hello world! 你好世界! <<🦸🏻♀️🧖♀️>>" | |
end | |
def update(model, _message), do: 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
alias ExTermbox.Bindings, as: Termbox | |
alias ExTermbox.{Cell, EventManager, Event, Position} | |
:ok = Termbox.init() | |
{:ok, _pid} = EventManager.start_link() | |
:ok = EventManager.subscribe(self()) | |
for {ch, x} <- Enum.with_index('Hello, World! 你好世界!') do | |
:ok = Termbox.put_cell(%Cell{position: %Position{x: x, y: 0}, ch: ch}) |
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 MnesiaExample do | |
def demo do | |
# Step 1: initialize | |
setup | |
# Step 2: write some datas into database | |
seed | |
# Step 3: read from database |
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" | |
"io" | |
"net" | |
) | |
func main() { | |
ln, err := net.Listen("tcp", ":8080") |
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
# find users nearby a certain location and print them | |
# by qhwa | |
require 'json' | |
require 'ostruct' | |
require 'logger' | |
class User < OpenStruct | |
OFFICE_GPS = [ 53.3381985, -6.2592576 ] |