Skip to content

Instantly share code, notes, and snippets.

View jstitch's full-sized avatar
💭
do not fix bad code, rewrite it

Javier Novoa Cataño jstitch

💭
do not fix bad code, rewrite it
View GitHub Profile
@jstitch
jstitch / my_calc.py
Last active March 7, 2017 23:21
a calc in python based on tutorial at Ruslan's blog: https://ruslanspivak.com/lsbasi-part3/
NUMBER, OPER, NONE = "NUMBER", "OPER", "NONE"
VALID_OPERS = ["+", "-", "*", "/", "^"]
class Token(object):
def __init__(self, type, value):
self.type = type
self.value = value
def __str__(self):
return "{} {}".format(self.type, self.value)
class ArrayDemo {
public static void main(String[] args) {
Integer[] anArray = new Integer[10];
for (Integer i = 0; i < 10; i++) {
anArray[i] = (i + 1) * 100;
}
for (Integer i = 0; i < 10; i++) {
System.out.println("Element at index " + i.toString() + ": " + anArray[i].toString());
class ArrayDemo {
public static void main(String[] args) {
// declares an array of integers
int[] anArray;
// allocates memory for 10 integers
anArray = new int[10];
// initialize first element
anArray[0] = 100;
public class BreakContinue {
public static void main(String [] args) {
Integer cuenta = 100;
System.out.println("Imprimiendo numeros pares");
for (Integer i=0; i<cuenta; i++) {
if (i % 2 != 0) {
continue;
}
System.out.println(i.toString());
public class BreakContinue {
public static void main(String [] args) {
Integer cuenta = 100;
for (Integer i=0; i<cuenta; i++) {
if (i % 13 == 0 && i > 20) {
System.out.println("saliendo prematuramente...");
break;
}
System.out.println("Numero: " + i.toString());
@jstitch
jstitch / serializeFields.py
Last active December 22, 2015 11:59
Method to serialize the contents of data structures in Python
def serializeFields(data):
try:
it = iter(data)
except TypeError as terr:
return unicode(data)
if type(it) == type(iter([])):
l = []
for e in it:
l.append(serializeFields(e))
return l
@jstitch
jstitch / stringdict2dict.py
Created March 15, 2012 20:35
Convert a string representing a dictionary into an actual dictionary
st = "{'a':'b','c':'d'}"
dc = dict([[g.replace("'","").replace('"',"") for g in f.split(":")] for f in st[1:-1].split(",")])
st2 = "'a':'b','c':'d'"
dc = dict([[g.replace("'","").replace('"',"") for g in f.split(":")] for f in st2[1:-1].split(",")])
@jstitch
jstitch / py_super_constructor_withaargs.py
Created December 12, 2011 18:20
Python superclass constructor calling, with arguments
class A:
def __init__(self, parama):
self.parama = parama
class B(A):
def __init__(self, parama):
A.__init__(self,parama)