Skip to content

Instantly share code, notes, and snippets.

@rishabhmhjn
rishabhmhjn / executeShellInGradle
Created November 5, 2014 07:26
Executing shell commands and getting output in gradle
def getVersionName = { ->
def hashStdOut = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = hashStdOut
}
def buildNumberStdOut = new ByteArrayOutputStream()
exec {
commandLine 'echo', "$BUILD_NUMBER"
@rishabhmhjn
rishabhmhjn / android_pkg_name_validate.js
Last active March 2, 2022 02:04
Regex to validate Android Package Name
var pattern = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/i;
[
"me.unfollowers.droid",
"me_.unfollowers.droid",
"me._unfollowers.droid",
"me.unfo11llowers.droid",
"me11.unfollowers.droid",
"m11e.unfollowers.droid",
"1me.unfollowers.droid",
@rishabhmhjn
rishabhmhjn / ArcProgressBar.java
Created December 19, 2014 17:33
Creating Arc shaped progress bars (http://i.imgur.com/WNFX38Z.png)
package me.rishabhmhjn.droid.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
@rishabhmhjn
rishabhmhjn / tweetLinky.js
Last active June 5, 2020 19:25
This is an AngularJS filter to linkify #hashtags and @mention texts into respective Twitter URLsDemo - http://plnkr.co/edit/vrdgxU?p=preview
var app = angular.module('tLinky', ['ngSanitize']);
app.filter('tweetLinky',['$filter', '$sce',
function($filter, $sce) {
return function(text, target) {
if (!text) return text;
var replacedText = $filter('linky')(text, target);
var targetAttr = "";
if (angular.isDefined(target)) {
package in.jasonleon.vanityviews.widget;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
@rishabhmhjn
rishabhmhjn / tmux_install.sh
Created January 16, 2014 04:20
Installing tmux for a local user
# Install libevent
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -zxf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/home/unix_user/usr
make && make install
# Install ncurses
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz
tar -zxf ncurses-5.7.tar.gz
@rishabhmhjn
rishabhmhjn / LoadMoreListView.java
Last active December 18, 2017 08:08
Custom ListView for use case such as endless scrolling
package me.rishabhmhjn.widgets;
import me.rishabhmhjn.R; // might be diffrent for your use
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
{
// The plugin looks for a .jsbeautifyrc file in the same directory as the
// source file you're prettifying (or any directory above if it doesn't exist,
// or in your home folder if everything else fails) and uses those options
// along the default ones.
// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: https://github.com/einars/js-beautify/
"html": {
"allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg"],
@rishabhmhjn
rishabhmhjn / ip-num-conversion.js
Created July 1, 2016 04:52
Convert IP into Integer and Integer into IP
import _ from 'lodash';
import {
reduce
} from 'lodash';
const IP_CAL = [Math.pow(256, 3), Math.pow(256, 2), Math.pow(256, 1), Math.pow(256, 0)];
function ipToNum(ip) {
@rishabhmhjn
rishabhmhjn / gem_install_do_mysql.sh
Last active January 4, 2016 21:48
bundle install troubleshooting on osx
## Error log
# Using dm-do-adapter (1.2.0)
# Using dm-master-slave-adapter (0.0.4)
# Installing do_mysql (0.10.13)
# Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
#
# /Users/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
# checking for mysql_query() in -lmysqlclient... no
# *** extconf.rb failed ***
# Could not create Makefile due to some reason, probably lack of