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
@ebridges
ebridges / GetVersion.java
Last active December 14, 2015 10:18
Get the versionCode & versionName attributes from `AndroidManifest.xml` at runtime
import android.app.Activity;
// http://stackoverflow.com/questions/3874775/detect-my-apps-own-androidversioncode-at-run-time
public class GetVersion {
public static Integer getVersion(Activity activity) {
Integer version = 0;
try {
version = activity.getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
// Todo: handle
@ebridges
ebridges / android-video-error-codes.pl
Created March 2, 2013 14:02
PVMF Error Codes for Android video playback using MediaPlayer. This perl script will generate a Java enum based on the listing of codes at the end of the gist. Error codes derived from https://github.com/android/platform_external_opencore/blob/master/pvmi/pvmf/include/pvmf_return_codes.h
# https://github.com/android/platform_external_opencore/blob/master/pvmi/pvmf/include/pvmf_return_codes.h
use strict;
my $enumName = "VideoErrorCode";
my $first = 1;
my %data;
for(<DATA>){
chomp;
my ($msg,$code) = split /,/;
@ebridges
ebridges / android-eclipse-mvn-config.xml
Created March 11, 2013 21:40
Maven configuration to generate Eclipse project for an Android POM.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<excludes>
<exclude>com.google.android:android</exclude>
</excludes>
<buildOutputDirectory>bin</buildOutputDirectory>
<classpathContainers>
@ebridges
ebridges / install-deps.pl
Last active December 16, 2015 05:59
Load a bunch of dependencies from a source repo into a local folder to make a POM portable.
#!/usr/bin/perl
use strict;
my $repo="$ENV{HOME}/.m2/repository";
my $cwd = `pwd`;
chomp($cwd);
my $localRepo=$cwd.'/lib';
for(<DATA>) {
#!/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 / 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