Skip to content

Instantly share code, notes, and snippets.

View mstaicu's full-sized avatar

Mircea Staicu mstaicu

  • Earth
View GitHub Profile
@mstaicu
mstaicu / mongoose.mjs
Last active November 5, 2024 14:30
MongoDB document migrate script from ObjectId to UUID
import mongoose from "mongoose";
import { randomUUID } from "node:crypto";
const relatedCollections = {
users: [
{ collectionName: "posts", foreignKey: "userId" },
],
};
async function dropIndexes(collectionName, db) {
@mstaicu
mstaicu / avl.mjs
Last active August 17, 2024 17:12
Functional Mixing to add AVL behaviour to a node object with a custom comparison function for generic data types as node values
var defaultCompare = (a, b) => {
if (a < b) return -1;
if (a > b) return 1;
return 0;
};
var withAvl =
(compareFn = defaultCompare) =>
(node) => {
function insert(value, currentNode) {
@mstaicu
mstaicu / withRedisCache.mjs
Last active October 19, 2024 09:53
Mongoose Redis cache functional mixin
/**
* Usage:
*
import mongoose from "mongoose";
import cacheMixin from "./cacheMixin.js";
withRedisCache(redis, mongoose.Query.prototype);
After that, any model can call .cache({ key: userId }); to enable caching
*/
@mstaicu
mstaicu / README.md
Last active December 5, 2023 13:42
Barebones NATS JetStream clustering in Kubernetes with PVC and no Helm charts
import crypto from "crypto";
import { renderToStaticMarkup } from "react-dom/server";
import createMailgun from "mailgun-js";
import type { ActionFunction, LoaderFunction, Session } from "remix";
import { createCookieSessionStorage, json, redirect } from "remix";
/*******************************************************************************
* Before we can do anything, we need to make sure the environment has
* everything we need. If anything is missing, we just prevent the app from
* starting up.
@mstaicu
mstaicu / VibrateModule.java
Created July 8, 2021 11:59
React Native BroadcastReceiver Vibrations
package com.mindfulness.vibrate;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
@mstaicu
mstaicu / mellon.sh
Created January 14, 2021 15:37
Debug shell scripts
#!/bin/bash
trap '(read -p "[$BASH_SOURCE:$LINENO] $BASH_COMMAND?")' DEBUG
var="mellon"
echo "$var"
@mstaicu
mstaicu / package.json
Created September 30, 2020 15:08
npx test
{
"name": "testing-npx",
"version": "1.0.0",
"description": "Let's see how awesome this is",
"bin": "./run.js"
}
@mstaicu
mstaicu / semaphore.js
Last active September 12, 2020 11:36
@nybblr inspired semaphore solution for limiting concurrent execution
/**
* OOP paradigm
*/
class Semaphore {
constructor(max) {
this.tasks = [];
this.counter = max;
this.dispatch = this.dispatch.bind(this);
}
@mstaicu
mstaicu / osx-for-hackers.sh
Created November 9, 2019 12:51 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx