Skip to content

Instantly share code, notes, and snippets.

View timoteoponce's full-sized avatar

Timoteo Ponce timoteoponce

View GitHub Profile
public void close ( Process process ){
statement.close(process);
}
@timoteoponce
timoteoponce / binary_tree.rb
Created April 4, 2012 04:44
BTree implementation on Ruby
require "test/unit"
class Node
attr_accessor :value, :left_node, :right_node, :parent_node
def initialize(value=nil, left_node=nil, right_node=nil, parent_node = nil)
@value = value
@left_node = left_node
@right_node = right_node
@parent_node = parent_node
@timoteoponce
timoteoponce / OrderSet.groovy
Created June 24, 2012 03:22
OrderSet class
class Order{
void perform(){
}
}
class OrderA extends Order{
}
@DependsOn(OrderA.class)
class OrderB extends Order{
@timoteoponce
timoteoponce / JPAUtils.java
Created August 22, 2012 19:45
Create an EntityManager programatically in JPA1
/**
* @return an in-memory HSQL entityManager
* @author Timoteo Ponce
*/
public static EntityManager createEntityManager() {
Properties properties = new Properties();
properties.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");
properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
properties.put("hibernate.connection.username", "sa");
properties.put("hibernate.connection.password" ,"");
@timoteoponce
timoteoponce / jpa1.java
Created September 17, 2012 04:13
JPA entityManager
User user = (User)entityManager.createQuery( "SELECT t FROM User t WHERE t.name like :param1" ).setParam("param1",parameter).singleResult();
doSomething( user );
@timoteoponce
timoteoponce / domain2.java
Created September 17, 2012 04:17
Domain query 2
User user = userLister.withName( param1 ).get(0);
doSomething( user );
// and what about something more complex?
List<User> list = userLister.withName( name ).beingSingle( true ).withChidrenGt( 3 ).list();
@timoteoponce
timoteoponce / ruby_warrior_beginnner.rb
Created October 3, 2014 19:36
ruby warrior solution-beginner
class Player
def initialize
@direction = :forward
end
def feel
return @warrior.feel @direction
end
@Stateless @LocalBean
public class MyClass{
@Resource(lookup = "java:openejb/Resource/helloDS")
private DataSource dataSource;
public int countSql(){
Connection conn = datasource.getConnection();
Statement st = null;
try{
@timoteoponce
timoteoponce / dates.java
Created July 18, 2016 17:14
Simple joda-time comparison demo
int difference = 0;
DateTime start = new DateTime(source);
DateTime end = new DateTime(target);
if (source.after(target)) {
start = end;
end = new DateTime(source);
}
switch (type) {
case MONTHS:
difference = Months.monthsBetween(start, end).getMonths();
@timoteoponce
timoteoponce / EXERCISE: Messaging service.md
Last active February 13, 2017 20:37
EXERCISE: Message service

Exercise: Messages list service

This exercise consists on creating a REST service that allows external applications to create and manage message lists, basically there are two contexts:

  • User management: Services that allow the register, update or removal of users
  • Messages management: Services that allow message exchange between registered users

So the service will allow users to be registered, send messages between them and retrieve all the messages directed to a specific user.

## Example