Skip to content

Instantly share code, notes, and snippets.

@jconwell
jconwell / asn1_null_fields.py
Last active December 15, 2022 00:48
Python example that shows two different ways to write arbitrary sized byte arrays into ASN.1 Null fields. This could be used when manually generating x509 certificates that contain some kind of data payload
import asn1
"""
This example shows two different ways to write arbitrary sized byte arrays into
ASN.1 Null fields. This could be used when manually generating x509 certificates that
contain some kind of data payload
"""
input_msg = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nec sem eros. Fusce mattis nunc eget eros viverra,
ac ultrices elit pellentesque. Proin quis neque vel ante vehicula egestas. Duis vestibulum nibh augue, non dapibus
@jconwell
jconwell / unique_email_addresses.gs
Created May 26, 2016 16:56
Google script to mine a unique list of email addresses from gmail
function getEmails() {
// get all messages
var allAddresses = [];
var start = 0;
var emailCount = 500;
var doIt = true;
while (doIt) {
var emails = GmailApp.getMessagesForThreads(GmailApp.search('after:2012/9/1', start, emailCount))
start += emails.length;
doIt = emailCount == emails.length;
@jconwell
jconwell / README
Created July 14, 2015 23:25
Remotly Debug ElasticSearch in IntelliJ
Pretty simple once you know how.
Step 1: In IntelliJ, create a new remote debug configuration. Name it something ElasticSearchy. All of the default values should be fine. The only thing you need to change is the Host value. If ElasticSearch is gonna be running locally, just use "localhost", otherwise use the IP address of the remote machine ElasticSearch is gonna run on
Step 2: When starting ElasticSearch, just add a -D argument with the standard java remote debug values like so:
bin/elasticsearch -D "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
ElasticSearch will start and if suspend is set to 'y', it'll pause execution until you have attached the IntelliJ debugger.
Step 3: In IntilliJ, run the remote debug configuration you created in step 1.
@jconwell
jconwell / ParrotActor.java
Created December 28, 2013 00:54
Testing utility actor to mimic the messaging behavior of an actor a test might interact with, but without actually creating an instance of the actor
package com.turbo.akka;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import java.util.HashMap;
import java.util.Map;
/**
@jconwell
jconwell / ChildCreationActor.java
Created December 27, 2013 23:51
Another utility actor used in unit testing. Use this when you need to refer to the actor being tested by its path, but don't want to create all the actor parent actors.
package com.turbo.akka;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
/**
* Utility actor that does nothing but take a Props and create
@jconwell
jconwell / ForwarderActor.java
Last active January 1, 2016 13:49
Akka actor that takes another ActorRef as a constructor argument, and forwards all incoming messages to the one passed in. This is useful for unit tests, where you can pass in a JavaTestKit instance to the constructor and all messages passed to this actor will be forwarded to the JavaTestKit instance.
package com.turbo.akka;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
/**
* Simple actor that takes another actor and forwards all messages to it.
* Useful in unit testing for capturing and testing if a message was received.
* Simply pass in an Akka JavaTestKit probe into the constructor, and all messages
* that are sent to this actor are forwarded to the JavaTestKit probe
@jconwell
jconwell / akkaTestPatterns.md
Last active September 22, 2016 17:13
Unit and functional test patterns for Akka actors in Java

AKKA Test Patterns for Java

NOTE: These patterns assume you have a working understanding of Akka's JavaTestKit

Testing Actors In Complete Isolation

AKKA is all about building hierarchies of actors to represent a system. I've found this is a great way to decompose, design, and if needed distribute a system. This means your system becomes a hierarchy of actors, where parent actors create and manage their child actors, and child actors either carry out some unit of work, and/or themselves become parent actors.

But this can be a bit of a pain when it comes to writing tests for your actors. For example, say we have an actor, actorA, who in turn creates one or more child actors. I could have actorA create its child actor(s) as part of its instantiation. This is attractive especially if I know the exact child actors its going to create.