Skip to content

Instantly share code, notes, and snippets.

View InfoSec812's full-sized avatar

Deven Phillips InfoSec812

View GitHub Profile
@InfoSec812
InfoSec812 / ParallelStreamWordCount.java
Created August 7, 2016 13:25
Use Java 8 parallel streams to read a file and tally word counts
package us.juggl.twentysixteen.august;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@InfoSec812
InfoSec812 / LDAPUtil.java
Created August 21, 2016 03:10
An OpenLDAP compatible implementation of Secure SHA password hashing
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
class LDAPUtil {
/**
* Hash the provided password using SHA-1 and return base64 encoded password hash
*
@InfoSec812
InfoSec812 / json_patch.sql
Created September 27, 2016 04:43
PostgreSQL json_patch(TEXT, TEXT) function using PLPYTHON
DROP FUNCTION json_patch(_data TEXT, _patch TEXT)
/*
* On the PostgreSQL host, you will need to install:
* postgresql95-plpython (RedHat/CentOS)
* postgresql-plpython-9.5 (Ubuntu/Debian)
* You will also need to install the jsonpatch library using either easy_install or pip
* pip install jsonpatch
* easy_install jsonpatch
*/
@InfoSec812
InfoSec812 / jsonb_patch.sql
Last active July 2, 2024 21:52
Pure PostgreSQL implementation of JSONPatch
!!
!! Implementation of JSONPatch (http://jsonpatch.com/) using PostgreSQL >= 9.5
!!
CREATE OR REPLACE FUNCTION jsonb_copy(JSONB, TEXT[], TEXT[]) RETURNS JSONB AS $$
DECLARE
retval ALIAS FOR $1;
src_path ALIAS FOR $2;
dst_path ALIAS FOR $3;
tmp_value JSONB;
@InfoSec812
InfoSec812 / Status.groovy
Created January 11, 2017 03:04
JaCoCo Groovy Madness
/**
* A {@link GroovyVerticle} which handles status requests
*/
class Status extends GroovyVerticle {
// JaCoCo Coverage report shows 3 of 6 branches missed on this logging definition!!!!
static final LOG = LoggerFactory.getLogger(Status.class.canonicalName)
static final CACHE_INTERVAL = 30 * 60
@InfoSec812
InfoSec812 / ambassador_service-proxy.js
Created July 31, 2017 15:41
Example Vert.x EventBus Service Proxy Issues
AmbassadorsService.createProxy = function(vertx, ebAddress) {
var __args = arguments;
// The `__args[0]._jdel` object is `undefined`...
if (__args.length === 2 && typeof __args[0] === 'object' && __args[0]._jdel && typeof __args[1] === 'string') {
if (closed) {
throw new Error('Proxy is closed');
}
j_eb.send(j_address, {"vertx":__args[0], "ebAddress":__args[1]}, {"action":"createProxy"});
return;
@InfoSec812
InfoSec812 / CallbackHell.java
Created August 22, 2017 14:07
Example of callback hell in Vert.x
public class SomeVerticle extends AbstractVerticle {
public void start() {
vertx.eventBus().send(SOME_ADDRESS, myMessage, response -> {
vertx.eventBus().send(ANOTHER_ADDRESS, anotherMessage, res2 -> {
// Ad infinitum....
});
});
}
}
@InfoSec812
InfoSec812 / CallbackVerticle.java
Last active August 22, 2017 14:26
Example Vert.x Class With Callbacks
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR;
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
@InfoSec812
InfoSec812 / MethodReferenceVerticle.java
Created August 22, 2017 14:42
Example of Vert.x Verticle using method references.
package org.rantue.server;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
@InfoSec812
InfoSec812 / AsyncExampleSpec.groovy
Last active September 22, 2017 16:27
Demonstration Of Spock AsyncConditions With Vert.x
import io.vertx.core.Vertx
import io.vertx.core.http.RequestOptions
import spock.lang.Specification
import spock.util.concurrent.AsyncConditions
class AsyncExampleSpec extends Specification {
def "Async request for google.com should return proper page content"() {
given: "An async HTTP client"
def client = Vertx.vertx().createHttpClient()
and: "Some HTTP request options"