Skip to content

Instantly share code, notes, and snippets.

View trasa's full-sized avatar

Tony Rasa trasa

  • Seattle, Washington
View GitHub Profile
import java.util.*;
public class Initials {
private String foo = null;
private int i = 0;
private Map<String, Integer> map = null;
}
// fragment
case "say":
// can we get this to work using the existing type from the map?
responsePrototypePtr := responseRegistry["say"]
log.Printf("responsePrototypePtr %s is at addr %p", reflect.TypeOf(responsePrototypePtr), responsePrototypePtr)
// allocate a new response based off of prototype
// this allocates a **Response
responseObjPtr := reflect.New(reflect.TypeOf(&responsePrototypePtr)).Interface()
log.Printf("responseObjPtr type %s, string %s", reflect.TypeOf(responseObjPtr), responseObjPtr)
@trasa
trasa / Lock.java
Created April 30, 2018 21:18
Simple Redis Lock
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import java.util.Random;
public class VolatileDoubleCheck {
private final Object resourceLock = new Object();
private volatile Resource resource; // the thing we want to make sure we only have 1 of, marked as volatile
public Resource getResource() {
if (resource == null) {
synchronized(resourceLock) {
if (resource == null) {
resource = new Resource();
}
@trasa
trasa / index.js
Created October 26, 2018 22:15
sqs demo using node
#!/usr/bin/env node
const
program = require('commander'),
aws = require('aws-sdk');
aws.config.update({region: 'us-east-1'});
const sqs = new aws.SQS()
program.version(module.exports.version);
@trasa
trasa / TWR.java
Created November 1, 2018 20:58
Java Try-With-Resources Example
@Slf4j
public class TWR implements Closeable() {
public void kaboom() throws IOException {
log.info("kaboom");
throw new IOException("io exception here");
}
@Override
public void close() {
log.warn("CLOSED!!");
@trasa
trasa / Application.java
Created January 31, 2019 22:03
JDBI 3 SpringBoot 4 Example
@Slf4j
@EnableSwagger2
@SpringBootApplication
@EnableScheduling
@SuppressWarnings("unused")
public class Application extends SpringBootServletInitializer {
/**
* Create our JDBI singleton. Configure plugins. Set options, pooling, etc.
*
@trasa
trasa / winstondemo.js
Created February 23, 2019 19:39
Example of trying to use winston and winston-es, demonstrating problems in a console app which terminates. see https://github.com/vanthome/winston-elasticsearch/issues/17
const winston = require('winston'); // 3.1.0
const winston_es = require('winston-elasticsearch'); // 0.7.7
const util = require('./lib/util.js');
var logger;
var transport;
// see https://github.com/vanthome/winston-elasticsearch/issues/17#issuecomment-463717315
winston_es.prototype.close = async function () {
console.log("closing winston_es");
@trasa
trasa / simple-elasticsearch-transport.js
Created February 23, 2019 19:47
A Winston Transport for Elasticsearch that doesn't have any queueing of messages to ES.
const winston = require('winston'),
_ = require('lodash'),
moment = require('moment'),
Transport = require('winston-transport'),
elasticsearch = require('elasticsearch');
module.exports = class SimpleElasticsearch extends Transport {
constructor(opts) {
super(opts);
this.name = 'simple_elasticsearch';
@trasa
trasa / DevUrandomSeedGenerator.java
Last active May 13, 2019 18:45
Generate UUIDs using urandom (nonblocking random number entropy)
// ============================================================================
// Copyright 2006-2010 Daniel W. Dyer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software