Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@pbalduino
pbalduino / install-java.sh
Created April 21, 2015 16:54
install-java.sh
#!/bin/sh
cd /home/amanda/Downloads
rm -rf /opt/jvm
rm -rf jre1.8.0_45
mkdir /opt/jvm
tar -zxf jre-8u45-linux-i586.tar.gz -C /opt/jdk
@pbalduino
pbalduino / primitive.clj
Last active August 29, 2015 14:19
Primitive
(def numeros (range 0 10000))
(def vetor (into-array Long/TYPE numeros))
(defmacro benchmark [code]
`(time (first (doall (repeatedly 1000 (fn [] ~code))))))
(benchmark (reduce + numeros))
; "Elapsed time: 123.946807 msecs"
(defn random-number [_]
(rand-int 22))
(defn a-validate [valor]
(> valor 10))
(defn a-errorhandler [ag ex]
(println "Error: " (.getMessage ex)))
(defn a-watcher [ref chave antigo novo]
@pbalduino
pbalduino / agent-watchers.clj
Last active August 29, 2015 14:14
Agent watchers
;; Primeiro criamos um agent a
(def a (agent 1))
;; A função watch deve ter quatro parâmetros: uma chave única,
;; a referência ao próprio agent, o valor antigo e o valor novo.
(defn a-watch [key ref old new]
(println "Watching" key ref old new))
;; vamos criar uma função que dobra o valor recebido e informa
;; quando está sendo executada
;; aqui eu crio um agent com o valor 1 e chamo de x
(def y (agent 1))
;; nossa função vai levar dez segundos a cada processamento
(defn triple [c]
(println "valor inicial:" c)
(Thread/sleep 10000)
(println "terminei")
(* c 3))
@pbalduino
pbalduino / macro-reader.clj
Created January 28, 2015 20:20
User defined macro reader
(dispatch-reader-macro \X xml-reader)
#X"
<compras>
<item>
<batata>
<preco>1.23</preco>
</batata>
</item>
</compras>"
@pbalduino
pbalduino / gen.clj
Last active August 29, 2015 14:13
Criando uma classe Java com Clojure
;; criei um arquivo chamado gen.clj
(ns capitulo08.gen
(:gen-class
:name "capitulo08.Uia"
:methods [[hello [] void]]))
(defn -hello [this]
(println "Olá!"))
;; agora no REPL:
@pbalduino
pbalduino / localstorage.js
Last active August 29, 2015 14:10
Small sample of HTML5 Local Storage
if(localStorage["demo.isRunning"] !== "true") {
alert("Let's write something on the local storage");
localStorage["demo.isRunning"] = true;
localStorage["demo.value"] = "It works!";
window.location.reload();
} else {
alert("Value of stored value is '" + localStorage["demo.value"] + "'");
@pbalduino
pbalduino / media4.cs
Created November 12, 2014 12:07
Cálculo de média usando IFs
private void btnCalcular_Click(object sender, EventArgs e)
{
// maior
if (txtNota0.Value > txtNota1.Value && txtNota0.Value > txtNota2.Value && txtNota0.Value > txtNota3.Value)
{
lblMaior.Text = txtNota0.Value.ToString();
}
else if (txtNota1.Value > txtNota0.Value && txtNota1.Value > txtNota2.Value && txtNota1.Value > txtNota3.Value)
{
lblMaior.Text = txtNota1.Value.ToString();
@pbalduino
pbalduino / media3.cs
Created November 12, 2014 11:45
Cálculo de média sem array
private void btnCalcular_Click(object sender, EventArgs e)
{
decimal maior = 0;
decimal menor = 99;
if (txtNota0.Value < menor) menor = txtNota0.Value;
if (txtNota1.Value < menor) menor = txtNota1.Value;
if (txtNota2.Value < menor) menor = txtNota2.Value;
if (txtNota3.Value < menor) menor = txtNota3.Value;