Skip to content

Instantly share code, notes, and snippets.

@jamiees2
jamiees2 / bfs.py
Created May 6, 2013 18:39
Breadth First Search in python
#!/usr/bin/python
# Head ends here
from collections import deque
class Node:
def __init__(self, point,parent=None):
self.point = point
self.parent = parent
explored = []
@jamiees2
jamiees2 / ucs.py
Last active September 17, 2016 07:14
Uniform Cost Search in python
#!/usr/bin/python
# Head ends here
import heapq
class Node:
def __init__(self, point,parent=None):
self.point = point
self.parent = parent
def nextMove( x, y, pacman_x, pacman_y, food_x, food_y, grid):
@jamiees2
jamiees2 / astar.py
Created May 7, 2013 11:20
A* Algorithm implementation in python.
# Enter your code here. Read input from STDIN. Print output to STDOUT
class Node:
def __init__(self,value,point):
self.value = value
self.point = point
self.parent = None
self.H = 0
self.G = 0
def move_cost(self,other):
return 0 if self.value == '.' else 1
# Enter your code here. Read input from STDIN. Print output to STDOUT
def read_words():
with open('words.txt') as f:
return [line.strip().lower() for line in f]
def strip_chars(word):
word = word.lower().strip()
if word.startswith('#'):
return word[1:]
if word.startswith('www'):
# Enter your code here. Read input from STDIN. Print output to STDOUT
def read_words():
with open('words.txt') as f:
return [line.strip().lower() for line in f]
def strip_chars(word):
word = word.lower().strip()
if word.startswith('#'):
return word[1:]
if word.startswith('www'):
# Enter your code here. Read input from STDIN. Print output to STDOUT
class Node:
def __init__(self,state,action):
self.state = state
self.action = action
self.parent = None
self.H = 0
self.G = 0
def move_cost(self,other):
return 1
# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
def read_corpus():
corpus = {}
with open('corpus.txt') as c:
for line in c:
words = re.findall(r"[a-z]+",line.strip().lower())
for word in words:
if word is '':
continue
@jamiees2
jamiees2 / 0_reuse_code.js
Created March 20, 2014 11:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jamiees2
jamiees2 / gist:6fd9805fb58fc0329c21
Created May 18, 2014 20:29
Set a git repository to its ssh version
git remote set-url origin $(echo "git@bitbucket.org:<TEAM>/$(git remote -v | grep -oh "[^/]*\.git" | head -n1)")
upstream blah_cluster {
server ip;
}
server {
server_name blah;
access_log /srv/logs/blah.log;
error_log /srv/logs/blah-error.log;