Author: | Baiju Muthukadan |
---|---|
Email: | baiju.m.mail AT gmail.com |
Version: | 0.3.2 |
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
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix. | |
;; | |
;; * :use makes functions available without a namespace prefix | |
;; (i.e., refers functions to the current namespace). | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; |
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
class Ns | |
def initialize | |
use.each do |pkg, method_names| | |
method_names.each do |name| | |
self.class.send(:define_method, name) do |*args| | |
pkg.method(name).call(*args) | |
end | |
end | |
end | |
end |
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
(ns mars_rover) | |
(use '[clojure.string :only (split)]) | |
(defmulti handle-move (fn [x y move facing] [(str move) facing])) | |
(defmethod handle-move ["M" "N"] [x y move facing] [x (+ y 1) facing]) | |
(defmethod handle-move ["M" "E"] [x y move facing] [(+ x 1) y facing]) | |
(defmethod handle-move ["M" "S"] [x y move facing] [x (- y 1) facing]) | |
(defmethod handle-move ["M" "W"] [x y move facing] [(- x 1) y facing]) |
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
;; 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. |
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 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) |
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 map-while [f s pred] | |
(map f (filter pred s))) |
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
#!/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 |
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 fabric.api import * | |
APTITUDE_CACHE = set() | |
PIP_CACHE = set() | |
EASY_INSTALL_CACHE = set() | |
def aptitude(package): | |
aptitude_update() | |
if package not in APTITUDE_CACHE: |
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 fabric.api import * | |
APTITUDE_CACHE = set() | |
PIP_CACHE = set() | |
EASY_INSTALL_CACHE = set() | |
def aptitude(package): | |
aptitude_update() | |
if package not in APTITUDE_CACHE: |