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 / ruby.karel
Created July 19, 2013 18:07
lenguaje ruby de karel
def gira-derecha
3 veces
gira-izquierda
fin
fin
gira-derecha
avanza
@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 / 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 / compare_digest.py
Created June 23, 2014 15:15
Validate GitHub signature in python
# validate github signature
import hashlib
import hmac
import json
signature = hmac.new(GITHUB_TOKEN, payload, hashlib.sha1).hexdigest()
# assuming that the 'payload' variable keeps the content sent by github as plain text
# and 'headers' variable keeps the headers sent by GitHub
@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 / MOUNTAIN_README.md
Last active January 18, 2017 21:40
Cosas para ir a la montaña

Cosas para ir a la montaña

Estas son algunas cosas que deberían pensar en tener en su mochila para salir de campamento a media montaña. Eviten a toda costa llevar cosas en las manos para viajar más cómodos, así que traten de meterlo todo en una mochila.

El equipaje se divide en abrigo, comidaytodo lo demás`.

Abrigo

El abrigo se suele dividir en tres capas, de la más interna a la más externa. Durante la caminta de ascenso es recomendable ir más bien ligero pues al caminar se suda, con un suéter o chaleco basta para cubrir las primeras tres cuartas partes del viaje.

@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;
@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 / make_tree.py
Last active July 29, 2016 16:17
given an array of strings make a tree of common prefixes
import unittest
from itertools import takewhile, dropwhile, zip_longest
import json
from pprint import pprint
def largest_prefix(string1, string2):
return '/'.join(
map(
lambda x:x[0],
takewhile(