Skip to content

Instantly share code, notes, and snippets.

@geraldodev
geraldodev / bound-input
Last active November 23, 2015 00:11
bound-input function to be called in place of dom/input when you want to update the underlying state key by key. It assumes a component with Ident
(ns credito.core
(:require
[cljs.pprint :refer [pprint]]
[datascript.core :as d]
[goog.dom :as gdom]
[om.dom :as dom]
[om.next :as om :refer-macros [defui]]
))
(enable-console-print!)
@geraldodev
geraldodev / brasileirao.clj
Created November 29, 2015 16:08
Copie este código para dentro do teste.core recarregue no repl com (require 'teste.core :reload) e tente resolver um a um
(def brasileirao
[
[2014 "Cruzeiro" "São Paulo" :pontos-corridos]
[2013 "Cruzeiro" "Grêmio" :pontos-corridos]
[2012 "Fluminense" "Atlético-MG" :pontos-corridos]
[2011 "Corinthians" "Vasco da Gama" :pontos-corridos]
[2010 "Fluminense" "Cruzeiro" :pontos-corridos]
[2009 "Flamengo" "Internacional" :pontos-corridos]
[2008 "São Paulo" "Grêmio" :pontos-corridos]
[2007 "São Paulo" "Santos" :pontos-corridos]
@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)))
(ns credito.core
(:require
[accountant.core :as accountant]
[clojure.string :as str]
[credito.guts.core :as app-guts :refer [g-conn]]
[datascript.core :as d]
[goog.dom :as gdom]
[om.dom :as dom]
[om.next :as om :refer-macros [defui]]
[cognitect.transit :as t]