Skip to content

Instantly share code, notes, and snippets.

View manewitz's full-sized avatar
👾

Mike Manewitz manewitz

👾
View GitHub Profile
@manewitz
manewitz / aoc_23_01_v2.ex
Created December 7, 2023 19:11
Advent of Code 2023 - Day 2 - Elixir
defmodule Cube.RegEx do
@regex_game_number ~r/Game (\d+)/
@regex_color_thresholds ~r/(1[3-9]|[2-9][0-9]) red|(1[4-9]|[2-9][0-9]) green|(1[5-9]|[2-9][0-9]) blue/
@spec count(binary()) :: any()
def count(filename) do
File.read!(Path.expand(filename))
|> String.split("\n", trim: true)
|> Enum.reject(&match_color_thresholds?/1)
|> Enum.reduce(0, &sum_game_numbers/2)
@manewitz
manewitz / aoc_23_01_v2.ex
Created December 6, 2023 16:22
Advent of Code 2023 - Day 1, V2 - Elixir
defmodule AdventOfCode23.Dec01.V2 do
@number_map %{
"zero" => 0,
"one" => 1,
"two" => 2,
"three" => 3,
"four" => 4,
"five" => 5,
"six" => 6,
"seven" => 7,
@manewitz
manewitz / unicorn_hat_hd_circuits_spi.ex
Last active July 25, 2023 22:04
Elixir - Unicorn Hat HD via Circuits.SPI [WIP]
{:ok, spi_ref} = Circuits.SPI.open("spidev0.0", speed_hz: 9_000_000)
off = <<0x72>> <> (<<0::8, 0::8, 0::8>> |> :binary.copy(16 * 16))
red = <<0x72>> <> (<<255::8, 0::8, 0::8>> |> :binary.copy(16 * 16))
green = <<0x72>> <> (<<0::8, 255::8, 0::8>> |> :binary.copy(16 * 16))
blue = <<0x72>> <> (<<0::8, 0::8, 255::8>> |> :binary.copy(16 * 16))
white = <<0x72>> <> (<<255::8, 255::8, 255::8>> |> :binary.copy(16 * 16))
Circuits.SPI.transfer(spi_ref, red)
@manewitz
manewitz / sieve_of_eratosthenes.ex
Last active February 16, 2023 17:14
Elixir implementation of the Sieve of Eratosthenes algorithm for finding prime numbers.
defmodule SieveOfEratosthenes do
@doc """
https://www.baeldung.com/cs/prime-number-algorithms
Naive implementation of the Sieve Of Eratosthenes for finding primes below `number`
"""
@spec primes(number) :: list
def primes(1), do: []
24 Diner
Arlo
Austin Ale House
Austin Java
Bacon
Bar Chi
Barley Swine
Biscuits and Groovy
Black Sheep Lodge
Black Star Co-op
@manewitz
manewitz / ruby_stuff.md
Created June 19, 2017 17:18
ruby_stuff.md

Ruby/Rails Tutorial Resources

Deep breath...

Ruby

@manewitz
manewitz / fql_music_likes.rb
Created July 4, 2013 19:45
Playing with the Facebook API. This is aggregates music 'Likes' from your Facebook Friends list. Visit https://developers.facebook.com/tools/explorer, click "Get Access Token", and assign appropriate permissions to get your token, assigning it to the FACEBOOK_GRAPH_ACCESS_TOKEN constant.
# Aggregated music 'Likes' from my Facebook Friends list
require 'koala'
# Visit https://developers.facebook.com/tools/explorer
# and click "Get Access Token", assigning appropriate permissions
@graph = Koala::Facebook::API.new(FACEBOOK_GRAPH_ACCESS_TOKEN)
@manewitz
manewitz / color_demo.rb
Last active October 12, 2015 00:17
Formatador Presentation
#! /usr/bin/env ruby
require "rubygems"
require "formatador"
styles = [
:bold,
:underline,
:blink_slow,
:blink_fast,
@manewitz
manewitz / rock_paper_scissors.rb
Created October 14, 2012 01:02
Rock Paper Scissors in Ruby
class WrongNumberOfPlayersError < StandardError ; end
class NoSuchStrategyError < StandardError ; end
VALID_MOVES = %w{R P S}
def rps_game_winner(game)
raise WrongNumberOfPlayersError unless game.count == 2
game.each do |move|
unless VALID_MOVES.include?(move[1])
@manewitz
manewitz / 01_ubb_tracks.rb
Created October 9, 2012 13:28
Ultimate Breaks and Beats data
# The Limit - "She's So Divine" (from CP-721 12" single) (1982)
# Kashif - "I Just Gotta Have You (Lover Turn Me On)" (from CP-728 12" single) (1982)
# Kenton Nix featuring Bobby Youngblood - "There's Never Been (No One Like You)" (from WES 22130 12" single) (1980)
# Mr. Magic - "Magic's Message (There Has to Be a Better Way)" (from POS-1213 12" single) (1984)
# Tia Monae - "Don't Keep Me Waiting" (from CART-320 12" single) (1983)
# Cloud One - "Flying High" (from HS-1010 12" single) (1982)
# Ednah Holt - "Serious, Sirius Space Party" (from WES 22138 12" single) (1981)
# Conversion - "Let's Do It" (from S-12336 12" single) (1980)
# The Monkees - "Mary Mary"* (from More of the Monkees) (1967) Colgems Records
# Wilbur "Bad" Bascomb - "Black Grass"* (from PAS-6048 7" single) (1972) Paramount Records