Skip to content

Instantly share code, notes, and snippets.

View ihercowitz's full-sized avatar

Igor Hercowitz ihercowitz

View GitHub Profile
@ihercowitz
ihercowitz / image_resize.py
Created October 23, 2010 20:19
Python Script to resize all the images, on a given directory, to a 1024x768 JPEG format.
#!/usr/bin/env python
import Image
import os, sys
def resizeImage(infile, dir, output_dir="", size=(1024,768)):
outfile = os.path.splitext(infile)[0]+"_resized"
extension = os.path.splitext(infile)[1]
if extension.lower()!= ".jpg":
@ihercowitz
ihercowitz / VisaVale.py
Created October 28, 2010 13:19
Script para obter o saldo do Visa Vale
import urllib2, urllib, sys
from BeautifulSoup import BeautifulSoup
import re
class VisaVale():
def get_visavale_informations(self,visa):
url = 'http://www.cbss.com.br/inst/convivencia/SaldoExtrato.jsp'
data = urllib.urlencode([('numeroCartao',visa),('primeiroAcesso','S')])
request = urllib2.Request(url)
import sys
def prime(number):
n = abs(number)
if n < 1:
return False
if n==2:
return True
@ihercowitz
ihercowitz / goldbach.lisp
Created January 9, 2012 17:32
Demonstrates the Goldbach's conjecture - Every even integer greater than 2 can be expressed as the sum of two primes
;*******************************************************************************************************************
;Demonstrates the Goldbach's conjecture - Every even integer greater than 2 can be expressed as the sum of two primes
;
;Author: Igor Hercowitz
;
;usage: clisp goldbach.lisp <number>
;output: the sum of the primes list
;
;Ex:
;> clisp goldbach.lisp 100
/* Demonstrates the Goldbach's conjecture - Every even integer greater than 2 can be expressed as the sum of two primes
*
* author: Igor Hercowitz
*
* usage: java Goldbach <number>
* output: the sum of the primes list
*
* ex:
* > java Goldbach 100
* 100 can be writen as: [97+3, 89+11, 83+17, 71+29, 59+41, 53+47]
%Demonstrates the Goldbach's conjecture - Every even integer greater than 2 can be expressed as the sum of two primes
%
% author: Bruno Jessen
%
-module(goldbach).
-export([primes/1, goldbach/1]).
package com.testes;
/* Demonstrates the Goldbach's conjecture - Every even integer greater than 2 can be expressed as the sum of two primes
*
* author: Luiz Vessosa
*/
import java.util.ArrayList;
@ihercowitz
ihercowitz / golsbach.js
Created February 22, 2012 00:48
Goldbach's conjecture
/* Goldbach's conjecture in JavaScript
*
* author: Igor Hercowitz
*/
function isPrime(n) {
if (n % 2 === 0) return false;
var sqrtn = Math.sqrt(n)+1;
@ihercowitz
ihercowitz / goldbach_recursion.js
Created February 22, 2012 02:14
Goldbach's conjecture in JavaScript - using Recursion
/* Goldbach's conjecture in JavaScript - using Recursion
*
* author: Igor Hercowitz
*/
function isPrime(n) {
if (n % 2 === 0) return false;
var sqrtn = Math.sqrt(n)+1;
@ihercowitz
ihercowitz / problem.js
Created February 23, 2012 00:35
The 3n + 1 Problem
/*
* The 3n + 1 Problem
*Consider the following algorithm to generate a sequence of numbers. Start with an
*integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this
*process with the new value of n, terminating when n = 1. For example, the following
*sequence of numbers will be generated for n = 22:
*22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
*It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for
*every integer n. Still, the conjecture holds for all integers up to at least 1, 000, 000.
*For an input n, the cycle-length of n is the number of numbers generated up to and