Skip to content

Instantly share code, notes, and snippets.

@jelies
jelies / AutowiringSpringBeanJobFactory.java
Last active June 14, 2024 06:00
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.
@josericardo
josericardo / PageableCollection.java
Last active September 26, 2023 06:21
Helper to iterate over pageable sources. Should reduce memory usage when querying large tables via Spring Data.
======================================
Usage:
Fetcher<Source, MyEntity> f = new Fetcher<Source, MyEntity>(source) {
@Override
public List<MyEntity> fetch(Pageable pageRequest)
{
return source.findAll(pageRequest);
}
};
@jonlabelle
jonlabelle / string-utils.js
Last active July 8, 2024 21:19
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();
@wvuong
wvuong / PlacesRESTController.java
Created May 29, 2013 20:38
Simple generic REST-ful Spring MVC controller, interops with Spring Data repositories
package com.willvuong.foodie.controller;
import com.willvuong.foodie.dao.PlaceRepository;
import com.willvuong.foodie.domain.Place;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@jeremyjarrell
jeremyjarrell / Idempotent migration in MySQL example
Created July 25, 2013 20:06
In MySQL, IF statements cannot exist outside of stored procedures. Therefore, to create an idempotent migration for MySQL it's necessary to wrap the migration in a stored procedure and execute that stored procedure against the database to perform the migration.
DELIMITER $$
DROP PROCEDURE IF EXISTS add_email_address_column_to_customers_table $$
-- Create the stored procedure to perform the migration
CREATE PROCEDURE add_email_address_column_to_customers_table()
BEGIN
-- Add the email_address column to the customers table, if it doesn't already exist
@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;
@nbouherrou
nbouherrou / SvnToGit.md
Last active October 21, 2019 14:43
Migrate to Git from SVN
@lolzballs
lolzballs / HelloWorld.java
Created March 22, 2015 00:21
Hello World Enterprise Edition
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();
@jedvardsson
jedvardsson / LabeledEnum.java
Created June 3, 2015 08:59
How to implement a custom Hibernate enum type indexed on a label
public interface LabeledEnum {
String getLabel();
}
@bradberger
bradberger / notZero.js
Last active September 27, 2016 08:15
A simple AngularJS directive to make sure a number is not zero. It sets the formName.elementName.$error.zero value accordingly.
/**
* @description A simple check to ensure a number is not zero. Sets the "zero" validation accordingly.
* @usage <input ng-model="myModel" not-zero>
*/
angular.module("app").directive("notZero", function() {
var linkFunc = function(scope, element, attrs, ngModel) {
var zeroValidator = function(value) {
var num = parseFloat(value);