Skip to content

Instantly share code, notes, and snippets.

View linusfoldemo's full-sized avatar

Linus Foldemo linusfoldemo

View GitHub Profile
@linusfoldemo
linusfoldemo / pack.js
Last active December 1, 2016 11:41 — forked from phillipj/pack.js
A node.js script to create a bundle containing an npm package, and all of its dependencies.
/*
* This script will download a package (and all of its dependencies) from the
* online NPM registry, then create a gzip'd tarball containing that package
* and all of its dependencies. This archive can then be copied to a machine
* without internet access and installed using npm.
*
* The idea is pretty simple:
* - npm install [package]
* - rewrite [package]/package.json to copy dependencies to bundleDependencies
* - npm pack [package]
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
class EmbeddedMQBroker {
public static final String ACTIVEMQ_URL = "vm://localhost";
private static Logger logger = LoggerFactory.getLogger(EmbeddedMQBroker.class);
Connection connection;
BrokerService broker;
private EmbeddedMQBroker(final String url) {
//Keep alive mq connection to stop ActiveMq from shutting down automatically.
#!/bin/bash
URL_TO_VERIFY=$1
EXPECTED_HTTP_CODE="200"
echo "Verifying '${URL_TO_VERIFY}' on $(hostname)"
RESULT=$(wget -O/dev/null --retry-connrefused -S "${URL_TO_VERIFY}" 2>&1 | grep "HTTP/" | cut -d' ' -f4)
if [ "$?" -ne "0" ]; then
echo "Unable to connect to '${URL_TO_VERIFY}"
export PS1="\u@\h:\W\[$(tput sgr0)\]$ "
@linusfoldemo
linusfoldemo / Sample.groovy
Last active December 9, 2015 06:35
Pooled SAXParser
withPooledSAXParser { SAXParser saxParser ->
def slurped = new XmlSlurper(saxParser).parseText(documentString);
}
public static int availablePort() {
int port = 0;
try (ServerSocket serverSocket = new ServerSocket(port)) {
port = serverSocket.getLocalPort();
} catch (IOException e) {
throw new IllegalStateException("Unable to get available port");
}
return port;
}
static int availablePort() {
final ServerSocket serverSocket = new ServerSocket(0)
serverSocket.withCloseable {
return serverSocket.getLocalPort();
}
}
@linusfoldemo
linusfoldemo / find-logs.sh
Created October 8, 2015 07:50
Simple script to locate logs in a directory structure
#!/bin/bash
die() {
echo $1
echo "Usage: $0 application environment date"
echo "environment is TEST/BETA/DEMO/PROD"
echo "date pattern is yyyy-MM-dd"
exit 1
}
@linusfoldemo
linusfoldemo / logbackAsserts.groovy
Last active October 6, 2015 11:59
Assert log events in logback
private final static Set<ILoggingEvent> loggingEvents = [] as Set
private void reset() {
loggingEvents.clear()
initializeMockLogAppender();
}
public void assertOneErrorLogEvent(String expectedMessage) {
assert loggingEvents.size() == 1
assert loggingEvents.first().getThrowableProxy().message == expectedMessage