Skip to content

Instantly share code, notes, and snippets.

View Alex1990's full-sized avatar
🐢
Get Things Done!

Alex Chao Alex1990

🐢
Get Things Done!
View GitHub Profile
@Alex1990
Alex1990 / isEqual.js
Created March 17, 2017 14:36
Lodash's isEqual method
/*
- null
- undefined
- number
- NaN
- string
- boolean
- number/string/boolean wrapper objects
- regexp
/**
* Prints a warning in the console if it exists.
*
* @param {String} message The warning message.
* @returns {void}
*/
export default function warning(message) {
/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message)
/**
* Ref: https://github.com/reactjs/redux/blob/master/src/compose.js
*
* Composes single-argument functions from right to left. The rightmost
* function can take multiple arguments as it provides the signature for
* the resulting composite function.
*
* @param {...Function} funcs The functions to compose.
* @returns {Function} A function obtained by composing the argument functions
* from right to left. For example, compose(f, g, h) is identical to doing
// Use rest operator and reduce method
function sum(...args) {
return args.reduce((a, b) => a + b);
}
@Alex1990
Alex1990 / repeat.js
Last active March 8, 2017 12:54
Repeat the specified string with n times.
if (typeof String.prototype.repeat !== function) {
Object.defineProperty(String.prototype, 'repeat', {
configurable: true,
enumerable: false,
writable: true,
value: function (n) {
let result = '';
while (n--) {
result += this;
}
@Alex1990
Alex1990 / getUnusedPorts.sh
Last active September 22, 2016 07:58
Find available ports in bash
#!/usr/bin/env bash
# Get available ports to be used by webpack-dev-server and mock server.
IP=127.0.0.1
start_port=8000
end_port=8100
scanner() {
local port="$start_port"
@Alex1990
Alex1990 / pagination.md
Created July 13, 2016 16:00 — forked from mislav/pagination.md
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@Alex1990
Alex1990 / d3-tip-browserify.js
Created July 5, 2016 06:47 — forked from Willmo36/d3-tip-browserify.js
d3-tip with browserify and webpack
let d3 = require("d3");
let d3tip = require("d3-tip");
d3tip(d3);
@Alex1990
Alex1990 / renderOptions.js
Created June 18, 2016 16:44
Render the <option>s by the settings.
/**
* Redner the <option>s by the settings
*/
function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}
function renderOptions(settings) {
var options = settings.options || [];
@Alex1990
Alex1990 / getCheckedValue.js
Created June 13, 2016 03:20
Get the value of the checked checkbox or radio.
/**
* Get the value of the checked checkbox(s) or radio.
* @param {Element} inputs the input:checkbox or input:radio elements
* @return {String|Array} the checkec value
*/
function getCheckedValue(inputs) {
var val;
var len = inputs.length;
if (inputs[0].type === 'checkbox') {