Skip to content

Instantly share code, notes, and snippets.

@mbuffa
mbuffa / pay.ex
Created October 26, 2023 12:52
World of Warcraft Trade
# This is a possible implementation for a trade in copper, silver and gold
# coins, as it happens in a few MMORPGs, such as World of Warcraft.
# A simpler and smarter approach would be to handle it as a single integer,
# and let the UI display the amount in the different coins. This is just
# an exercise for fun.
# Run with `elixir pay.ex`
defmodule Trade do
defmodule Amount do
@mbuffa
mbuffa / advent-of-code-2020-day-3.rs
Last active December 3, 2020 17:24
Day 3 of Advent of Code 2020 in Rust
use std::fs;
type Tiles = Vec<Vec<char>>;
struct Map {
tiles: Tiles
}
impl Map {
fn load(filename: &str) -> Map {
@mbuffa
mbuffa / ruby-ecs.rb
Last active March 13, 2019 10:56
An attempt at creating an Entity-Component-System architecture, in Ruby
require 'securerandom'
Entity = Struct.new(:uuid)
class Component
attr_accessor :entity_uuid
def initialize(entity_uuid)
@entity_uuid = entity_uuid
ComponentsStore.register_component(self)
@mbuffa
mbuffa / some-controller.rb
Created October 10, 2016 19:03
Rails Controller / Serializer / Service
class Controller
def create
outcome = Services::SomeCreation.new(params).call
return render_json Serializers::SomeSerializer(outcome, DEFAULT_STATUS_CODE).to_h
end
end
# In app/services
puts 'oh hey!'
class SomeService
end
@mbuffa
mbuffa / gist:e2baf8357955e212d35391c39974958e
Created August 25, 2016 11:49 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@mbuffa
mbuffa / hinting-module.rb
Created May 20, 2016 23:44
Hacky and dirty way to implement type hinting in ruby classes
# Author: Maxime Buffa <mbuffa@gmail.com>
# Copied from: https://github.com/mbuffa/ultima
# This module allow some sort of type hinting for instance methods.
# Set required variable types with #hint, and don't forget to call
# #hint_method(your_method_symbol) after its definition.
# It'll raise an ArgumentError if types mismatch.
module Hinting
@@hinting = Hash.new()
def self.extended(base)