Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
(defun tom-show-agenda (prefix)
(interactive "P")
(org-agenda-list)
(delete-other-windows)
(unless prefix
(calendar)
(other-window 1)
(split-window-vertically)
(other-window 1)
(find-daypage)))
@almost
almost / countries.json
Last active April 29, 2024 13:41 — forked from keeguon/countries.json
A list of countries along 2 letter ISO codes in JSON format (the gist I forked from was valid JS but not valid JSON)
[
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},
@almost
almost / generators-webserver.coffee
Created July 21, 2013 10:48
CoffeesScript generator based webserver
// Translated from https://github.com/maccman/mach/blob/150c06a0991674b1cb122bb9b1b0e801c52a72ac/prototypes/generators.js
// Uses my fork of CoffeeScript with the yield statement added at https://github.com/almost/coffee-script
mach = require('mach')
app = mach.stack()
Q = require('q')
sleep = (millis, answer) ->
deferredResult = Q.defer()
setTimeout((->
deferredResult.resolve(answer)
{% if tweets %}
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Tweet</th>
<th>When?</th>
<th>View on Twitter</th>
</tr>
</thead>
<!DOCTYPE html>
<html lang="en">
<head>
<link
href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<div class="masthead">
# Another from Programming Pearls (again, my attempt before reading
# the rest of the chapter). Given a dictionary and a word, find all
# anagrams of the word in the dictionary.
words = (x.strip().lower() for x in open("/usr/share/dict/words"))
lookup = {}
for word in words:
letters = "".join(sorted(list(word)))
lookup.setdefault(letters, []).append(word)
# Another from Programming Pearls (again, my attempt before reading
# the rest of the chapter). Rotate a vector left in place by some
# amount without using extra memory proportional to the length of the
# input vector and while running in in O(n)
def rotate_left(vec, n):
i = 0
start = 0
letter = vec[i]
seen = 0
# Given a dictionary of words and scores and prefix return the top 10
# words in the dictionary that start with that prefix ordered by score
# (highest first)
# Builds a trie (a suffix tree) from the dictionary. The score
# ordering thing is my idea of how that could work, I haven't look at
# how others do it yet so it might be crazy :)
import random
import random
# Given a (possible) large list of random numbers (positive and
# negative) find the largest sum of a contiguous sub-sequence.
#
# From chapter 8 of programming pearls. My attempt before reading past
# the first page.
def largestsub(lst):
prev = 0
largest = float("-inf")
import random
# Generate n random numbers in the range start...end (inclusive) with no duplicates
# end-start must by a power of 2 minus 1 (so that we can keep on dividing into 2 without accounting for off by ones)
def rnd(start, end, n):
mid = (end-start)/2+start
assert end >= start
if n == 0:
return