Skip to content

Instantly share code, notes, and snippets.

View niksumeiko's full-sized avatar

Nik Sumeiko niksumeiko

View GitHub Profile
@niksumeiko
niksumeiko / exercises.creditcard.js
Created April 22, 2014 13:12
JavaScript exercise that requires to create credit card input fields validation functions.
/**
* @fileoverview Utils Interface credit card validation methods.
* @author (Wind Tammer)
*/
utils = {};
/** @type {Object<Function>} */
utils.creditcard = {};
@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 / git.migrate
Last active April 30, 2024 12:54
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.
#!/bin/bash
#
# This script will make a webcam snapshot every commit. The jpg file will have
# the commit id as the filename.
#
# This script requires imagesnap. Install with: 'brew install imagesnap'
#
# Put this file in the '.git/hooks/' name it 'post-commit' and chmod it by:
# 'chmod +x .git/hooks/post-commit'
#
@niksumeiko
niksumeiko / git.color
Last active August 29, 2015 13:55
Git command to enable colors for all git commands in Mac OSX Terminal.
# By executing this command in your Mac OSX Terminal, all git commands will have
# colors, so you're more comfortable reading git produced output.
git config --global color.ui true
@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 / utils.getLocalStorageUsedSpace.js
Last active December 24, 2015 15:49
JavaScript function that calculates allocated localStorage memory. Also applicable to get sessionStorage used memory.
/**
* Returns localStorage (or its particular key) allocated memory
* in Megabytes (MB).
* @param {string=} opt_key inside the storage to calculate
* used space for.
* @return {number} with 2 decimal points.
*/
function getLocalStorageUsedSpace(opt_key) {
var allocatedMemory = 0,
@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 / laravel.controllers.users.php
Last active December 22, 2015 06:49
Demonstration of PHP Laravel framework Response class methods that sets custom HTTP status codes in your Controller response. Especially handy when wish to manage your REST API error responses.
<?php
class Users_Controller extends Base_Controller {
public function action_index() {
$id = Input::get('id');
if ($id) {
$user = DB::table('users')->where('id', $id)->first();
@niksumeiko
niksumeiko / jquery.scrollDirection.js
Created July 14, 2013 09:03
jQuery function that identifies page scrolling direction. Used when it's needed to apply different functionality for different (up/down) scrolling directions.
// Variable that is going to hold previous 'document' scrollTop
// value (/vertical scrollbars position).
var prevScrollTop;
// Function that returns 'true' (/boolen) if user scrolls the
// page up, 'false' (/boolen) if user scrolls the page down.
function scrollsUp(scrollTop) {
var before = prevScrollTop;