Skip to content

Instantly share code, notes, and snippets.

View captainsafia's full-sized avatar

Safia Abdalla captainsafia

View GitHub Profile
@captainsafia
captainsafia / pe_019.py
Created August 18, 2012 21:56
Solution to Project Euler Problem 19 in Python
from datetime import date
sundays=0
for year in range(1901,2001):
for month in range(1,13):
if date(year,month,1).weekday()==6:
sundays+=1
print sundays
@captainsafia
captainsafia / pe_020.py
Created August 20, 2012 22:43
Solution to Project Euler Problem 20 in Python
from math import factorial
num=factorial(100)
num_list=[int(x) for x in list(str(num))]
print sum(num_list)
@captainsafia
captainsafia / killprocess.py
Created August 30, 2012 19:46
Python Application to Kill a Process
import subprocess, signal
import os
import re
a_process = "postgres"
def is_running(process):
s = subprocess.Popen(["ps", "axw"],stdout=subprocess.PIPE)
for x in s.stdout:
if re.search(process, x):
@captainsafia
captainsafia / gist:3711263
Created September 13, 2012 01:33
Solution to Project Euler Problem 22 in Python
f=open("names.txt",'r')
char_num_dict={"A":1,"B":2,"C":3,"D":4,"E":5,"F":6,"G":7,"H":8,"I":9,"J":10,"K":11,"L":12,"M":13,"N":14,"O":15,"P":16,"Q":17,"R":18,"S":19,"T":20,"U":21,"V":22,"W":23,"X":24,"Y":25,"Z":26}
names=sorted(f.read().replace('"','').split(','),key=str)
sum=0
for ind,val in enumerate(names):
temp=0
for x in val:
temp+=char_num_dict[x]
sum+=temp*(ind+1)
from random import randint, randrange, random, choice
from string import letters
from math import floor
import pygal
from pygal.style import CleanStyle
def generatechromosome(length):
chromosome = ""
for index in xrange(length):
chromosome += choice(letters)
@captainsafia
captainsafia / aiplayground.js
Created February 5, 2013 17:36
My solutions to the AI Playground aritificial intelligence challenges -- http://aichallenges.appspot.com/mainpage
// You are given a map of arbitrary size represented
// as a two-dimensional array, and your job is to
// return the same map, but rotated 180 degrees.
this.run = function(map) {
var newmap = [];
for (var i = map.length-1; i >= 0; i--) {
newmap.push(map[i].reverse());
}
return newmap;
set number
set lisp
set expandtab
set shiftwidth=4
set softtabstop=4
set autoindent
set smartindent
filetype plugin indent on
set showmatch
syntax on
# Sets the prefix key to C-a
unbind-key C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Start numbering windows at 0
set -g base-index 0
# Set default color scheme
set -g default-terminal "screen-256color"
(if (member "--no-linedit" sb-ext:*posix-argv* :test 'equal)
(setf sb-ext:*posix-argv*
(remove "--no-linedit" sb-ext:*posix-argv* :test 'equal))
(when (interactive-stream-p *terminal-io*)
(require :sb-aclrepl)
(require :linedit)
(funcall (intern "INSTALL-REPL" :linedit) :wrap-current t)))
(sb-alien:alien-funcall
(sb-alien:extern-alien "disable_lossage_handler" (function sb-alien:void)))
from random import choice
from string import ascii_lowercase
def generate_gibberish(length):
gibberish = []
for x in xrange(0, length):
gibberish.append(choice(ascii_lowercase))
return "".join(gibbeirish)
print gibberish(10)