Skip to content

Instantly share code, notes, and snippets.

View Tombarr's full-sized avatar
:octocat:
Coding

Tom Barrasso Tombarr

:octocat:
Coding
View GitHub Profile
@Tombarr
Tombarr / multi-upload.js
Created June 20, 2024 01:06
AWS SDK v3 - S3 Multipart Upload
const {
CreateMultipartUploadCommand,
UploadPartCommand,
CompleteMultipartUploadCommand,
AbortMultipartUploadCommand,
S3Client,
} = require('@aws-sdk/client-s3');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
@Tombarr
Tombarr / InfiniteScroll.svelte
Created May 1, 2023 22:04
Infinite scroll Svelte component that appends DOM elements in increments of page sizes as the user scrolls beyond a threshold
<!--
InfiniteScroll.svelte
Author: Tom Barrasso
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
@Tombarr
Tombarr / object_iterator.js
Created May 7, 2019 00:55
Make all Objects iterable in ES6
Object.prototype[Symbol.iterator] = function() {
let props = Object.getOwnPropertyNames(this);
return {
next: () => {
let name = props.shift();
let done = (name === undefined);
let value = (done) ? undefined : [name, this[name]];
return { value, done };
}
}
const hashCode = str => Array.from(str)
.reduce((h, c) => Math.imul(31, h) + c.charCodeAt(0) | 0, 0)
@Tombarr
Tombarr / zip2.js
Created March 26, 2019 13:04
Zip multiple arrays (of equal length) using Symbol.iterator
function zip(...arrs) {
let i = -1;
return {
[Symbol.iterator]() {
return this;
},
next: () => ({
done: ++i === arrs[0].length,
value: arrs.map(arr => arr[i])
})
@Tombarr
Tombarr / function_passing.ex
Created January 19, 2019 23:22
Functions as arguments in Elixir
add_ten = fn (x) -> x + 10 end
do_a_thing_to_x = fn (thing, x) ->
thing.(x)
end
do_a_thing_to_x.(add_ten, 10) # 20
@Tombarr
Tombarr / function_passing.js
Created January 19, 2019 23:22
Functions as arguments in Javascript
const addTen = (x) => x + 10;
const doAThingToX = (thing, x) => thing(x);
doAThingToX(addTen, 10); // 20
@Tombarr
Tombarr / default_args.ex
Created January 19, 2019 23:21
Default function arguments in Elixir
def add_ten(x \\ 10) do
x + 10
end
add_ten() # 20
@Tombarr
Tombarr / default_args.js
Created January 19, 2019 23:20
Javascript default function arguments
const addTen = (x = 10) => {
return x + 10;
};
addTen(); // 20
@Tombarr
Tombarr / function.ex
Last active January 19, 2019 23:16
Functions and lambdas in Elixir
def add_ten(x) do
x + 10
end
add_five = fn x -> x + 5 end
add_two = &(&1 + 2)
add_ten(10) # 20
add_five.(10) # 15
add_two.(10) # 12