Skip to content

Instantly share code, notes, and snippets.

@aada
aada / countries.json
Created March 11, 2023 10:52 — forked from keeguon/countries.json
A list of countries in JSON
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
load and get sheet data
@aada
aada / parse_lambda_execution_log.js
Created August 12, 2020 18:32
parse cloudwatch lambda logs
const lambda_report_pattern = /REPORT RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\s{1,}Duration: (\d{1,}.\d{1,}) ms\s{1,}Billed Duration: (\d{1,}) ms\s{1,}Memory Size: (\d{1,}) MB\s{1,}Max Memory Used: (\d{1,}) MB/;
const lambda_start_pattern = /START RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\s{1,}Version: /;
const lambda_end_pattern = /END RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/;
const lambda_report_example = `REPORT RequestId: 4af5ccd9-fef7-11e8-8de1-bfd74775c3f5 Duration: 38.07 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 32 MB`;
const lambda_start_example = `START RequestId: 698e4612-06da-43ee-93d1-623b6946bc24 Version: $LATEST`;
const lambda_end_example = `END RequestId: 698e4612-06da-43ee-93d1-623b6946bc24`;
if (lambda_report_pattern.test(lambda_report_example)) {
@aada
aada / UTF8byteLength.js
Created April 29, 2020 04:54 — forked from lovasoa/UTF8byteLength.js
Compute the length in bytes of a javascript string, when encoded in UTF8
function byteLength(str) {
// returns the byte length of an utf8 string
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
}
return s;
const delay = ms => {
return new Promise(res => {
setTimeout(res, ms);
});
};
const run = () => {
const promise = MakeQuerablePromise(delay(1000));
console.log(promise.isPending());
};
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Node Inspector",
"type": "node",
"request": "launch",
const PromiseAll = (inputArray, asyncFunction) => {
const promises = inputArray.map((input, index) => {
return asyncFunction(input)
.then(e => {
return { in: input, out: e, status: 'resolved', index };
})
.catch(e => {
return { in: input, err: e, status: 'rejected', index };
});
});
//
export async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
export function split(arr, n) {
var res = [];
while (arr.length) {
res.push(arr.splice(0, n));
@aada
aada / inmemory-webpack-compiler.js
Created September 28, 2019 02:44 — forked from kisenka/inmemory-webpack-compiler.js
Webpack in-memory filesystem
var webpack = require('webpack');
var MemoryFS = require('memory-fs');
var SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDependency');
var fs = new MemoryFS();
fs.mkdirpSync('/src');
fs.writeFileSync('/src/app.js', 'require("./dep.js")', 'utf-8');
fs.writeFileSync('/src/dep.js', 'module.exports = function(msg){console.log(msg)}', 'utf-8');
fs.writeFileSync('/src/extra-entry.js', 'require("./dep.js")', 'utf-8');
@aada
aada / readme.md
Last active August 29, 2015 14:08
Compiling templates at runtime

make sure you add SpacebarsCompiler package with meteor add SpacebarsCompiler