Skip to content

Instantly share code, notes, and snippets.

View ebridges's full-sized avatar
🛠️
Fixing things

Edward Q. Bridges ebridges

🛠️
Fixing things
View GitHub Profile
#!/usr/bin/env bash
set -o errtrace
set -o errexit
facter_version=$1
puppet_version=$2
target_volume=$3
@ebridges
ebridges / Base64EncodedPrivateKey.java
Created April 20, 2013 13:30
Adapt a p12 file into a private key usable by Google APIs. Provides two constructors: one that receives a base64 encoded string, the other a p12 file.
import static javax.xml.bind.DatatypeConverter.parseBase64Binary
import static javax.xml.bind.DatatypeConverter.printBase64Binary;
import java.security.PrivateKey;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException
public class Base64EncodedPrivateKey implements PrivateKey {
@ebridges
ebridges / install-deps.pl
Created April 25, 2013 02:28
Takes part of the output of `mvn dependency:list` and installs it into a local repo (under a folder named `lib`)
# mvn dependency:list
for(<DATA>){
chomp;
s/\[INFO\]\s+//;
my ($g,$a,$t,$v,$s) = split /\:/;
`mvn install:install-file \\
-DgroupId=$g \\
@ebridges
ebridges / JarList.java
Created April 25, 2013 02:30
Given a jar file, extract out the `pom.properties` and create a java.util.Properties object from it.
import java.io.*;
import java.util.*;
import java.util.jar.*;
public class JarList
{
public static void main (String args[]) throws IOException
{
if (args.length != 1)
{
@ebridges
ebridges / check-for-column.sql
Last active December 16, 2015 18:29
Check to see if a column exists before creating it in a PostgreSQL database.
--changeset <user>:<rev> splitStatements:false
DO $$
BEGIN
BEGIN
ALTER TABLE <table_name> ADD COLUMN <column_name> <column_type>;
EXCEPTION
WHEN duplicate_column THEN RAISE NOTICE 'column <column_name> already exists in <table_name>.';
END;
END;
$$
@ebridges
ebridges / estimate-table-size.sql
Created April 28, 2013 19:37
Estimate how many rows are in all tables in a PostgreSQL database.
-- cf.: http://stackoverflow.com/a/2611745/87408
SELECT
nspname AS schemaname,relname,reltuples
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE
nspname NOT IN ('pg_catalog', 'information_schema') AND
relkind='r'
ORDER BY reltuples DESC;
@ebridges
ebridges / pushing-to-heroku.sh
Created July 16, 2013 01:37
Pushing non-master things to heroku
## push a non-master branch 'yourbranch' to heroku
$ git push heroku yourbranch:master
## push a tag named 'v1.1' to heroku
$ git push -f heroku v1.1^{}:master
@ebridges
ebridges / pom.xml
Created July 27, 2013 15:02
Basic pom.xml Populate: `${artifactId}` and `${groupId}`
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${artifactId}</name>
@ebridges
ebridges / spring-batch-archetype.sh
Last active December 20, 2015 13:09
Create a basic spring batch project
## TODO: fork this repo and customize
## https://github.com/chrisjs/maven-springbatch-archetype/blob/master/src/main/resources/archetype-resources/pom.xml
##
## • Add JGitFlow to pom.xml
## • set jdk version to 1.7
## • …
groupId=
artifactId=
packageName=${groupId}
@ebridges
ebridges / new-project.py
Last active December 20, 2015 21:09
Generates a mvn archetype:generate command for a new project.
#!/usr/local/bin/python
import argparse
DEFAULT_VERSION = '1.0-SNAPSHOT'
DEFAULT_PACKAGE = 'com.delve.etl'
def command_props(client, project, version):
job_props = {}