Skip to content

Instantly share code, notes, and snippets.

View halan's full-sized avatar
🛹

Halan Pinheiro halan

🛹
View GitHub Profile
@halan
halan / decrypt.rb
Last active June 5, 2016 13:44
This small ruby can decrypt AES-CBC encrypted at https://jsfiddle.net/kq8Lfpar/7/
require 'openssl'
require 'base64'
puts 'Go to https://jsfiddle.net/kq8Lfpar/7/ and encrypt some text for decrypt here'
print 'Password: '
password = gets.chomp
print 'Encrypted: '
encrypted = gets.chomp
@halan
halan / anotações
Last active August 19, 2016 00:00
ufrn
Anotações da palestra:
https://www.youtube.com/watch?v=oar-T2KovwE
require 'openssl'
SIZE = 128
# Preenche uma string com 0x0 em múltiplos de 128
# e divide em blocos de 128 bytes na forma de array de inteiros
def blocks(input)
final_size = input.bytes.length + (SIZE - input.bytes.length % SIZE)
pad_char = 0x0.chr
input += pad_char * (final_size - input.bytes.length)
@halan
halan / Lunh.elm
Last active November 3, 2016 13:33
Algoritmo de Lunh para calcular CPF e CNPJ. (também segue o mesmo algoritmo reescrito em Haskell. A versão em Haskell tem uma aparência ligeiramente mais simples devido a recursos como guardas, listas de compreensão e ciclos...)
import Html exposing (text, p, div)
-- based on https://en.wikipedia.org/wiki/Luhn_algorithm
lunh : ( Int -> Int ) -> Int -> List Int -> List Int
lunh f len nums =
let
cycles = ceiling (toFloat len / (toFloat (List.length nums)))
cycle nums len =
nums
str.split(',')
.map(section => section.split(';'))
.map(([page, rel]) => [
Number(rxPage.exec(page)[1]),
rxRel.exec(rel)[1]
]).reduce((acc, [ page, rel ]) => (
{...acc, [rel]: page}), {}
)
@halan
halan / algo.js
Last active November 19, 2016 01:18
module.exports = (distribuicao) => {
const pulaLinha = (linha, coluna) => [linha+1, coluna]
const pulaLinhaIniciaColuna = (linha, coluna) => [linha+1, 0]
const pulaLinhaColuna = (linha, coluna) => [linha+1, coluna+1]
const pulaLinhaDiminuiColuna = (linha, coluna) => [linha+1, coluna-1]
@halan
halan / distribui.js
Last active November 23, 2016 01:34
const count = arr =>
arr.map( (subarr) =>
subarr.length ).reduce( (acc, l) => acc + l, 0)
const step = ({
source: [ [ head, ...mtail ], ...tail],
result
}) => ({
source: mtail.length === 0 ? [...tail] : [ [...mtail], ...tail ],
result: [...result, head]
const reduce = (reducer, initial, [head, ...tail]) =>
head // condition to go or stop
? reduce(reducer, reducer(initial, head), tail) // recursion
: initial // stop
const map = (mapper, [head, ...tail]) =>
head // condition to go or stop
? [ mapper(head), ...map(mapper, tail) ] //recursion
: [] // stop
@halan
halan / curry.js
Last active November 23, 2016 12:30
Técnicas com curry e composição
const map = transform => arr => {
let transformed = []
for(let i=0; i<=arr.length; i++) {
transformed = [...transformed, transform(arr[i], i)]
}
return transformed
}
import { createStore } from 'redux'
const eevee = { especie: 'Eevee', level: 1 };
const eeveelution = (state = eevee, action) => {
switch (action.type){
case 'WATER_STONE':
return { ...state, specie: 'Vaporeon' };
case 'THUNDER_STONE':
return { ...state, specie: 'Jolteon' };