Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@pbalduino
pbalduino / autores.clj
Last active August 29, 2015 13:56
09. Qual autor tem mais livros publicados?
(ns autores.core
(:require [clojure.pprint :as pp]
[net.cgrand.enlive-html :as en]
[clojure.string :as str])
(:import [java.net URL]))
(defn- get-links [url]
(let [links (-> url
URL.
en/html-resource
@pbalduino
pbalduino / grokpodcast.clj
Last active August 29, 2015 13:56
09. Baixando os episódios do Grok Podcast
(ns grokpodcast.core
(:require [clojure.java.io :as io]
[clojure.pprint :as pp]
[clojure.string :as str]
[net.cgrand.enlive-html :as en])
(:import [java.net URL]))
(def file-dir "~/Music/grokpodcast/")
(defn- get-archive [url]
; If we list all the natural numbers below 10 that are multiples of 3 or 5,
; we get 3, 5, 6 and 9. The sum of these multiples is 23.
; Find the sum of all the multiples of 3 or 5 below 1000.
(reduce + (filter #(or (= 0 (mod % 3))
(= 0 (mod % 5)))
(range 1000)))
#lang racket
; If we list all the natural numbers below 10 that are multiples of 3 or 5,
; we get 3, 5, 6 and 9. The sum of these multiples is 23.
; Find the sum of all the multiples of 3 or 5 below 1000.
(foldl + 0 (filter (lambda (num)
(or (= 0 (remainder num 3))
(= 0 (remainder num 5))))
class Cachorro
def nome(n)
@nome = n
end
def self.especie(n)
@@especie = n
end
def status
(defmacro %w [& coll]
`(map str (quote ~coll)))
(%w 1 2 3 4)
; ("1" "2" "3" "4")
(%w a b c d)
; ("a" "b" "c" "d")
(%w + - * /)
@pbalduino
pbalduino / core.clj
Last active August 29, 2015 13:57
Function ola-mundo decompiled
(ns capitulo03.core)
(defn ola-mundo [] (println "Olá mundo!"))
; public final class capitulo03.core$ola_mundo extends clojure.lang.AFunction {
; public static final clojure.lang.Var const__0;
;
; public static {};
; Code:
; 0: ldc #11 // String clojure.core
@pbalduino
pbalduino / memoization.js
Last active August 29, 2015 13:57
Memoization implemented in JavaScript
function memoize(fun) {
var mem = {};
return function() {
var args = arguments.toString();
if(mem[args] == undefined) {
mem[args] = fun.apply(this, arguments);
}
return mem[args];
}
}
......... ...
mov %edx,%edi
jmp 0x40143b <__mingw_CRTStartup+699>
mov %edx,%ebx
jmp 0x40128b <__mingw_CRTStartup+267>
mov %edx,%eax
nop
jmp 0x40134b <__mingw_CRTStartup+459>
mov %edx,%ebx
jmp 0x4014dc <__mingw_CRTStartup+860>
(defn fatorial [n]
{:pre [(> n 0)]}
(if (< n 2) 1
(* n (fatorial (dec n)))))
(fatorial 3)
; 6
(fatorial -2)
; AssertionError Assert failed: (> n 0)