Skip to content

Instantly share code, notes, and snippets.

View anurag-roy's full-sized avatar
🌠
Less is more

Anurag Roy anurag-roy

🌠
Less is more
View GitHub Profile
@anurag-roy
anurag-roy / camelToSentence.ts
Last active January 8, 2021 14:25
Camel Case to Sentence Case Converter
const camelEdges: RegExp = /([A-Z](?=[A-Z][a-z])|[^A-Z](?=[A-Z])|[a-zA-Z](?=[^a-zA-Z]))/g;
// Input Array consisting of codes starting with "WS_Something_"
const inputArray: string[] = [
"WS_BLDNGMGMT_CertificationUpdateFailed",
"WS_USRMGMT_CompanyNotFound",
"WS_GEN_UnauthorizedOperation",
];
@anurag-roy
anurag-roy / sortObjectByKeys.ts
Created January 8, 2021 14:24
Sort Object by Keys (Alphabetically)
let inputObject: {[key: string]: string} = {
"ServerError": "Could not connect. Try again",
"WS_BLDNGMGMT_AssignOpportunitiesFailure": "Assignment Failed",
"WS_GEN_GenericError": "Some Error Occurred",
"WS_SCRCRDMGMT_CriteriaCodeAlreadySelected": "Criteria with same Criteria Code already Selected",
};
let sortedKeys: string[] = Object.keys(inputObject).sort((a,b) => a.localeCompare(b));
let resultObject: {[key: string]: string} = {};
console.clear();
const carrierArray = [
"T-Mobile - 3G *(US)*",
"T-Mobile - 4G *(US)*",
"Verizon Wireless - 3G *(US)*",
"Verizon Wireless - 4G *(US)*",
"Sprint - 3G *(US)*",
"Sprint - 4G *(US)*",
"AT&T - 3G *(US)*",
//Sorting Hex Color:
class Color {
hex: string;
constructor(hexVal: string) {
//define a Color class for the color objects
this.hex = hexVal;
};
@anurag-roy
anurag-roy / webp-convert-directory.sh
Last active September 8, 2021 21:18 — forked from tabrindle/webp-convert-directory.sh
Convert all files in directory to webp, with default params, or standard cwebp params passed from command
#!/bin/bash
PARAMS=('-m 6 -q 70 -mt -af -progress')
if [ $# -ne 0 ]; then
PARAMS=$@;
fi
cd $(pwd)
# Install Postgres if not exists
which psql
if [ "$?" -ne 0 ]
then
echo "Installing Postgres..."
sudo apt-get install postgresql --yes
echo "Altering password for user 'postgres'"
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"
else
@anurag-roy
anurag-roy / createPokeData.js
Last active October 1, 2021 20:52
Script to create custom Pokemon data from the PokeAPI data at https://github.com/PokeAPI/api-data
// .../api-data/data/createPokeData.js
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const baseDir = dirname(fileURLToPath(import.meta.url));
const pokemonDir = join(baseDir, 'api', 'v2', 'pokemon');
const outDir = join(baseDir, 'out');
let input = [{
"id": "REPORT1",
"application": "APP1",
"type": "TYPE1",
"title": ""
},
{
"id": "REPORT2",
"application": "APP1",
"type": "TYPE1",
@anurag-roy
anurag-roy / potd.js
Last active September 4, 2022 17:04
"Pokémon of the Day" Widget for Scriptable
const pool = 151; // use the pool of your choice: 151 for Gen-1, etc.
const showName = false; // determines if the name of the Pokemon should be displayed or not
// Get data
const apiRequest = new Request(
`https://pokeapi.deno.dev/pokemon/potd?pool=${pool}`
);
const pokemon = await apiRequest.loadJSON();
const imageRequest = new Request(pokemon.imageUrl);
const image = await imageRequest.loadImage();
@anurag-roy
anurag-roy / parseTick.ts
Last active February 27, 2023 17:39
Example to parse a full tick from Kite Websocket.
// Tick structure reference: https://kite.trade/docs/connect/v3/websocket/#message-structure
const parseBinary = (dataView: DataView) => {
const numberOfPackets = dataView.getInt16(0);
let index = 4;
const ticks: { token: number; firstBid: number; firstAsk: number }[] = [];
for (let i = 0; i < numberOfPackets; i++) {
const size = dataView.getInt16(index - 2);
// Parse whatever you need