Skip to content

Instantly share code, notes, and snippets.

@jomoespe
jomoespe / change-workspaces.sh
Last active August 21, 2017 10:30
Change workspaces in ubuntu via CLI
#!/bin/bash
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize 4
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize 1
@jomoespe
jomoespe / closechannel.go
Last active May 10, 2017 20:57
Closing a channel
package main
import (
"fmt"
"time"
)
const (
iterations = 5
sleepTime = 500 * time.Millisecond
@jomoespe
jomoespe / repetive-gorutine.go
Last active March 19, 2018 19:10
How to run a gorutine repetitive.
// Based on http://stackoverflow.com/questions/16466320/is-there-a-way-to-do-repetitive-tasks-at-intervals-in-golang
// Probably need to read more if some mutex if gotunite needs to access shared information.
package main
import (
"log"
"time"
)
const (
@jomoespe
jomoespe / HackInmutable.java
Last active February 10, 2017 20:18
Example of access and modify final static (inmutable) fields in Java
import java.lang.reflect.Field;
public final class HackInmutable {
static final class InmutableEmployee {
private final int id;
private final String name;
private final Float salary;
private InmutableEmployee(final int id, final String name, final Float salary) {
this.id = id;
@jomoespe
jomoespe / find table.sql
Last active June 2, 2016 12:47
Query to find a table in Oracle
SELECT owner, table_name
FROM dba_tables
WHERE table_name like '%'
ORDER BY table_name
@jomoespe
jomoespe / StreamUtil.java
Created May 25, 2016 09:42
Class with a utility method to divide a list in diferent chunks and returns a Stream of lists
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class StreamUtil {
public static <T> Stream<List<T>> buffer(final List<T> source, final int length) {
if (length <= 0) throw new IllegalArgumentException("length = " + length);
int size = source.size();
if (size <= 0) return Stream.empty();
int fullChunks = (size - 1) / length;
# Remove all containers
$ docker ps -q -a | xargs docker rm
or
$ docker rm `docker ps -aq`
# Delete all untagged images
$ docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
@jomoespe
jomoespe / LambdaExceptionUtil.java
Last active December 22, 2023 12:36
Utility class to handle checked exceptions from
/**
* Utility class to handle checked exceptions in lambdas.
* <p>
* From <a href="http://stackoverflow.com/questions/27644361/how-can-i-throw-checked-exceptions-from-inside-java-8-streams">How can I throw CHECKED exceptions from inside Java 8 streams?</a>.
* This class helps to handle checked exceptions with lambdas. Example, with Class.forName method, which throws checked exceptions:
* </p>
* <pre>
* Stream.of("java.lang.Object", "java.lang.Integer", "java.lang.String")
* .map(rethrowFunction(Class::forName))
* .collect(Collectors.toList());