Skip to content

Instantly share code, notes, and snippets.

View therealshabi's full-sized avatar

Shahbaz Hussain therealshabi

View GitHub Profile
@therealshabi
therealshabi / AutoAdjustImage.js
Last active January 28, 2025 16:57
React Native Auto Adjust Image Component
import React, {useState, useEffect} from 'react';
import {Image} from 'react-native';
const AutoAdjustImage = ({source, width, height, ...props}) => {
const [dimensions, setDimensions] = useState({width: 0, height: 0});
useEffect(() => {
if (width && height) {
setDimensions({width: width, height: height});
return;
@therealshabi
therealshabi / CombineLiveData.java
Created August 12, 2022 13:54
A utility class to combine 2 LiveData in one, which basically emits value only when both the live data emits some non-null value value
package com.magicpin.local.groceryorders;
import android.util.Pair;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
public class CombineLiveData<A, B> {
private A lastA = null;
@therealshabi
therealshabi / FileUtils.java
Created March 22, 2020 18:00
File Utility to resolve real path
public class FileUtils {
public static String getRealPath(Context context, Uri fileUri) {
String realPath;
// SDK < API11
if (Build.VERSION.SDK_INT < 19) {
realPath = FileUtils.getRealPathFromURI_API11to18(context, fileUri);
}
// SDK > 19 (Android 4.4) and up
else {
realPath = FileUtils.getRealPathFromURI_API19(context, fileUri);
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@therealshabi
therealshabi / CrashlyticsTree.kt
Created July 24, 2019 05:11
Log Error Stacktrace into Crashlytics in addition to logging into the Logcat
package com.example.shahbaz
import android.util.Log
import com.crashlytics.android.Crashlytics
import timber.log.Timber
class CrashlyticsTree : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
super.log(priority, tag, message, t)
if (priority != Log.ERROR) return
@therealshabi
therealshabi / index.html
Created March 11, 2018 20:45
Pixel Art Maker
<!DOCTYPE html>
<html>
<head>
<title>Pixel Art Maker!</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Monoton">
<link rel="stylesheet" href="styles.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<h1>Lab: Pixel Art Maker</h1>
@therealshabi
therealshabi / index.html
Last active February 25, 2018 18:24
Udacity Animal Trading Card
<html>
<head>
<meta charset="utf-8">
<title>Animal Trading Cards</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="container-div">
<!-- your favorite animal's name goes here -->
<h3>The Royal Bengal Tiger</h3>
@therealshabi
therealshabi / AsyncRoute.js
Created May 4, 2017 15:07
How to make Asynchronous Route in nodejs
var calls = [];
// HomeStreamPost Part-2
// route to get the homeStream post of a particular user
server.get("/user/homeStreamPost/:email_address",function(req,res,next){
var result=[];
req.assert('email_address','Email Address is required').notEmpty().isEmail();
var errors = req.validationErrors();
if (errors) {
helpers.failure(res,next,errors[0],400);
import java.util.*;
public class Testing
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String password = in.nextLine();
String key = in.next();
int i;
// Restify Server CheatSheet.
// More about the API: http://mcavage.me/node-restify/#server-api
// Install restify with npm install restify
// 1.1. Creating a Server.
// http://mcavage.me/node-restify/#Creating-a-Server
var restify = require('restify');