Skip to content

Instantly share code, notes, and snippets.

@lesleh
lesleh / build.gradle
Last active August 29, 2015 13:57
APK signing configuration for Android Gradle projects
// APK signing
def signingPropFile = new File(project.rootDir, "signing.properties")
if(signingPropFile.exists()) {
Properties props = new Properties()
props.load(new FileInputStream(signingPropFile))
android {
signingConfigs {
release {
storeFile file(props['signing.keystore'])
@lesleh
lesleh / RatioImageView.java
Last active August 29, 2015 14:00
An implementation of ImageView for Android that restricts the image to a given aspect ratio, if possible. This is a more generalised way of doing SquareImageView, just set both the width and height ratios to 1 for a square image.
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
public class RatioImageView extends ImageView {
private static final float DEFAULT_WIDTH_RATIO = 1;
private static final float DEFAULT_HEIGHT_RATIO = 1;
@lesleh
lesleh / data_uri
Created January 15, 2015 12:25
Bash script to create data URIs.
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "No filename specified." >&2
exit 1
fi
FILENAME=$1
MIMETYPE=$(file -b --mime-type "$FILENAME")
DATA=$(cat "$FILENAME" | base64)
@lesleh
lesleh / number-suffix.js
Created January 18, 2015 17:09
Get the suffix for a given number, e.g. 2nd, 3rd, 4th.
/*
1st
2nd
3rd
4th
11th
12th
21st
22nd
121st
@lesleh
lesleh / move_to_music
Last active August 29, 2015 14:16
Add a music file to your music library, with the format {artist}/{album}/{track} {title}.{ext}. Automatically removes illegal filename characters.
#!/usr/bin/env ruby
# Ubuntu: apt-get install libtagc0-dev
# gem install taglib-ruby
require 'taglib'
require 'fileutils'
#------------------------------------------------
# Configuration
@lesleh
lesleh / public_ip
Created June 2, 2015 10:00
Script to detect public IP
#!/bin/bash
SERVICE_URL=http://icanhazip.com/
if hash wget 2>/dev/null; then
wget -qO- $SERVICE_URL
elif hash curl 2>/dev/null; then
curl $SERVICE_URL
else
>&2 echo Need wget or curl.
#!/bin/bash
cd $HOME
echo Updating system
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install -y curl
@lesleh
lesleh / git_subprojects_status.sh
Created June 5, 2015 14:36
Recursively list git status for all sub projects
#!/bin/bash
DIR=$(dirname $(readlink -f $0))
find $DIR -maxdepth 2 -mindepth 2 -name .git -type d | while read REPO; do
REPO=${REPO//.git/}
echo $REPO
pushd $REPO >/dev/null
git status -s
@lesleh
lesleh / each_repo.sh
Last active August 29, 2015 14:22
Run command on all Git repositories in current directory.
#!/bin/bash
# Example usage: ./each_repo.sh 'git pull'
if [ $# -ne 1 ]; then
2>&1 echo "No command specified."
exit 1
fi
DIR=$(pwd) # $(dirname $(readlink -f $0))
# nginx
description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PID=/opt/nginx/logs/nginx.pid