Skip to content

Instantly share code, notes, and snippets.

View lilpolymath's full-sized avatar
:octocat:
Exploring

Favour lilpolymath

:octocat:
Exploring
View GitHub Profile
@lilpolymath
lilpolymath / iframechange.js
Created February 8, 2023 12:23 — forked from hdodov/iframechange.js
HTML iframe URL change listener for tracking when a new iframe page starts to load
function iframeURLChange(iframe, callback) {
var lastDispatched = null;
var dispatchChange = function () {
var newHref = iframe.contentWindow.location.href;
if (newHref !== lastDispatched) {
callback(newHref);
lastDispatched = newHref;
}
@lilpolymath
lilpolymath / index.ts
Last active October 18, 2022 09:17
Electron
/* eslint-disable-line global-require */
import {
app,
BrowserWindow,
BrowserView,
ipcMain,
IpcMainEvent,
} from 'electron';
@lilpolymath
lilpolymath / LRUCache.md
Created April 12, 2022 14:30
Implementing a given cache size behaving as an LRU cache with an expiry time and auto cache burst

Question

Implement Promise based memoization with a given cache size behaving as an LRU cache with an expiry time and auto cache burst.

Answer

First, what we have to do is breakdown the terms in the problem statement to understand what is going on and what we are asked to do.

  1. Promise based memoization: Memoization is one of the ways we can improve the performance of functions by eliminating redundant calls. Memoization is a technique where we store the results of a function call in a cache and return the result from the cache if the function is called again with the same arguments.
@lilpolymath
lilpolymath / rename.sh
Created May 3, 2021 16:22
How to change the file extension of multiple files
zsh -c "autoload zmv && zmv '(*).js' '\$1.jsx'"
Convertinf *.js -> *.jsx
@lilpolymath
lilpolymath / eval.js
Last active December 4, 2021 06:22
An expression evaluator in JavaScript.
const WHITESPACE = /\s/;
const NUMBER = /[0-9]/;
const OPERATORS = /[+\-/*()^]/;
const NICHED_OPERATORS = /[+\-/*^]/;
const NUMALPHABET = /[0-9\.]/;
const OPERATOR_PRECEDENCE = { '*': 2, '/': 2, '+': 1, '-': 1 };
const tokenize = expression => {
let cursor = 0;
let tokens = [];
const tokenizer = code => {
let cursor = 0;
let tokens = [];
const KEYWORDS = /\b(False|None|True|and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b/;
const IDENTIFIERS = /([A-Za-z_][A-Za-z0-9_]*)/;
const LETTER = /([A-Za-z]|a-z][_])/;
const DIGITS = /[0-9]+/;
const NUMBER = /[0-9]/;
@lilpolymath
lilpolymath / fonts.scss
Created April 7, 2021 16:15
SCSS mixin to load fonts.
@mixin font($font-family, $font-file, $font-weight) {
@font-face {
font-family: $font-family;
// Add font types here
src: url($font-file+'.ttf') format('truetype');
font-weight: $font-weight;
font-style: normal;
font-display: swap;
}
}
@lilpolymath
lilpolymath / MooreVoting.js
Created March 29, 2021 04:23
An implementation of Moore's Voting Algorithm
export const isMajority = (arr, candidate_index) => {
const candidate = arr[candidate_index];
let count = 0;
const halfSize = arr.length / 2;
for (let i = 0; i < arr.length; i++) {
if (candidate === arr[i]) {
count++;
}
image: reactnativecommunity/react-native-android
pipelines:
custom:
no-test:
- step:
name: Build without Test
caches:
- node
- gradle
@lilpolymath
lilpolymath / grid-gen.scss
Created January 15, 2021 21:47
Dynamic Grid generator
// Chnage these as per your requirement
$columns: 1, 2, 3;
// these are just placeholders for reference, change the actual values in mixin: grid-gen
// $breakpoints: "sm", "md", "lg", "xl";
// $breakpoint-sizes: 576px, 768px, 992px, 1200px;
// creates CSS grid template columns with $columns
@mixin mk-columns($breakpoint) {
@each $column in $columns {