Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
kaushikgopal / aliases_an_img
Last active August 29, 2015 13:56
Helper scripts for handling different Android screen sizes
# REPO=$HOME/put/your/repo/dir/here
# Generate Android resource directory structure and create lower res version of images
function an_img_gen_res {
if [ ! -f "$1" ]; then
echo "File not found!"
return
fi
@kaushikgopal
kaushikgopal / git_changed_from_last_tag
Last active August 29, 2015 13:56
Git script to check changes to a file since last tagged release
#!/usr/bin/env ruby
require 'optparse'
tag_name = %x[git tag | tail -1].strip
optparse = OptionParser.new
optparse.parse!
filename = ARGV.pop
@kaushikgopal
kaushikgopal / git_quick_add_from_status_changed
Last active August 29, 2015 13:57
A ruby script that makes it easier to quickly add to git the last files
#!/usr/bin/env ruby
=begin
# sample output for git status -s
M pkk/src/main/java/com/micromobs/pkk/fragments/GuestProfileQuestionnaireStep1Fragment.java
M pkk/src/main/java/com/micromobs/pkk/fragments/GuestProfileQuestionnaireStep2Fragment.java
M pkk/src/main/java/com/micromobs/pkk/ui/viewmodels/MembershipViewModel.java
M pkk/src/main/res/layout/fragment_guest_profile_questionnaire_step_2.xml
#!/usr/bin/env ruby
# Get line number for file that needs to be added
argument = ARGV.pop
# do a git status and get the second argument
# filename = %x[git status -s | sed -n '#{argument}p'].split(" ", 2)[1]
filename = %x[git status -s | awk 'NR==#{argument}'].split(" ", 2)[1] # using awk baby!
system("git diff-index --quiet HEAD -- || clear; git diff --patch-with-stat #{filename}")
#!/usr/bin/env ruby
# Get line number for file that needs to be added
argument = ARGV.pop
# do a git status and get the second argument
# filename = %x[git status -s | sed -n '#{argument}p'].split(" ", 2)[1]
filename = %x[git status -s | awk 'NR==#{argument}'].split(" ", 2)[1] # using awk baby!
system("git checkout -- #{filename}")
# First check imagemagick versions
brew versions imagemagick
brew uninstall imagemagick
cd /usr/local/Cellar
git checkout 834ce4a /usr/local/Library/Formula/imagemagick.rb
brew install imagemagick
@kaushikgopal
kaushikgopal / Truss.java
Created June 5, 2014 15:50 — forked from JakeWharton/Truss.java
Extremely simple wrapper around SpannableStringBuilder to make the API more logical and less awful. Apache 2 licensed. (courtesy JakeWharton)
import android.text.SpannableStringBuilder;
import java.util.ArrayDeque;
import java.util.Deque;
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */
public class Truss {
@kaushikgopal
kaushikgopal / Bundler.java
Last active August 29, 2015 14:02
A nice helper utility that creates your Bundle with extras quickly. Apache 2 licensed
import android.os.Bundle;
// see my gist for [https://gist.github.com/kaushikgopal/9eea148a2188dc58fe37](ParcelableSparseArray) implementation
public class Bundler {
private Bundle _bundle;
public Bundler() {
_bundle = new Bundle();
@kaushikgopal
kaushikgopal / ScopedBus.java
Created July 3, 2014 00:16
An enhanced (otto) event bus - Apache 2 Licensed
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
import java.util.HashSet;
import java.util.Set;
/*
@kaushikgopal
kaushikgopal / AndroidColorUtils.java
Created August 2, 2014 18:31
Some handy utility methods for dealing with Color in Android
private int _darkenOrLightenColor(int color, boolean darken) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
// value component
if (darken) {
hsv[2] *= Math.max(hsv[2] * 0.99f, 0);
} else {
hsv[2] = Math.max(hsv[2] * 1.5f, 1);
}