Skip to content

Instantly share code, notes, and snippets.

@lfborjas
lfborjas / shiny-datamapper.rb
Created October 23, 2010 06:45
A template generated by railswizard but with datamapper goodness thrown in!
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
template = {"authentication"=>"omniauth", "templating"=>"haml", "unit_testing"=>"test_unit", "css"=>"sass", "javascript"=>"jquery", "integration_testing"=>"on", "orm"=>"datamapper"}
recipes = template.values.flatten
def say_recipe(name); say "\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say "\033[36m" + "wizard".rjust(10) + "\033[0m" + " #{text}" end
@lfborjas
lfborjas / exam.sty
Created October 24, 2010 06:37
A modified version of [this](http://www.math.auckland.ac.nz/Teaching/Samples/) latex template for exams
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% exam.sty a style file for exams in the Dept of Maths
%%
%% concocted from: fancyheadings.sty and personal files by Paul Hafner
%% with minor amendments by David McIntyre 7/9/95, 7/5/96 and 16/5/97
%% and further amendments by David McIntyre 5/5/98
%%
%% Revised for the post-nDeva style on 14/5/01
@lfborjas
lfborjas / Main.java
Created October 25, 2010 02:46
Un ejemplo de uso de HashMap y datos estáticos
import java.util.Map.Entry;
import java.util.ArrayList;
public class Main{
public static void main(String[] args){
Diccionario es = new Diccionario();
Diccionario fr = new Diccionario("francés");
es.addPalabra("examen", "hora y media de estrés");
fr.addPalabra("quiz", "une chose très amusante");
System.out.printf("Significado de %s en %s: %s\n", "examen", es.getLenguaje(), es.getSignificado("examen"));
System.out.printf("Significado de %s en %s: %s\n", "imposible", es.getLenguaje(), es.getSignificado("imposible"));
@lfborjas
lfborjas / Baraja.java
Created October 26, 2010 22:05
Solución a la segunda parte del examen, con pruebas automatizadas agregadas.
package parte2;
import java.util.ArrayList;
import java.util.Collections;
/**
* @author lfborjas
*/
public class Baraja {
public static String[] palos={"diamantes", "tréboles", "corazones", "espadas"};
@lfborjas
lfborjas / create_forks.rb
Created October 28, 2010 03:14
A post receive hook for notifying a teacher that a student has turned in a homework via git. Placed by default in gitosis administrated folders - modified the system template (/usr/share/git-core/templates) for that.
require 'rubygems'
require 'grit'
include Grit
GIT_PATH = "/home/git/repositories"
KEYPATH = "/home/git/repositories/gitosis-admin.git/gitosis-export/keydir/"
original_repo = Repo.init_bare_or_open("#{GIT_PATH}/examen1_template.git")
puts "#{Dir.entries(KEYPATH).reject{|name| name=="." || name==".." || name["@"] }.each do |student_key|
puts "Creando repositorio para #{student_key}"
original_repo.fork_bare "#{GIT_PATH}/#{student_key.split("_")[1].split(".")[0]}.git"
end.length} Repositorios creados"
@lfborjas
lfborjas / Brontosaurio.java
Created November 3, 2010 06:18
El ejemplo de clases abstractas y polimorfismo del 3 de noviembre de 2010
public final class Brontosaurio extends Herbivoro{
public Brontosaurio(double p){
super(p);
}
public void comer(SerVivo algo){
peso = Math.pow(peso, algo.peso);
}
}
@lfborjas
lfborjas / unswp.sh
Created November 4, 2010 19:05
Fucking swap files...
for i in `find . -name *.swp`; do; rm $i; done
@lfborjas
lfborjas / omniauth_template.rb
Created November 8, 2010 20:51
My rails 3 templates, given that now jquery-ujs has a generator
# >---------------------------[ Install Command ]-----------------------------<
# rails new APP_NAME -m http://railswizard.org/257558554d274cfab160.rb -J
# >---------------------------------------------------------------------------<
#
# _____ _ _ __ ___ _
# | __ \ (_) | \ \ / (_) | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
# |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
Característica: administrar libros y solucionarios
Para pasar mis clases
Como un alumno inteligente
Quiero obtener solucionarios y aportarlos
Escenario: buscar solucionarios
Dado que existen los siguientes solucionarios:
|nombre| autor|
| física | chuck norris|
| mate | tarantino |
import java.util.List;
import java.util.LinkedList;
import java.util.HashMap;
public class Pokemon implements Comparable{
String nombre;
int nivel;
int vida;
static List ataquesPosibles;
List ataquesAprendidos;
{