Skip to content

Instantly share code, notes, and snippets.

View motss's full-sized avatar
🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!

The web walker motss

🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!
View GitHub Profile
@motss
motss / detect-ie.js
Last active March 24, 2016 12:02
Feature detection for IEs
// http://stackoverflow.com/questions/10964966/detect-ie-version-prior-to-v9-in-javascript
// http://tanalin.com/en/articles/ie-version-js/
var ie = (function (){
if (window.ActiveXObject === undefined) return null;
if (!document.querySelector) return 7;
if (!document.addEventListener) return 8;
if (!window.atob) return 9;
if (!document.__proto__) return 10;
return 11;
})();
// Given a integer n, output the first n numbers of the Fibonacci sequence efficiently.
// Input: 5
// Output: [1, 1, 2, 3, 5]
function fib(n) {
if (n < 2) {
return 1;
}
@motss
motss / gulpfile.js
Last active May 3, 2016 07:31
minify everything inside bower_components
var gulp = require('gulp');
var del = require('del');
var runSequence = require('run-sequence');
// var minifyHTML = require('gulp-minify-html');
var minifyInline = require('gulp-minify-inline');
var size = require('gulp-size');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var options = {
@motss
motss / route-change-for-Polymer's-<app-route>.js
Last active January 8, 2017 06:36
app-route route change with JS
// Via route property.
this.set('route.path', '/the/new/path')
// Or to change the full absolute url:
window.history.pushState({}, null, '/the/new/absolute/path');
this.fire('location-changed', {node: window});
@motss
motss / awesome-terminal-theme.js
Created August 22, 2016 05:48
To get awesome theme on terminal
// https://github.com/robbyrussell/oh-my-zsh
// https://github.com/wesbos/Cobalt2-iterm
@motss
motss / git-merge-squash-commits.js
Last active January 8, 2017 06:35
git merge squash commits
// http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
@motss
motss / git-fetch-merge-upstream.js
Last active September 2, 2016 15:59
git-fetch-merge-upstream
// https://help.github.com/articles/configuring-a-remote-for-a-fork/
// https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches
// List current configured remote repo for your fork.
git remote -v
// Specify a new remote upstream repo.
git remote add upstream <GITHUB_REPO_URL>
// https://help.github.com/articles/syncing-a-fork/
@motss
motss / install-node-with-intl.js
Last active September 26, 2016 05:15
Install Node with Intl
brew install node --with-intl=full-icu --download-all
// To reinstall with all locales.
brew reinstall node --with-full-icu
@motss
motss / ce-v0_plus_sd-v0-demo.js
Created September 3, 2016 15:33
Custom Element v0 + Shadow DOM v0 demo
const a = document.createElement('div');
document.body.appendChild(a);
const b = document.createElement('template');
b.innerHTML = `
<style>
:host { display: block; box-sizing: border-box; }
.container { background-color: var(--fancy-bg, red);
@media (min-width: 768px) {
@motss
motss / trap-focus-within-modal-dialog.js
Created September 3, 2016 18:09
trap focus within modal dialog
_trapFocusWithinModal (ev, focusableNodes, callback) {
const _kc = ev.keyCode;
if (ev.type === 'keydown' && _kc === TAB_KEY) {
console.log('keyboard tab on:', ev.target, focusableNodes);
// Prevent default TAB operation.
ev.preventDefault();
const _maxAllowableFocusableNodesLength = focusableNodes.length - 1;