Skip to content

Instantly share code, notes, and snippets.

@davide-romanini
davide-romanini / BaseRepository.java
Created April 15, 2011 07:43
BaseRepository that delegates to spring-data-jpa SimpleJpaRepository. Useful inside java ee 6 cdi container where you don't want to use spring ifrastructure.
public abstract class BaseRepository<T extends Object, ID extends Serializable>
implements JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
private @PersistenceContext EntityManager em;
private SimpleJpaRepository<T, ID> target;
protected EntityManager getEntityManager() {
return em;
}
@davide-romanini
davide-romanini / Repositories.java
Created April 15, 2011 08:15
CDI producer for spring-data-jpa based repositories
public interface PersonRepository extends JpaRepository<Person, Long>, JpaSpecificationExecutor<Person> {
List<Person> findByEmailAddressAndLastname(String emailAddress, String lastname);
// find all persons and apply eclipselink batch hint to fetch their addresses
@Query("select p from Person p")
@QueryHints({@QueryHint(name="eclipselink.batch", value="p.addresses")})
List<Person> findAllWithAddresses();
}
public class Repositories {
<?php
$row = array_pop($db->query("SELECT my_blob_col FROM my_blob_table"));
$blob = $ros['my_blob_col'];
assertEquals(TRUE, is_resource($blob));
while(!feof($blob)) {
echo fread($blob, 8192);
}
SELECT SUBSTR(my_blob_col, 1, 8192) FROM my_blob_table WHERE blob_id=?
SELECT blob_id, CHAR_LENGTH(my_blob_col) AS blob_len FROM my_blob_table
importPackage(Packages.java.text);
HolidayEndpoint = {
setService: function(hr) {
this.service = hr;
},
invoke: function(req) {
default xml namespace = "http://mycompany.com/hr/schemas";
var params = {
startDate: this.parseDate(req..StartDate),
endDate: this.parseDate(req..EndDate),
<beans>
<bean name="holidayEndpoint" class="org.springframework.scripting.rhino.JavaScriptPayloadEndpointFactory">
<constructor-arg value="classpath:holiday.js" />
<property name="service" ref="hrService" />
</bean>
<bean name="hrService" class="test.rhino.DefaultHumanResourceService" />
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="mappings">
<props>
<prop key="{http://mycompany.com/hr/schemas}HolidayRequest">holidayEndpoint</prop>
importPackage(Packages.java.net);
importPackage(Packages.org.w3c.tidy);
var Euribor = function() {
var tidy = new Tidy();
tidy.XHTML = true;
tidy.fixComments = true;
tidy.trimEmptyElements = true;
tidy.onlyErrors = true;
tidy.showWarnings = false;
tidy.quiet = true;
@davide-romanini
davide-romanini / nginx_unique_id
Created July 21, 2012 08:22
nginx unique id
perl_set $uid '
use Digest::MD5 qw(md5_hex);
sub {
return md5_hex(`od -vAn -N4 -tu4 < /dev/urandom`);
}';
#pass to fcgi
location ... {
fastcgi_param UNIQUE_ID $uid
@davide-romanini
davide-romanini / gist:4995884
Last active December 13, 2015 23:59
Throttle.java
package throttle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Throttle {
/**