Posts

Showing posts from July, 2016

Data Analytics Platforms

upstart script (tiny)

Simple upstart script


env PORT=5001

start on runlevel [2345]
stop on runlevel [016]
respawn

setuid john
chdir /home/john/Applications/my-nodejs-server/
exec node index.js


Can configure environment variables in a faux 12 factor style.NodeJS app will automatically start on boot, and stop on shutdown.Upstart will restart the app if it crashes.Runs as unpriveleged user 'john'.Upstart (1.4 and above) logs all output to /var/log/upstart/my-nodejs-server.log which will be rotated by logrotate.Can manage the lifecycle with sudo service my-nodejs-server {start,stop,restart}.Can temporarily disable the app from starting on boot with an override file: 
$ echo manual | sudo tee /etc/init/my-nodejs-server.override.

SocketListener

import java.io.IOException;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Socket listener for unit test to listen for messages.
 *
 * @author dev
 *
 */
public class SocketListener {
String host;
int port;

ServerSocket s;

ExecutorService executor = Executors.newSingleThreadExecutor();

public SocketListener(String host, int port) {
this.host = host;
this.port = port;
}

public SocketListener init() {
try {
s = new ServerSocket(port, 10, Inet4Address.getByName(host));
Worker worker = new Worker();
executor.submit(worker);
} catch (IOException e) {
throw new RuntimeException("Failed to listen", e);
}
return this;
}

public void close() {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// ignore
}
}
}

public class Worker implements Runnable {

@Override
public void run() {
Socket k = null;
try {
while (true) {
k = s.accept();
InputStream is = k.getIn…

Browsing ADFS

connecting to the AD domain controller via ldap using Apache Directory Studio.
No special access required.
Same as how your user authenticates on OS.

ldap://10.10.10.10:636 (bind as your domain account)
Search for user:
Base DN: DC=youDomain,DC=smtf,DC=ds
Windows account id: (sAMAccountName=tcollinsworth)
Name: (displayName=Troy*)


WebHook testing

Stacktrace of Java process

jstack

To quickly dump stack from command line for eclipse process

jps | grep RemoteTestRunner | cut -f 1 -d ' ' | xargs jstack

Stacktrace of Java process

jstack

To quickly dump stack from command line for eclipse process

jps | grep RemoteTestRunner | cut -f 1 -d ' ' | xargs jstack

Force IPv4

-Djava.net.preferIPv4Stack=true
-Djava.net.preferIPv6Addresses=false

Java 8 UTC datetime as string

public static String getUTCDatetimeAsString() {    return LocalDateTime.now(Clock.systemUTC()); }

Code monitoring and continuous inspection

General RPC

Top Web Sites Technology

Technology used in most popular websites

Most used:

Javascript 100%MySQL / MariaDB 53%Java 47%C++ 33%Python 27%