Skip to content

Instantly share code, notes, and snippets.

View vladymir's full-sized avatar

Vladymir Bezerra vladymir

View GitHub Profile
@vladymir
vladymir / 00_destructuring.md
Created December 8, 2022 17:59 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

Keybase proof

I hereby claim:

  • I am vladymir on github.
  • I am vladymirlb (https://keybase.io/vladymirlb) on keybase.
  • I have a public key ASBmzIREtN1_TU0C_rGd_G3QjyqMFvXHX3WDU-QjPKLTRAo

To claim this, I am signing this object:

drop database mercadinho;
create database mercadinho;
use mercadinho;
create table produto (
id int auto_increment primary key,
nome varchar(255) not null,
valor decimal(10,2) not null
);
@vladymir
vladymir / banco1.sql
Last active November 13, 2019 20:30
Exemplo para aula de BD
CREATE TABLE Pessoa (
id_pessoa int NOT NULL AUTO_INCREMENT,
nome VARCHAR(255) NOT NULL,
PRIMARY KEY(id_pessoa));
CREATE TABLE Gato (
id_gato int NOT NULL AUTO_INCREMENT,
nome VARCHAR(255) NOT NULL,
id_pessoa int,
PRIMARY KEY(id_gato),

Fecho Transitivo e Reflexivo

Seja um conjunto A = {a,b,c} e R uma relação em A onde R = {(a,b), (b,c)}, o fecho transitivo deve conter a tupla (a,c), uma vez que (a,b) e (b,c) pertencem à R, então, por transitividade, (a,c) deve estar na nova relação: R+ = {(a,b),(b,c),(a,c)} Já o fecho reflexivo de R resulta em {(a,b),(b,c),(a,a),(b,b),(c,c)} O fecho transitivo-reflexivo será {(a,b),(b,c),(a,c),(a,a),(b,b),(c,c)}

Já a função flatten, o exemplo é o seguinte: seja A uma lista A=[1,[2,[3,[4]]]], flatten(A) = [1,2,3,4] (obs. não importando a profundidade do aninhamento das listas, a função deve sempre retornar uma lista plana)

Flatten

@vladymir
vladymir / bfs.py
Created December 18, 2017 18:11
BFS and DFS
from collections import deque
from math import inf
# BFS (Breadth-First Search) implementado em Python3
# Prof. Vladymir Bezerra
#chamar BFS(grafo1, 2)
grafo1 = [[1], [0,2], [1,3], [2,4,5], [3,5,6,7], [3,4,6], [4,5,7], [4,6]]
def menu():
opt = -1
while opt != 4:
print(""" ##########################################################
## ##
## Escolha um Menu: ##
## 1 ) Menu 1 ##
## 2 ) Menu 2 ##
## 3 ) Menu 3 ##
## 4 ) Sair ##
###########################
## JOGO DA VELHA ##
## IFCE - Boa Viagem ##
###########################
# Copyright: Vladymir Bezerra
# O Jogo todo é representado apenas por funcoes. Cada funcao tem uma funcionalidade
# bastante específicas. As funcoes devem ser pequenas e devem fazer apenas UMA coisa.
package monoids;
public abstract class Monoid<T> {
public abstract T combine(T one, T other);
public abstract T identity();
public T fold(Iterable<T> elements) {
T result = identity();
for (T i : elements) {
import datetime
dias = ['segunda', 'terça', 'quarta', 'quinta', 'sexta', 'sábado', 'domingo']
meses = ['', 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro']
startdate = datetime.date(2012,1,1)
while(startdate.year == 2012):
if startdate.weekday() in [5,6]:
print "%s %d %s" % (meses[startdate.month],startdate.day,dias[startdate.weekday()])
startdate += datetime.timedelta(1)