Skip to content

Instantly share code, notes, and snippets.

View silveira's full-sized avatar

Silveira Neto silveira

View GitHub Profile
@silveira
silveira / flatten
Last active March 17, 2017 16:49
Examples of non-recursive function to flatten and sort a list. Keeping sorting by the way is greatly better because of timsort on Python.
#!/usr/bin/python
"""
Flatten a list
"""
def flatten(notflat):
flat = []
while notflat:
element = notflat.pop()
if isinstance(element, list):
@silveira
silveira / Example.java
Created September 30, 2011 20:49
PriorityQueue order
import java.util.*;
class Example {
public static void main(String[] args) {
Queue<String> q = new PriorityQueue<String>();
q.offer("carrot");
q.offer("apple");
q.offer("banana");
for(String fruit: q)
@silveira
silveira / gbkrename.py
Created February 18, 2012 16:08
Rename a genbank file to the description of the it's first sequence
#!/usr/bin/env python
import sys
import os
# Biopython libraries or nothing
try:
from Bio import SeqIO
except ImportError:
sys.exit("Biopython library not found. See http://biopython.org for installation instructions.")
/*****************************************************
* Jogo Batalhao *
* Arquivo: perspectiva.h *
* Descrição: Cuida da perpectiva visual do jogo. *
* Se um objeto está atrás de uma árvore, a árvore é *
* desenhada depois do objeto. *
* por José Maria Silveira Neto *
* e Marco Diego Aurelio Mesquita *
* *
* Este programa esta disponível sob licensa GPL. *
@silveira
silveira / tree_substitution.py
Created March 9, 2012 02:44
Substitutions in a phylogenetic tree file (http://silveiraneto.net/?p=4073)
#!/usr/bin/env python
import csv
import sys
# check parameters
if len(sys.argv) < 2:
sys.exit('Usage: %s TREE_FILE ID_FILE' % sys.argv[0])
# initiates the tree
#!/usr/bin/env python
"""
Problem: merge k sorted lists of size up to n.
Solution: two approaches, functions merge_and_sort and merge_many.
"""
"""
A trivial solution, put all lists together and sort it.
Time complexity: O(log(nk))
#!/usr/bin/env python
counter = 0
def parentheses(symbol='(', depth=0, n=5):
global counter
counter += 1
if(depth<n*2):
parentheses(symbol+'(', depth+1, n)
parentheses(symbol+')', depth+1, n)
(((((((((((
(((((((((()
((((((((()(
((((((((())
(((((((()((
(((((((()()
(((((((())(
(((((((()))
((((((()(((
((((((()(()
#!/usr/bin/env python
# Tries to decrypt a Caesar cipher without the key.
# Uses brute force and compare the results against the English letter frequency.
# Letters in the English alphabet
LETTERS = 26
# Frequency per letter in the English alphabet
english = {
'a': 0.082, 'b': 0.015, 'c': 0.028, 'd': 0.043, 'e': 0.127, 'f': 0.022,
@silveira
silveira / decode_a_exploit.php
Created February 1, 2013 19:39
decoding a php exploit
$code = gzinflate(base64_decode("DZVHDqwIAkPv0qv/xQKKjEa9IOec2bTIOaeC00/dwLbs5/JKhz/1207VkB7lnyzdSxz9ryjzuSj//MMlgbDtvlzX3gWt+1qG/NhFS5NsaRUX+qMThmWBpCzmm6ypFASoFQCvfQqtFqlAF9LvHBBgHhYpHgjKhVVdMnICPQk/LTSetpe/w2Fur+PgZseuerkmcZZ0jEKjd0k7WLL6KVefJyPjhztLi7AuHOyNkNDkveRUrVTvKuUAGgSZVHBIQzz5L5+1p6nZc6IF4Z6e8MYNy9VKRXReWIK6/swk6Y5laXNjRuZKqb2ctaFkho83eySK0T361+EiN0Xdy9xnPjHjmqRt+myumN2rdaZej6+eBSSApvmInHbsUNcMCPsp4q/4pC2RRd5IcxGUuDQXj7kF4yuyOVU/+qVvTduEQXjAkTlBlSCgW6cFQu6MilOhXUasWgjDbgDnOSoYq0V1kLyJQdjNigiIM2iAl5DlEgSjJpaIR85mYzKLsWwDj+YFjqyHpKDZ6fY1hd3JRABdfg0Hwe9dhTGQ0rQn2j/2VwUBy3O3dQ4hdfAqkqh6b6NmX/0eZV8Ki4AyginkigpU59BwyB75RFkvm6uJIEBdSaoD1MNeECFyL0C7zCYqBkMfIZmlHZHm6YbD+XddXBWkGtqqTljf3zUEBhbGjWl54cBU12ZFdBlmuk/F4gNuaB6txoNNfRDs7hM9DdK8ctULOqVWeTC/CJczXG30JuOx9hrmo+QQ/llHfq4amTbo1HEgnRWnvaw5bHX2T0K1IogO/ShXgBSCObVqeYqe9/AdPX2Q4fSqLEjt0vO0I40AzJxLE5JasHzdpMEfVWb7FqPWFZ09RsbcxTDdViHnBiYr63cT57oea1X6MRxf38OJV+I4svOStSxLP7Ou5RfqWx33SqtVYkSSLRbIYDWDwr7DJ5rT02M+zUIdOWBVxIJqfsKCmxUIKPi2NX6XWsQwfAdTG85w2A5nmf1ZzVi