Skip to content

Instantly share code, notes, and snippets.

View rodrigosetti's full-sized avatar
💭
I may be slow to respond.

Rodrigo Setti rodrigosetti

💭
I may be slow to respond.
View GitHub Profile
@rodrigosetti
rodrigosetti / reasons-i-love-php-interactive-shell.md
Last active November 23, 2020 21:54
Reasons I love PHP interactive shell

Reasons I love the PHP interactive shell

It won't display result of the evaluation. You have to output yourself

php > $x = "foo";
php > $x
php > ;
php > 
php > echo $x;

PHP have different namespaces for methods and value attributes.

<?php

class C {
    function d() {
        return "d-value";
    }
}
@rodrigosetti
rodrigosetti / sif.ipynb
Created May 20, 2014 06:49
IPython Notebook - Fractais com Sistema Iterativo de Funções
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rodrigosetti
rodrigosetti / gist:5529270
Created May 6, 2013 23:58
Print random unicode characters gibberish! Don't know what for.
from random import randint
print "".join(unichr(randint(0, 0x10000)) for i in xrange(100))
@rodrigosetti
rodrigosetti / remove-unused-imports.py
Created February 7, 2013 21:49
Removes unused imports from a bunch of Java files.
#! /usr/bin/env python
# coding: utf-8
"""This script reads all .java files from a directory tree and removes unused
import statements. It may have errors in detecting import lines (e.g. import
lines within block comments, or import lines with another statement in the same
line), and it may have false-negatives when deciding to remove an import (i.e.
it only removes if the last import symbol word doesn't appear at all -
including comments - in the code).
@rodrigosetti
rodrigosetti / add-copyright.py
Created February 7, 2013 21:48
Adds Copyright Notice to a bunch of Java files
@rodrigosetti
rodrigosetti / pi-approximator.py
Created September 9, 2012 21:03
Pi Approximating by Monte Carlo method
#
# The probability that two integers randomly chosen are primes between then
# is surprisingly related to pi, this probability value is equal to 6/pi**2.
# This was discovered by Cesaro, in 1883.
# This code uses Monte Carlo method to test 10**7 pairs of random integers between
# 1 and 10**10 to approximate numerically the value of pi.
#
from math import sqrt # square root (to calculate pi from pi**2)
@rodrigosetti
rodrigosetti / kmeans.py
Created April 24, 2012 20:52
K-Means algorithm
# coding: utf-8
from __future__ import division
from random import uniform, choice
from math import sqrt
def euclidean(x, y):
"calculates the euclidean distance between two points"
assert( len(x) == len(y) )
return sqrt(sum((i-j)**2 for i,j in zip(x,y)))
@rodrigosetti
rodrigosetti / knn.py
Created April 24, 2012 20:04
K Nearest Neighbors
# coding: utf-8
from __future__ import division
from random import uniform
from math import sqrt
def euclidian(x, y):
"calculates the euclidian distance between two points"
assert( len(x) == len(y) )
return sqrt(sum((i-j)**2 for i,j in zip(x,y)))
@rodrigosetti
rodrigosetti / googlon.py
Created April 19, 2012 23:27
Full script for the Google Developer Day Quiz (http://developerquiz.appspot.com) in 23 lines
#! /usr/bin/env python
from string import maketrans, lowercase, split
G_FOO = 'pgjck' # Googlon special letters
G_PREP_C = 'j' # Preposition character
G_PREP = 3 # Preposition size
G_VERB = 8 # Verb size
G_ORDER = 'kgpvbmzfhtxqcrlnjsdw' # Letter ordering
G_NUM_MOD = 5 # Pretty number divisor