Skip to content

Instantly share code, notes, and snippets.

View akshayjai1's full-sized avatar

Akshay Vijay Jain akshayjai1

View GitHub Profile
@akshayjai1
akshayjai1 / google-maps-geofence-complete-example.markdown
Created February 11, 2019 10:48
Google Maps Geofence Complete Example
let customer = {
name: "Carl",
details: { age: 82 },
surname: ""
};
console.log(customer?.city ?? "Unknown city";); // Unknown city
console.log(customer?.city ?? "Unknown city";); // Unknown city
console.log(customer?.surname ?? "Unknown city";); // ''
console.log(customer?.surname || "Unknown city";); // Unknown city
@akshayjai1
akshayjai1 / copy-file.js
Last active April 2, 2020 03:49
node snippet to copy files matching a pattern from a folder to a new location with specific file name
const fs = require('fs-extra');
const folders = [
{
path: './build/static/css',
regex: /^(main).[\w]*.css$/,
outputFile: '../public-pages/style/sme.css'
},
{
path: './build/static/js',
regex: /^(main).[\w]*.js$/,
@akshayjai1
akshayjai1 / remove-node.sh
Last active June 13, 2020 06:18
a shell file to remove node completely from macos
sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp
brew uninstall node
@akshayjai1
akshayjai1 / assertNonNull.ts
Last active July 13, 2020 23:53
Code snippet to throw an error for Null or Undefined
/**
* Code snippet to throw an error for Null or Undefined
* Container = object containing variables for example
* if we want to assert that a variable x is not null or undefined
* we can use function like this
* let x;
* assertNonNull({x}) // if x is null or undefined,
* this function will throw appropriate error
*/
export const assertNonNull = (container: any) => {
@akshayjai1
akshayjai1 / Dispatch.ts
Created October 2, 2020 14:41
typescript type for redux dispatch
import { Dispatch } from 'redux';
export interface IDom {
value?: string;
name?: string;
className?: string;
style?: any;
}
export interface IEvent {
target?: IDom;
@akshayjai1
akshayjai1 / logger.tsx
Last active November 18, 2020 14:28
a very useful logger while development
/**
* logger
* @param data object
*/
export const log = (data: any) => {
console.log('------------------logger------------------------');
Object.entries(data || {}).forEach((t, i) => {
console.log(`\n ${i}. \t ${t[0]} is ${JSON.stringify(t[1], null, 2)}`);
});
console.log('------------------logger------------------------');
[
{
"code": "AF",
"text": "Afghanistan",
"address_config": {
"city": {"tem": {"label": "City", "field": "city", "sequence": 3}},
"state": {"tem": {"label": "State", "field": "state", "sequence": 4}},
"address1": {
"tem": {"label": "Address Line 1", "field": "address1", "sequence": 1}
},
{
"editor.wordWrap": "on",
"editor.formatOnSave": true,
"editor.formatOnType": true,
"prettier.tabWidth": 2,
"prettier.endOfLine": "lf",
"prettier.jsxBracketSameLine": true,
"editor.useTabStops": false,
"git.autofetch": true,
"git.confirmSync": false,
Last login: Mon Oct 4 10:58:38 on console
akshay@Akshays-MacBook-Pro ~ % cd code/w
akshay@Akshays-MacBook-Pro w % ls
developer-portal wso2am-3.2.0 wso2am-3.2.0.zip
akshay@Akshays-MacBook-Pro w % cd wso2am-3.2.0
akshay@Akshays-MacBook-Pro wso2am-3.2.0 % ls
INSTALL.txt bin release-notes.html tmp
LICENSE.txt business-processes repository updates
README.txt dbscripts resources wso2carbon.pid
XMLInputFactory.properties lib samples