Skip to content

Instantly share code, notes, and snippets.

View BDF's full-sized avatar

Brian Forester BDF

View GitHub Profile
@BDF
BDF / DiceRoller
Created May 29, 2023 20:29
Playing with Python Dice Roller
from random import randint
def main(debug=0):
if debug == 1:
results = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(0, 5000):
results[rolldice(2, 6)] += 1
for i in range(0, 26):
@BDF
BDF / CreateIAMUserWithClusterAccessStack.ts
Created March 13, 2023 14:00
Sample typescript code for creating an AWS user with cluster access.
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {Role, ServicePrincipal, PolicyStatement, User, PolicyDocument, Policy} from 'aws-cdk-lib/aws-iam';
/**
* Create an AWS IAM user with access (DescribeCluster, ListClusters, ListTagsForResource)
* to named cluster.
* Warning: minimal testing so far, 2023-03-13
*/
@BDF
BDF / dice.js
Last active October 26, 2022 19:20
Random Number Generator for 3d6 or any number of dice for a given sided dice.
// Random number from 1 to numberOfSides.
function dx(numberOfSides) {
return Math.floor(Math.random() * numberOfSides + 1);
}
let xDy = (n, f) => { let x = 0; while(n-- > 0) x += dx(f); return x};
// usage: numDiceSideDrop(4,6,1)
// examples:
// numDiceSideDrop(4,6,1) Roll four six sided dice and drop the lowest die:
@BDF
BDF / application.yaml
Last active July 25, 2022 20:01
Sample HAPI FIHR config
#Adds the option to go to eg. http://localhost:8080/actuator/health for seeing the running configuration
#see https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints
management:
endpoints:
web:
exposure:
include: "health,prometheus"
spring:
main:
allow-circular-references: true
@BDF
BDF / sparseCheckout.sh
Created October 11, 2021 19:36
git Sparse Checkout.
#!/usr/bin/env bash
# Copied from:
# https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
% git clone --no-checkout https://github.com/derrickstolee/sparse-checkout-example --depth 1
% cd sparse-checkout-example/
% git sparse-checkout init --cone
# git sparse-checkout init to skip top level files.
// A very simple using restlet ( org.restlet.resource.ClientResource ) to get a JSON resource.
ClientResource resource=new ClientResource(url);
Representation representation=resource.get(MediaType.APPLICATION_JSON);
ObjectMapper mapper=new ObjectMapper();
AnAnnotatedJsonObject npr = mapper.readValue(representation.getStream(), AnAnnotatedJsonObject.class);
package com.proquest.xslt;
import java.io.StringReader;
import java.util.Iterator;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
public XdmNode chainNodes(List<XdmNode> nodesToChain) throws SaxonApiException {
XdmNode node;
switch (nodesToChain.size()) {
case 1:
node = nodesToChain.get(0);
break;
case 2:
node = append(nodesToChain.get(0), nodesToChain.get(1));
break;
@BDF
BDF / gist:f3b2a1483a6c19c4f57d8142dd52e99e
Created May 16, 2016 16:03
H2 vs MYSQL differences.
To minimize the differences:
1. On the JDBC connection string: 'MODE=MySQL', full example jdbc:h2:mem:test_one;DB_CLOSE_DELAY=-1;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;IGNORECASE=TRUE;
2. Interactive SQL: SET MODE MySQL;
H2 does not like multiple 'ADD COLUMN' commands for one ALTER TABLE.
In mysql the following works
ALTER TABLE SOME_TABLE
ADD COLUMN USER VARCHAR(64) NOT NULL SET DEFAULT '',
ADD COLUMN DESCRIPTION VARCHAR(1024) NOT NULL SET DEFAULT '' AFTER USER,
@BDF
BDF / mavenNotes.md
Last active March 8, 2021 12:21
Using the maven shade plugin on a Spring Boot application
  • Maven shade with Spring Boot

The goal was to create an uber-jar out of the Spring boot application. Following the directions given at Apache went very smoothly yet when I tried to execute the jar a large number of spring beans were missing and not getting loaded during runtime. For example, one of the beans not getting loaded was 'AutoConfigurationPackages'

jar -tvf name.jar | grep AutoConfigurationPackages showed that the class file was present in tha jar.