This file contains 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
; Thoughts on a query API for clj-record. | |
(require '[clj-record.query :as q) | |
(manufacturer/find-records { | |
:founded "1910" ; still just a simple equality | |
:grade (q/between 85 95) | |
:name (q/in "Ford" "GM")}) | |
; where between and in return functions that know what they're about ... |
This file contains 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 clj-record.query | |
(:require [clojure.contrib.str-utils :as str-utils])) | |
(defn- clause-and-parameters [join-with values] | |
[(str-utils/str-join join-with (reduce (fn [v1 v2] (conj v1 (if (nil? v2) "NULL" "?"))) [] values)) (filter (complement nil?) values)]) | |
(defn between [value1 value2] | |
(fn [attribute] | |
(let [[clause parameters] (clause-and-parameters " AND " [value1 value2])] |
This file contains 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
# Allows you to specify the position of a column in your migrations' add_column and change_column calls. | |
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do | |
def add_column_options!(sql, options) | |
super | |
if options[:after] | |
sql << " AFTER #{quote_column_name(options[:after])}" | |
elsif options[:first] | |
sql << " FIRST" | |
end | |
end |
This file contains 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
A #<Class:0x44e38467> occurred in controller_name_was_here#show: | |
org.jruby.javasupport.JavaClass.installClassFields(JavaClass.java:843) | |
org.jruby.javasupport.JavaClass.installClassFields(JavaClass.java:843) | |
org.jruby.javasupport.JavaClass.setupProxy(JavaClass.java:710) | |
org.jruby.javasupport.Java.createProxyClass(Java.java:520) | |
org.jruby.javasupport.Java.getProxyClass(Java.java:449) | |
org.jruby.javasupport.Java.getInstance(Java.java:358) |
This file contains 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
# in lib/tasks | |
namespace :couchdb do | |
task :migrate => :environment do | |
migration_files = Dir[Rails.root.join('db/migrate/*.rb')] | |
migration_files_by_id = Hash[*migration_files.map {|path| [migration_number_from_file(path), path] }.flatten] | |
applied_migration_ids = SchemaMigration.all.map(&:id) | |
migration_ids_to_apply = migration_files_by_id.except(*applied_migration_ids).sort | |
if migration_ids_to_apply.empty? | |
puts "DB already up to date." | |
else |
This file contains 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 example.first) |
This file contains 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
(ring.adapter.jetty/run-jetty | |
(ring.middleware.params/wrap-params | |
(ring.middleware.multipart-params/wrap-multipart-params | |
(fn [request] | |
(if (= :get (:request-method request)) | |
(render-html-form-with-file-field-called "my-file") | |
(let [file (get-in req [:params "my-file" :tempfile])] | |
; file is a java.io.File | |
(with-open [reader (clojure.java.io/reader file)] | |
; reader is a--You guessed it!--java.io.Reader |
This file contains 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 get-fb-access-token [code redirect-uri] | |
(run-pipeline (access-token-url code redirect-uri) | |
{:error-handler (fn [_])} | |
#(http-request {:url %}) | |
read-access-token-from-response)) | |
(defn get-fb-user-with-token [access-token] | |
(run-pipeline access-token | |
{:error-handler (fn [_])} | |
fb-user-url |
This file contains 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
(defmodel widget db | |
(associations | |
(:has-many :sizes)) | |
(validation | |
(:name "Name is required" #(not (empty? %))))) |
This file contains 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
module RapidFTR | |
module AddOns | |
def self.add_exporter(e) | |
exporters << e | |
end | |
def self.exporters | |
@exporters ||= [] | |
end |
OlderNewer