Skip to content

Instantly share code, notes, and snippets.

@pceccato
pceccato / nbit.cpp
Last active November 2, 2016 11:16
a class for computing the n-bit sequences with no adjacent 1's. A going test. Run it here: http://ideone.com/aqMQ5w
#include <iostream>
#include <string>
//
// a class for computing the n-bit sequences with no adjacent 1's
//
// Approach taken was to search the entire solution space for all n-bit
// sequences that satisfy the criteria
// An small optimization was made to prune the solution space by not checking
// the lower bits of a sequence if
@pceccato
pceccato / creategaecert.sh
Last active July 26, 2016 13:42
Interactively create a 2048 bit ssl certificate for a domain using letsencrypt suitable for Google App Engine. The second command converts the private key to PEM format suitable for GAE gaeconvertcert.sh. GAE can't handle certificates any bigger than 2048
./letsencrypt-auto certonly -a manual --rsa-key-size 2048 --email [email protected] -d shop.rhubarbfood.org.au
@pceccato
pceccato / KnightsTravail.cpp
Last active November 2, 2016 11:24
The Knights Travail is a problem in finding the shortest path between two squares on a chess board as travelled by a knight. This uses a uniform cost search - basically a bredth first search with each move on the chess board being having an equal cost, so the shortest path will always have the least number of moves.
#include <string>
#include <iostream>
#include <stdexcept>
#include <ctype.h>
#include <utility>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
@pceccato
pceccato / gist:7f5bfd75b12276222448
Last active November 2, 2016 11:26
Caesar Cypher Solver in Haskell using trigram probabilities
-- caesarsolver.hs
-- this is part one of the optional programming assignment for the
-- Stanford Univerity Introduction to Artificial Intelligence class
-- it solves a rotating or caesar cypher by using the probabilities
-- of three letter trigrams for the english language.
-- All 26 rotations are generated, scored and the top 3 most likely
-- candidates are displayed. Apologies for the Haskell, it's my first program
--
-- source for trigram data is here: http://home.ccil.org/~cowan/trigrams
-- the trigram data is read from input
@pceccato
pceccato / wunderground.py
Created September 15, 2012 14:47
Calling wunderground weather api...
import urllib2
import json
# make sure you put your api key in the request string
def getWeatherFromWunderground(country, city):
request = 'http://api.wunderground.com/api/YOUR_API_KEY_HERE/geolookup/conditions/forecast/q/%s/%s.json' % (country, city)
f = urllib2.urlopen(request)
json_string = f.read()