Skip to content

Instantly share code, notes, and snippets.

View rvazquezglez's full-sized avatar

Raúl Vázquez rvazquezglez

  • Mexico City, Mexico
View GitHub Profile
@rvazquezglez
rvazquezglez / rfc.html
Created July 27, 2011 00:13
Calcula RFC (registro federal de causantes) sin homoclave usando jQuery
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function calculaRFC() {
function quitaArticulos(palabra) {
return palabra.replace("DEL ", "").replace("LAS ", "").replace("DE ",
"").replace("LA ", "").replace("Y ", "").replace("A ", "");
}
function esVocal(letra) {
@rvazquezglez
rvazquezglez / Dependencias Hibernate
Created December 1, 2012 07:46
Dependencias de hibernate para usar en curso java frameworks
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
@rvazquezglez
rvazquezglez / hibernate.cfg.xml
Created December 1, 2012 10:18
archivo cfg para hibernate con h2.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.password">sa</property>
<property name="hibernate.connection.url">jdbc:h2:tcp://localhost/mem:test</property>
<property name="hibernate.connection.username">sa</property>
@rvazquezglez
rvazquezglez / Banco.java
Created December 1, 2012 11:25
Clase de dominio que hace referencia a banco.
public class Banco implements java.io.Serializable {
private Integer idbanco;
private String nombre;
public Banco() {
}
public Banco(Integer idbanco, String nombre) {
this.idbanco = idbanco;
@rvazquezglez
rvazquezglez / Banco.hbm.xml
Created December 1, 2012 11:27
Archivo para el mapeo de la clase banco.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 1/12/2012 04:06:04 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="javagurus.curso.frameworks.model.Banco" table="BANCO" schema="PUBLIC" catalog="TEST">
<id name="idbanco" type="integer">
<column name="IDBANCO"/>
<generator class="increment" />
</id>
@rvazquezglez
rvazquezglez / Hibernate Util
Created December 1, 2012 11:29
Clase de utilería para mantener una sola fábrica de sesión.
public class HibernateUtil {
private static final SessionFactory sessionFactory;
/**
* Inicializa la fabrica de sesiones de hibernate
*/
static {
sessionFactory = new Configuration().
configure().
buildSessionFactory();
}
@rvazquezglez
rvazquezglez / BancoDAO.java
Created December 1, 2012 11:36
Clase DAO para Banco.
public class BancoDAO {
public int insertar(Banco banco) {
Session session = HibernateUtil.getSessionFactory().openSession();
// Inicia una transaccion
Transaction transaccion = session.beginTransaction();
int idBanco = -1;
try {
idBanco = (Integer) session.save(banco); // INSERT INTO BANCO .....
transaccion.commit();
@rvazquezglez
rvazquezglez / BancoDAOTest.java
Created December 1, 2012 11:42
Clase de prueba para BancoDAO
public class BancoDaoTest {
private BancoDAO bancoDAO = new BancoDAO();
@Test
public void testInsertar() {
Banco banco = new Banco();
banco.setNombre("Banco 11082012");
int idBanco = bancoDAO.insertar(banco);
assertTrue(idBanco != -1);
}
}
@rvazquezglez
rvazquezglez / Jetty.xml
Created December 7, 2012 21:14
Agrega un DataSource por JNDI a Jetty.
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>java:url/datasource</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<Set name="DriverType">thin</Set>
<Set name="URL">jdbc:oracle:thin:@host:1521:name</Set>
@rvazquezglez
rvazquezglez / struts2-config-browser-plugin
Created December 8, 2012 09:22
struts2-config-browser-plugin url
http://localhost:8080/nombreproyecto/config-browser/actionNames.rock