Skip to content

Instantly share code, notes, and snippets.

View or9's full-sized avatar

Rahman Malik or9

  • Detroit
View GitHub Profile
@or9
or9 / xlsx.mjs
Last active June 24, 2024 14:25
Heavy handed approach adds text wrapping to all cells exported by SheetJS library
/**
* Heavy handed approach adds text wrapping to all cells.
* Doesn't seem to break anything for other field types….
* Haven't thoroughly tested.
* New:
<cellXfs count="2">
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1">
<alignment wrapText="true"/>
</xf>
<xf numFmtId="3" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1">
@or9
or9 / ffmpeg.sh
Created July 25, 2022 02:19
ffmpeg combine photos into video
#!/bin/sh -e
# Just the base command required to run ffmpeg docker image
# Probably need to append additional arguments such as
# -i input_file.ext
# -parm1 arg
# -parm2 arg
# output_filename.ext
docker run \
@or9
or9 / PriorityQueue.mjs
Created February 24, 2021 13:39
Example heap implementation from Mike Peritz for comparison purposes via https://codeburst.io/implementing-a-complete-binary-heap-in-javascript-the-priority-queue-7d85bd256ecf
class PriorityQueue {
constructor() {
this.heap = [null]
}
insert(value, priority) {
const newNode = new PriorityQueueNode(value, priority);
this.heap.push(newNode);
let currentNodeIdx = this.heap.length - 1;
let currentNodeParentIdx = Math.floor(currentNodeIdx / 2);
@or9
or9 / BinarySearchTree.js
Last active January 9, 2021 02:43
Binary search tree stuff
class Node {
constructor (value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor () {
@or9
or9 / repeated_strings.js
Created January 5, 2021 22:13
Hackerrank stuff
function repeatedString(s, n) {
if (n < 1) return 0;
let initialMatches = s.match(/a/gm);
// Hackerrank is not down with nullish coalesce or even optional chaining AT ALL
// Otherwise, you could simply say if (!initialMatches?.length)
if (!initialMatches || !initialMatches.length) return 0;
if (n < initialMatches.length) {
return n;
@or9
or9 / kth_element.js
Created January 2, 2021 23:39
Extract the kth element from a list of lists without a heap
function kth (m, k) {
return m.reduce((curr, next) => curr.concat(next))
.sort((x, y) => x >= y? 1: -1)
[k];
}
// e.g., [[1, 5, 9], [10, 11, 13], [12, 13, 15]], 7
@or9
or9 / sort_asc_linkedlist.js
Created January 2, 2021 23:20
Sort linked list
[
{ "node": 1, "link": 4 },
{ "node": 4, "link": 5 },
{ "node": 5, "link": null },
{ "node": 1, "link": 3 },
{ "node": 3, "link": 4 },
{ "node": 4, "link": null },
{ "node": 2, "link": 6 },
{ "node": 6, "link": null }
]
@or9
or9 / least frequently used cache.js
Last active December 21, 2020 03:28
Linked list exercise
class LFUCache {
constructor(capacity) {
this.capacity = capacity;
this.lru = [];
this.cache = Object.create(null, {});
}
get(key) {
if (!this.cache[key]) return -1;
@or9
or9 / isAsc.js
Created April 26, 2020 02:37
Check if an array of numbers is ascending.
function isAsc (list = []) {
return list.reduce((curr, acc, index, arr) => {
if (curr === false) return false;
if (acc > curr) {
if (index === arr.length - 1) {
return true;
} else {
return acc;
}
@or9
or9 / Trie.js
Last active April 8, 2020 13:35
Javascript Trie class
class TrieNode {
constructor (word) {
this.word = word;
this.nodes = {};
this.end = false;
}
}
export default class Trie {
constructor (word) {