Skip to content

Instantly share code, notes, and snippets.

View niksumeiko's full-sized avatar

Nik Sumeiko niksumeiko

View GitHub Profile
@niksumeiko
niksumeiko / EXERCISE.md
Last active June 30, 2024 20:33
Exercise for React Native developer job technical interview

Overview

Provide weather and water forecasts to the customer to find a good day for a swim.

Acceptance criteria

  1. Create a view to display the following information:
    • Title
    • Location (static)
  • Day selector
// AuthProvider.tsx (this is an abstraction)
type AuthProvider = () => {
getToken(): Promise<string>;
};
export const {
useContext,
createContextProvider: provideAuth,
} = createGenericContext<AuthProvider>();
@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 / 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 / sendToNative.ts
Created May 16, 2017 10:15
Sending data from webView to native Android/iOS layer in hybrid mobile app
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 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 / disable-html-form-input-autocomplete-autofill.md
Last active October 8, 2024 10:08
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 / object-to-style-attribute.js
Created June 30, 2015 08:32
Converts style object into the corresponding CSS `style` attribute value
/**
* 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 June 30, 2015 08:03
Sums up function arguments
/**
* 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 August 29, 2015 14:23
Promises chaining that solves "callbacks hell"
'use strict';
var Promise = require('promise');
function build() {
return new Promise(function(fulfill, reject) {
fulfill('zero');
});