Skip to content

Instantly share code, notes, and snippets.

View DNA's full-sized avatar

Leonardo Prado DNA

View GitHub Profile
@DNA
DNA / cheatsheet.md
Created January 17, 2022 16:13
Personal annotations as I learn C#

C# Cheat Sheet

Strings

"Foo" // string
'F'   // Char

Interpolations

@DNA
DNA / sql_server.rb
Created October 28, 2021 20:01
Fix Rails SQL Server Adapter when using Arel::Nodes::TableAlias
# frozen_string_literal: true
module Arel
module Visitors
class SQLServer < Arel::Visitors::ToSql
def table_From_Statement o
core = o.cores.first
table_From_Node(core.from) || table_From_Node(core.source)
@DNA
DNA / serializable_report.rb
Created April 19, 2021 21:00
Testing hash refinement on jsonapi-serializable
# 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 September 12, 2020 15:41
simple example for ruby pattern matching
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 / cheatsheet.txt
Created June 4, 2020 01:49
Terminal colors cheat sheet
"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 / blocks.rb
Last active December 20, 2019 19:16
Just tinkering with some algorithms to solve a nonogram
#! /usr/bin/env ruby
require 'matrix'
# puts "▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟"
EMPTY = ' '
BLOCK = '░'
BOX = '█'
@DNA
DNA / code-test.rb
Last active July 22, 2020 14:29
Code test
#! /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 / cpf.js
Created August 24, 2018 17:31
JS CPF validation
#! /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 / stats.py
Created July 2, 2018 04:01
Stats class for Renpy
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 / worktime.rb
Last active July 30, 2018 22:23
check when its time to go home
#! /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