Skip to content

Instantly share code, notes, and snippets.

View dliberalesso's full-sized avatar

Douglas Liberalesso dliberalesso

View GitHub Profile
@dliberalesso
dliberalesso / 2016 - The Daily Stoic.md
Created January 14, 2023 23:07
Create a bookcard based on Frontmatter data (needs Dataview and CustomJS plugins)

tags: Book asin: B01KAFIQE6 title: The Daily Stoic subtitle: 366 Meditations for Clarity, Effectiveness, and Serenity author:

  • "[[Ryan Holiday]]"
  • "[[Stephen Hanselman]]" date: 2016-10-27 publisher: Profile Books
@dliberalesso
dliberalesso / fizzbuzz.ex
Created May 15, 2017 19:05
FizzBuzz in Elixir
defmodule FizzBuzz do
def compute(n), do: fb(n, rem(n, 3), rem(n, 5))
defp fb(_, 0, 0), do: "FizzBuzz"
defp fb(_, 0, _), do: "Fizz"
defp fb(_, _, 0), do: "Buzz"
defp fb(n, _, _), do: n
end
@dliberalesso
dliberalesso / VHDL
Last active August 29, 2015 14:23
VHDL stuff
Some VHDL stuff
@dliberalesso
dliberalesso / fizzbuzz.rb
Created November 7, 2014 18:22
FizzBuzz Ruby TDD
#!/usr/local/bin/ruby -w
require 'test/unit'
class FizzBuzz
def self.fizzbuzz(number)
result = ""
result << "Fizz" if is_divisible_by_three?(number)
result << "Buzz" if is_divisible_by_five?(number)
return result if result != ""
@dliberalesso
dliberalesso / fizzbuzz.py
Created October 7, 2014 22:31
Python FizzBuzz
#!/usr/local/bin/python3
def fizzbuzz(n):
string = ''
if n % 3 == 0:
string += 'Fizz'
if n % 5 == 0:
string += 'Buzz'
@dliberalesso
dliberalesso / mega_sena.rb
Last active December 30, 2015 12:09
Gera um array contendo números para apostar na Mega-Sena.
#!/usr/local/bin/ruby -w
class Mega
attr_reader :apostas
def initialize(n = 6, l = 1)
@l = l
@n = n
@apostas = Array.new
apostar
jogos
@dliberalesso
dliberalesso / snail.rb
Created December 5, 2013 20:41
Sort an array of arrays like a snail (clockwise spiral sorting) with Ruby.
def snail(array)
result = Array.new
n = array.length
runs = n.downto(0).each_cons(2).to_a.flatten
delta = [[1,0], [0,1], [-1,0], [0,-1]].cycle
x, y = -1, 0
for run in runs
dx,dy = delta.next
run.times do |i|
x += dx
@dliberalesso
dliberalesso / pascals_triangle.rb
Created December 5, 2013 19:30
Script to generate a Pascal's Triangle.
def pascalsTriangle(n = 1)
return nil if n == nil || n < 1
rows = [[1]]
2.upto(n) do |i|
row = [1]
1.upto(i-2) do |j|
row << rows.last[(j-1) % rows.last.size] + rows.last[j % rows.last.size]
end
rows << (row << 1)
end
@dliberalesso
dliberalesso / roman_numerals.rb
Last active December 30, 2015 06:39
Roman to-from Numeral in Ruby
class RomanNumerals
MAX = 4999
FACTORS = [['M', 1000], ['CM', 900], ['D', 500],
['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40],
['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]]
def self.to_roman(i)
if i <= 0 || i > MAX then fail "Roman values must be > 0 and <= #{MAX}" end
roman = ''
for code, factor in FACTORS