Skip to content

Instantly share code, notes, and snippets.

View JensRantil's full-sized avatar

Jens Rantil JensRantil

View GitHub Profile
@JensRantil
JensRantil / gzip_strace.txt
Created January 9, 2017 14:03
What `gzip` does.
$ gzip hej
...
open("hej", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=27, ...}) = 0
rt_sigprocmask(SIG_BLOCK, [HUP INT PIPE TERM XCPU XFSZ], [], 8) = 0
open("hej.gz", O_WRONLY|O_CREAT|O_EXCL, 0600) = 4
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(3, "dsfkjfh'\nsdf\nsdf\nf\ndsf\nsdf\n", 65536) = 27
read(3, "", 65509) = 0
write(4, "\37\213\10\10f\215sX\0\3hej\0K)N\313\316J\313P\347*NI\3\3434\256\224b"..., 43) = 43
@JensRantil
JensRantil / elasticsearch-shutdown.conf
Created January 4, 2017 13:33
Elasticsearch upstart sample for safe shutdown (for unattended security updates etc.)
description "Elastic Search"
pre-stop script
triesleft=3600
while true
do
curl -s localhost:9200/_cluster/health?pretty | grep status | grep green > /dev/null
exitcode=$?
#echo $exitcode
if [ $exitcode -ne 0 ]
APT "";
APT::Architecture "amd64";
APT::Build-Essential "";
APT::Build-Essential:: "build-essential";
APT::Install-Recommends "1";
APT::Install-Suggests "0";
APT::NeverAutoRemove "";
APT::NeverAutoRemove:: "^firmware-linux.*";
APT::NeverAutoRemove:: "^linux-firmware$";
APT::NeverAutoRemove:: "^kfreebsd-image.*";
@JensRantil
JensRantil / create-destroy-session.sh
Last active June 30, 2016 13:26
Consul semaphore implementation in shell script. Unfinished.
#!/bin/sh
USAGE="Usage: $0 SERVICENAME CMD [CMDARGS1 ... CMDARGN]"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
SERVICENAME=$1
@JensRantil
JensRantil / tell-me-when-elasticsearch-is-done.go
Created June 2, 2016 11:43
Script that runs in the background and tells you when ElasticSearch migration/cluster has stabilised. Requires the "say" command that exists on MaxOSX.
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"time"
@JensRantil
JensRantil / UserLister.java
Last active May 22, 2016 20:04
Create an observable that fetches smaller batches of users based on prefix
class UserLister {
...
public Observable<User> streamAll(int batchSize) {
final int prefixLength = estimatePrefixLength(batchSize);
Preconditions.checkState(prefixLength > 0);
log.debug("Estimated prefix length: " + prefixLength);
return Observable.from(RepositoryUtils.hexPrefixes(prefixLength)).flatMapIterable(new Function1<String, List<User>>() {
public List<User> call(String prefix) {
repository.listByIdPrefix(useridPrefix);
@JensRantil
JensRantil / ExecutorOperator.java
Created May 21, 2016 13:45
Example of an `OperatorObserveOn` alternative. Not sure it works, though.
package my.application;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import rx.Observable.Operator;
import rx.Subscriber;
import my.application.ExecutorServiceUtils;
import my.application.User;
public class ExecutorOperator implements Operator<User, User> {
@JensRantil
JensRantil / snapci_build_output.txt
Created April 29, 2016 06:45
Snap CI build output
$ git clone git@localhost:JensRantil/jensrantil.github.io .
/opt/local/gnocci/vendor/cache/mixlib-shellout-e30a3b6a9e49/lib/mixlib/shellout/unix.rb:277: warning: Insecure world writable dir /opt/local/rbenv/shims in PATH, mode 040777
Cloning into '.'...
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
Command git clone git@localhost:JensRantil/jensrantil.github.io . exited successfully with status 0. Took 0.87956 seconds.$ git checkout develop
/opt/local/gnocci/vendor/cache/mixlib-shellout-e30a3b6a9e49/lib/mixlib/shellout/unix.rb:277: warning: Insecure world writable dir /opt/local/rbenv/shims in PATH, mode 040777
Already on 'develop'
Your branch is up-to-date with 'origin/develop'.
Command git checkout develop exited successfully with status 0. Took 0.02847 seconds.$ git reset --hard 734e9670a4e0be86b38ebbe391bb54e8b52dbbbd
/opt/local/gnocci/vendor/cache/mixlib-shellout-e30a3b6a9e49/lib/mixlib/shellout/unix.rb:277: warning: Insecure world writable dir /opt/local/rbenv/shims in PATH, m
@JensRantil
JensRantil / MainContainer.java
Last active April 7, 2016 10:46
Pseudo code for layered architecture.
public class MainContainer {
public static void main(String[] args) {
// Frameworks and drivers
DatabaseDriver jdbcDatabaseDriver = new MysqlDatabaseDriver();
// Interface adapters
UserRepository userRepository = new UserMySQLRepository(jdbcDatabaseDriver);
// Use cases.
UserBusinessUseCases userBusinessCases = new UserBusinessCases(userRepository);
@JensRantil
JensRantil / install.sh
Last active March 7, 2019 02:31
Install jass - a utility to encrypt/decrypt stuff to/from SSH keys.
#!/bin/bash
# Install using:
# curl https://gist.github.com/JensRantil/ba21c50e7720bfc62050/raw/c34825afc94940388b1b1dca2abe4c813211ecd0/install.sh | bash -e
# ...but PLEASE have a look at the URL to make sure its sane first!
#
# An alternative is obviously to download the script and executing it.
# Fail early.
set -e