Skip to content

Instantly share code, notes, and snippets.

@squarepegsys
squarepegsys / get_aws_log
Created May 17, 2019 15:09
search and show wrapper around awslogs
#!/bin/bash
# Quick and dirty script to find the log and show it via https://github.com/rpgreen/apilogs
# basically this automates the work I would do 90% of the time
if [ -z "$1" ]
then
echo "no stream supplied!"
exit 13
fi
group=`awslogs groups|grep $1`
@squarepegsys
squarepegsys / some_report.py
Last active February 24, 2019 01:02
Dynamic Header in ReportLab
from functools import partial
# lots of other imports, esp for reportlab
# this function is ran for each page.
def some_header(canvas,doc,content):
canvas.saveState()
P = Paragraph(content,style=some_style)
@squarepegsys
squarepegsys / onHashCodeAndEquals.markdown
Created December 1, 2011 01:25
Some thoughts on .hashCode and .equals in Java

Thoughts about .equals and .hashCode

Here is a little context: we were tracking down a memory leak in our application and saw this big HashMap in the dump file. The HashMap was from ehcache. The problem was that the objects that were used as the key did not implement .hashCode. Oops. We used Eclipse's generated .equals and .hashCode to get us by and that got us through the heat of the moment.

So, today, a couple of developers were on a PMD/FindBugs hunt and,

@squarepegsys
squarepegsys / pick_thread_user.py
Created January 25, 2019 17:42
Quick and dirty script to randomly choose a user from a forum thread at BGG
#!/usr/bin/env python
import xml.etree.ElementTree as ET
from urllib.request import urlopen
import random
import time
def seed():
t = int( time.time() * 1000.0 )
@squarepegsys
squarepegsys / resources.groovy
Created August 19, 2015 00:43
HikariCP in Grails
// Shameless stolen from http://stackoverflow.com/questions/25772324/defining-an-alternate-connection-pool-in-grails-2-3-6
def config = Holders.config
def dataSources = config.findAll {
it.key.toString().contains("dataSource_")
}
dataSources.each { key, value ->
def ds = value
@squarepegsys
squarepegsys / mvn2gradle.py
Created July 5, 2018 17:58
Convert maven deps to gradle format
#!/usr/bin/env python
import xml.etree.ElementTree as ET
ns = {'pom': "http://maven.apache.org/POM/4.0.0" , }
def find_exclusions(exclusions):
@squarepegsys
squarepegsys / build.gradle
Last active July 5, 2018 15:36
snapshots and gradle
// shamelessly stolen from https://discuss.gradle.org/t/preferred-way-to-publish-snapshots-releases-to-artifactory/20246/2
// all I need to do it set -PreleaseVersion in the build
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'java'
apply plugin: 'maven-publish'
//..
if (project.properties.containsKey("releaseVersion")) {
version = version.split(/-/)[0]
@squarepegsys
squarepegsys / monogo-mbean.groovy
Created February 28, 2018 15:44
A quick and dirty Groovy script to monitor Mongo connections for a short time
import javax.management.remote.*
import javax.management.*
import groovy.jmx.builder.*
// see https://mongodb.github.io/mongo-java-driver/3.0/driver/reference/management/monitoring/
attrs = ['CheckedOutCount','MinSize','MaxSize','WaitQueueSize','Size']
def print_mbeans(def mbeans) {
def webBean = mbeans.queryNames(new ObjectName('org.mongodb.driver:*'), null).find {
@squarepegsys
squarepegsys / EchoNumberService.groovy
Created October 21, 2015 01:57
Event-Driven Grails
package grails3.event.driven
import reactor.spring.context.annotation.*
@Consumer
class EchoNumberService {
@Selector('int.echo')
void echo(Integer i) {
println "##### number id ${i}"
@squarepegsys
squarepegsys / gvmup.sh
Created April 7, 2015 14:55
A handy little alias for Grails developers that support apps that could be one of many Grails versions
alias gvmup="gvm use grails `grep app.grails.version application.properties|gawk -F = '{print $2}'`"