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
#!/bin/bash
# Manual zsysctl gc
clear
garbagespace=
kernelscount=
kernelstrim=
check () {
garbagespace=$(zpool list | awk -F '[% ]+' '/bpool/ {print $8}')
kernelscount=$(zsysctl show --full | grep -c -C 2 Kernel)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>name</key>
<string>GitHub Dark</string>
@anurag-roy
anurag-roy / insert.ts
Last active August 26, 2023 12:46
Efficiently insert a number to an already sorted array of numbers. Can easily be extended for other types or objects.
export const getPositionToInsert = (
numbers: number[],
numberToInsert: number
) => {
if (numberToInsert < numbers[0]) return 0;
if (numberToInsert > numbers[numbers.length - 1]) return numbers.length;
const getIndex = (start: number, end: number): number => {
if (numbers[start] === numberToInsert) return start;
if (numbers[end] === numberToInsert) return end;
@anurag-roy
anurag-roy / shiki-github-theme.css
Last active April 24, 2023 15:43
GitHub theme for Shiki using css variables (supports light/dark mode switching). Can be used in Next.js, Nextra, Astro, etc.
:root {
/* Light Theme */
--shiki-color-text: #24292f;
--shiki-color-background: #f6f8fa;
--shiki-token-constant: #0550ae;
--shiki-token-string: #0a3069;
--shiki-token-comment: #6e7781;
--shiki-token-keyword: #cf222e;
--shiki-token-parameter: #116329;
--shiki-token-function: #8250df;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Json to PDF</title>
<script src="https://unpkg.com/jspdf@2.5.1/dist/jspdf.umd.min.js"></script>
</head>
<body></body>
@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
@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();
let input = [{
"id": "REPORT1",
"application": "APP1",
"type": "TYPE1",
"title": ""
},
{
"id": "REPORT2",
"application": "APP1",
"type": "TYPE1",
@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');
# 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