Skip to content

Instantly share code, notes, and snippets.

(def init-data {:clientes [{:id 1
:nome "geraldo"
:versao 0}
{:id 2
:nome "luiz"
:versao 1}]
:form-cliente {:id 1
:nome "geraldo"
:versao 0}})
(defn filter-options
[{:keys [options filter-fn value-key] :as props} filter-value exclude-options]
{:pre [(ifn? value-key)
(or (vector? exclude-options) (nil? exclude-options))]}
(let [exclude-options (if (vector? exclude-options)
(set exclude-options)
#{})]
(cond
(empty? filter-value)
options
@geraldodev
geraldodev / boxed_exceptioninfo.clj
Created September 6, 2016 13:56
It's annoying that exceptions created with ex-info are boxed inside another ex-info, because we need to use guard to capture our ex-info data. Imho (very humble), since core-match is called on ex-data it is data already, a simple map. When catching the exception pedestal could check if it is a ex-info and merge its keys with its data, qualified …
(def service-error-handler
(error-int/error-dispatch [ctx ex]
[({:exception-type :clojure.lang.ExceptionInfo}
:guard #(= (:type (ex-data (:exception %))) :guts.core/validation-failed))
](do
(pprint (ex-data ex))
(assoc ctx :response {:status 400
:body (:errors (ex-data ex))}))
;; If we don't match, forward it on
:else
@geraldodev
geraldodev / comp_transducer.clj
Last active October 21, 2016 19:42
mostra exemplo de comp e sua ordem de execução da direita pra esquerda. E a diferença da ordem de execução quando usamos transducer
;; observe que funciona (ordem direita pra esquerda
;; (str (inc 2)) faz sentido né
((comp str inc) 2)
;; porque nao funciona
((comp inc str) 2)
;; rode este pro debaixo ser possível
(def options-map {
"3" {:code "3" :label "tres"}
@geraldodev
geraldodev / escutar_atom.clj
Last active October 27, 2016 19:45
Escutando atom, pra capturar a transição :is-open de false para true. Observe que na linha 5 eu uso a desestruturação de mapa sem keys, porque quero fazer com que :is-open do estado anterior fique na variável was-open. A linha 6 já captura o is-open atual
(add-watch state-atom :watch
(fn [k
r
{was-open :is-open}
{:keys [is-open input-value]}]
(cond
(and
(not was-open)
is-open
Plug 'autozimu/LanguageClient-neovim', {'branch': 'next', 'do': 'bash install.sh'}
Plug 'reasonml-editor/vim-reason-plus'
let g:LanguageClient_serverCommands = {
\ 'reason': ['ocaml-language-server', '--stdio'],
\ 'ocaml': ['ocaml-language-server', '--stdio'],
\ }
" Automatically start language servers.
let g:LanguageClient_autoStart = 1
@geraldodev
geraldodev / InsertionPoint.re
Created April 25, 2018 20:29
Implementation in reason of https://material-ui-next.com/customization/css-in-js/#other-html-element to allow creation of <noscript id="jss-insertion-point> for injecting material-ui at the start of the index.html and let others libraries css taking precedence over material-ui 's
type jssObj = {
.
"options": {. [@bs.set] "insertionPoint": Dom.element},
};
[@bs.module "jss"] external createJss : {.} => jssObj = "create";
[@bs.module "material-ui/styles"]
external jssPreset : unit => {.} = "jssPreset";
@geraldodev
geraldodev / JssProvider.re
Last active April 25, 2018 20:51
Bare translation of the bits I needed from react-jss/lib/JssProvider just to integrate with bs-material-ui
[@bs.module "react-jss/lib/JssProvider"]
external myJssProvider : ReasonReact.reactClass = "default";
let make = (~jss: InsertionPoint.jssObj, ~generateClassName: string, children)=>
ReasonReact.wrapJsForReason(
~reactClass=myJssProvider,
~props={ "jss": jss, "generateClassName": generateClassName},
children,
);
type breakpoint = [ | `lg | `md | `sm | `xl | `xs ];
type breakpointsObj = {
.
"keys": array(string),
"values": {
.
"lg": int,
"md": int,
"sm": int,