Skip to content

Instantly share code, notes, and snippets.

View mohsin's full-sized avatar

Saifur Rahman Mohsin mohsin

View GitHub Profile
@mohsin
mohsin / pre-push
Created November 30, 2016 08:47
Plugin public-private repo issue solution
#!/bin/sh
remote="$1"
url="$2"
message=$(git log -1 HEAD --pretty=format:%s)
public_repo="/Users/Moz/Desktop/public"
[ -d lang ] && yes | cp -rf lang/* $public_repo/lang
[ -d updates ] && yes | cp -rf updates/* $public_repo/updates
cd $public_repo
@mohsin
mohsin / AES-256-CBC-keygen.php
Created October 20, 2016 13:25
Random secret generator for AES-256-CBC
//JS Version
var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
randomString = ''
for (var i = 0; i < length; i++) {
var randomPos = Math.floor(Math.random() * charSet.length)
randomString += charSet.substring(randomPos, randomPos + 1)
}
return randomString
@mohsin
mohsin / StringUtils.java
Last active April 11, 2021 13:40
Function to convert Android menu.xml into string array for use in ArrayAdapter for NavigationDrawer
import android.view.Menu;
import android.view.MenuInflater;
import android.content.Context;
import android.support.v7.view.menu.MenuBuilder;
public class StringUtils {
/*
* Usage: String[] mMenuItems = StringUtils.getArrayFromMenu(this, R.menu.menu_main);
* And then mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.item_listview_drawer, mMenuItems));
@mohsin
mohsin / ListViewUtils.java
Last active August 24, 2018 04:56
setListViewHeightBasedOnChildren fix for TwoLineListItem
public static void setListViewHeightBasedOnChildren(ListView listView)
{
ListAdapter listAdapter = listView.getAdapter();
if(listAdapter == null) return;
if(listAdapter.getCount() <= 1) return;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
int totalHeight = 0;
View view = null;
for(int i = 0; i < listAdapter.getCount(); i++)
@mohsin
mohsin / HackFB.diff
Created January 15, 2016 18:59 — forked from creativepsyco/HackFB.diff
Facebook Android SDK 3.6.0 OAuth using embedded Web View
diff --git i/facebook-android-sdk-3.6.0/facebook/src/com/facebook/widget/WebDialog.java w/facebook-android-sdk-3.6.0/facebook/src/com/facebook/widget/WebDialog.java
index 70ac868..c2c9af0 100644
--- i/facebook-android-sdk-3.6.0/facebook/src/com/facebook/widget/WebDialog.java
+++ w/facebook-android-sdk-3.6.0/facebook/src/com/facebook/widget/WebDialog.java
@@ -17,6 +17,7 @@
package com.facebook.widget;
import android.annotation.SuppressLint;
+import android.app.AlertDialog;
import android.app.Dialog;
@mohsin
mohsin / build.gradle
Created January 15, 2016 18:37 — forked from creativepsyco/build.gradle
Gist for creating Dex file for class files in Android Library
/**
* The Task Below uses the Dex Tool to create classes.dex file for the archive
* This dex file can be then be loaded at runtime to prevent the 64K Dalvik Method Limit
*/
import org.apache.tools.ant.taskdefs.condition.Os
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
return; // Skip debug builds.
}
@mohsin
mohsin / README.md
Created November 26, 2015 15:38 — forked from Coeur/README.md
Write to NTFS on OSX Yosemite and El Capitan
@mohsin
mohsin / numberToCurrency.php
Created October 8, 2015 20:37
Convert PHP number to Indian rupee format
public function numberToCurrency($num)
{
if(setlocale(LC_MONETARY, 'en_IN'))
return money_format('%.0n', $num);
else {
$explrestunits = "" ;
if(strlen($num)>3){
$lastthree = substr($num, strlen($num)-3, strlen($num));
$restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
$restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
function push() {
if [ -z "${1}" ]; then
echo "Usage: push <remote-name>"
return 1
fi;
GIT_DIR_="$(git rev-parse --git-dir)"
BRANCH="$(git rev-parse --symbolic --abbrev-ref $(git symbolic-ref HEAD))"
@mohsin
mohsin / Sass version of PHP explode
Created April 13, 2015 22:25
Sass version of PHP explode
//
// Returns list after splitting a string by a delimiter string.
// Similar to PHP's explode function
//
@function explode($string, $delimiter: "", $separator: "space")
@if type-of($string) != "string"
@warn "`explode` function expecting a string; #{type-of($string)} given."
@return null
@if type-of($delimiter) != "string"
@warn "`explode` function expecting a string; #{type-of($delimiter)} given."