Skip to content

Instantly share code, notes, and snippets.

View jyeary's full-sized avatar
🐝
in the hive mind

John Yeary jyeary

🐝
in the hive mind
View GitHub Profile
@jyeary
jyeary / jstatd-jdk8.policy
Last active October 12, 2021 13:52
jstatd and policy files for Mac and Unix Java 8 and Java 11+
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
@jyeary
jyeary / persistence.xml
Last active August 27, 2021 14:16
Jakarta EE 8, JPA 3.0, Hibernate 5, and SQLite persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="sqlitePU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
@jyeary
jyeary / Timezone.js
Created May 25, 2021 12:55
A Javascript method to determine the timezone of the browser.
function getTimezoneName() {
const today = new Date();
const short = today.toLocaleDateString(undefined);
const full = today.toLocaleDateString(undefined, { timeZoneName: 'short' }); // Trying to remove date from the string in a locale-agnostic way
const shortIndex = full.indexOf(short);
if (shortIndex >= 0) {
const trimmed = full.substring(0, shortIndex) + full.substring(shortIndex + short.length); // by this time `trimmed` should be the timezone's name with some punctuation -
// trim it from both sides
return trimmed.replace(/^[\s,.\-:;]+|[\s,.\-:;]+$/g, ''); }
else {
@jyeary
jyeary / SessionFilter.java
Last active August 25, 2017 19:18
This filter starts an {@link HttpSession} at the start of the request to avoid JSF late session binding. Based on BalusC suggestions https://stackoverflow.com/questions/8072311/adding-hform-causes-java-lang-illegalstateexception-cannot-create-a-session.
package com.bluelotussoftware.servlets.filter;
import java.io.IOException;
import java.text.MessageFormat;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@jyeary
jyeary / com.apple.serviceproxy.sh
Created August 9, 2017 20:11
Commands to Disable com.apple.serviceproxy to allow Docker to run on ports 80 and 443.
# Unload the Service Service
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist
# Load the Service Service
sudo launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist
# Check the status of the Server Service
sudo launchctl list com.apple.serviceproxy
package com.bluelotussoftware.jsf.phaselisteners;
import java.util.logging.Logger;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
/**
*
* @author John Yeary <jyeary@bluelotussoftware.com>
/*
* Copyright 2013-2017 John Yeary <jyeary@bluelotussoftware.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
Copyright (c) <YEAR>, <OWNER>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.
package com.bluelotussoftware.io;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
/**
*
@PersistenceUnit(unitName="SamplePersistenceWebPU")
EntityManagerFactory emf;
public Customer[] getCustomers() {
EntityManager em = emf.createEntityManager();
Query q = em.createQuery("SELECT c FROM Customer c");
List list = q.getResultList();
return list.toArray(new Customer[list.size()]);
}