Skip to content

Instantly share code, notes, and snippets.

@mandava
mandava / useCookie.ts
Created January 29, 2024 16:45 — forked from KristofferEriksson/useCookie.ts
A hook to easily read and update browser cookies. Plus, it auto-updates your component when cookie values change
import { useEffect, useState } from "react";
type UseCookieReturnType = {
cookie: string | undefined;
setCookie: (value: string, days?: number) => void;
};
const useCookie = (cookieName: string): UseCookieReturnType => {
const getCookie = (name: string): string | undefined => {
const value = `; ${document.cookie}`;
@mandava
mandava / client.tsx
Created May 15, 2023 16:44 — forked from mishushakov/client.tsx
A React hook for calling Next.js Server Actions from client components
'use client'
import { test } from './server'
import { useServerAction } from './hook'
export default function Home() {
const { data, loading, error, execute: testAction } = useServerAction(test)
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
@mandava
mandava / log.js
Created May 3, 2023 18:54 — forked from vikas5914/log.js
Custom Logger Library with winston
const { createLogger, format, transports } = require('winston')
const moment = require('moment')
// set default log level.
const logLevel = 'info'
var logger = createLogger({
level: logLevel,
levels: {
fatal: 0,
@mandava
mandava / import_backup.py
Created July 30, 2021 01:10 — forked from jehna/import_backup.py
App Engine import data from Datastore Backup to localhost
"""
# App Engine import data from Datastore Backup to localhost
You can use this script to import large(ish) App Engine Datastore backups to your localohst dev server.
## Getting backup files
Follow instructions from Greg Bayer's awesome article to fetch the App Engine backups:
http://gbayer.com/big-data/app-engine-datastore-how-to-efficiently-export-your-data/
@mandava
mandava / tailwind-1-color-update.js
Created September 18, 2020 17:44 — forked from MiniCodeMonkey/tailwind-1-color-update.js
Replaces tailwind 0.x color CSS classes with 1.0 names
const fs = require('fs');
const path = require('path');
/**
* Replaces tailwind 0.x color CSS classes with 1.0 names
* E.g. "bg-grey-light" is replaced with "bg-gray-400"
*
* This is a "dumb" replacement that searches for string patterns across the
* specified files,
*
@mandava
mandava / idea.vmoptions
Created July 26, 2018 14:48
IntelliJ Idea Custom VM Options
-Xmx2048m
-Xms1024m
-XX:NewRatio=1
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops
-Dfile.encoding=UTF-8
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
@mandava
mandava / git_submodules.md
Created June 18, 2018 20:12 — forked from gitaarik/git_submodules.md
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of advantages of using submodules:

  • You can separate the code into different repositories.
@mandava
mandava / nvm.sh
Created June 4, 2018 14:49
Manage Node.js versions using NVM
# List all installed versions.
nmv ls
# Install a specific version.
nvm install 9.6.0
# Use a specific version.
nvm use 9.6.0
# Set the Default Version.

Effective Engineer - Notes

What's an Effective Engineer?

  • They are the people who get things done. Effective Engineers produce results.

Adopt the Right Mindsets

@mandava
mandava / resize_local_machine.sh
Created November 27, 2017 03:05 — forked from claygriffiths/resize_local_machine.sh
Resize Local by Flywheel VirtualBox image
# Steps we will take:
# 1. Change Local (Docker Machine) image type (this will take a bit)
# 2. Resize image
# 3. Resize partion
#
# Also see: https://docs.docker.com/articles/b2d_volume_resize/
# IMPORTANT: Make sure Local is not running!
VM_NAME="local-by-flywheel"
NEW_DISK_SIZE=50000