Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

219c219,220
< 'save': {method:'POST'},
---
> 'create': {method:'POST'},
> 'update': {method:'PUT'},
421a423,431
>
> Resource.prototype.$save = function(a1, a2, a3) {
> if (this.id) {
> Resource.prototype.$update.call(this, a1, a2, a3);
@geraldodev
geraldodev / gist:5392638
Created April 16, 2013 01:22
sequel transaction beauty
DB.transaction do
rows_affected = DB[:cod_pro].returning.where({:CD_COD_PRO => cd_cod_pro}).update({:DS_CODIGO_COBRANCA => cd_unimed,
:DS_NOME_COBRANCA => descricao_unimed})
puts "atualizou cd_cod_pro #{cd_cod_pro} #{ary.inspect} "
raise "sql update cod_pro errado " if rows_affected != 1
end
(ns bindboom
(:use [seesaw core table mig])
(:require [seesaw.bind :as bind]))
(defn example
[]
(let [a (atom nil)
p (mig-panel
:constraints ["", "[left]"]
:items [
(defr LikeButton
[component props state]
:get-initial-state #(identity {:liked true})
[:p {:on-click #(swap! component update-in [:liked] not)}
"You " (if (:liked state) "liked" "not liked") " this. Click to toggle"]
)
@geraldodev
geraldodev / gist:8309684
Created January 8, 2014 00:48
Toying with components with Om
(ns app.crud
(:require
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[ajax.core :refer [GET]]
[app.utils :refer [e-value]]))
(defn js-margin-right []
#js {:margin-right "10px"})
@geraldodev
geraldodev / "partialfied" get-state which receives where to store through opts
Created January 19, 2014 23:35
component with constructed in a way the caller decides where to save state.
(defn empresa-ficha [{:keys [id nome cnpj inscricao-estadual] :as empresa} _ {:keys [state-owner state-korks]}]
(let [get-state (partial om/get-state state-owner state-korks)
set-state! (partial om/set-state! state-owner state-korks)]
(reify
om/IRender
(render [_]
(dom/form
#js {:className "form form-condensed"
:role "form"
:style #js {:margin-top "10px"}}
(defn concat-korks
[korks k2orks]
(if-not (sequential? korks)
(if-not (sequential? k2orks)
[korks k2orks]
(if (list? k2orks)
(conj k2orks korks)
(into [korks] k2orks)))
(if (list? korks)
(if-not (sequential? k2orks)
@geraldodev
geraldodev / get-state-map
Created January 21, 2014 01:34
Attempt to centralize state when you are relying on get-state set-state!
(defn concat-korks
"Takes two sequentials and concats them. Respects the type of the first sequential.
Favors vector in none is a sequential"
[korks k2orks]
(if-not (sequential? korks)
(if-not (sequential? k2orks)
[korks k2orks]
(if (list? k2orks)
(conj k2orks korks)
(into [korks] k2orks)))
@geraldodev
geraldodev / gist:8855252
Created February 7, 2014 00:21
edit-buttons
(defn edit-buttons [_ _ {:keys [ch>]}]
(reify
om/IRender
(render [_]
(dom/div #js {:className "form-group btn-group"
:style (js-margin-right)}
(dom/button #js {:className "btn btn-default"
:onClick (fn [e]
(.preventDefault e)
(put! ch> {:event e
(defroutes rotas
#_(ANY "/empresa" []
(resource
:available-media-types ["application/edn"]
:method-allowed? (request-method-in :get :post)
:handle-ok (fn [ctx]
(k/select ent/empresa (k/fields :id :nome)))
:post! (fn [ctx]
(let [empresa (read-edn-from-body ctx)]
{::result (insert-empresa empresa)}))