#Linux Cheat Sheet
##File Commands:
- ls – directory listing
- ls -al – formatted listing with hidden files
- cd dir - change directory to dir
- cd – change to home
- pwd – show current directory
- mkdir dir – create a directory dir
- rm file – delete file
#Deploy and rollback on Heroku in staging and production | |
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag'] | |
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag'] | |
namespace :deploy do | |
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU' | |
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU' | |
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag] | |
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on] |
# Example encoding of an email message in JSON | |
{ | |
headers: [ # in an array since order matters | |
{ name: 'Subject', value: 'An email' }, | |
{ name: 'Date', value: 'Thu, 4 Mar 2010 15:35:32 -0800' }, | |
{ name: 'From', value: 'george@foo.com' }, | |
{ name: 'To', value: 'paul@goo.com' } | |
{ name: 'Sender', value: 'paul@goo.com' } | |
{ name: 'Reply-to', value: 'paul@goo.com' } |
(ns type-level-tagger | |
{:doc "Implements State-of-the-art Unsupervised Part-of-speech Tagger | |
from \"Simple Type-Level Unsuperivsed POS Tagging\" | |
by Yoong-Keok Lee, Aria Haghighi and Regina Barzilay | |
(http://www.cs.berkeley.edu/~aria42/pubs/typetagging.pdf) | |
blog post: http://wp.me/pcW6S-x" | |
:author "Aria Haghighi (aria42@gmail.com)"} | |
(:use [clojure.java.io :only [reader]] | |
[clojure.contrib.duck-streams :only [with-out-writer]] | |
[clojure.contrib.seq-utils :only [indexed]] |
import qualified Data.Map as M | |
import Control.Applicative | |
import Data.Maybe (mapMaybe) | |
-- A BK-Tree is has a root word and more trees connected to it with branches of | |
-- lengths equal to the Levenshtein distance between their root words (i.e. an | |
-- n-ary tree). | |
data BKTree s = BKTree s (M.Map Int (BKTree s)) | Empty deriving (Show) | |
-- Inserting a word is done by inserting it along a branch of lenght |
> module Main where | |
First, import all the needed modules. | |
> import Text.Parsec hiding (State) | |
> import Text.Parsec.Indent | |
> import Control.Monad.State | |
Next, define our new Parser type. This replaces the Identity monad | |
with the (State SourcePos) monad. |
;;; http://srfi.schemers.org/srfi-26/srfi-26.html | |
(defn ^:private cut* | |
[[a f] form] | |
(cond | |
(nil? form) [a f] | |
(seq? (first form)) | |
(let [[arg-list xform] (cut* [[] '()] (first form))] | |
(recur [(reduce conj a arg-list) (concat f (list xform))] (next form))) |
#Linux Cheat Sheet
##File Commands:
object KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
type EValidation[+T] = Validation[String, T] | |
implicit val binding = new Bind[EValidation] { | |
def map[A, B](fa: EValidation[A])(f: A => B): EValidation[B] = fa.map(f) | |
def bind[A, B](fa: EValidation[A])(f: A => EValidation[B]): EValidation[B] = fa.flatMap(f) | |
} |
(ns dojo.core | |
(:require | |
[clojure.string :as str])) | |
;;; | |
(def digits | |
[[" _ " "| |" "|_|"] | |
[" " " |" " |"] | |
[" _ " " _|" "|_ "] |
(defmacro test-> | |
"Takes an expression and a set of test/form pairs. Threads expr (via ->) | |
through each form for which the corresponding test expression (not threaded) is true." | |
[expr | |
& clauses] | |
(assert (even? (count clauses))) | |
(let [g (gensym) | |
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))] | |
`(let [~g ~expr | |
~@(interleave (repeat g) (map pstep (partition 2 clauses)))] |