Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
(ns almost.core)
(defn hello [] "WORLD")
@almost
almost / gist:2862895
Created June 3, 2012 10:09
Problems running lein deps, help appreciated!
> lein deps
Downloading: org/clojure/clojure/1.2.0-RC1/clojure-1.2.0-RC1.pom from repository central at http://repo1.maven.org/maven2
Unable to locate resource in repository
[INFO] Unable to find resource 'org.clojure:clojure:pom:1.2.0-RC1' in repository central (http://repo1.maven.org/maven2)
Downloading: org/clojure/clojure/1.2.0-RC1/clojure-1.2.0-RC1.pom from repository clojars at http://clojars.org/repo/
Unable to locate resource in repository
[INFO] Unable to find resource 'org.clojure:clojure:pom:1.2.0-RC1' in repository clojars (http://clojars.org/repo/)
Downloading: org/clojure/clojure-contrib/1.2.0-RC1/clojure-contrib-1.2.0-RC1.pom from repository central at http://repo1.maven.org/maven2
Unable to locate resource in repository
[INFO] Unable to find resource 'org.clojure:clojure-contrib:pom:1.2.0-RC1' in repository central (http://repo1.maven.org/maven2)
@almost
almost / gist:3116180
Created July 15, 2012 10:18
setf from cl-macs.el from Emacs (elisp source for setf macro)
(defmacro setf (&rest args)
"Set each PLACE to the value of its VAL.
This is a generalized version of `setq'; the PLACEs may be symbolic
references such as (car x) or (aref x i), as well as plain symbols.
For example, (setf (cadar x) y) is equivalent to (setcar (cdar x) y).
The return value is the last VAL in the list.
\(fn PLACE VAL PLACE VAL ...)"
(if (cdr (cdr args))
(let ((sets nil))
@almost
almost / cl-macs.el
Created July 15, 2012 10:19
cl-macs.el - Common lisp macros in elisp (from the standard GNU Emacs distribution)
;;; cl-macs.el --- Common Lisp macros
;; Copyright (C) 1993, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
;; 2009, 2010, 2011 Free Software Foundation, Inc.
;; Author: Dave Gillespie <daveg@synaptics.com>
;; Version: 2.02
;; Keywords: extensions
;; This file is part of GNU Emacs.
@almost
almost / dropbox_oauth_requests.js
Created August 28, 2012 09:40
How to make signed requests for Dropbox API in Node.JS using node-oauth (for Dan)
// I assume here that you have already done your oauth authentication with dropbox
// (maybe using everyauth) and you have the access_token and access_token_secret (which are per-user).
// You also need the consumer_key and consumer_secret values for your Dropbox API account (these should
// be part of you application configuration).
// Step 1: Create an oauth object (do this once and store it, you can use the same object over and over)
var OAuth= require('oauth').OAuth;
dropboxOAuth = new OAuth("https://api.dropbox.com/1/oauth/request_token",
"https://api.dropbox.com/1/oauth/access_token",
@almost
almost / gist:3497955
Created August 28, 2012 13:27
I just received this email from DirectNIC, can you spot what's wrong? (and yes, I did change the letters for this post)
Thank you for using the directNIC.com Trouble Ticket System.
The following response is from a qualified directNIC customer support team member:
Date: 08/28/12 08:25am
From: *****
Tom,
A hint to your password is that it begins with s and ends with j.
If you cannot remember your password or the answer to the security question, we can only send the login details via postal mail to the account address on file. Please verify that address if still needed and will mail them out promptly.
@almost
almost / gol.coffee
Created September 8, 2012 13:21
Quick and Dirty Game of Life in CoffeeScript (30 mins in)
_ = require('./underscore')
makeGrid = (height, width) =>
_.map(_.range(height), -> _.map(_.range(width), -> undefined))
GRID_SIZE = 80
grid = makeGrid(GRID_SIZE, GRID_SIZE)
@almost
almost / allocate.py
Created October 24, 2012 12:56
Allocate API example in Python
# Using the "requests" library http://docs.python-requests.org/en/latest/
import requests
token = 'yourtoken'
response = requests.get('https://example.allocate.co.uk/api/v2/offers/1', auth=(token, 'x'))
assert response.status_code == 200
print response.json
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
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")