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
# For binary 0000 0001 0100 0000 1000 1000 | |
# The result is 0b1 + 0b100_0000 + 0b1000 = 73 | |
defmodule BinaryParseFast do | |
def parse(bin) do | |
parse(bin, 0) | |
end | |
# A byte beginning with 0 means the end, but still need to add the last 7 bits | |
def parse(<<0::1, x::7, _::bits>>, acc), do: acc + x | |
# A byte beginning with 1 means there is more data needed to be processed. |
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
for a1 <- 0..1, | |
a2 <- 0..1, | |
a3 <- 0..1, | |
a4 <- 0..1, | |
a5 <- 0..1, | |
a6 <- 0..1, | |
a7 <- 0..1, | |
a8 <- 0..1, | |
a9 <- 0..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
# For 0000 0001 0100 0000 1000 1000 | |
# The result is 0b1 + 0b100_0000 + 0b1000 = 73 | |
defmodule BinaryParseFast do | |
def parse(bin) do | |
parse(bin, 0) | |
end | |
# def parse(<<0::1, x::7, _::bits>>, acc), do: acc + x | |
# def parse(<<1::1, x::7, rest::bits>>, acc) do | |
# parse(rest, acc + x) |
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 Foo do | |
Enum.each(1..100, fn i -> | |
def field(unquote(:"foo#{i}")) do | |
"field #{unquote(i)}" | |
end | |
def unquote(:"field_foo#{i}")() do | |
"field #{unquote(i)}" | |
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
var protobuf = require('protobufjs'); | |
protobuf.load("test.proto", function (err, root) { | |
if (err) | |
throw err; | |
var Message = root.lookupType("test.Message"); | |
var payload = { foo1: 123.0, foo2: 123.5 }; | |
var errMsg = Message.verify(payload); |
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 Sentry.Fingerprinter do | |
def custom_fingerprints(metadata, _msg) do | |
file = Keyword.get(metadata, :file) | |
line = Keyword.get(metadata, :line) | |
if file && line do | |
%{ | |
application: Keyword.get(metadata, :application), | |
module: Keyword.get(metadata, :module), | |
function: Keyword.get(metadata, :function), |
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
export PS1="\\u@\\h:\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ " | |
#set-option -g mouse on | |
setw -g mode-keys vi | |
bind-key -Tcopy-mode-vi 'v' send -X begin-selection | |
bind-key -Tcopy-mode-vi 'y' send -X copy-selection | |
# set -g terminal-overrides 'xterm*:smcup@:rmcup@' | |
## Debian apt |
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 Foo do | |
def foo1(bin, arg \\ 0) do | |
case do_foo1(bin) do | |
{:end, bin} = r -> | |
{r, arg} | |
{a, rest} -> | |
foo1(rest, arg + 1) | |
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
package main | |
import ( | |
"log" | |
"os" | |
"sync" | |
"time" | |
"golang.org/x/net/context" | |
"google.golang.org/grpc" |
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
require 'google/protobuf/timestamp_pb' | |
# Use official Message.new() instead | |
class Pb | |
class << self | |
def message_to_pb(message, msg_klass) | |
unless msg_klass.ancestors.include?(Google::Protobuf::MessageExts) | |
raise ArgumentError, "message class should be a pb message" | |
end | |
if msg_klass == Google::Protobuf::Timestamp && message.is_a?(::Time) |