Skip to content

Instantly share code, notes, and snippets.

View a-thomas's full-sized avatar

Alexandre THOMAS a-thomas

View GitHub Profile
@a-thomas
a-thomas / InputStreamToString.java
Last active October 13, 2015 20:47
Formation Android 2)
public class InputStreamToString {
public static String convert(InputStream is) {
String line = "";
StringBuilder builder = new StringBuilder();
BufferedReader rd=new BufferedReader(new InputStreamReader(is));
try {
while ((line = rd.readLine()) != null) {
@a-thomas
a-thomas / DefaultHttpClient.java
Created December 8, 2012 00:39
Formation Android 1)
try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(request);
InputStream content = response.getEntity().getContent();
// ...
} catch (ClientProtocolException e) {
@a-thomas
a-thomas / gist:3952140
Created October 25, 2012 11:41
Maven Invoker API
InvocationRequest request = new DefaultInvocationRequest();
File pom = new File("MY_PROJECT/pom.xml");
request.setPomFile(pom);
File baseDir = new File("MY_PROJECT");
request.setBaseDirectory(baseDir);
ArrayList<String> goals = new ArrayList<String>();
goals.add("clean");
@a-thomas
a-thomas / gist:3103858
Last active October 7, 2015 04:17
git standup
[alias]
standup = log --all --since yesterday --oneline --author <your_firstname>
myproject
|_src
|_templates
|_main.ftl
|_pages
|_home.ftl
|_...
public class Application {
public static void main(String[] args) throws IOException {
final Configuration cfg = configureFreemarker();
get(new Route("/") {
@Override
public Object handle(Request request, Response response) {
//freemarker needs a Writer to render the final Html code
<h1>Welcome to my website!</h1>
<p>This is the home page!</p>
<html>
<head>
<title>${title}</title>
</head>
<body>
<#include page />
</body>
</html>
@a-thomas
a-thomas / gist:2668298
Created May 12, 2012 19:14
Spark web main
public class Application {
public static void main(String[] args) {
get(new Route(“/”) {
@Override
public Object handle(Request request, //
Response response) {
return “Welcome!”
}
});
}
@a-thomas
a-thomas / HttpDigestAuthInterceptor.java
Created April 13, 2012 09:00
HTTP Digest Interceptor for Spring RestTemplate
package com.blogtag.digest;
import java.io.IOException;
import java.util.Random;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;