Skip to content

Instantly share code, notes, and snippets.

View shiv19's full-sized avatar
🎯
Focusing

Shiva Prasad shiv19

🎯
Focusing
View GitHub Profile
@shiv19
shiv19 / nCr.js
Created May 17, 2023 01:51
Generate nCr Combinations for a given set
// Author: ChatGPT
function generateCombinations(set, r) {
const combinations = [];
function generate(currentCombination, remainingSet, r) {
if (currentCombination.length === r) {
combinations.push(currentCombination);
return;
}
@shiv19
shiv19 / mapSetSerialiseDeserialise.js
Last active February 23, 2023 20:19
Serialise/Deserialise JavaScript Maps and Sets
function replacer(key, value) {
if (value instanceof Map) {
return { __type: 'Map', value: Object.fromEntries(value) }
}
if (value instanceof Set) {
return { __type: 'Set', value: Array.from(value) }
}
return value
}
@shiv19
shiv19 / requestReview.js
Created August 7, 2020 05:09
Implementation of Google Play In-App Review API for NativeScript Apps
/*
https://developer.android.com/guide/playcore/in-app-review
In app reviews implementation for NativeScript Apps
Pre-requisites:
Add Google Play Core lib to your app.gradle's dependency list
app/App_Resources/Android/app.gradle ->
@shiv19
shiv19 / chromapp.sh
Created March 16, 2020 21:19
Launch website as Chrome PWA on MacOS
# Launch website as Chrome PWA on MacOS
function chromeapp {
url=$1;
{ nohup /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=$url & } &;
}
@shiv19
shiv19 / decodeString.js
Created February 11, 2020 01:55
Decompress A Given String
// An alternate solution for this challenge
// https://www.adimation.info/2019/12/01/decompress-a-given-string
function decodeString(str) {
let res = '';
const letters = str.split(/[0-9]+/).join('').split('');
letters.forEach(v => {
if (str.match(new RegExp(`${v}[0-9]+`))) {
res += v.repeat(str.match(new RegExp(`${v}[0-9]+`))[0].split(v)[1]);
} else {
@shiv19
shiv19 / gradientActionbarIosNativeScript.js
Last active April 17, 2021 09:21
use this code with loaded event of a page to get gradient actionbar on iOS for NativeScript Apps
import { Frame } from '@nativescript/core/ui/frame';
import { Color } from '@nativescript/core/color';
import { isIOS } from '@nativescript/core/platform';
/*
// Legacy require statements if using Vanilla {N}
const Frame = require('@nativescript/core/ui/frame').Frame;
const Color = require('@nativescript/core/color').Color;
const isIOS = require('@nativescript/core/platform').isIOS;
*/
@shiv19
shiv19 / arrayDifference.js
Created December 18, 2019 02:33
Tells you what's different in the incoming array when compared to exisiting array
/**
* Tells you what's different in the incoming array when compared to exisiting array
* Either pass in array of objects or pass in array of strings. Don't pass mixed array.
*
* @param incomingArray
* @param existingArray
* @param {'object'|'string'} compareType
*/
function difference(incomingArray, existingArray, compareType = 'object') {
const convertToStringIfNecessary = v => compareType === 'object' ? JSON.stringify(v) : v;
@shiv19
shiv19 / NativeScriptBottomSheet.txt
Created October 15, 2019 22:39
Contains link to Bottom Sheet example playground
https://play.nativescript.org/?template=play-js&id=ozM5gs&v=2
@shiv19
shiv19 / howToUse.js
Created September 25, 2019 02:19
NativeScript trace writer setup
// in app.ts before application.start
import * as trace from "tns-core-modules/trace";
trace.setCategories(trace.categories.concat(
// trace.categories.Layout, // add these two for detailed
// trace.categories.ViewHierarchy, // add these two for detailed
trace.categories.NativeLifecycle, // these two are for brief
trace.categories.Navigation // these two are for brief
));
// trace.setCategories(trace.categories.All); // this option is extremely detailed
import { setupTimestampConsoleWriter } from "./shared/traceWriter";
@shiv19
shiv19 / randColor.js
Last active August 9, 2019 23:03
get random hex color codes
const randColor = () => '#' + ('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);