Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe H. Rahme joehakimrahme

  • Red Hat
  • Milano
View GitHub Profile
@joehakimrahme
joehakimrahme / game_life.js
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<matrix.length; ++i) {
line = matrix[i];
for (var j=0; j<line.length; ++j) {
@joehakimrahme
joehakimrahme / inc_rand_mat.js
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<matrix.length; ++i) {
line = matrix[i];
for (var j=0; j<line.length; ++j) {
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]);
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);
View millerrabin.py
import sys
import random
def toBinary(n):
r = []
while (n > 0):
r.append(n % 2)
n = n / 2
return r
@joehakimrahme
joehakimrahme / prime4.py
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
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:
@joehakimrahme
joehakimrahme / prime2.py
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))):
@joehakimrahme
joehakimrahme / prime1.py
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
@joehakimrahme
joehakimrahme / prompt.sh
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="$ "