Skip to content

Instantly share code, notes, and snippets.

@SINGHPRT
SINGHPRT / gist:4aa42a4df146bac940b4128d9717191a
Created September 23, 2020 07:43
jQuery to format phone number in US telephone format: XXX-XXX-XXXX (without country code)
$('[name=mobilePhone]').on('keyup', function(e){
var enteredNumberStr=this.$('[name=mobilePhone]').val(),
//Filter only numbers from the input
cleanedStr = (enteredNumberStr).replace(/\D/g, ''),
inputLength=cleanedStr.length,
formattedNumber=cleanedStr;
if(inputLength>3 && inputLength<7) {
formattedNumber= cleanedStr.substr(0,3) + '-' + cleanedStr.substr(3,inputLength-1) ;
@SINGHPRT
SINGHPRT / Resolving Conflicting Jar versions in classpath in MAVEN Java projects
Last active January 3, 2020 11:44
Resolving issues with Conflicting versions of jars in Java maven project
Read through following links:
=============================
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
https://dzone.com/articles/solving-dependency-conflicts-in-maven
Now you must have some good idea on how Maven allows you to handle such issues.
Following steps should lead to resolution:
@SINGHPRT
SINGHPRT / Migrating App engine SDK to Cloud SDK
Last active January 2, 2020 05:06
Upgrading appengine sdk to cloud sdk
As standalone appengine sdk based app development and deployment is out of support by 30 July 2010 as per the following notice by GCP.
" [Action Required] Migrate your App Engine projects from the legacy SDK (appcfg) before July 30, 2020"
This gist will walk you through on
--> How to upgrade to cloud sdk
--> How to convert your App engine Java eclipse project into Maven project if needed.
--> If eclipse project uses Data Nucleus plugin to Enhancement of JDO classes, Maven integration is must.
--> Datanucleus Plugin Integration
@SINGHPRT
SINGHPRT / AppengineExecutor.java
Created August 31, 2019 20:45 — forked from nilsmagnus/AppengineExecutor.java
Appengine executorservice usage
package no.nilsapp.someapp.cronjobs;
import com.google.appengine.api.ThreadManager;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
1. Get by Keys
================
@SuppressWarnings("unchecked")
public List<Message> getByIdList(List keys) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery("select from " + Message.class.getName() + " where :keys.contains(key)");
//Query q = pm.newQuery("select from " + Message.class.getName() + " where key == :keys");
return (List<Message>) q.execute(keys);
What is Event Debouncing:
==========================
There are several situations in UI event paradigm where you want
control to limit/bound an event to fire only once after a specific amount of time has passed or within a given time-interval.
Event listeners bound to the keyup in search boxes, screen resize and scroll events are the typical candidates for debouncing in JAVASCRIPT.
Android has similar issues found with button click.
How to debounce an Button Click event in Android:
====================================================
1. Extend Click Listener with timer to track click events
@SINGHPRT
SINGHPRT / JAVASCRIPT REFACTORING EXAMPLE
Last active August 10, 2017 11:16
JAVASCRIPT REFACTORING SNIPPETS
SNIPPET 1- Exact match of multiple possible matching word.
POOR CODE:
==========
isMatchingEventTopic: function(event) {
if (event.eventTopic.indexOf('TASK') != -1 ||
event.eventTopic.indexOf('CLAIM') != -1 ||
event.eventTopic.indexOf('ORDER') != -1 || e
vent.eventTopic.indexOf('PLAN_ENROLLMENT') != -1 ||
event.eventTopic.indexOf('CAMPAIGN_GOAL') != -1 ||
@SINGHPRT
SINGHPRT / Getting All fields of Java Class
Last active August 29, 2015 14:27
Getting All fields(including inherited) from a JAVA class[POJO]
package com.pratap.utils;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.apache.commons.lang3.ArrayUtils;
@SINGHPRT
SINGHPRT / Form_Sanitizer.html
Last active December 16, 2015 05:19
Form Sanitizer: This jQuery plugin is meant to keep the form fields sanitized from restricted characters like special characters etc. The JavaScript plugin written here allows DEVs to: 1. choose any regex pattern to decide black-lised/white-listed characters for form fields 2. choose which message to display as an error to educate user of this r…
<doctype html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Form Sanitizer Demo</title>
<style type="text/css">
label{min-width:100px;display:block;}
.errorLbl_sanitizer{color:red;font-weight:bold;font-size:0.8em;display:inline-block;padding:4px;}
.errorField{background-color:pink;border:2px solid red;}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>