Skip to content

Instantly share code, notes, and snippets.

View guilhermesilveira's full-sized avatar

Guilherme Silveira guilhermesilveira

View GitHub Profile
@guilhermesilveira
guilhermesilveira / BaseEnvironments.java
Last active December 23, 2015 22:49
points: . type safe . type safe . no missing parameter . option to create MANDATORY parameter . applicationscoped if the custom vraptor plugin is applicationscoped, the plugin docs will let you know...
/**
* My application desires
**/
@ApplicationScoped // PROBABLY IMPORTANT, or will CDI read the parent one?
@Environment({"development", "test", "acceptance"})
public class AcceptanceAndTest extends EmailConfig {
// mandatory configuration
public File getBaseDir() {
return new File("/tmp");
@guilhermesilveira
guilhermesilveira / ApplicationHelper.java
Last active April 24, 2018 17:31
View helper example
public class ApplicationHelper implements ViewHelper {
private final PrettyTimeFormatter formatter;
public ApplicationHelper(PrettyTimeFormatter formatter) {
this.formatter = formatter;
}
public String format(AbstractInstant instant) {
return formatter.format(instant);
@guilhermesilveira
guilhermesilveira / Hibernate.java
Last active December 16, 2015 04:49
SQL Injection Example
Criteria criteria = session.createCriteria(User.class);
criteria.add(eq("email", email);
criteria.add(eq("password", password);
User found = criteria.setMaxResults(1).uniqueResult();
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@guilhermesilveira
guilhermesilveira / robot.js
Created December 5, 2012 16:55 — forked from fabiopimentel/robot.js
[CAELUM TEAM]Megatron
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@guilhermesilveira
guilhermesilveira / gist:3315116
Created August 10, 2012 15:40
heroku does not love me anymore
# updated from https://gist.github.com/3316290
rm -rf xpto
rails _3.2.8_ new xpto -d postgresql --skip-bundle
cd xpto
bundle install
git init
@guilhermesilveira
guilhermesilveira / gist:2378419
Created April 13, 2012 17:10
abusing _ scala in javascript
<script>
function next(a) {
return a + 1;
}
function map(els, f) {
var current = [];
for(var i in els) {
var el = els[i];
current.push(f(el));
}
@guilhermesilveira
guilhermesilveira / gist:2215876
Created March 27, 2012 13:30
monad lists, o basico do map
package br.com.caelum.example.monad;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
interface Monad<A> {
<B> Monad<B> map(Function<A, B> f);
}
@guilhermesilveira
guilhermesilveira / gist:2007714
Created March 9, 2012 17:43
biased? imagina...
import java.util.*;
void getTimeDiffGroupedByCat() {
Scanner sc = new Scanner(new File("textfile.txt"));
Map<String, Long> lastCatTime = new HashMap<String, Long>();
TreeMap<String, Vector<Long>> catTimeDiffs = new TreeMap<String, Vector<Long>>();
while (sc.hasNext()) {
Long thisTime = sc.nextLong();
String category = sc.next();
Long oldCatTime = lastCatTime.put(category, thisTime);
if(oldCatTime != null) {