Skip to content

Instantly share code, notes, and snippets.

View gonzula's full-sized avatar
🥥
Em horário de almoço

Gonzo Fialho gonzula

🥥
Em horário de almoço
View GitHub Profile
#!/usr/bin/env python3
import argparse
import hashlib
BUFFER_SIZE = 2 ** 19 # 512k
def read_args():
parser = argparse.ArgumentParser(
from decimal import Decimal as D
values = [
'7.18', '7.13', '10.11', '7.67', '7.8', '6.77', '6.45', '6.57',
'6.61', '7.86', '6.79', '6.76', '6.7', '7.72', '6.71', '7.45', '6.54',
'6.75', '7.18', '6.77', '9.09', '26', '5.61', '7.41', '5.9', '9.35', '7.29',
'6.25', '11.62', '7.34', '8.29', '6.95', '7.54', '8.36', '7.51', '6.2', '6.09',
'7.3', '6.86', '6.67', '6.85', '6.17', '7.26', '5', '6.11', '6.07', '7.42',
#!/usr/bin/env python3
import string
from itertools import product
password_length = 3
def match(password1, password2):
right_place = 0
import CommonCrypto
func otp() -> String {
let secret = Data() // change this
let now = Date().timeIntervalSince1970
let count = Int(now) / 30
var fixedCounter = NSSwapHostLongLongToBig(UInt64(count))
let hash = malloc(1000)!
defer {free(hash)}
@gonzula
gonzula / ValidatedStringExamples.swift
Created April 27, 2019 14:38
Examples for validated string
// Use cases of ValidatedString (https://gist.github.com/gonzula/dbc7194fd9afde7b7b59fb772a543e91)
// With very little code you create very safe data types with a lot of cool features
// Let's create a username validator
typealias Username = ValidatedString<UsernameValidator>
enum UsernameValidator: StringValidator {
/// Accepts any username with length between 3 and 10 inclusive
static func validate(_ string: String) -> String? {
@gonzula
gonzula / ValidatedString.swift
Last active April 27, 2019 14:39
Generic struct to create validated type safe strings
// Examples, how to use and more @ https://gist.github.com/gonzula/3bdfb73957d4aae776cb656ee738c897
public protocol StringValidator {
/// Returns a sanitized string if the input is valid or nil otherwise
static func validate(_ string: String) -> String?
}
public protocol StringNormalizer {
/// Returns a normalized version of `rawValue`
static func normalize(_ rawValue: String) -> String
func send(_ message: String, to email: String) {
guard email.isValidEmailAddress else {return}
// code that sends email
}
@gonzula
gonzula / proxy_icon.vim
Last active November 8, 2018 21:18
vimscript to set proxy icon in iTerm2
function! ITerm2ProxyIconTitle(wait) abort
if a:wait
sleep 10m // when resuming to foreground it only works if waits some time (don't ask me why)
endif
let arg = "\e]1337;SetProxyIcon=" . expand('%:p') . "\<c-G>"
if has('nvim')
call chansend(2, arg)
else
@gonzula
gonzula / p_inter.py
Created November 8, 2018 13:18
La Grange Polynomial
#!/usr/bin/env python3
import numpy as np
from matplotlib import pyplot as plt
from numpy.polynomial import polynomial as poly
x = np.array([1,2, 3])
y = np.array([-1, 12, 39])
L = []