Skip to content

Instantly share code, notes, and snippets.

View frohoff's full-sized avatar

Chris Frohoff frohoff

View GitHub Profile
@eirnym
eirnym / sqlalchemy_exists_patch.py
Last active December 21, 2023 17:22
SQLAlchemy 'if exists' patch
import re
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.schema import CreateTable, DropTable, \
CreateSequence, DropSequence, CreateIndex, DropIndex
from sqlalchemy.dialects.postgresql import DropEnumType
patches = (
(CreateTable, 'visit_create_table', "^\s*CREATE TABLE", "CREATE TABLE IF NOT EXISTS"),
(CreateIndex, 'visit_create_index', "^\s*CREATE INDEX", "CREATE INDEX IF NOT EXISTS"),
@n0ts
n0ts / get_oracle_jdk_x64.sh
Last active September 16, 2023 12:07
Get latest Oracle JDK package bash shell script for linux/osx/windows
#!/bin/bash
# You must accept the Oracle JDK License Update
# https://www.oracle.com/java/technologies/javase-downloads.html
# usage: get_oracle_jdk_x64.sh <jdk_version> <platform> <ext>
# jdk_version: 14
# platform: linux or osx or windows
# ext: rpm or dmg or tar.gz or exec
jdk_version=${1:-14}
@telent
telent / gist:9742059
Last active February 19, 2024 09:30
12 factor app configuration vs leaking environment variables
App configuration in environment variables: for and against
For (some of these as per the 12 factor principles)
1) they are are easy to change between deploys without changing any code
2) unlike config files, there is little chance of them being checked
into the code repo accidentally
3) unlike custom config files, or other config mechanisms such as Java
@P7h
P7h / jdk_download.sh
Last active February 20, 2024 11:29
Script to download JDK / JRE / Java binaries from Oracle website from terminal / shell / command line / command prompt
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
### Shell script to download Oracle JDK / JRE / Java binaries from Oracle website using terminal / command / shell prompt using wget.
### You can download all the binaries one-shot by just giving the BASE_URL.
### Script might be useful if you need Oracle JDK on Amazon EC2 env.
### Script is updated for every JDK release.
### Features:-
# 1. Resumes a broken / interrupted [previous] download, if any.
# 2. Renames the file to a proper name with including platform info.
@erickok
erickok / SelfSignedCrtCertificate.java
Last active May 11, 2023 14:25
Loading a self-signed SSL certificate .crt file and packaging it into a SSLSocketFactory for use with a HttpsURLConnection.
// Usage example...
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://someurl.com").openConnection();
connection.setSSLSocketFactory(buildSslSocketFactory());
private static SSLSocketFactory buildSslSocketFactory(Context context) {
// Add support for self-signed (local) SSL certificates
// Based on http://developer.android.com/training/articles/security-ssl.html#UnknownCa
try {
@arschles
arschles / scalaConcurrentPatterns.scala
Last active August 23, 2018 15:00
examples of common concurrency patterns that you can achieve with the scala.concurrent package
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Random
import java.util.{Timer, TimerTask}
object Util {
sealed trait BaseResponse
case class Response1(res: Int) extends BaseResponse
case class Response2(res: String) extends BaseResponse
@andrewconner
andrewconner / FutureGoodies.scala
Last active May 4, 2016 11:34
SafeFuture, TimeoutFuture, CancelableFuture implementations. See https://eng.42go.com/future-safefuture-timeout-cancelable for further explanation.Thanks to @bretthoerner for spotting an error!
/* We've run into a few common pitfalls when dealing with Futures in Scala, so I wrote these three helpful
* classes to give some baked-in functionality.
*
* I'd love to hear about other helpers you're using like these, or if you have improvement suggestions.
* github@andrewconner.org / @connerdelights
*/
import scala.concurrent.{ExecutionContext, CanAwait, Awaitable, Future, Promise}
import scala.concurrent.duration.Duration
import scala.util.Try
@brikis98
brikis98 / Cache.scala
Last active February 1, 2021 05:24
A quick hack to wrap Java's ConcurrentHashMap with a slightly more scala-friendly API. Scala's built-in ConcurrentMap does the same thing, but its getOrElseUpdate is NOT atomic. Hopefully, the getOrElseUpdate in the version below works correctly :)
package com.linkedin.playplugins.common.util
import Cache._
import play.api.Configuration
import java.util.concurrent.ConcurrentHashMap
import collection.JavaConverters._
/**
* A Scala wrapper for a Java's ConcurrentHashMap (CHM). Exposes the basic underlying methods of CHM and adds a
* getOrElseUpdate(key, value) method that lazily evaluates the value parameter only if the key is not already present
@viktorklang
viktorklang / InterruptibleCancellableFuture.scala
Last active June 1, 2020 13:45
Interruptible-Cancellable-scala.concurrent.Future
/*
Copyright 2018 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software