Skip to content

Instantly share code, notes, and snippets.

(ns user)
(def users (atom #{}))
(defn full-name [{:keys [fname lname]}] (str fname " " lname))
(defn all-names [] (map full-name @users))
(ns user-expectations
(:use expectations user))
(expect "John Dory" (full-name {:fname "John" :lname "Dory"}))
(ns user-expectations.scenarios
(:use expectations.scenarios user))
(scenario
(with-redefs [users (atom #{{:fname "Mary", :lname "Dory"} {:fname "John", :lname "Dory"}})]
(ns user-expectations
(:use expectations user))
(expect "John Dory" (full-name {:fname "John" :lname "Dory"}))
(expect ["Mary Dory" "John Dory"]
(with-redefs [users (atom #{{:fname "Mary", :lname "Dory"} {:fname "John", :lname "Dory"}})]
(all-names)))
<!DOCTYPE HTML>
<html>
<head>
<link href="css/web-repl.css" rel="stylesheet" type="text/css">
<script src="js/lib/jquery-1.5.min.js" type="text/javascript"></script>
<script src="js/lib/jquery.websocket-0.0.1.js" type="text/javascript"></script>
<script src="js/lib/jquery.console.js" type="text/javascript"></script>
<script src="js/web-repl.js" type="text/javascript"></script>
<title>Web REPL</title>
</head>
var ws = null;
$(document).ready(function () {
ws = $.websocket("ws://" + window.location.host + "/websocket", {
events: {
'web-repl-response': function(info) {
currentCallback([
{msg: info.response,
className:"jquery-console-message-value"}
]);
(ns web-repl
(:require clojure.main)
(:use [clojure.stacktrace :only [root-cause]]))
(defonce repl-sessions (ref {}))
(defn current-bindings []
(binding [*ns* *ns*
*warn-on-reflection* *warn-on-reflection*
*math-context* *math-context*
; the code I work with has a publish-fn that we use to publish json back to a web-socket.
; therefore, the following line is all we need to add to our application to get the web REPL working
(publish-fn (hash-map :type :web-repl-response :response (web-repl/do-eval command publish-fn))))
#console {
height: 820px;
background: #eee;
margin: 10px;
border-radius: 5px;
-moz-border-radius: 5px;
border: 1px solid #aaa;
}
#console div.jquery-console-inner {
ruby did you know:
$ ruby --version
ruby 1.8.7
$ irb
>> {[:a], "a", [:b], "b", [:c], "c"}
=> {[:b]=>"b", [:a]=>"a", [:c]=>"c"}
@jaycfields
jaycfields / gist:3072090
Created July 8, 2012 18:07
spy and verify
require 'spec_helper'
describe MyController do
describe "create" do
it "filters sensitive data from the log" do
invocations = Rails.logger.spy_on.add
post :create, :myobj => {:social_security_number => "123-45-6789"}
invocations.grep(/Parameters:/).first.should include('"social_security_number"=>"[FILTERED]"')