Skip to content

Instantly share code, notes, and snippets.

View tejpratap46's full-sized avatar
🏠
Working from home

Tej Pratap Singh tejpratap46

🏠
Working from home
View GitHub Profile
@tejpratap46
tejpratap46 / styles.xml
Created January 1, 2021 18:45
Transparent Bottom Sheet
<resources>
<style name="TransparentBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorSecondary">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="bottomSheetStyle">@style/TransparentBottomSheetStyle</item>
</style>
<style name="TransparentBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
@tejpratap46
tejpratap46 / speechrec.md
Last active July 8, 2018 13:07
things TODO for speech recognition app.
@tejpratap46
tejpratap46 / CustomLinearLayoutManager.java
Last active July 26, 2017 11:57
Make RecyclerView smooth scroll in a NestedScrollView
public class CustomLinearLayoutManager extends LinearLayoutManager {
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
// It will always pass false to RecyclerView when calling "canScrollVertically()" method.
@Override
public boolean canScrollVertically() {
return false;
@tejpratap46
tejpratap46 / PDFUtil.java
Last active February 23, 2022 06:18
Android Generate PDF from view, Use https://github.com/tejpratap46/PDFCreatorAndroid for simple use
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.pdf.PdfDocument;
import android.graphics.pdf.PdfRenderer;
import android.os.AsyncTask;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.util.Log;
@tejpratap46
tejpratap46 / ImageUtil.java
Created July 5, 2017 07:15
Generate Bitmap from view in android
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;
import android.view.View;
import java.util.ArrayList;
public class ImageUtil {
/**
@tejpratap46
tejpratap46 / proxy-microservice.js
Created June 15, 2017 13:22
A simple proxy microservice
module.exports = (url = 'world', context, callback) => {
var http = require("https");
var req = http.get(url, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
@tejpratap46
tejpratap46 / SingletonEvent.js
Created May 25, 2017 14:39
A singleton class to manage events (pus-sub)
// A singleton class to manage events (pus-sub)
let eventManagerInstance = null;
export default class Event {
constructor(){
if (!stateManagerInstance) {
stateManagerInstance = this;
this.events = {};
@tejpratap46
tejpratap46 / SnapAdapter.java
Created February 13, 2017 12:10
Android RecyclerView Snap Adapter
// Horizontal snap adapter for recycler view, LinearSnapHelper is available from support lib 24.2.0
LinearSnapHelper snapHelper = new LinearSnapHelper() {
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager lm, int velocityX, int velocityY) {
View centerView = findSnapView(lm);
if (centerView == null)
return RecyclerView.NO_POSITION;
int position = lm.getPosition(centerView);
int targetPosition = -1;
@tejpratap46
tejpratap46 / app.js
Created December 26, 2016 07:16
Disable angularjs debug mode.
module.config(["$httpProvider", "$compileProvider", (
$httpProvider:IHttpProvider,
$compileProvider:ICompileProvider
) => {
$httpProvider.useApplyAsync(true);
$compileProvider.debugInfoEnabled(false);
}]);
@tejpratap46
tejpratap46 / fuzzysearch.md
Created August 26, 2016 06:44
Fuzzy search algorithm

What you need is (as i know) not supported by Parse Engine. You need a Phonetic search algorithm, but you have to retrieve all records from your PFObject to perform a Phonetic match on all the names (or fetch all starting with "D" and then perform the match on those only).

The Phonetic search algorithm is called SoundEx and various implementations have been done by developers all over the world, taking into account i.e. UK abbreviations like "St. = Saint" etc.

The SoundEx algorithm is very intelligent and is working as follows:

  1. Retain the first letter of the name and drop all other occurrences of a, e, i, o, u, y, h, w.
  2. Replace consonants with digits as follows (after the first letter):
  3. b, f, p, v => 1
  4. c, g, j, k, q, s, x, z => 2