Skip to content

Instantly share code, notes, and snippets.

View neenjaw's full-sized avatar
:shipit:
Shippin' code

Tim Austin neenjaw

:shipit:
Shippin' code
View GitHub Profile
@neenjaw
neenjaw / day05.exs
Last active December 6, 2020 03:36
day 5
tickets = File.read!("input.txt") |> String.split("\n", trim: true)
row_num = fn row ->
row
|> String.replace("F", "0")
|> String.replace("B", "1")
|> String.to_integer(2)
end
seat_num = fn seat ->
@neenjaw
neenjaw / day5_variation.ex
Created December 6, 2020 02:44
Elixir variation
defmodule AdventOfCode.Day05 do
import Bitwise, only: [<<<: 2]
def walk(line) do
line
|> String.reverse()
|> do_walk()
end
def do_walk(ticket, sum \\ 0, place \\ 0)
@neenjaw
neenjaw / aoc-2020-d5.rb
Created December 5, 2020 06:23 — forked from SleeplessByte/aoc-2020-d5.rb
aoc-2020-d5.rb
require 'benchmark'
class BoardingPass
def self.from_binary(binary_position)
rows = binary_position[0...7].gsub("F", "0").gsub("B", "1")
columns = binary_position[7..].gsub("L", "0").gsub("R", "1")
row = rows.to_i(2)
column = columns.to_i(2)
@neenjaw
neenjaw / passport.rb
Last active December 4, 2020 06:10
Day04
require 'benchmark'
lines = <<~MAP
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
@neenjaw
neenjaw / day03.rb
Created December 3, 2020 05:28
AoC Day3
require 'benchmark'
# lines = <<~MAP
# ..##.......
# #...#...#..
# .#....#..#.
# ..#.#...#.#
# .#...##..#.
# ..#.##.....
# .#.#.#....#
@neenjaw
neenjaw / parse.awk
Last active November 24, 2020 18:40
Parse Elixir Tests to meta
#!/usr/bin/awk -f
# Strip all whitespace from the left-side of a string
function left_strip (string) {
sub(/^\s+/, "", string);
return string;
}
# Escape all double quotes in a string
function escape_double_quote (string) {
@neenjaw
neenjaw / meta_csv_parser.ex
Created November 24, 2020 13:43
example parsing csv in elixir
defmodule Meta.CSVParser do
@csv_parser_module TestCSVParser
alias Meta.AssertParser
defp define_parser() do
unless Code.ensure_loaded?(@csv_parser_module) do
NimbleCSV.define(@csv_parser_module, separator: ",", escape: ~S'"')
end
end
@neenjaw
neenjaw / ES5 class.js
Created November 9, 2020 03:04 — forked from apal21/ES5 class.js
Example for blog to show the difference between ES5 and ES6 javascript classes using inheritance and prototypes use cases.
'use strict';
/**
* Person class.
*
* @constructor
* @param {String} name - name of a person.
* @param {Number} age - age of a person.
* @param {String} gender - gender of a person.
*/
@neenjaw
neenjaw / composing-software.md
Created November 5, 2020 07:04 — forked from Geoff-Ford/composing-software.md
Eric Elliott's Composing Software Series

Eric Elliott's "Composing Software" Series

A collection of links to the excellent "Composing Software" series of medium stories by Eric Elliott.

Edit: I see that each post in the series now has index, previous and next links. However, they don't follow a linear flow through all the articles with some pointing back to previous posts effectively locking you in a loop.

@neenjaw
neenjaw / count-button.jsx
Created November 5, 2020 02:55
Simple Button
import React, { useState } from "react";
export default function App() {
const [count, setCount] = useState(0);
return (
<div className="App">
<button onClick={() => setCount(count + 1)}>{count}</button>
</div>
);
}