Skip to content

Instantly share code, notes, and snippets.

@robshep
robshep / PGPCrypto.java
Created June 6, 2017 17:36
PostgreSQL/Java - interoperable PGP encryption
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.openpgp.examples.ByteArrayHandler;
/**
* Crypto utilities using both pure-Java (from bouncycastle's OpenPGP implementation) and
{
"type":"message",
"attachments":[
{
"contentType":"application/vnd.microsoft.card.adaptive",
"contentUrl":null,
"content":{
"type": "AdaptiveCard",
"body": [
@robshep
robshep / JsonWriterPebbleExtension.java
Last active September 4, 2022 03:18
Output arbitrary JSON into a pebble template.
@Component
public static class JsonWriterPebbleExtension extends AbstractExtension
{
@Autowired ObjectMapper objectMapper;
@Override
public Map<String, Function> getFunctions() {
HashMap<String, Function> functions = new HashMap<String,Function>();
functions.put("json", new JsonWriterPebbleFunction(objectMapper));
return functions;
@robshep
robshep / test_celery_mongo.py
Last active July 7, 2022 14:05
Quick test of Celery with MongoDB broker using mongo in docker
"""
Self-contained test for a simple Celery task interaction using an ephemeral MongoDB broker.
* MongoDB is created using docker with a temporary directory for storage.
* Celery broker is designated with the above containers random host-port.
* Celery worker is created using python Multi-process and managed.
* Triggers a distributed task
* Stops celery workers
* Stops mongodb container
* Removes temp directory.
@robshep
robshep / index.html
Created June 21, 2022 21:49
Load data from API and display on web page
<!DOCTYPE html>
<html style="padding: 0; margin: 0;">
<head>
<meta charset="UTF-8" />
<style>
body, html {
margin:0;
padding:0;
}
{
"swagger": "2.0",
"basePath": "",
"info": {
"title": "ChirpStack Application Server REST API",
"version": "1.0.0",
"description": "\nFor more information about the usage of the ChirpStack Application Server (REST) API, see\n[https://www.chirpstack.io/application-server/api/](https://www.chirpstack.io/application-server/api/).\n"
},
"schemes": null,
"consumes": [
@robshep
robshep / FullAddressLookup-lombok.java
Created February 22, 2016 11:24
ClickToAddress POJO Objects for Jackson/JSON (Both lombok annotated and de-Lombok-ed)
/**
* Uses Lombok to reduce boilerplate
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
@robshep
robshep / README.md
Last active July 16, 2021 15:25
Changing Frame's Height By Child-to-parent browser messaging

Using Child-to-parent browser messaging to signal a frame's height based on rendered content

message listener which listens for messages from child objects to (this) parent.

handles string-encoded JSON messages with {widgetId: id, height: x} and handles changing child object height from its declared height -

@robshep
robshep / script.js
Created November 3, 2020 10:12
fiddle with CSS dynamically on static sites using URL params
(function(){
/*! js-ready - v0.0.1
* https://github.com/zombiept2/js-ready
* Copyright (c) 2014; Licensed MIT */
var ready=(function(){var f,b,c={};c["[object Boolean]"]="boolean";c["[object Number]"]="number";c["[object String]"]="string";c["[object Function]"]="function";c["[object Array]"]="array";c["[object Date]"]="date";c["[object RegExp]"]="regexp";c["[object Object]"]="object";var d={isReady:false,readyWait:1,holdReady:function(g){if(g){d.readyWait++}else{d.ready(true)}},ready:function(g){if((g===true&&!--d.readyWait)||(g!==true&&!d.isReady)){if(!document.body){return setTimeout(d.ready,1)}d.isReady=true;if(g!==true&&--d.readyWait>0){return}f.resolveWith(document,[d])}},bindReady:function(){if(f){return}f=d._Deferred();if(document.readyState==="complete"){return setTimeout(d.ready,1)}if(document.addEventListener){document.addEventListener("DOMContentLoaded",b,false);window.addEventListener("load",d.ready,false)}else{if(document.attachEvent){document.attachEvent("onreadystatechange",b);window.
@robshep
robshep / hostwatch
Last active June 9, 2020 13:48
Dump disk and mem to syslog
*/10 * * * * admin (echo "========= Disk ==========="; df -h; echo "========== Mem ==========="; free -h) | logger -t SYS