Skip to content

Instantly share code, notes, and snippets.

View tomtobac's full-sized avatar

Tomeu tomtobac

View GitHub Profile
@leosh1d
leosh1d / deferedPersist.ts
Created December 23, 2022 22:17
Zustand (^4.1.5) persist middleware with deferred hydration.
import { persist, PersistOptions } from "zustand/middleware"
import { StateCreator, StoreApi, StoreMutatorIdentifier } from "zustand/vanilla"
type DeferredPersistOptions<S extends object> = PersistOptions<S> & {
hydrateOnResolve?: Promise<void>
}
const DEFAULT_GET_STORAGE = () => localStorage
export default function deferredPersist<
git_current_branch () {
local ref
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]]
then
[[ $ret == 128 ]] && return
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
fi
echo ${ref#refs/heads/}

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);
@nnja
nnja / config-editor.md
Created October 5, 2017 05:00
Configure git editor

Set which editor git should use.

This is the program that will open during a commit with no -m flag, a merge, a rebase, etc...

Select from any installed editor. Examples:

  • emacs: emacs
  • vi: vi or vim

How to calculate your hourly rate as a freelancer?

Many people struggle with this question. Some just try to make as much as a full-time employee makes (and ignore that they won't be able to bill as many days). Others follow tips on startup related websites that suggest to ask for 20% to 50% more than an salary would yield (and ignore the additional risk and expenses they have).

Below you will find some numbers to help you calculate how high your hourly or daily rate should be.

Your yearly income should be higher than an average salary

  • You take more risk than full time employees, phases without income are likely
@meain
meain / whatasppSpam.js
Last active June 9, 2017 17:15
Whatsapp web spam script
// for send function to select input
function dispatch(target, eventType, char) {
var evt = document.createEvent("TextEvent");
evt.initTextEvent (eventType, true, true, window, char, 0, "en-US");
target.focus();
target.dispatchEvent(evt);
}
// enters input and clicks button
function send(msg){

Git Cheat Sheet

Commands

Getting Started

git init

or

@jlis
jlis / gist:5669677
Created May 29, 2013 11:40
Javascript format function to replace placeholders in a string with content
// usage:
// string.format({key: replacement})
//
// example:
// 'Hello {name}, how are you doing? I am doing {mood}.'.format({name: 'Mike', mood: 'fine'});
String.prototype.format = function() {
var formatted = this;
if (arguments.length && typeof arguments[0] == 'object') {
var vars = arguments[0];
for (v in vars) {