Skip to content

Instantly share code, notes, and snippets.

View danilobellini's full-sized avatar

Danilo de Jesus da Silva Bellini danilobellini

  • Sao Paulo, Brazil
View GitHub Profile
@danilobellini
danilobellini / inline_or_funcptr.cpp
Created September 25, 2014 03:34
Inline and function pointer example (C++ but that's almost C)
// 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 / t9.py
Created September 12, 2012 18:24
T9 Message to cell phone numbers to be pressed
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 11 20:48:25 2012
T9 Message to cell phone numbers to be pressed
Problem description:
http://dojopuzzles.com/problemas/exibe/escrevendo-no-celular/
@danilobellini
danilobellini / doomsday.py
Created September 21, 2012 05:13
Eruption explosive doomsday calculation
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 05:54:37 2012
Eruption explosive doomsday calculation.
Copyright (C) 2012 Danilo de Jesus da Silva Bellini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@danilobellini
danilobellini / pyqt.py
Created September 29, 2012 14:49
Python GUI toolkits simple example
#!/usr/bin/env python
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
# Main window, sizers and widgets
win = QtGui.QMainWindow()
wd = QtGui.QWidget()
vb = QtGui.QVBoxLayout()
@danilobellini
danilobellini / metametaclass.py
Created October 13, 2012 08:21
Metaclass of a metaclass
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created on Sat Oct 13 by Danilo de Jesus da Silva Bellini
#
# This code raises:
# TypeError: Can't instantiate abstract class A with abstract methods blablah
# However, it does not when class A inherits from "type" or "ABCMeta".
from abc import ABCMeta, abstractproperty
class A(object):
@danilobellini
danilobellini / warnbug.py
Created November 14, 2012 04:03
Strange behaviour with pytest + warnings
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 14 01:39:53 2012
@author: Danilo J. S. Bellini
"""
from warnings import warn, catch_warnings
import pytest
@danilobellini
danilobellini / roleta.py
Created January 16, 2013 11:11
Roleta Romana - Solução em Python para o problema do dojo de PHP que ocorreu no dia 2013-01-15 na iMasters.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 16 01:17:27 2013
Copyright (C) 2012 Danilo de Jesus da Silva Bellini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@danilobellini
danilobellini / gist:5022087
Created February 24, 2013 00:45
Gram-Schmidt orthonormalization with itertools.
# -*- coding: utf-8 -*-
# Gram-Schmidt orthonormalization with itertools.
# Copyright (C) 2012 Danilo de Jesus da Silva Bellini
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@danilobellini
danilobellini / descriptor_example.py
Created March 28, 2013 02:54
Descriptor use case example (based on Luciano Ramalho "Encapsulation with descriptors" video at PyCon 2013)
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 27 23:36:30 2013
Descriptor use case example
@author: Danilo J. S. Bellini
"""
class Quantity(object):
@danilobellini
danilobellini / mastermind.py
Created April 4, 2013 15:32
Mastermind guess description
#!/usr/bin/env py.test
# -*- coding: utf-8 -*-
# Mastermind guess description
# Created on Thu Mar 14 2013
# Danilo de Jesus da Silva Bellini
def mastermind(guess, secret):
"""