Skip to content

Instantly share code, notes, and snippets.

@manutter51
manutter51 / gist:1117190
Created July 31, 2011 20:50
Strange agent behavior
user> (def a (agent 100))
#'user/a
user> @a
100
user> (agent-error a)
nil
user> (send a + 100)
#<Agent@73cc11: 100>
user> @a
100
@manutter51
manutter51 / na
Created August 30, 2011 13:34
My solution to Prob #27
#(every? true? (map = % (reverse %)))
@manutter51
manutter51 / salty-test-1.clj
Created November 7, 2011 22:00
Quick test of clojure-selenium interaction
(defn test-with-google []
(let [driver (FirefoxDriver.)]
(.get driver "http://www.google.com/")
(println "Original page title is " (.getTitle driver))
(let [element (.findElement driver (By/name "q"))]
(.sendKeys element (into-array ["clojure\n"]))
(.submit element)
(-> (WebDriverWait. driver 10)
(.until (proxy [ExpectedCondition] []
(apply [d]
@manutter51
manutter51 / .sublimerc
Created May 19, 2013 15:32
Cygwin command line helper for Sublime Text 2
#!/bin/bash
### INSTALLATION:
### Add the following 4 lines to your .bashrc or .bash_profile
### # source the sublimerc file if it exists
### if [ -f "${HOME}/.sublimerc" ] ; then
### source "${HOME}/.sublimerc"
### fi
###
### Strip off the leading "### " of course.
@manutter51
manutter51 / Sublime Text 2.desktop
Created May 26, 2013 18:34
Linux/gnome desktop entry file. Put this file in ~/.local/share/applications/ to get Ubuntu desktop to use Sublime Text 2 as a well-known text editor. Note that I've hard coded my personal directory paths in the Exec and Icon lines, so edit this to suit your own situation.
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=Sublime Text 2
GenericName=Text Editor
Comment=View and edit files
Exec=/home/mark/SublimeText2/sublime_text %F
Icon=/home/mark/SublimeText2/Icon/128x128/sublime_text.png
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;text/x-clj;text/x-cljs
@manutter51
manutter51 / sql2ent.rb
Last active December 18, 2015 05:49
Ruby script to generate rudimentary Doctrine 2 Entity files from SQL "CREATE TABLE" queries.
#!/Users/mnutter/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
def toCamel(s)
while s =~ /([^_]+)_(.)(.*)$/ do
s = $1 + $2.upcase + $3
end
return s
end
def toSnake(s)
@manutter51
manutter51 / auth.clj
Last active December 20, 2015 01:19
Restricting access for sensitive pages.
(ns share-for-all.routes.auth
;; ...
(:require ;; ...
[cemerick.friend :as friend]
(cemerick.friend [workflows :as workflows]
[credentials :as creds])))
;; ...
(defroutes secured-routes
(GET "/register" req
@manutter51
manutter51 / localhost
Last active December 20, 2015 01:28
Local nginx config for using http-kit with and without SSL
upstream http_backend {
server localhost:33333;
keepalive 32;
}
server {
listen 3333 default_server;
server_name localhost;
@manutter51
manutter51 / auth.clj
Created July 21, 2013 23:20
The right way.
;; ...
(defn- lock [handler]
(friend/requires-scheme handler :https {:http 3333
:https 3334}))
(defroutes sensitive-routes
(GET "/register" []
(layout/render "auth/register.html"))
@manutter51
manutter51 / gist:6066118
Last active December 20, 2015 03:49
If you make multiple syntax errors in a row, iex repeats the error output of the first mistake for the second and following errors.
Erlang R16B01 (erts-5.10.2) [source-bdf5300] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (0.10.1-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1 + 3
4
...
iex(5)> a = "foo"
"foo"
iex(6)> 8 + a
** (ArithmeticError) bad argument in arithmetic expression