Skip to content

Instantly share code, notes, and snippets.

View JohnZavyn's full-sized avatar

John A. Marsh JohnZavyn

View GitHub Profile
require 'my_sql_encryption'
text = 'Sensitive data'
encrypted = MySQLEncryption.mysql_encrypt(text, @password)
decrypted = MySQLEncryption.mysql_decrypt(encrypted, @password)
log.info("Encrypted: #{encrypted}")
log.info("Decrypted: #{decrypted}")
expect(decrypted).to eq(text)
@JohnZavyn
JohnZavyn / my_sql_encryption.rb
Created May 14, 2018 18:46
MySQL AES Encryption for Ruby
require 'openssl'
# This module provides AES encryption compatible with MySQL AES_ENCRYPT
# and AES_DECRYPT functions.
module MySQLEncryption
# Takes an unencrypted text string, encrypts it with the password,
# and encodes the results to a hexadecimal string
def self.mysql_encrypt(unencrypted_text, password)
encrypt(unencrypted_text, mysql_key(password))
@JohnZavyn
JohnZavyn / pom.xml
Last active May 1, 2018 18:47
Spring Boot Maven Plugin that Includes all dependency JARs in a WAR or JAR package
...
<packaging>war</packaging>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
@JohnZavyn
JohnZavyn / microservice.docker
Created May 1, 2018 18:36
Docker file to run an exploded Spring Boot WAR
FROM openjdk:8-alpine
ENV TZ America/New_York
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
RUN echo "${TZ}" > /etc/timezone
# Declare the working directory
WORKDIR /microservice
# Copy and explode the WAR to the working directory
/**
* <p>Workaround to allow OpenPojo version 0.8.6 to work with Java 9.</p>
* <p>TODO: Remove when OpenPojo is updated</p>
*/
@BeforeClass
public static void setSystemProperty()
{
System.setProperty("sun.boot.class.path", System.getProperty("java.class.path"));
}
@JohnZavyn
JohnZavyn / LargestModulus.java
Created August 7, 2017 13:34
Find all even divisors for a number
import java.io.*;
/** Find all the even divisors of a number. */
class LargestModulus
{
/**
* Find all the divisors for a number (a.k.a., a dividend). The number must be a positive integer. It may be provided on the command line, or entered interactively when prompted.
*
* @param args if a command line parameter is detected, the first argument is used.
package com.threeleaf.util;
import java.util.Comparator;
/**
* A {@link Comparator} that allows any two objects to be sorted based on {@link Object#toString()}.
* This works best when the object's toString returns something meaningful, but can still be
* useful in cases where a object one has not control over needs to be placed in a sorted
* collection.
* <p>
@JohnZavyn
JohnZavyn / applicationContext.xml
Created August 17, 2016 15:08
Fix for "HibernateJpaDialect - JDBC Connection to reset not identical to originally prepared Connection" warning
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="pu"/>
<property name="packagesToScan">
<list>
<value>com.appia.model.beans</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
@JohnZavyn
JohnZavyn / ApkService.java
Created August 5, 2016 17:53
Extract the icon from an APK file
import net.dongliu.apk.parser.ApkParser;
import net.dongliu.apk.parser.bean.Icon;
import org.apache.log4j.Logger;
import java.io.*;
/** Services for managing APK (Adroid Application Package) objects. */
public class ApkService
{
/** The {@link Logger}. */
@JohnZavyn
JohnZavyn / pom.xml
Created August 5, 2016 16:54
Renaming a dependency JAR before buiding a WAR in Maven
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>