Skip to content

Instantly share code, notes, and snippets.

View akshayjai1's full-sized avatar

Akshay Vijay Jain akshayjai1

View GitHub Profile
@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------------------------');
@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 / 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 / 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 / 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$/,
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 / google-maps-geofence-complete-example.markdown
Created February 11, 2019 10:48
Google Maps Geofence Complete Example