Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / BigDecimalCodec.java
Created November 15, 2017 15:37
How to get BigDecimal to behave in MongoDb
public class BigDecimalCodec implements Codec<BigDecimal> {
// Note that you may not want it to be double -- choose your own type.
@Override
public void encode(final BsonWriter writer, final BigDecimal value, final EncoderContext encoderContext) {
writer.writeDouble(value);
}
@Override
public BigDecimal decode(final BsonReader reader, final DecoderContext decoderContext) {
return reader.readDouble();
@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 / MySqlServerDialect.groovy
Created September 18, 2015 18:53
Taming SQLServer
import java.sql.Types
public class MySqlServerDialect extends org.hibernate.dialect.SQLServerDialect {
public MySqlServerDialect() {
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");
registerColumnType(Types.CHAR, "nchar(1)");
registerColumnType(Types.VARCHAR, 4000, "nvarchar(\$l)");
@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 / slow_copy.py
Created July 24, 2015 16:14
slow copy for lima
#!/opt/local/bin/python
import time
import shutil
import os
dest = "/path/to/lima"
completed = [x for x in os.listdir(dest) if os.path.isdir(x)]
music = [x for x in os.listdir(".") if os.path.isdir(x)]
@squarepegsys
squarepegsys / profile.ps1
Last active October 18, 2021 16:44
Powershell setup
# install Github Desktop to get their config
# then you can do this
# https://desktop.github.com/
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
# then install psget and install modules
# before putting these lines in here
# see https://github.com/psget/psget
Import-Module PowerLs