Skip to content

Instantly share code, notes, and snippets.

View ryangraham's full-sized avatar
😝

Ryan Graham ryangraham

😝
View GitHub Profile
@ryangraham
ryangraham / track2_encode.cpp
Last active May 7, 2020 13:22
track2_encode
// track2 4-bit BCD encode
std::string track2 = ";4088490010739415=24082260007000?3";
std::string encoded = "";
uint8_t acc = 0;
bool full = false;
for (uint8_t c : track2)
{
if (!full)
{
acc = c - 0x30;
character decimal binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
@ryangraham
ryangraham / ISO7811.csv
Last active May 7, 2020 12:47
ISO7811 5-bit
character binary
0 10000
1 00001
2 00010
3 10011
4 00100
5 10101
6 10110
7 00111
8 01000
@ryangraham
ryangraham / main.cpp
Created April 30, 2020 06:11
to_lower
#include <string>
#include <iostream>
char to_upper(char c)
{
// between 97 and 122?
if (c >= 'a' && c <= 'z')
return c ^ 32; // unset 6th bit
return c;
@ryangraham
ryangraham / make.sh
Created April 30, 2020 06:08
Run case
$ make
g++ -std=c++11 main.cpp
./a.out
123456789abcdef
123456789ABCDEF
@ryangraham
ryangraham / iex.sh
Last active April 30, 2020 06:01
ASCII Alphabet in Base 2
$ iex
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Interactive Elixir (1.11.0-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> as_binary = &IO.inspect(&1, base: :binary)
#Function<7.91303403/1 in :erl_eval.expr/5>
iex(2)> ?a..?z |> Enum.each(as_binary)
0b1100001
0b1100010
0b1100011
@ryangraham
ryangraham / nested_maps.md
Created March 10, 2020 20:48 — forked from blackode/nested_maps.md
Nested Maps in Elixir

#Get a value from nested maps

The get_in function can be used to retrieve a nested value in nested maps using a list of keys.

nested_map = %{ name: %{ first_name: "blackode"} }     #Example of Nested Map
first_name = get_in(nested_map, [:name, :first_name])  # Retrieving the Key

# Returns nil for missing value 
nil = get_in(nested, [:name, :last_name])              # returns nil when key is not present
@ryangraham
ryangraham / abr.sh
Last active April 30, 2020 07:43
rebase macro
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
set -o xtrace
GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT" || exit
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
{
"detect_indentation": true,
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns": "public/assets/source_maps",
"font_size": 20,
"ignored_packages":
[
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
@ryangraham
ryangraham / gist:b54d3d4b5e013a586fa5
Created September 16, 2014 20:05
weakref to parent object in python class constructor
import weakref
Class MyClass():
def __init__(self, parent):
self.parent = weakref.ref(parent)