This file contains hidden or 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 create | |
@post = Post.new(params[:post]) | |
@post.user = current_user | |
respond_to do |format| | |
if @post.save | |
format.html { redirect_to @post, notice: 'Post was successfully created.' } | |
format.json { render json: @post, status: :created, location: @post } | |
else | |
format.html { render action: "new" } |
This file contains hidden or 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
(fn [f coll] | |
(letfn | |
[(pair-to-map [pair] | |
(hash-map (first pair) (second pair)))] | |
(apply merge-with concat | |
(map pair-to-map | |
(partition 2 | |
(interleave (map f coll) (map vector coll))))))) |
This file contains hidden or 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
(fn [f coll] | |
(letfn | |
[(pair-to-map [pair] | |
(hash-map (first pair) (second pair)))] | |
(apply merge-with concat | |
(map pair-to-map | |
(partition 2 | |
(interleave (map f coll) (map vector coll))))))) |
This file contains hidden or 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 fibs | |
([] (cons 0 (fibs 0 1))) | |
([a b] | |
(lazy-seq (cons b (fibs b (+ a b)))))) |
This file contains hidden or 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
(use '[clojure.string :only (split-lines split)]) | |
(defn read-lines [args] | |
{ :lines (split-lines (slurp (:filename args))) }) | |
(defn lines-to-words [args] | |
{ :words (map #(split % #"\s") (:lines args)) }) | |
(defn words-to-freqs [args] | |
{ :word-freqs (map #(frequencies %) (:words args)) }) |
This file contains hidden or 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 inf-nums-from [n] | |
"A sequence of n to infinity." | |
(lazy-seq (cons n (inf-nums-from (inc n))))) | |
(take 10 (inf-nums-from 0)) |
This file contains hidden or 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 deps-sandbox.core | |
(:require [hiccup.core :as hic])) | |
(defn -main [& args] | |
(println "Here I am.")) |
This file contains hidden or 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 mongo-sandbox.core | |
(:use somnium.congomongo)) |
This file contains hidden or 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 clojure-distance.test.core | |
(:use [clojure.test]) | |
(:require clojure-distance.core) | |
(:import [clojure-distance.core Miles])) | |
(deftest miles-to-miles | |
(is | |
(= (to-miles (Miles. 5)) 5) | |
"Converting miles to miles returned a different length.")) |
This file contains hidden or 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 distance.test.miles | |
(:use [clojure.test]) | |
(:require [distance.units]) | |
(:import [distance.units Miles]) | |
(:import [distance.units Kilometers]) | |
(:import [distance.units Meters]) | |
(:use [distance.units])) | |
(deftest miles-to-miles | |
(is |