Skip to content

Instantly share code, notes, and snippets.

View Meldiron's full-sized avatar
♥️

Matej Bačo Meldiron

♥️
View GitHub Profile
@Meldiron
Meldiron / timezone-awareness.js
Created September 6, 2022 08:55
Methods for converting dates between input type="datetime-local" and server-acceptable ISO 8610 format with timezone awareness.
function prefixWithZero(value, minLength = 2) {
value = value + "";
while (value.length < minLength) {
value = `0${value}`;
}
return value;
}
@Meldiron
Meldiron / scrypt-modified.md
Created June 17, 2022 09:11
What is Scrypt Modified? 🤔

Scrypt is a hashing algorithm first published in 2009 to address the security of passwords stored in a database. Generating such a hash is computationally intensive, meaning it takes a "long" time to generate a hash. This is fast enough for the sign-in process but makes it extremely costly to attempt brute-force to crack an existing password's hash.

SCrypt Modified is a fork of this algorithm. From its documentation, the intentions of the fork are unclear.

While official SCrypt takes password and salt to generate the hash, modified has a few additional steps:

  1. Generate derivedKey by creating a Scrypt hash where password is utf8-encoded, and salt is base64-decoded salt + base64-decoded salt separator
  2. Generate hash by encrypting base64-decoded signerKey with aes-256-ctr where key is the first 32 characters of derivedKey, while using an empty initialization vector of length 16
  3. Final hash must be base64-encoded
@Meldiron
Meldiron / docker-compose.yml
Last active March 16, 2022 09:23
File not found fix
version: '3'
services:
traefik:
image: traefik:2.5
container_name: appwrite-traefik
command:
- --providers.file.directory=/storage/config
- --providers.file.watch=true
- --providers.docker=true
- --providers.docker.exposedByDefault=false
@Meldiron
Meldiron / backup.sh
Last active April 23, 2024 14:38
Backup and Restore Appwrite, the lazy way 🐌
# Make sure to stop Appwrite before this backup,
# and make sure you have enough space on the machine.
# After backing up, make sure there is a file in 'backups/backup-___.tar.gz'.
# Also please check size of this file, it should be at least 5kb, even for small instances.
docker run --rm \
-v appwrite_appwrite-mariadb:/backup/appwrite-mariadb \
-v appwrite_appwrite-redis:/backup/appwrite-redis \
-v appwrite_appwrite-cache:/backup/appwrite-cache \
@Meldiron
Meldiron / appwrite-categories.ts
Created January 19, 2022 10:12
Almost Netflix Web - Snippets
export type AppwriteCategory = {
title: string;
queries: string[];
orderAttributes: string[];
orderTypes: string[];
collectionName?: string;
}
export const AppwriteMovieCategories: AppwriteCategory[] = [
{
@Meldiron
Meldiron / offset_and_cursor.csv
Created January 10, 2022 12:07
Offset pagination article data (2)
Offset pagination (ms) Cursor pagination (ms)
0% offset 3.73 6.27
10% offset 52.39 4.07
20% offset 96.83 5.15
30% offset 144.13 5.29
40% offset 216.06 6.65
50% offset 257.71 7.26
60% offset 313.06 4.61
70% offset 371.03 6.00
80% offset 424.63 5.60
@Meldiron
Meldiron / offset.csv
Last active January 10, 2022 12:06
Offset pagination article data
Offset pagination (ms)
0% offset 3.73
10% offset 52.39
20% offset 96.83
30% offset 144.13
40% offset 216.06
50% offset 257.71
60% offset 313.06
70% offset 371.03
80% offset 424.63
@Meldiron
Meldiron / app.ts
Created August 16, 2021 10:07
Typescript snippet for sync-like function execution in Appwrite
// This snippets expect that your functions use JSON as both input and output
// Connect to appwrite, should be globaly shared
let sdk = new Appwrite();
sdk
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
.setProject("5df5acd0d48c2"); // Your project ID
// Shared type for strict type definition
@Meldiron
Meldiron / app.ts
Last active August 1, 2021 11:01
Typescript: Get current weekdays
// v1.0.1
// consts
const weekInMs = 1000 * 60 * 60 * 24 * 7;
const dayInMs = 1000 * 60 * 60 * 24;
// main function
const getWeekArray = (currentDate: Date, page: number) => {
if (page > 0) {
currentDate = new Date(currentDate.getTime() + weekInMs * page); // Add X weeks where X is page