ruby

A 6-post collection

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

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

Insights from Advent Of Code (Week 1)

My first week solving advent of code has almost ended, which makes it a good time to reflect on the quizzes, my solutions and other solutions I found online. tl;dr Advent of Code is a series of coding quizzes delivered daily during December. Project website is: https://adventofcode.com AOC turned out to be a very nice way to learn a new programming language (I'm learning Elixir). Most puzzles are very easy, as seen in the leaderboard times. Practising a short coding quiz every day

Read more

A Developer's Guide To Working With PayPal

PayPal provides two main options for integration into your online store. In this short guide I'll describe both and show how and when to use each. How It Works Payment system providers will typically have two options for integrating with online stores: The first is to use an on-demand payment page, and then notify back to the store via IPN when the purchase was completed. The second uses the API to create a specific payment page per-request. With the API a store can query PayPal for

Read more

How Safe Is This Code?

A Recent code example I found online got me thinking about how explicit should our security procedures be, or in other words that one should still use best security practices even when the framework provides these tests automatically. Below you'll find the example and my reasoning. As always would love to hear your opinion too. The Code This time we're dealing with ruby and this following snippet shows how to handle file upload in Sinatra: post '/save_image' do @filename = params[:file][:filename] file = params[

Read more