Skip to content

Instantly share code, notes, and snippets.

Avatar

Danilo de Jesus da Silva Bellini danilobellini

View GitHub Profile
@danilobellini
danilobellini / ethereum_note.py
Created Jul 24, 2018
Sanic (Python) web server for storing a single information note in the Ethereum blockchain
View ethereum_note.py
"""
Application to store a single message note in the Ethereum blockchain.
In order to run this web server, the ethereum node daemon
(e.g. the Geth HTTP RPC on 8545) should be running in the same host.
Input parameters should be on the following environment variables:
export ETH_CONTRACT_ADDRESS=0xAAAA... # Enforced
export ETH_NODE_URL='http://localhost:8545' # Optional
@danilobellini
danilobellini / example.py
Created May 13, 2018
A really simple/incomplete bottle/flask-like "single blocking worker thread" web server implementation (Python 2)
View example.py
from server import WebServer
app = WebServer()
@app.route("/")
def root():
return "Hello World!"
@app.route("/file")
def file_route():
with open("server.py", "rb") as f:
@danilobellini
danilobellini / genetic.py
Last active Oct 18, 2017
A "Hello World" genetic algorithm I've made based on the C# code shown by Italo Jose de Oliveira at his TDC São Paulo 2017 presentation
View genetic.py
#!/usr/bin/python3
"""
Genetic algorithm example that finds the best string match using the
hamming distance to define an aptitude function.
"""
from random import choice, seed, randrange
from functools import partial
import string
def crossover(a, b):
@danilobellini
danilobellini / kruskal.py
Last active Aug 6, 2017
Kruskal's algorithm
View kruskal.py
"""
Kruskal's algorithm
Pure Python implementation by Danilo J. S. Bellini
"""
import pytest
def kruskal_sets(graph):
nodes = frozenset.union(*graph)
@danilobellini
danilobellini / plugin_talk_ptbr_2016.py
Created Jul 26, 2016
[Proposta/ementa de apresentação] Plugin pytest-doctest-custom (2016, PtBr)
View plugin_talk_ptbr_2016.py
#!/usr/bin/env python
# coding: utf-8
"""
>>> "Apresentação sobre doctest e py.test" is "nice"
True
>>> "O.o heeey, como assim?"
HUAHUAHUAHUA
>>> "Apresentação sobre doctest e py.test" is "a bad idea"
False
>>> # Ok, ¬¬ chega de strings
@danilobellini
danilobellini / viral_maths_puzzle_sympy_solution.py
Created May 2, 2016
Smallest quadratic equations that answers a viral math puzzle using Sympy
View viral_maths_puzzle_sympy_solution.py
#!/usr/bin/python
# By Danilo J. S. Bellini
# 2016-05-02 17:31:56 BRT
"""
Smallest quadratic equations that answers the viral math puzzle below,
using Sympy
1 + 4 = 5
2 + 5 = 12
3 + 6 = 21
8 + 11 = ?
@danilobellini
danilobellini / inline_or_funcptr.cpp
Created Sep 25, 2014
Inline and function pointer example (C++ but that's almost C)
View inline_or_funcptr.cpp
// Created on Thu Sep 25 00:23:24 2014
// @author: Danilo de Jesus da Silva Bellini
// Inline and function pointer example (C++ but that's almost C)
//
// g++ inline_or_funcptr.cpp
//
#include <iostream>
using namespace std;
typedef int (*IntOpPtr)(int, int);
@danilobellini
danilobellini / python_nordeste_show.py
Created Jan 8, 2014
"AudioLazy Band Show" Python Nordeste 2014 talk proposal description
View python_nordeste_show.py
# -*- coding: utf-8 -*-
# Created on Wed Jan 8 04:03:53 2014
# @author: Danilo J. S. Bellini
# Python Nordeste 2014 talk proposal description
# http://2014.pythonnordeste.org/
# Type it in IPython Shell.
# Using this as a script would need to replace lazy_band assignment to
@danilobellini
danilobellini / closure.clj
Last active May 23, 2020
Simple closure example in Scheme, Haskell, Smalltalk, Python, Ruby, Clojure, CoffeeScript and JavaScript/ECMAScript
View closure.clj
; Clojure
(defn mul [value]
(fn [data]
(map
(fn [item] (* item value))
data)))
; user=> ((mul 2) [3 2 8 -2])
; (6 4 16 -4)
@danilobellini
danilobellini / divisors.py
Last active Jul 25, 2016
Find all the divisors from a given number
View divisors.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created on Wed Oct 30 10:55:51 2013
# By Danilo J. S. Bellini
# Based on https://gist.github.com/anonymous/7123189
"""
Find all the divisors from a given number
"""
# Ensure compatibility in both Python 2 and 3