Skip to content

Instantly share code, notes, and snippets.

View glombard's full-sized avatar

Gert Lombard glombard

View GitHub Profile
@glombard
glombard / generate_robolectric_files_pom.py
Last active March 7, 2018 04:57
Generate a pom.xml file to download the jars needed to use the Robolectric Test Runner in offline mode
#!/usr/bin/env python
"""
This is a quick and dirty script to parse SdkConfig.java from the
Robolectric sources on GitHub to determine the list of dependencies we need
to use the Robolectric Test Runner in offline mode. It then generates a Maven
pom.xml file that can be used to download all the necessary depedenency jars
from maven central.
Author: @codeblast
@glombard
glombard / dagger.gradle
Created February 6, 2015 01:36
How to apply android-apt plugin from a shared gradle file using the fully qualified class name
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
@glombard
glombard / download-dict.sh
Created January 23, 2015 21:53
Installing an additional spelling dictionary in OS X from LibreOffice
cd ~/Library/Spelling/
curl -O http://cgit.freedesktop.org/libreoffice/dictionaries/tree/af_ZA/af_ZA.aff
curl -O http://cgit.freedesktop.org/libreoffice/dictionaries/tree/af_ZA/af_ZA.dic
# Now go to System Preferences -> Keyboard -> Text -> Set up and select the language.
@glombard
glombard / nginx-centos.repo
Created December 28, 2014 23:10
/etc/yum.repos.d/nginx-centos.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
@glombard
glombard / check-android-avd-images.sh
Last active August 29, 2015 14:11
Find missing Android emulator system images
DIRS=$(find ~/.android/avd -name '*ini' | xargs grep 'sysdir' | cut -d '=' -f 2)
IFS=$'\n' read -rd '' -a array <<< "$DIRS"
for d in "${array[@]}"
do
X="${ANDROID_HOME}/$d"
if [ ! -d $X ]; then
echo Missing emulator image: $X
fi
done
@glombard
glombard / new_obj.py
Created December 9, 2014 19:57
Python anonymous object
# Sometimes it's handy to create small anonymous objects instead of explicitly defining a class for it, especially while prototyping.
def new(name, data):
return type(name, (object,), data)
person = new('Person', { 'name': 'Joe', 'age': 30 })
print(person.name)
@glombard
glombard / gerrit_users.py
Created December 1, 2014 18:37
Get the Gerrit users emails as a string list using ssh and gsql query.
class GerritUsersListProvider(object):
def get_users(self):
"""Gets the Gerrit users emails as a string list."""
server = os.environ.get('GERRIT_SERVER', GERRIT_SERVER)
logging.debug('Querying all user accounts from ' + server)
text = subprocess.check_output([
'ssh', '-p', '29418', server, 'gerrit', 'gsql', '--format',
'JSON_SINGLE', '-c', "'select preferred_email from accounts'"])
accounts_json = json.loads(text)
return self.json_to_list(accounts_json)
@glombard
glombard / combine.py
Created November 24, 2014 00:22
Merging 4 images into one with Python and PIL/Pillow
# Combine multiple images into one.
#
# To install the Pillow module on Mac OS X:
#
# $ xcode-select --install
# $ brew install libtiff libjpeg webp little-cms2
# $ pip install Pillow
#
from __future__ import print_function
@glombard
glombard / install-apparix.sh
Created November 3, 2014 18:48
Setting up Apparix for directory bookmarks on Mac OS X
brew install -v apparix
# Installed to: /opt/foo/Cellar/apparix/11-0/bin/apparix
# Add bm/to Bash functions from man page to .bashrc or .local.bash:
man -P cat apparix | awk '/BASH-style functions/{p=1} /---/{if(p==1)p=2; else p=0; next} p>1{print}' >> ~/.local.bash
# Reload my bash config:
source ~/.local.bash
# Now create a bookmark:
@glombard
glombard / ssh-vm.sh
Created October 14, 2014 20:10
Connect to my VMWare Fusion linux vm
GUEST_VMX=`vmrun list | tail -n+2`
GUEST_IP=`vmrun getGuestIPAddress "$GUEST_VMX"`
ssh root@$GUEST_IP