Skip to content

Instantly share code, notes, and snippets.

@daemianmack
daemianmack / gdrive_filelister.rb
Created February 10, 2014 16:58
Authenticate via OAuth to the Google Drive API and list all files in the account
# Given a client_secrets.json file, authenticate via OAuth to the
# Google Drive API and list all files in the account.
# Setup:
## gem install google-api-client
## Under Google Developers Console, enable the Drive API and Drive SDK.
### Under Credentials > OAuth, create a new client ID.
#### This provides the client_secrets.json.
#### The Redirect URI must exactly match what the app actually sends.
(defrecord Server [service-map]
component/Lifecycle
(start [component]
(info :msg "Starting server.")
(let [server (bootstrap/create-server (:service-map service-map))]
(bootstrap/start server)
(assoc component :server server)))
(stop [component]
(info :msg "Stopping server.")
(update-in component [:server] bootstrap/stop)))
@daemianmack
daemianmack / gist:b3468a8eb3d6df37d5b7
Created November 8, 2014 18:34
SML mode tweaks for REPL workflow
(require 'sml-mode)
(global-set-key (kbd "C-c S") 'sml-run)
;; Requires sml binary on PATH...
;; export PATH=$PATH:/usr/local/smlnj/bin
;; README
;; To load a file and run sml repl -> Press C-c C-v inside a sml file.
;; To run the current files tests -> Press C-c C-r inside a sml file. It assumes the tests are inside the same directory.
;; For example, If your code file is hw1.sml your test file should be named as hw1test.sml in the same directory
var CSS="body { background: #fff; color: #000; font-family: Helvetica, Verdana, sans-serif; } .section { background: #e6b277; padding: 1em; margin: 1em; border: 1px solid #521302; } .example code { display: block; background: #e6d4a5; border: 1px solid #521302; padding: 0.8em; line-height: 1.4em; } #ex1 ul .first { font-size: 1.5em; color: #f0f; }";
var directChildMatch = CSS.match(/[a-zA-Z0-9\.-_\+\~#\s]*?\>\s?[a-zA-Z0-9\.-_\+\~#]*/gi);
if(directChildMatch) directChildMatch=directChildMatch.join(", ");
alert(directChildMatch);
@daemianmack
daemianmack / ianschenk's fabfile
Created October 15, 2010 17:33
Looks like a good springboard to start with.
from fabric.api import *
APTITUDE_CACHE = set()
PIP_CACHE = set()
EASY_INSTALL_CACHE = set()
def aptitude(package):
aptitude_update()
if package not in APTITUDE_CACHE:
@daemianmack
daemianmack / ianschenk's fabfile
Created October 18, 2010 11:06
Looks like a good starting point.
from fabric.api import *
APTITUDE_CACHE = set()
PIP_CACHE = set()
EASY_INSTALL_CACHE = set()
def aptitude(package):
aptitude_update()
if package not in APTITUDE_CACHE:
#!/usr/bin/env python
from __future__ import with_statement # needed for python 2.5
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.contrib import files
USAGE = """
================================================================
NOTE:
using this fabfile expects that you have the python utility
(defn map-while [f s pred]
(map f (filter pred s)))
@daemianmack
daemianmack / gist:2054543
Created March 17, 2012 02:47
Breaking dollars
(def coin-values {"h" 50 "q" 25 "d" 10 "n" 5 "p" 1})
(defn get-range [x cents]
(range (+ 1 (/ cents (coin-values x)))))
(defn list-combos [cents]
(for [h (get-range "h" cents)
q (get-range "q" cents)
d (get-range "d" cents)
n (get-range "n" cents)
@daemianmack
daemianmack / gist:2166073
Created March 23, 2012 01:37
My mars-rover solution
;; A squad of robotic rovers are to be landed by NASA on a plateau on
;; Mars. This plateau, which is curiously rectangular, must be
;; navigated by the rovers so that their on-board cameras can get a
;; complete view of the surrounding terrain to send back to Earth.
;; A rover's position and location is represented by a combination of
;; x and y co-ordinates and a letter representing one of the four
;; cardinal compass points. The plateau is divided up into a grid to
;; simplify navigation. An example position might be 0, 0, N, which
;; means the rover is in the bottom left corner and facing North.