Skip to content

Instantly share code, notes, and snippets.

@jelies
jelies / upload_progress.rb
Created September 19, 2014 15:19
Capistrano function to upload files displaying a progress percentage.
desc "Uploads a file displaying the progress"
def upload_progress(source, target)
upload(source, target, :via => :sftp) do |event, options, *others|
if event.to_s == "put"
print ("\r * " + (("#{others[1]}".to_f / "#{others[0].size}".to_f) * 100).round(2).to_s + "%").ljust(10, ' ')
elsif event.to_s == "close"
print "\r"
end
end
end
@jelies
jelies / CustomSchemaValidationConfiguration.java
Created February 12, 2014 08:33
Custom Hibernate schema validator that collects all the validation errors to display them all together instead of crashing one by one. Using Hibernate 3.6.4.
package com.jelies.hibernate.validation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
@jelies
jelies / MyRepositoryImpl.java
Last active October 12, 2023 04:30
A Spring FactoryBean to create a Hibernate's StatelessSession to be injected in your custom repository implementation when using Spring Data JPA.
package com.jelies.spring3tomcat7.repository;
import org.hibernate.Criteria;
import org.hibernate.ScrollableResults;
import org.hibernate.StatelessSession;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
@jelies
jelies / AutowiringSpringBeanJobFactory.java
Last active October 24, 2024 16:38
Quartz (2.1.6) java config with spring (3.2.1). Using a SpringBeanJobFactory to automatically autowire quartz classes.
package com.jelies.spring3tomcat7.config.quartz;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
/**
* This JobFactory autowires automatically the created quartz bean with spring @Autowired dependencies.