Skip to content

Instantly share code, notes, and snippets.

@jColeChanged
jColeChanged / index.html
Last active August 29, 2015 14:25
Naruto Visualization
<html>
<head>
<script type="text/javascript"
src="http://d3js.org/d3.v3.min.js"
charset="utf-8">
</script>
<style type="text/css">
.two-col {
display: -ms-flex;
@jColeChanged
jColeChanged / interview.py
Created May 21, 2014 20:35
Sometimes insertion sort if better than nlngn sorting methods
from operator import itemgetter
def inefficient_most_common(d, n):
"""
Returns the n most common words in a dictionary.
Args:
d: A dictionary of the frequencies or counts.
n: An integer representing the number of words to be returned.
@jColeChanged
jColeChanged / Sorting a million 32-bit integers in 2MB of RAM
Created May 20, 2014 17:24
This is my personal attempt at sorting a million 32-bit integers in 2MB of RAM.
from random import randint
from sys import maxint
import tempfile
import array
def write_a_million_ints():
f = file("ints.bin", "wb")
ints = array.array('i', [randint(-maxint + 1, maxint - 1) for i in range(1000000)])
ints.tofile(f)
@jColeChanged
jColeChanged / ipython notebook test file
Created August 24, 2013 23:13
A test gist to see how to share python notebooks.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 27 09:46:27 2013
@author: joshua
"""
import matplotlib.pyplot as plt
vectors = [[1, 2], [3, 4], [-2, -4]]
import random
def initialize_urn():
reds = ["red" for i in range(50)]
blacks = ["black" for i in range(50)]
return reds + blacks
def get_pair(urn):
choice_1 = random.choice(urn)
urn.remove(choice_1)
@jColeChanged
jColeChanged / gist:5810617
Last active December 18, 2015 16:19
A simple recommendation engine that I learned to make while reading Programming Collective Intelligence
from math import sqrt
# A dictionary of movie critics and their ratings of a small set of movies
critics={'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5,
'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5,
'The Night Listener': 3.0},
'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5,
'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 3.5},
'Michael Phillips': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0,
@jColeChanged
jColeChanged / student.py
Created May 28, 2013 21:04
An implementation of Student, a program capable of solving basic math problems in which a variable needs to be isolated
"""
Student was an AI program developed in the late sixties which used
pattern matching to solve basic algebraic word problems. This an
attempt to implement Student in Python through study of the Common
Lisp imlpementation outlined in Paradigms of Artificial Intelligence
Programming: Case Studies in Common Lisp (PAIP) by Peter Norvig.
"""
import operator
import re
@jColeChanged
jColeChanged / eliza.clj
Last active February 26, 2021 04:02
Subset of Eliza Chatbot in Clojure
(ns paip.eliza
(:require [clojure.string :as string])
(:gen-class))
(defn index-of
"Returns the index of item. If start is given indexes prior to
start are skipped."
([coll item] (.indexOf coll item))
([coll item start]
@jColeChanged
jColeChanged / month_utils.py
Created June 22, 2012 00:21
These are a few helper functions I ended up wanting while working with months while doing freelance work. I'm putting them up here since, though simple, they ended up being useful enough that if I ever work with dates again I'll probably end up using them
import datetime
from dateutil.relativedelta import relativedelta
def relative_month(d, months):
"""Accepts a datetime or date object and returns another datetime object.
The returned datetime is the start of the datetime n months away. This does
not have side effects.
Args:
d - a date or datetime object