Skip to content

Instantly share code, notes, and snippets.

View niksumeiko's full-sized avatar

Nik Sumeiko niksumeiko

View GitHub Profile
// AuthProvider.tsx (this is an abstraction)
type AuthProvider = () => {
getToken(): Promise<string>;
};
export const {
useContext,
createContextProvider: provideAuth,
} = createGenericContext<AuthProvider>();
@niksumeiko
niksumeiko / git.migrate
Last active April 25, 2024 04:04
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@niksumeiko
niksumeiko / disable-html-form-input-autocomplete-autofill.md
Last active April 22, 2024 17:49
Disable HTML form input autocomplete and autofill

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...
@niksumeiko
niksumeiko / git-checkout-their-remote-branch-ohmyzsh-alias.zsh
Last active November 10, 2021 06:29
Git checkout remote branch · ohmyzsh custom alias
# ~/.oh-my-zsh/custom/git-checkout-remote-branch-ohmyzsh-alias.zsh
unalias gcor
function gcor() {
if [ -n "$1" ]; then
if git show-ref -q --heads $1; then
gco $1
else
gfo $1
gco -t origin/$1
fi
@niksumeiko
niksumeiko / handlebars.helpers.ifEquals.js
Created October 1, 2013 12:02
Handlebars.js templates engine custom IF condition helper. Allows to compare values one to each other like you are used to in programming.
// Compares first value to the second one allowing entering IF clouse if true.
// Otherwise entering ELSE clause if exist.
Handlebars.registerHelper('ifEquals', function(a, b, options) {
if (a === b) {
return options.fn(this);
}
return options.inverse(this);
});
@niksumeiko
niksumeiko / mongoose-findOrCreate.js
Last active May 15, 2020 23:53
Mongoose schema static `findOrCreate` method in ES6/7 async/await syntax
import mongoose from 'mongoose';
let schema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true }
});
schema.statics.findOrCreate = async (conditions, opt_attr) => {
let document = await User.findOne(conditions);
@niksumeiko
niksumeiko / git-rebase-master-ohmyzsh-alias.zsh
Last active April 27, 2020 09:55
Git rebase current branch onto latest master without switching · ohmyzsh custom alias
# ~/.oh-my-zsh/custom/git-rebase-master-ohmyzsh-alias.zsh
alias grbmo='gup origin master'
@niksumeiko
niksumeiko / utils.numberToDay.js
Last active February 7, 2020 18:29
JavaScript function that converts a number into the 2 digits day of the month with leading zeros (01-31). Very useful when working with the output that holds days of the month without leading zeros (1-31).
/**
* Turns a number/string to 2 digits day of the month with leading zero.
* @param {number|string} day to turn into day.
* @return {string}
*/
function numberToDay(j) {
return ('0' + j).slice(-2);
}
// Examples:
@niksumeiko
niksumeiko / gslint.conf
Created April 7, 2014 10:53
Sample Closure Linter configuration file used within WebStorm IDE
--strict
--jsdoc
--summary
--beep
--check_html
--nomultiprocess
--debug_indentation
--time
@niksumeiko
niksumeiko / webstorm.watchers.handlebars.xml
Last active September 8, 2017 17:21
Handlebars templates watcher for WebStorm 6. Watcher complies Handlebars template file to a JavaScript file on every change.
<?xml version="1.0" encoding="UTF-8"?>
<TaskOptions>
<TaskOptions>
/*
* Compiled .js files are saved into generated '/compiled' folder.
*/
<option name="arguments" value="$FileDir$/$FileName$ -f $FileDir$/compiled/$FileNameWithoutExtension$.js" />
<option name="checkSyntaxErrors" value="false" />
<option name="description" value="Compiles .handlebars, .hbs templates into .js files" />
<option name="exitCodeBehavior" value="ERROR" />