Skip to content

Instantly share code, notes, and snippets.

@jeremiah-ang
jeremiah-ang / PrettyObjectPrinter
Created June 19, 2017 08:35
A function to print javascript object nicely
PrettyObjectPrinter.prototype.objectToString = function (obj, brackets, spacing, space='') {
if (typeof obj != "object")
return obj;
var acc = "";
var commaFlag = false;
for (var key in obj) {
acc += ((commaFlag) ? ",\n" : "") + space + key + ": ";
acc += this.print (obj[key], brackets, spacing, space);
commaFlag = true;
@jeremiah-ang
jeremiah-ang / pattern_in_array_finder.js
Created June 20, 2017 06:33
Few functions to help search for a matches of a substring in an array
var arr = [
'1 Chronicles', '1 Corinthians', '1 John', '1 Kings',
'1 Peter', '1 Samuel', '1 Thessalonians', '1 Timothy',
'2 Chronicles', '2 Corinthians', '2 John', '2 Kings',
'2 Peter', '2 Samuel', '2 Thessalonians', '2 Timothy',
'3 John', 'Acts', 'Amos', 'Colossians',
'Daniel',
'Deuteronomy', 'Ecclesiastes', 'Ephesians', 'Esther',
'Exodus', 'Ezekiel', 'Ezra', 'Galatians',
'Genesis', 'Habakkuk', 'Haggai', 'Hebrews',
@jeremiah-ang
jeremiah-ang / execute-java-test.sh
Last active August 23, 2017 05:22
Execute java project with input and output
#!/bin/sh
# Set variables
PROJECT_NAME=$1
PROJECT_NAME_LOWER=$(echo $PROJECT_NAME | tr '[:upper:]' '[:lower:]')
TEST_CASE=$PROJECT_NAME_LOWER$2
PATH_TO_TEST_INPUTS=input
PATH_TO_TEST_OUTPUTS=output
echo "Project: $PROJECT_NAME"
@jeremiah-ang
jeremiah-ang / asyncAwait.js
Created June 8, 2020 13:05
Converting callback to promises to async/await
// Async Await
function showLoading() {
console.log('Loading...');
}
function populateTable(data) {
console.log(`populate table with ${data}`);
}
function updatePagination(count) {
console.log(`Pagination: ${count}`);
const a = {
foo: function (target) {
return this === target;
},
bar: function() {
return (target) => this === target;
}
}
b = {
@jeremiah-ang
jeremiah-ang / esm-package.md
Created February 16, 2022 03:08 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@jeremiah-ang
jeremiah-ang / README.md
Created March 15, 2018 08:12
Single-Pass In-Memory Indexing