Skip to content

Instantly share code, notes, and snippets.

View olddustysocksunderthecouch's full-sized avatar

Adrian Bunge olddustysocksunderthecouch

View GitHub Profile
@olddustysocksunderthecouch
olddustysocksunderthecouch / generateBase64ThumbHash.ts
Created June 2, 2024 07:52
Generate Base64 Thumbhash with a Supabase Edge Function
import { SupabaseClient } from "https://esm.sh/@supabase/[email protected]";
import { rgbaToThumbHash } from "https://esm.sh/[email protected]";
import { Image, decode } from "https://deno.land/x/[email protected]/mod.ts";
import * as base64 from "https://denopkg.com/chiefbiiko/base64/mod.ts";
async function generateBase64ThumbHash(
data: ArrayBuffer,
): Promise<string> {
const image = await decode(new Uint8Array(data)) as Image;
image.resize(100, 100);
@olddustysocksunderthecouch
olddustysocksunderthecouch / LivedataExtensions.kt
Last active April 23, 2019 08:28
Kotlin Extensions for Livedata
import androidx.lifecycle.*
import io.reactivex.Flowable
/**
* Description:
* Observe LiveData with LifecycleOwner.
* Usage:
* observe(viewModel.liveData) {
* it ?: return@observe
let arr = [1,2,3,4,5,6];
let even = arr.filter(element => {
return element % 2 === 0;
});
// Result: even = [2,4,6]
let newArr = oldArr.filter(callback);
let newArr = oldArr.filter(callback);
let arr = [1, 2, 3, 4, 5, 6];
let even = [];
for(var i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) even.push(arr[i]);
}
// Result: even = [2,4,6]
let plus5 = arr.map((element) => {
return element + 5;
});
// Result: plus5 = [6,7,8,9]
let newArr = oldArr.map((element, index, arr) => {
// return element to new Array
});
const arr = [1, 2, 3, 4];
let plus5 = [];
for(var i = 0; i < arr.length; i++) {
plus5[i] = arr[i] + 5;
}
//OR WITH FOREACH SYNTAX
arr.forEach((element, index) => {
plus5[index]= element + 5
function numOfArgs(...theArgs) {
console.log(theArgs.length);
}
numOfArgs(); //logs: 0
numOfArgs(5); //logs: 1
numOfArgs(5, 6, 7); //logs: 3