This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Goldbach's conjecture in JavaScript | |
* | |
* author: Igor Hercowitz | |
*/ | |
function isPrime(n) { | |
if (n % 2 === 0) return false; | |
var sqrtn = Math.sqrt(n)+1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LEVEL=1.3&& RES=92 && gs -sDEVICE=pdfwrite -dCompatibilityLevel=$LEVEL -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -dColorImageDownsampleType=/Bicubic \ -dColorImageResolution=$RES \ -dGrayImageDownsampleType=/Bicubic \ -dGrayImageResolution=$RES \ -dMonoImageDownsampleType=/Subsample \ -dMonoImageResolution=$RES \ -sOutputFile=output.pdf input.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some Tips to do a better code or points to have in mind when do a cross code-review: | |
- Classes and methods small -> Classes should represent simple entities. Methods should have one job. This is crucial for testing, refactoring, understanding, and maintaining. | |
- Make class fields private, and provide getters when necessary -> This is necessary to encapsulate the logic in a class, so callers are not dependent on the class implementation. | |
- Immutable classes -> Usage of setters are not a good practice. Using this on the classes, will let the data mutable, and the results can be catastrophic. Also, use final on variables (this will make them immutable). | |
- Avoid large blocks of code -> Use whitespace to separate tiny, logical chunks of code. (Do not be afraid of whitespace. It is your friend.) Use inline documentation to describe unclear bits of code, but better yet, restructure your code and rename methods/variables until the code is clear. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Bingo Real recriado em Lisp | |
;; - Roda direto no Emacs - | |
;; | |
;; Como rodar: | |
;; - Abrir o arquivo no Emacs | |
;; - Alt-x | |
;; - Digitar eval-current-buffer | |
;; - Os assuntos serao gerados na area de mensagens apertando Control-F2 | |
(require 'cl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
**************************************************************************************** | |
Building a XML Tree as Easy as ABC in Python | |
This implementation requires lxml | |
Created by Igor Hercowitz | |
2012-07-04 | |
****************************************************************************************** | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmulti std-to-militar (fn [hour time-info] (keyword time-info))) | |
(defmethod std-to-militar :AM [hour _] | |
(format "%02d" (if (= hour 12) 0 hour))) | |
(defmethod std-to-militar :PM [hour _] | |
(if (= hour 12) hour (+ hour 12))) | |
(defn convert-time [hour] | |
(let [[hour minute seconds time-info] (rest (re-find #"(\d+):(\d+):(\d+)(\w+)" hour))] |
NewerOlder