Skip to content

Instantly share code, notes, and snippets.

View categulario's full-sized avatar
🚲
Always remote

Abraham Toriz Cruz categulario

🚲
Always remote
View GitHub Profile
@categulario
categulario / commas.py
Last active August 29, 2015 14:02
one line code to put commas on a large number (python3)
number = 3988322153843625493168050
with_commas = ''.join([['', ','][i%3==0]+a for i, a in enumerate(str(number)[::-1])])[:0:-1]
print(with_commas)
@categulario
categulario / generator.js
Last active January 3, 2016 12:59
Native javascript generators
var gen = (function(){
this.next++;
return Math.pow(this.next, 2);
}).bind({'next': 0})
console.log(gen()); // 1
console.log(gen()); // 4
console.log(gen()); // 9
console.log(gen()); // 16
console.log(gen()); // 25
@categulario
categulario / ruby.karel
Created July 19, 2013 18:07
lenguaje ruby de karel
def gira-derecha
3 veces
gira-izquierda
fin
fin
gira-derecha
avanza
head = document.getElementsByTagName("head")[0];
s = document.createElement('script');
s.setAttribute('src', 'http://localhost:83/jquery.js');
head.appendChild(s);
//Con esto logramos inyectar jquery en un sitio web
@categulario
categulario / tetris.py
Created March 7, 2013 05:02
Un sencillo juego de tetris
import curses
from random import randrange
curses.initscr()
curses.curs_set(0)
win = curses.newwin(18,18,0,0) # Create window and draw border
win.keypad(1)
win.nodelay(1)
f = [ [0x315,0x4cd,0x13f,0xc47],[0x31d,0x4cf,0x137,0xc45],[0x374,0x374,0x374,0x374],[0x741,0x51c,0xdc3,0xf34],
[0xfc1,0x73c,0x543,0xd14],[0x311,0x4cc,0x133,0xc44],[0xc34,0x341,0x41c,0x1c3]]
def chkFig(crds,s): # collision detection
# Arhivo de experimentos con python
from random import choice
lista_palabras = {
'pollo': ['Es un ave que se come', 'Se hace caldo de esto'],
'verdura':['Son vegetales', 'Son verdes'],
'sal':['es un mineral']
}
@categulario
categulario / infinite.py
Created August 16, 2012 16:53
bucle for infinito en python
def inf(i=0, step=1):
#un generador de iteradores infinitos, como el xrange, pero infinito
while True:
yield i
i+=step
for i in inf():
print i
@categulario
categulario / tweety.py
Created August 16, 2012 02:03
Juegos diversos con la API de twitter
# http://search.twitter.com/search.json?q=query
#Juegos diversos con twitter
from urllib import urlopen
import json
from pprint import pprint
def busca_tweets(cadena):
result = urlopen("http://search.twitter.com/search.json?q=" + cadena)
tweets = json.loads(result.read())
for tweet in tweets['results']:
@categulario
categulario / hello_evil_world.py
Last active August 13, 2020 00:50
The most wicked hello world ever
print(u'\xa1'+[{'foo': i, 'var': ['pez', 'rana', lambda a: (str(a), u'678hHola mundo!nguy')]} for i in ['a' in 'pan']][not True]['var'][2](1)[1][4:15]) #Jaque mate
@categulario
categulario / quicksort.cpp
Created June 28, 2012 02:17
Aplicando el algoritmo quicksort
/*
* Este programa lee un numero entero positivo n y llena un arreglo
* con n elementos para luego ordenarlos usando el algoritmo quicksort
*/
#include<iostream>
using namespace std;
void quicksort(int arreglo[], int inicio, int fin){