Skip to content

Instantly share code, notes, and snippets.

View amir-arad's full-sized avatar

Amir Arad amir-arad

  • Tel-aviv, Israel
View GitHub Profile
const dataUrlPrefix = "data:application/octet-stream;base64,";
export async function bufferToBase64(buffer: Uint8Array): Promise<string> {
const base64url = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.readAsDataURL(new Blob([buffer]));
});
return base64url.slice(dataUrlPrefix.length);
@amir-arad
amir-arad / snippet.js
Created September 13, 2022 18:43
download pgotobucket gallery
/*
To use this:
1. paste the following code in chrome developer tools
*/
const { downloadZip } = await import(
"https://cdn.jsdelivr.net/npm/client-zip/index.js"
);
async function allImgs() {
const res = new Set();
@amir-arad
amir-arad / README.md
Created July 22, 2022 18:53
save/load feature for colyseus schema objects

I'm adding a save/load feature to my WIP game and thought someone might find this small module useful

example usage:

const saveGameData = new SaveGame(); // make a custom schema for saved games data
... /* add all state objects from your game manager to saveGameData */
const serialized = await schemaToString(saveGameData);
... /* save to file, read from file etc. */
const loadedGameData: SaveGame = await stringToSchema(SaveGame, serialized );
... /* take game state object from loadedGameData into your game manager */
@amir-arad
amir-arad / definitions.json
Created January 19, 2022 12:12
rabbitMQ test setup
{
"users": [
{
"name": "test",
"password": "test",
"tags": "administrator"
}
],
"vhosts": [
{
@amir-arad
amir-arad / convert.js
Created November 28, 2021 11:36
convert folder of markdown files to google docs in windows
const fs = require('fs');
const path = require('path');
var execSync = require('child_process').execSync;
const getAllFiles = function (dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
@amir-arad
amir-arad / meckano.js
Created October 31, 2021 16:05
meckano monthly report clock faker
const endTime = [];
const WORK_DAY_TIME_RANGE = {
half: {
min: 450,
max: 550
},
full: {
min: 540,
max: 660
}
@amir-arad
amir-arad / gist:ec7c286ff59be2621ecff592f4980409
Created August 3, 2021 16:13
a typescript map that generates default values if none exists
/**
* a map that generates default values if none exists
*/
export class MagicMap<K,V> extends Map<K,V> {
constructor(private defVal: () => V){
super();
}
has = (key:K) => true;
get = (key:K): V => {
// originally copied from https://gist.github.com/amir-arad/3c140b3c44b81dcc1ec108e109355c27
export type LineData = {
name: string;
y: number[];
x: number[];
};
export type GraphPointInput = {
annotate: (t: string) => unknown;
@amir-arad
amir-arad / ploty-graph-builder.ts
Created November 22, 2020 09:10
ploty graph builder
export type LineData = {
name: string;
y: number[];
x: number[];
};
export type GraphPointInput = {
annotate: (t: string) => unknown;
addtoLine: (n: string, v: number) => unknown;
};
export class PlotlyGraphBuilder {
@amir-arad
amir-arad / Starwards-CLA.md
Last active July 2, 2020 08:42 — forked from merqurio/CLA.md
Starwards CLA

Contributor License Agreement

The following terms are used throughout this agreement:

  • You - the person or legal entity including its affiliates asked to accept this agreement. An affiliate is any entity that controls or is controlled by the legal entity, or is under common control with it.
  • Starwards - a project whose digital assets are stored under github's starwards organization (https://github.com/starwards), owned by Amir Arad.
  • Project - is an umbrella term that refers to any and all Starwards's projects.
  • Contribution - any type of work that is submitted to a Project, including any modifications or additions to existing work.
  • Submitted - conveyed to a Project via a pull request, commit, issue, or any form of electronic, written, or verbal communication with Starwards's contributors or maintainers.

1. Grant of Copyright License.