Skip to content

Instantly share code, notes, and snippets.

@bcoughlan
bcoughlan / validation.js
Created May 9, 2012 21:51
jQuery validation - IP address
//Validation
jQuery.validator.addMethod('validIP', function(value) {
var split = value.split('.');
if (split.length != 4)
return false;
for (var i=0; i<split.length; i++) {
var s = split[i];
if (s.length==0 || isNaN(s) || s<0 || s>255)
return false;
@bcoughlan
bcoughlan / humanize.js
Created June 15, 2012 06:08
Javascript - Format seconds to (hh:m)m:ss
function formatTime (t) {
if (typeof (t) !== "number" || t < 0) {
return "";
}
function it(param) {
var p = t % param;
if (p < 10) p = '0' + p;
t = Math.floor(t / param);
return p;
}
@bcoughlan
bcoughlan / countduplicates
Created July 2, 2012 02:09
OpenOffice calc - count duplicates
=COUNTA(A2:A23)-SUMPRODUCT((A2:A23<>"")/(COUNTIF(A2:A23,A2:A23)+(A2:A23="")))
@bcoughlan
bcoughlan / HTTPFileServer.py
Last active December 20, 2015 23:48
Python HTTP file server for writing tests that retrieve files
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
import httplib
import threading
from os.path import join, abspath
class RequestHandler(SimpleHTTPRequestHandler):
def do_QUIT (self):
self.send_response(200)
self.end_headers()
@bcoughlan
bcoughlan / lock.py
Created December 4, 2013 06:31
Python global lock using files
from contextlib import contextmanager
class LockError(Exception): pass
@contextmanager
def lock(lock_filename, force_lock=False):
forced = False
lockerror = False
try:
@bcoughlan
bcoughlan / ReplaceAlgorithms.java
Created April 14, 2015 23:44
Replacing a SecureRandom.getInstance() algorithm in Java for mocking
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.SecureRandomSpi;
import java.security.Security;
public class ReplaceAlgorithms {
public static void main(String[] args) throws NoSuchAlgorithmException {
byte[] bytes = new byte[16];
@bcoughlan
bcoughlan / README.md
Last active December 12, 2017 10:51
Tail multiple log files with filename

The output of tailing multiple files looks like this:

==> ./tomcat/catalina.2017-11-09.log <==
09-Nov-2017 17:53:31.496 WARNING [localhost-startStop-1] com.sun.faces.mgbean.BeanManager.addBean JSF1074
09-Nov-2017 17:53:31.496 WARNING [localhost-startStop-1] com.sun.faces.mgbean.BeanManager.addBean JSF1074
09-Nov-2017 17:53:31.496 WARNING [localhost-startStop-1] com.sun.faces.mgbean.BeanManager.addBean JSF1074
==> ./tomcat/catalina.2017-11-11.log <==
11-Nov-2017 17:53:31.496 WARNING [localhost-startStop-1] com.sun.faces.mgbean.BeanManager.addBean JSF1074
11-Nov-2017 17:53:31.496 WARNING [localhost-startStop-1] com.sun.faces.mgbean.BeanManager.addBean JSF1074
@bcoughlan
bcoughlan / forward.sh
Last active February 10, 2020 11:23
SSH forward a remote Docker daemon in a bash script
function ssh_forward_docker_daemon {
# Create a temporary file and delete. We just want the filename.
# Needed for the cleanup to identify which SSH process to kill
SSH_SOCKET=$(mktemp)
rm $SSH_SOCKET
# Clean up on exit
trap "exit" INT TERM
trap "ssh -S $SSH_SOCKET -O exit $1" EXIT
@bcoughlan
bcoughlan / README.md
Created February 21, 2020 00:01
kubeadm: Enable service topology in 1.17