Skip to content

Instantly share code, notes, and snippets.

View pbalduino's full-sized avatar

Plínio Balduino pbalduino

View GitHub Profile
@pbalduino
pbalduino / heroku.scm
Created December 14, 2011 17:15
To remember
#lang scheme
; sudoku solver
; sample:
;+-------+-------+-------+
;| 6 7 . | . 2 1 | . 4 . |
;| . . . | 7 . . | . 3 . |
;| . 5 . | 8 . . | 6 . . |
;+-------+-------+-------+
;| 7 . 6 | 1 . 2 | 9 . . |
@pbalduino
pbalduino / sudoku-board.scm
Created February 15, 2012 01:37
Sudoku board
#lang scheme
; http://www.dailysudoku.com/sudoku/archive/2012/02/2012-02-10.shtml
(define easy-game "020580000093600007001007000609102300180030059005908104000800500200009760000015080")
(define (to-number char)
(- (char->integer char) 48))
(define (to-vector string)
(list->vector (map to-number (string->list string))))
(def ^{:private true} empty-string "")
(def ^{:private true} single-comma ",")
(def ^{:private true} l-or-st #"(((L|ST)=\w*)| )")
(def ^{:private true} multiple-commas #"(,{2,}|,*\z)")
(def ^{:private true} lost-commas #"(\A,*|,*\z)")
(defn- remove-local [issuer-name]
(reduce
(fn[a b]
(replace a (first b) (second b)))
(defn setup []
println "Yes, we have setup!")
(defmacro run-if-exists [name]
`(if (clojure.test/function? '~name)
((println "Calling function")
~name)
(println "Function not found")))
(macroexpand '(run-if-exists setup))
@pbalduino
pbalduino / gist:2381227
Created April 14, 2012 00:54
Refactoring with functional programming
; I need to write code to make this pass:
; https://github.com/pbalduino/north/blob/master/test/north/test/core.clj
; First I wrote that
(defn be-true [result]
(assert (= result true) (format "Assertion failed. %s was expected to be true" result)))
; So I added be-false and slightly changed be-true
; Then I noticed there's duplication of code there
@pbalduino
pbalduino / gist:2512603
Created April 27, 2012 20:21
Console result
$ lein test north.test.result
Running tests
Feature name: In some strange context it should do this
--> Uhu!
OK
Feature name: In some strange context and it should do that
--> Another test
OK
@pbalduino
pbalduino / gist:2559812
Created April 30, 2012 16:32
RSpec hierarchy
Before all - root
Before each - root
Test - root before
After each - root
Before each - root
Test - root after
After each - root
Before all - context
Before each - root
Before each - context
#import "FirstClass.h"
@implementation FirstClass
-(NSString *) meh;
{
NSLog(@"meh");
return @"meh";
}
-(NSString *) foo: (int)bar;
#import <Foundation/Foundation.h>
@interface FirstClass : NSObject {
NSString* name;
}
-(NSString*) meh;
-(NSString*) foo: (int)bar;
@end
@pbalduino
pbalduino / gist:2885405
Created June 6, 2012 23:09
Lista de compras + tédio
# lista de compras
lista = []
lista << meia.duzia * cenoura
lista << meia.duzia * cebola
lista << 1.saco_cheio * batatas
if ovo.price <= 2.5
lista << 1.bandeja * ovo