Skip to content

Instantly share code, notes, and snippets.

View sebastienblanc's full-sized avatar

Sebastien Blanc sebastienblanc

View GitHub Profile
@sebastienblanc
sebastienblanc / twitterSearchDSL.groovy
Created June 2, 2011 19:21
Basic Twitter search DSL
import groovyx.net.http.*
@Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.1' )
def http = new HTTPBuilder( 'http://search.twitter.com/' )
def tweets = 'tweets'
def search = {String s -> [about: {String s2 ->
http.get( path: 'search.json',
query: [q:s2] ) { resp, json ->
json.results.each {

removeUser works well in this case (Method called during startup) :

public class BoostrapUsers {


    @PersistenceContext(type = PersistenceContextType.EXTENDED)
    private EntityManager entityManager;

    @Inject
    private IdentityManager identityManager;
@Test
public void testCreate() throws Exception {
AeroGearUser user = buildUser("john") ;
identityManagement.create(user);
User user1 = new SimpleUser("john");
when(identityManager.getUser(("john"))).thenReturn(user1);
user1 = identityManager.getUser("john");
assertNotNull(user1);
}
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
@Override
public AeroGearUser get(String id) {
User user = identityManager.getUser(id);
if(user != null){
return Converter.convertToAerogearUser(identityManager.getUser(id));
}
return null;
}
public interface PagedResult<T> {
List<T> next();
List<T> prev();
List<T> page(int offset, int limit);
}
public interface PagedResult<T> {
PagedResult<T> next();
PagedResult<T> prev();
PagedResult<T> withOffset(int offset);
PagedResult<T> withLimit(int limit);

Pipe uses default offset and limit so no need to define those, just tell it that it's paged via headers.

var pagedPipe = AeroGear.Pipeline({
    name: "cars",
    settings: {
        paged: "headers"
    }
}).pipes.cars;

Below is a comparison of the method usage proposed by each lib for handling paged resources.

Read Next Page

Android

ReadFilter filter = new ReadFilter();
filter.setLimit(5);
@sebastienblanc
sebastienblanc / Fs.java
Last active December 11, 2015 07:09
basic open / write / close
/**
* script run by nodeJ :
* var fs = require('fs');
* fs.writeFile("/tmp/test", "Hey there!", function(err) {
* if(err) {
* console.log(err);
* } else {
* console.log("The file was saved!");
* }
* });