Skip to content

Instantly share code, notes, and snippets.

View zippy's full-sized avatar

Eric Harris-Braun zippy

View GitHub Profile
@zippy
zippy / gist:768656
Created January 6, 2011 21:43
debugger run of error thrown in #compute_public_path
737 def compute_public_path(source, dir, ext = nil, include_host = true)
738 return source if is_uri?(source)
739
740 source += ".#{ext}" if rewrite_extension?(source, dir, ext)
741 source = "/#{dir}/#{source}" unless source[0] == ?/
=> 742 source = rewrite_asset_path(source, config.asset_path)
743
744 has_request = controller.respond_to?(:request)
745 if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/}
746 source = "#{controller.config.relative_url_root}#{source}"
@zippy
zippy / devise-1-0-9-password-on-confirmation.rb
Created January 9, 2011 13:41
Implementation of getting user password as part of confirmation for Devise 1.0.9
#This is for Devise 1.0.9
# To your routes file add:
map.update_user_confirmation '/user/confirmation', :controller => 'confirmations', :action => 'update', :conditions => { :method => :put }
# Add this replacement confirmations controller as app/controllers/confirmations_controller.rb
class ConfirmationsController < ApplicationController
@zippy
zippy / devise-1-2-x-password-on-confirmation.rb
Created January 9, 2011 13:58
Implementation of getting user password as part of confirmation for Devise 1.2.x
#This is for Devise 1.2.x
# To your routes file add:
as :user do
match '/user/confirmation' => 'confirmations#update', :via => :put, :as=> :update_user_confirmation
end
# Add this inherited confirmations controller as app/controllers/confirmations_controller.rb
@zippy
zippy / gist:863513
Created March 10, 2011 03:09
clojure defmacro problem
(defprotocol T "test" (getclass [this]))
(extend-type clojure.lang.PersistentArrayMap T (getclass [this] (class this)))
(getclass {})
(defmacro makeT [klass] `(extend-type ~klass T (getclass [this] (class this))))
(makeT String)
@zippy
zippy / passwords_controller.rb
Created April 11, 2011 01:17
How to get Devise 1.2 to reset passwords in the case of multiple accounts with the same e-mail
class PasswordsController < Devise::PasswordsController
before_filter :set_request_for_mailer
# POST /resource/password
def create
@resources = User.send_reset_password_instructions(params[resource_name])
self.resource = @resources.is_a?(Array) ? @resources[0] : @resources
if resource.errors.empty?
set_flash_message :notice, :send_instructions
redirect_to new_session_path(resource_name)
@zippy
zippy / instantiation_exception_error.clj
Created May 11, 2011 14:58
clojure macro instantiation error
(defmacro make-obj [n & args]
(let [name (if (instance? clojure.lang.Symbol n) n (eval n))]
`{(keyword '~name) [~@args]} ))
(make-obj bar :foo) ; => {:bar [:foo]}
(make-obj (symbol (str (name :bar))) :foo) ; => {:bar [:foo]}
(defmacro make-fn [n & b] `(defn ~n ~@b))
(make-fn keyword-maker [k] (make-obj (symbol (str (name k))) :foo)) ;=> Thrown class java.lang.InstantiationException
@zippy
zippy / cmp.clj
Created May 20, 2011 01:21
compojure problem
(ns cmp.core
(:use compojure.core, ring.adapter.jetty)
(:require [compojure.route :as route]
[compojure.handler :as handler])
)
(defn view-form []
(str "<html><head></head><body>"
"<form method=\"post\">"
@zippy
zippy / gist:1223636
Created September 17, 2011 04:52
clojurescript getValue bug
(ns test.core
(:require [clojure.browser.dom :as dom]
[goog.ui.Dialog :as Dialog]
[goog.events :as events]
[goog.ui.LabelInput :as LabelInput]
))
(def d (goog.ui.Dialog.))
(def l (goog.ui.LabelInput. "User name"))
@zippy
zippy / gist:1232866
Created September 21, 2011 18:19
clojurescript closure problem
; This fails:
(doseq [hid ["a" "b" "c"]]
(goog.dom.appendChild (goog.dom.$ "some-element-id") (goog.dom.createDom "div" (.strobj {"id" hid}) (str "Test-"hid)))
(goog.events.listen (goog.dom.$ hid) goog.events.EventType.CLICK, (fn [e] (js/alert hid))))
;This works:
(defn hidfn [hid]
(fn [e] (js/alert hid))
)
(doseq [hid ["a" "b" "c"]]
@zippy
zippy / gist:1268340
Created October 6, 2011 19:12
http-handler
(defn make-http-handler [host _r]
(app
["api"] {:post (fn [request]
(try
(let [b (trim (bytes->string (:body request)))
{command :cmd params :params} (clojure.contrib.json/read-json b)]
(println (str "POST REQUEST: from " (:remote-addr request) " for: " b))
{:status 200
:headers {"content-type" "application/json"
"Access-Control-Allow-Origin" "*"}