Skip to content

Instantly share code, notes, and snippets.

@basinilya
basinilya / etc-profile.d-ssh-agent.sh
Created June 5, 2015 19:13
Alternative to killing ssh-agent in ~/.bash_logout
# prevent leaked/orphaned ssh-agent processes
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "`ssh-agent`" >/dev/null
ssh-add 2>/dev/null
# create pipe handle to share across all processes
coproc (
read s # to avoid race condition do not die until we disown/do stuff with $COPROC
# detach from tty
setsid sh -c "
@basinilya
basinilya / ksh.txt
Last active August 20, 2016 14:40
Building ksh from RedHat on other Linux (with -fsanitize=address)
==================================================================
Building ksh from RedHat on other Linux (with -fsanitize=address)
==================================================================
# First login to a RHEL 6.8 host
# download ksh source package
cd ~/rpmbuild/SRPMS/
yumdownloader --source ksh
@basinilya
basinilya / fillrand.inc.h
Last active February 22, 2017 18:43
Fill buffer with random data using rand()
/*
Fill buffer with random data using rand()
void fillrand(unsigned char *buf, size_t sz);
void wfillrand(unsigned short *buf, size_t nelems);
Fastest functions according to test results:
i686:
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
/* opaque glib structures */
typedef struct _GTreeNode GTreeNode;
@basinilya
basinilya / DelayingFilter.java
Last active September 14, 2017 07:32
Delay writing to log file in log4j 1x
/*
* How to delay log4j messages targeted for a FileAppender until certain condition is met?
*
* My java program is a command line tool that is supposed to run single-instanced. For that a
* pidfile support was added to it. However, there's some 3rd-party initialization code that runs
* before the pidfile check and writes to log4j.
*
* I'm not happy that my logfile contains messages from a process that exited due to the locked
* pidfile, however, I want the ConsoleAppender to keep working as today.
*
package org.foo.unfairqueue;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
/** see ForwardingBlockingQueue from guava */
public class ForwardingBlockingQueue<E> implements BlockingQueue<E> {
@basinilya
basinilya / ConcurrentAuthenticator.java
Last active September 17, 2017 10:05
ConcurrentAuthenticator
package org.foo.concurrentauthenticator;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
@basinilya
basinilya / PidFileLock.java
Last active September 27, 2017 13:39
PidFileLock
package org.foo.pidfilelock;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.lang.management.ManagementFactory;
import java.nio.CharBuffer;
import java.nio.channels.Channels;
package org.foo.inject;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
@basinilya
basinilya / README.txt
Last active January 30, 2018 08:45
wagon-ssh
wagon-ssh requires patching settings.xml