Skip to content

Instantly share code, notes, and snippets.

View trasa's full-sized avatar

Tony Rasa trasa

  • Seattle, Washington
View GitHub Profile
@trasa
trasa / quickdirtyparsing.cpp
Created December 2, 2021 05:51
Quick and dirty string parsing in C++
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main()
{
// our data to be "serialized"
int turnNumber = 5;
@trasa
trasa / LICENSE
Last active October 25, 2019 19:39
This license applies to all public gists - https://gist.github.com/trasa
The MIT License (MIT)
Copyright (c) 2019 Tony Rasa
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@trasa
trasa / ThrowCounter.java
Created August 12, 2019 23:58
how bad are exceptions vs performance in a tight loop, really? especially with modern JVMs...
public class ThrowCounter {
public static void main(String[] args) {
if (args.length == 0 || args[0].equalsIgnoreCase("bool")) {
runBooleanTest();
} else {
runThrowTest();
}
}
@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
@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 / 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 / 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 / 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 / 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);
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();
}