Skip to content

Instantly share code, notes, and snippets.

Avatar

Nik Sumeiko niksumeiko

View GitHub Profile
@niksumeiko
niksumeiko / git-checkout-their-remote-branch-ohmyzsh-alias.zsh
Last active Apr 27, 2020
Git checkout their remote branch · ohmyzsh custom alias
View git-checkout-their-remote-branch-ohmyzsh-alias.zsh
# ~/.oh-my-zsh/custom/git-checkout-their-remote-branch-ohmyzsh-alias.zsh
function gcor() {
if [ -n "$1" ]
then
gfo $1
gco -t origin/$1
else
echo "Unspecified branch name"
fi
}
@niksumeiko
niksumeiko / git-rebase-master-ohmyzsh-alias.zsh
Last active Apr 27, 2020
Git rebase current branch onto latest master without switching · ohmyzsh custom alias
View git-rebase-master-ohmyzsh-alias.zsh
# ~/.oh-my-zsh/custom/git-rebase-master-ohmyzsh-alias.zsh
alias grbmo='gup origin master'
@niksumeiko
niksumeiko / sendToNative.ts
Created May 16, 2017
Sending data from webView to native Android/iOS layer in hybrid mobile app
View sendToNative.ts
function sendToNative(data: string) {
if (/android/i.test(window.navigator.userAgent)) {
if (window.quicketNative) {
return window.quicketNative.send(data);
}
}
let frame = document.createElement('iframe');
frame.width = '100';
@niksumeiko
niksumeiko / mongoose-findOrCreate.js
Last active May 15, 2020
Mongoose schema static `findOrCreate` method in ES6/7 async/await syntax
View mongoose-findOrCreate.js
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 / disable-html-form-input-autocomplete-autofill.md
Last active Jul 20, 2021
Disable HTML form input autocomplete and autofill
View disable-html-form-input-autocomplete-autofill.md

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 / object-to-style-attribute.js
Created Jun 30, 2015
Converts style object into the corresponding CSS `style` attribute value
View object-to-style-attribute.js
/**
* Takes a style object and returns the corresponding
* attribute value. Converts camel case property names
* to proper CSS selector names.
* @param {Object} obj Map of CSS properties to values.
* @return {string} The style attribute value.
*/
function toStyleAttribute = function(obj) {
return Object.keys(obj).map(function(key) {
@niksumeiko
niksumeiko / sum-function-arguments.js
Created Jun 30, 2015
Sums up function arguments
View sum-function-arguments.js
/**
* Sums up all given arguments.
* @param {...*} var_args Numbers or numbers alike to sum up.
* Numbers will be added as is, numbers in strings (e.g. '123.45')
* will be converted to numbers and added. NaNs are skipped.
* @return {number} The sum of number arguments.
*/
function sum(var_args) {
var args = [].slice.call(arguments);
@niksumeiko
niksumeiko / promises-chaining.js
Last active Aug 29, 2015
Promises chaining that solves "callbacks hell"
View promises-chaining.js
'use strict';
var Promise = require('promise');
function build() {
return new Promise(function(fulfill, reject) {
fulfill('zero');
});
@niksumeiko
niksumeiko / catching-promise-errors.js
Last active Jul 15, 2017
Catching errors thrown inside Nodejs promise
View catching-promise-errors.js
'use strict';
var Promise = require('promise');
/** @desc A function that returns a promise with an error-prone code. */
function build() {
return new Promise(function(fulfill, reject) {
@niksumeiko
niksumeiko / exercises.creditcard.js
Created Apr 22, 2014
JavaScript exercise that requires to create credit card input fields validation functions.
View exercises.creditcard.js
/**
* @fileoverview Utils Interface credit card validation methods.
* @author (Wind Tammer)
*/
utils = {};
/** @type {Object<Function>} */
utils.creditcard = {};