Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@pbalduino
pbalduino / gist:7268251
Last active December 27, 2015 04:39
Argument verification with Clojure
(defn -main[& args]
(if-let [_ args]
(println "with args")
(println "without args")))
; $ lein run
; without args
; $ lein run meh
; with args
(ns logic.core
(use [clojure.math.combinatorics]))
(defn solve-logic-puzzle-1 []
"http://rachacuca.com.br/logica/problemas/1/"
(let [people [:espanhol :alemao :italiano]]
(first
(for [[casa1 casa2 casa3] (permutations people) ; casas
[azul vermelha preta] (permutations people) ; cores
; O Espanhol mora diretamente à direita do homem que mora na casa vermelha.
import java.sql.*;
public class SqliteSample {
private Connection conn;
private boolean inserting;
public void openDB() throws ClassNotFoundException {
Class.forName("org.sqlite.JDBC");
try {
digraph repl {
LER -> EXECUTAR -> IMPRIMIR -> LER
}
@pbalduino
pbalduino / def.clj
Last active December 18, 2015 06:08
Qual o valor mostrado?
; Qual o valor mostrado na tela? 10, 20, 30 ou nem compila?
(def m 10)
(defn foo [m]
(def m 20)
(println m))
(foo 30)
#!/bin/bash
# SCRIPT: method1.sh
# PURPOSE: Process a file line by line with PIPED while-read loop.
FILENAME=$1
count=0
cat $FILENAME | while read LINE
do
ufw deny from $LINE
done
;;; base64.clj: Experimental Base-64 encoding and (later) decoding
;; by Stuart Sierra, http://stuartsierra.com/
;; August 19, 2009
;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
;; distribution. By using this software in any fashion, you are
@pbalduino
pbalduino / obfuscated.clj
Last active December 17, 2015 12:59
Obfuscation example
; first I received this, and its result is 5. why?
((fn [[?<& %*+ $*|]](?<& %*+ $*|))({['*$] [+ (+ (*) (*)) (* 3 (*))]} ['*$]))
; so I formatted the code
((fn [[?<& %*+ $*|]]
(?<& %*+ $*|))
({['*$] [+ (+ (*) (*)) (* 3 (*))]} ['*$]))
; ?<& is the first parameter, %*+ is the second and $*| is the last. let's rename to x, y and z
@pbalduino
pbalduino / sudoku.txt
Last active December 16, 2015 22:19
Sudoku solver
Inicio
+---------+---------+---------+
| 6 | 3 | 8 4 |
| | | |
| 5 3 7 | 9 | |
| | | |
| 4 | 6 | 3 7 |
+---------+---------+---------+
| 9 | 5 1 | 2 3 8 |
| | | |
@pbalduino
pbalduino / group-by.clj
Last active December 16, 2015 20:29
Group by
(group-by even? (range 1 11))
; {false [1 3 5 7 9], true [2 4 6 8 10]}
(group-by #(= (mod % 3) 0) (range 1 15))
; {false [1 2 4 5 7 8 10 11 13 14], true [3 6 9 12]}
(group-by #(mod % 3) (range 1 15))
; {1 [1 4 7 10 13], 2 [2 5 8 11 14], 0 [3 6 9 12]}