Skip to content

Instantly share code, notes, and snippets.

View codingtony's full-sized avatar

Tony Bussières codingtony

View GitHub Profile
@codingtony
codingtony / buildHAProxy.sh
Last active December 11, 2024 17:48
Recipe to build HAProxy 1.7 using LibreSSL. Builds an almost static binary. See https://github.com/codingtony/docker-build-haproxy for how to use with a Docker Image
#!/bin/bash -e
DIR=$PWD/work
mkdir -p ${DIR}
rm -f ${DIR}/*.tar.gz
LIBRESSL=libressl-2.4.5
HAPROXY=haproxy-1.7.5
PCRE=pcre-8.39
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@Test
@codingtony
codingtony / prettyprint_xml_perl
Created May 2, 2014 12:16
Perl one liner to pretty print xml.
#Taken from http://lo-f.at/glahn/2008/01/PerlOneliners.html
perl -MXML::LibXML \
-e 'print XML::LibXML->new->parse_file($ARGV[0])->toString(1);' \
somefile.xml
#!/bin/bash
WAV="$1"
if [ -z "$WAV" ]; then
echo "Usage: $0 OUTPUT.WAV" >&2
exit 1
fi
rm -f "$WAV"
# Get sink monitor:
MONITOR=$(pactl list | egrep -A2 '^(\*\*\* )?Source #' | \
@codingtony
codingtony / disableScreenSaver.sh
Last active January 15, 2024 17:53
Temporary disable Screensaver (tested with KDE) by simulating fake user activity
#!/bin/bash
# credits goes to http://silviumc.wordpress.com/2011/12/05/how-to-stop-the-screen-saver-in-kde-while-watching-long-flash-clips-in-a-web-browser/
while /bin/true
do
qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null;
sleep 1m;
done
@codingtony
codingtony / BindExceptionFutureExample.java
Created September 24, 2013 21:10
Example to add a ChannelFutureListener to trap the BindException in Netty
//...
final int port=8888;
ServerBootstrap b = new ServerBootstrap();
//...
b.bind(port).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
if (future.cause() instanceof BindException) {
@codingtony
codingtony / ChunkedBuffer.java
Last active December 23, 2015 02:29
Trying to output 1GB of zero bytes in chunks. Seems to have a memory leak....
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.stream.ChunkedInput;
import io.netty.util.CharsetUtil;
public abstract class ChunkedBuffer implements ChunkedInput<ByteBuf> {
int offset = -1;
boolean closed = false;
protected byte[] buffer = null;
@codingtony
codingtony / ChunkOutputStream.java
Last active December 21, 2017 04:37
An handy, yet simple ChunkedOutputSteam for HTTP chunked response with Netty 4.0 Useful when you have an application that writes to an OutputStream and you don't want (or cannot) rewrite it. Released under APL 2.0 Any bugs? let me know!
/************************************************************************
Copyright 2013 Tony Bussieres
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
Unless required by applicable law or agreed to in writing, software
@codingtony
codingtony / addlookup.sh
Last active December 14, 2015 01:28
Little bash script to quickly add lookup and reverse lookup to dnsmasq.
#!/bin/bash -e
# USAGE :
# $0 IP NAME DOMAIN
if [ "$#" != "3" ]
then
echo "Usage:"
echo $0 IP HOSTNAME DOMAIN