{{ message }}

Instantly share code, notes, and snippets.

# Joe H. Rahme joehakimrahme

• Red Hat
• Milano
Created Sep 18, 2012
Conway's Game of life
View game_life.js
 function draw_matrix(context, matrix, startx, starty, cellsize) { var x = startx; var y = starty; var colors = ['yellow', 'red']; for (var i=0; i
Created Sep 18, 2012
Incremental random matrix
View inc_rand_mat.js
 function draw_matrix(context, matrix, startx, starty, cellsize) { var x = startx; var y = starty; var colors = ['yellow', 'red']; for (var i=0; i
Created Sep 18, 2012
Colored Matrix
View color_mat.js
 window.onload = function () { var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var matrix = []; var colors = ['yellow', 'red']; //filling the matrix with style B-) matrix.push([1, 1, 0]); matrix.push([0, 1, 0]);
Created Sep 18, 2012
Canvas matrix
View mat.js
 window.onload = function () { var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); context.beginPath(); for (var i=100; i<= 200; i += 25) { context.moveTo(i, 50); context.lineTo(i, 150);
Created Jul 4, 2012
isprime - MillerRabin
View millerrabin.py
 import sys import random def toBinary(n): r = [] while (n > 0): r.append(n % 2) n = n / 2 return r
Created Jul 4, 2012
isprime - 6k +/- 1
View prime4.py
 import math.sqrt as sqrt def prime4(n): if n<=1: return False if n % 2 == 0 and n != 2: return False if n % 3 == 0 and n != 3: return False
Created Jul 4, 2012
isprime - even
View prime3.py
 import math.sqrt as sqrt def prime3(n): if n<=1: return False if n % 2 == 0 and n != 2: return False for i in xrange(2, int(sqrt(n)), 2): if n % i == 0:
Created Jul 4, 2012
isprime - up to sqrt()
View prime2.py
 import math.sqrt as sqrt def prime2(n): if n <= 1: return False # The sqrt is turned into an int() because of the # deprecation warning I got for passing a float as argument # to xrange() for i in xrange(2, int(sqrt(n))):
Created Jul 4, 2012
isprime - Definition
View prime1.py
 def prime(n): if n <= 1: return False for i in xrange(2, n): if n % i == 0: return False return True
Created Jun 15, 2012
prompt() bash function
View prompt.sh
 prompt () { [[ \$# = 1 ]] || exit 255 mode="\$1" case "\$mode" in none) export PS1="" ;; off) export PS1="\$ "