Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonardo Prado DNA

View GitHub Profile
@DNA
DNA / cheatsheet.txt
Created Jun 4, 2020
Terminal colors cheat sheet
View cheatsheet.txt
"WTF IS \033[30;47m???", a practical cheat-sheet
Font color definitions can be intimidating and nonsense at first,
but it is quite easy, lets just follow character by character:
┌────────┤\033├── Escape character (ESC)
│┌───────┤ [ ├── Define a sequence (many characters in a code)
││
││┌──────┤ X ├── Parameter (optional) ┐
│││┌─────┤ ; ├── Parameter separator │ SGR Code
@DNA
DNA / serializable_report.rb
Created Apr 19, 2021
Testing hash refinement on jsonapi-serializable
View serializable_report.rb
# frozen_string_literal: true
class SerializableReport < JSONAPI::Serializable::Resource
using Refinements::SerializableHash
id { @object['id'] }
attributes :foo, :bar
end
@DNA
DNA / pattern_matching.rb
Created Sep 12, 2020
simple example for ruby pattern matching
View pattern_matching.rb
def beach(*temperature)
case temperature
in :celcius | :c, (20..45)
:favorable
in :kelvin | :k, (293..318)
:scientifically_favorable
in :fahrenheit | :f, (68..113)
:favorable_in_us
else
:avoid_beach
@DNA
DNA / code-test.rb
Last active Jul 22, 2020
Code test
View code-test.rb
#! /usr/bin/env ruby
# Write a function that returns true if the brackets in a given string are balanced.
# Balanced means that every parenthesis/bracket or brace that is opened must be closed
# And it must be closed in the right order (Always close the last symbol you opened)
# The function must handle parens (), square brackets [], and curly braces {}.
# "(a[0]+b[2c[6]]) {24 + 53}" should return true
# "f(e(d))" should return true
# "[()]{}([])" should return true
@DNA
DNA / anotacoes_curso.md
Created Mar 23, 2013
Anotações do Curso de produção e edição de podcasts
View anotacoes_curso.md

Palestra Radiofobia

Primeira nota importante: Nunca confiar em adaptadores VGA-HDMI

Do rádio ao postcast

Número de anos para a mídia atingir 50 milhões de usuários

  • Rádio: 38 anos
  • Internet: 4 anos
  • iPod: 3 anos
@DNA
DNA / blocks.rb
Last active Dec 20, 2019
Just tinkering with some algorithms to solve a nonogram
View blocks.rb
#! /usr/bin/env ruby
require 'matrix'
# puts "▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟"
EMPTY = ' '
BLOCK = '░'
BOX = '█'
@DNA
DNA / cpf.js
Created Aug 24, 2018
JS CPF validation
View cpf.js
#! /usr/bin/env node
function validate_cpf(strCPF) {
if (new Set(strCPF).size == 1) return false
cpf = Array.from(strCPF).map(Number);
return [9, 10].every(pos => {
multiplier = pos + 1
@DNA
DNA / worktime.rb
Last active Jul 30, 2018
check when its time to go home
View worktime.rb
#! /usr/bin/env ruby
# ./worktime 10:12 [13:06] [14:15] [19:40]
now = Time.now
expected_work_time = 28800
if ARGV[0].nil?
puts 'Você precisa fornecer ao menos o horário de entrada'
exit 1
@DNA
DNA / stats.py
Created Jul 2, 2018
Stats class for Renpy
View stats.py
class Stat(object):
class Delta(object):
def __init__(self, parent):
self.parent = parent
self.value = parent.value
def __repr__(self):
return '<Stat.Delta value={}>'.format(self.calculate())
def __str__(self):
@DNA
DNA / twitch_collection_download.rb
Created May 1, 2018
Pass a Twitch collection URL as an argument and it'll download all of them
View twitch_collection_download.rb
#! /usr/bin/env ruby
require 'net/http'
require 'json'
require 'tempfile'
download_list = Tempfile.new
CLIENT_ID = 'TWITCH_CLIENT_ID'
collection_id = ARGV.first.split('/').last
twitch_uri = URI("https://api.twitch.tv/kraken/collections/#{collection_id}/items")