This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-fn | |
[inputs outputs] | |
(doseq [x (ns-publics (the-ns `clojure.core))] | |
(try | |
(if (= outputs | |
(binding [*out* java.io.StringWriter] | |
(apply | |
(if (-> (second x) meta :macro) | |
(macroexpand `(second x)) | |
(second x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-fn | |
[in out] | |
(map first (filter | |
(fn [x] | |
(try | |
(= out | |
(binding [*out* java.io.StringWriter] | |
(apply | |
(if (-> (second x) meta :macro) | |
(macroexpand `(second x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:servers ["irc.freenode.net"] ; A list of servers. | |
:prepends #{"@"} ; The character you want for a prepend. Currently set to @ | |
:bitly-login "" ; Your bit.ly login. | |
:bitly-key "" ; API key and login above needed for URL shortening. | |
:wordnik-key "" ; API key needed for dictionary access. | |
:max-operations 3 ; The maximum number of operations that can be running at any given time. | |
:pending-ops 0 ; The number of operations running right now | |
:admin-add? true ; only admins can add help topics | |
:admin-rm? true ; only admins can remove help topics | |
:eval-prefixes {:defaults ["->" "." "," ; prefixes in any channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rotatel | |
([n col] | |
(let [n (mod n (count col))] | |
(concat | |
(drop n col) | |
(take n col)))) | |
([col] | |
(rotatel 1 col))) | |
(defn rotater |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bayes(a, b_given_a, b_given_not_a): | |
"""Calculates P(a|b) using bayes theorem. | |
Bayes theorem states that: | |
P(b|a) * P(a) | |
P(a|b) = -------------------------------- | |
P(b|a) * P(a) + P(b|~a) * P(~a) | |
Intuitively this is saying that the probability of b given a is equivalent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function merge(array_one, array_two) | |
{ | |
var new_array_length = array_one.length + array_two.length; | |
var array_three = new Array(new_array_length); | |
var p_one = 0; | |
var p_two = 0; | |
for (var p_three = 0; p_three < new_array_length; p_three++) | |
{ | |
if (array_one.length == p_one) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fn-and | |
"Takes a set of functions and returns a fn which returns whether | |
every item in the juxtaposition of those functions is true." | |
([& fns] | |
(let [juxted-fns (apply juxt fns)] | |
(fn [& args] (every? true? (apply juxted-fns args)))))) |
OlderNewer