Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@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 / 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 / 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 / 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:
;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 / 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 [~andrewhr@179.159.190.106] has joined #clj-br
[09:56] == andreanastacio [~andreanas@179.159.190.106] 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. :-)
(def matches [[:bra 3 :cro 1]
[:mex 1 :cam 0]
[:esp 1 :hol 5]
[:chi 3 :aus 1]
[:col 3 :gre 0]
[:cdm 2 :jap 1]
[:uru 1 :cos 3]
[:ing 1 :ita 2]
[:sui 2 :equ 1]
[:fra 3 :hon 0]
(def trans (transient []))
(conj! trans "Main thread")
(defn outra-thread []
(conj! trans "New thread"))
(. (Thread. outra-thread) start)
; Exception in thread "Thread-21" java.lang.IllegalAccessError: Transient used by non-owner thread
; at clojure.lang.PersistentVector$TransientVector.ensureEditable(PersistentVector.java:464)
@pbalduino
pbalduino / ratio.clj
Last active August 29, 2015 14:00
Por que existe um tipo para números racionais em Clojure?
;; Por que existe um tipo para números racionais em Clojure?
(/ 1 3) ; Clojure retorna o tipo Ratio por padrão numa divisão
; 1/3
(double (/ 1 3)) ; agora temos um tipo Double do Java
; 0.3333333333333333
(->> 1/3 ; o valor de 1 / 3
double ; é convertido para Double
@pbalduino
pbalduino / regex.txt
Last active August 29, 2015 13:59 — forked from anonymous/regex.txt
Para a resposta, basta apresentar a expressão regular utilizada e o parâmetro, caso seja utilizado,
1. Dada uma lista de CEPs válidos, escreva uma expressão regular que funcione com todos os itens:
04567003
04567-003
04.567-003
04.567.003
04 567 003
04567 003
04567.003