Skip to content

Instantly share code, notes, and snippets.

View halan's full-sized avatar
🛹

Halan Pinheiro halan

🛹
View GitHub Profile
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 / 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]
@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]
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 / 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
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 / anotações
Last active August 19, 2016 00:00
ufrn
Anotações da palestra:
https://www.youtube.com/watch?v=oar-T2KovwE
@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 / gist:734b5380baa1502aa887b3f9902f8ea6
Created June 5, 2016 04:15
Ruby AES Encryption using OpenSSL
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
define 'components/singleton', [], ->
###
Singleton class
###
class Singleton extends Backbone.View
# @static
@getInstance = ->
@_instance = new @ unless @_instance?
@_instance