Skip to content

Instantly share code, notes, and snippets.

View jotak's full-sized avatar

Joel Takvorian jotak

View GitHub Profile
@jotak
jotak / gist:277aef843126ef24bd01
Created April 30, 2014 14:10
That's collector
@SuppressWarnings("unchecked")
private static <T,U> Map<U, List<T>> formatMapClefEnsembleValeursAvecOuSansLimitateur(List<Map<String, Object>> liste,
String identifiant, String valeur, Integer limitation) {
final Map<U, List<T>> mapKeyValue = new HashMap<U, List<T>>();
final Map<U, Integer> mapLimitation = new HashMap<U, Integer>();
if (!isEmpty(liste)) {
final boolean ligneComplete = StrUtil.isEmpty(valeur);
for (final Map<String, ?> map : liste) {
final U key = (U) map.get(identifiant);
// The ultimate Eclipse guide. Should work after 10-15 iterations
while (!working) {
try {
servers.clean();
servers.deleteAll();
project.clean();
maven.clean();
eclipse.restart();
maven.install();
@jotak
jotak / gist:eac2aca66591b3b7cbb2
Last active August 29, 2015 14:06
Does Typescript make javascript safe? Not so sure about that...
// ...
app.get(libRoot + '/get/:start/:count', function(req, res) {
getSongsPage([/*some data*/], req.params.start, req.params.count);
// ...
});
// ...
function getSongsPage(allSongs: SongInfo[], start: number, count: number): SongInfo[] {
// File Controller.js
function search(str) {
var layers = getAllActiveLayers();
layers.forEach(function(layer) {
layer.search(str);
});
}
// Layer interface
interface Layer {
search: (str: string)=>void;
}
// File Controller.js
function search(str) {
var layers: Layer[] = getAllActiveLayers();
layers.forEach(function(layer) {
layer.search(str);
@jotak
jotak / voitures1.java
Last active August 29, 2015 14:16
Voitures bleues & mocking db
public class Persister {
public Collection<Voiture> query(String q) {
// get from DB
}
}
public class Voiture {
private final int couleur;
public Voiture(int couleur) {
@jotak
jotak / Cat.java
Created March 16, 2015 14:36
querydsl-collections with Optional
package cat;
import static com.mysema.query.alias.Alias.$;
import static com.mysema.query.alias.Alias.alias;
import static com.mysema.query.collections.CollQueryFactory.from;
import java.util.ArrayList;
import java.util.Collection;
import com.google.common.base.Optional;
var i = 0;
var async = function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(i++);
}, 500);
});
};
@jotak
jotak / example.java
Last active October 29, 2015 07:31
Uniqueness
// Check out Uniqueness API: https://github.com/jotak/jmisc/tree/master/jotak-misc/src/main/java/com/jotak/misc/collection
// Build a collection with removed duplicates on a custom criteria, regardless the "equals" and "hashCode" of the data object
// Here we build a "unique key" based on Something::getField1
final List<Something> allFields = Uniqueness.from(inputList)
.constraintOn(ImmutableList.of(Something::getField1))
.asList();
@jotak
jotak / Optionals.java
Created December 2, 2015 10:33
Optional improvements
import java.util.Optional;
import java.util.function.Consumer;
/**
* @author jtakvorian
*/
public final class Optionals {
private Optionals() {
}