S3 Beginner Scripts

AWS S3 has a very fun and easy API to work with, but the management console is somewhat lacking. I couldn't find a fast way to list my buckets and their sizes, or to delete all buckets. So instead I scripted it in ruby. Listing All Bucket Sizes Getting the total size of all your buckets require very little code in ruby. The only hard part here was to display the size in human readable format. require 'pp' UNITS = %w(B KiB MiB GiB TiB).freeze

Read more

Reversing Advent Of Code Day 23

My favorite question in AoC2017 required reverse engineering of a small machine code snippet. Let's examine the snippet and work on reversing it together. The Code Here's the code snippet as published on the site: 1 set b 65 2 set c b 3 jnz a 2 4 jnz 1 5 5 mul b 100 6 sub b -100000 7 set c b 8 sub c -17000 9 set f 1 10 set d 2 11 set e 2 12 set g d 13 mul g

Read more

Hash Keys Manipulations

Atoms, strings and numbers are three different things. But when type coercion enters the game, some languages can be confusing. Elixir: Atoms And Strings Unsurprisingly this map: %{foo: 10} is not the same as this map: %{"foo" => 10} This of course is easy to see here, but when maps are not defined in code it can be confusing. For example this code: input = IO.stream(:stdio, :line) |> Enum.at(0) |> String.trim Map.get(%{p: "Hello"}, input) |> IO.

Read more

Recursion Exercises

Recursions are one of those things that are easy to understand in theory, but in practice can take some getting used to. If you're struggling with it here are some exercises that might help you along. Implement Loops Using Recursion Write a function that prints Hello World n times without using loops. Usage example: say_hi(5) # Prints: # 0: Hello World # 1: Hello World # 2: Hello World # 3: Hello World # 4: Hello World What is the maximum value you can pass to the function without raising

Read more

Implementing BFS in Elixir

After 12 days of adventofcode I think I'm starting to understand Elixir's mindset, or at least I'm starting to write code I wasn't able to read 2 weeks ago. Let's try to use my BFS implementation below to explain some Elixir concepts. Graph Representation Before we can dive into the actual algorithm code for breadth first search we need to figure out a way to store the graph. The original problem input arrived in text format and looked like this: 0 <-> 2 1

Read more