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 / change.php
Created June 20, 2014 17:44
php change file encoding
<?php
$filename = "changeme.csv";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
if (!mb_check_encoding($contents, 'UTF-8')
OR !($contents === mb_convert_encoding(mb_convert_encoding($contents, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
@categulario
categulario / stdlog.php
Created August 13, 2014 13:24
Simple helper for logging things to a file in php
<?php
if(!defined('STDOUT'))
{
define('STDOUT', fopen(base_path().'/application.log', 'a'));
}
/**
* provides an useful function for logging things to a file instead of sendind
* anything to the browser, for example var_dumps
*/
@categulario
categulario / cantor.py
Created June 20, 2015 04:22
Crea el fractal de la alfombra de cantor usando la tortuga de python
from turtle import *
def square(size):
for i in range(4):
forward(size)
left(90)
def cantor(size, tolerance):
init = pos()
@categulario
categulario / eleccion_advanced.py
Created March 12, 2012 02:54
Elección aleatoria de equipos y usuarios para una clase de cálculo, con soporte de cambios
#eleccion.py
"""
Este script soporta ser reiniciado varias veces, guardando los cambios cada vez
"""
from random import shuffle, choice
if __name__ == "__main__":
print "+--------------------------------+"
@categulario
categulario / eleccion.py
Created March 12, 2012 02:52
Elección aleatoria de equipos y usuarios para una clase de cálculo
#eleccion.py
from random import shuffle, choice
# La funcion shuffle del modulo random puede revolver una lista de forma aleatoria
# La funcion choice escoje de forma aleatoria un elemento de una lista
if __name__ == "__main__":
print "+--------------------------------+"
print "! Sistema de eleccion !"
print "! Aleatoria !"
@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){
@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 / clock.html
Created October 3, 2014 14:22
A simple html clock (requires moment.js, jquery.js)
<!doctype html>
<html>
<head>
<meta charset="utf8">
<title>Clock</title>
<style type="text/css">
.hero-circle{
width:180px;
height:180px;
position:relative;
# 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']
}