Skip to content

Instantly share code, notes, and snippets.

@echiesse
echiesse / grid.py
Created March 9, 2017 20:14
Grid template tag for django
from django import template
import re
register = template.Library()
def isNumber(x):
return (type(x) is int) or (type(x) is float)
@echiesse
echiesse / ex_asm.cpp
Created May 1, 2017 23:12
Exemplo de assembler com Visual Studio
#include <iostream>
int soma(int a, int b);
int main()
{
printf("Total: %i", soma(2,3));
}
@echiesse
echiesse / dnaRev.lua
Created May 20, 2017 04:45
DNA strand reverse
function strandComplRev(s)
local complements =
{
A = "T",
T = "A",
C = "G",
G = "C",
}
local s2 = ""
class Player:
def __init__(self, name, customMsg = "com"):
self.score = 0
self.name = name
self.customMsg = customMsg
def __str__(self):
return "{}: {} pontos".format(self.name, self.score)
@echiesse
echiesse / passwordPolicy.py
Created June 25, 2017 05:57
SImple password policy checker.
import string
def minLengthCriterion(minLength):
def f(password):
return len(password) > minLength
return f
def hasCharInGroup(text, group):
@echiesse
echiesse / c_encapsulation.c
Created July 26, 2017 00:30
Example of structure encapsulation in C
/* pair.h */
#ifndef __PAIR_H__
#define __PAIR_H__
typedef struct SPair Pair;
Pair* createPair(int x, int y);
void destroyPair(Pair *pair);
int getX(Pair *pair);
function map(f, l)
local nl = {}
for i, v in ipairs(l) do
nl[i] = f(v)
end
return nl
end
@echiesse
echiesse / InputValidatorExample.py
Created October 4, 2017 16:24
Console input validation example.
class ValidationError(Exception):
def __init__(self, msg):
super().__init__(msg)
def weightValidator(minWeight = None, maxWeight = None):
def validator(val):
val = float(val)
isValid = (minWeight == None or val >= minWeight) and (maxWeight == None or val <= maxWeight)
@echiesse
echiesse / combineSets.py
Created October 6, 2017 05:22
Combinar elementos de vetores distintos (produto cartesiano)
A = ["a", "b", "c", "d"]
B = ["d", "e", "f"]
C = ["1", "2", "3"]
D = ["X", "Y"]
def combineSets(sets):
n = len(sets)
if n == 0 :
@echiesse
echiesse / binConverter.py
Last active October 18, 2017 18:41
Exemplo de conversão de decimal para binário
num = int(input("Escolha um número decimal para transformar em binario: "))
result = []
while num >= 1:
bit = num % 2
result.append(bit)
num = int(num/2)
# Imprimir em ordem inversa
print("".join(map(str, result))[::-1])