Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@pbalduino
pbalduino / freenode_clj-sp_2014-07-29.txt
Last active August 29, 2015 14:04
Freenode #clj-br 2014-07-29
[09:50] == pbalduino [b3a45769@gateway/web/freenode/ip.179.164.87.105] has joined #clj-br
[09:50] <pbalduino> mario-goulart: bom dia
[09:51] <mario-goulart> Alô pbalduino. Bom dia.
[09:56] == andrewhr [[email protected]] has joined #clj-br
[09:56] == andreanastacio [[email protected]] has joined #clj-br
[10:01] <mario-goulart> andreanastacio e andrewhr: vocês são a mesma pessoa? :-)
[10:02] <andreanastacio> hehe nao
[10:02] <andreanastacio> trabalhamos juntos
[10:02] <mario-goulart> !
[10:02] <mario-goulart> Bacana. :-)
;annotation syntax
(import [java.lang.annotation Retention RetentionPolicy Target ElementType]
[javax.xml.ws WebServiceRef WebServiceRefs])
(definterface Foo (foo []))
;annotation on type
(deftype ^{Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
@pbalduino
pbalduino / retaining-head.clj
Created September 6, 2014 17:25
Retaining the head
(defn better-count [lista] ; 1
(loop [lista lista ; 2
items 0] ; 3
(if (empty? lista) ; 4
items ; 5
(recur (rest lista) ; 6
(inc items))))) ; 7
;; ----------------------------
;; o jeito errado:
@pbalduino
pbalduino / primos.clj
Last active August 29, 2015 14:06
Primos
(loop [fs []
nums (range 2 23)]
(let [f (first nums)]
(if (empty? nums)
fs
(recur (conj fs f)
(filter #(not= 0 (mod % f)) nums)))))
@pbalduino
pbalduino / media1.cs
Created November 12, 2014 11:22
Cálculo de média usando for
private void btnCalcular_Click(object sender, EventArgs e)
{
decimal[] notas = new decimal[4];
notas[0] = txtNota0.Value;
notas[1] = txtNota1.Value;
notas[2] = txtNota2.Value;
notas[3] = txtNota3.Value;
Array.Sort(notas);
@pbalduino
pbalduino / media2.cs
Created November 12, 2014 11:31
Cálculo de média da forma curta
private void btnCalcular_Click(object sender, EventArgs e)
{
decimal[] notas = {txtNota0.Value, txtNota1.Value, txtNota2.Value, txtNota3.Value};
lblMenor.Text = notas.Min().ToString();
lblMaior.Text = notas.Max().ToString();
lblMedia.Text = notas.Average().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;
@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 / 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 / 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: