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 / setup-babun.md
Created October 29, 2016 15:39
Babun - your favorite Windows Shell
@motss
motss / encodeURIComponentForFirebase.js
Last active November 17, 2016 14:19
strict encodeURIComponent for Firebase
// Strict escaping symbols not accepting by Firebase.
// https://www.firebase.com/docs/web/guide/understanding-data.html#section-creating-references
// Data Limits - A child node's key cannot be longer than 768 bytes, nor deeper than 32 levels.
// It can include any unicode characters except for . $ # [ ] / and ASCII control characters 0-31 and 127.
function encodeURIComponentForFirebase(str) {
return encodeURIComponent(str).replace(/[\.\#\$\[\]]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16);
});
},
@motss
motss / play_and_reverse_using_<Element.animate>.js
Last active November 21, 2016 14:35
play and reverse using Element.animate
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<base href="https://polygit2.appspot.com/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<script>
@motss
motss / deploy-to-firebase.sh
Created December 10, 2016 10:43
deploy-to-firebase Bash script
#! /bin/bash
clear
echo -e "#1 - Removing build/ directory for a fresh build of the project..."
if [ -d "build/" ]; then
rm -rf build/
fi
echo -e "\n#2 = Building project..."
@motss
motss / errors-indexeddb-sw.md
Created December 12, 2016 04:44
app-indexeddb-mirror not copied in build & not cached by sw
@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 / 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 / convert-native-date-object-with-timezone-offset.js
Created January 12, 2017 08:48
Convert native Date object with timezone offset
d = new Date();
dl = new Date(d.getTime() - d.getTimezoneOffset() * 60 * 1E3);
console.log(d);
console.log(dl.toISOString());
console.log(d.getTimezoneOffset / -60);
@motss
motss / vscode-snippets-simple-guid.md
Last active January 15, 2017 16:23
vscode-snippets-simple-guide

Simple pre-requisites.

  1. npm install -g vsce
  2. Create a free account at https://www.visualstudio.com/en-us/get-started/setup/sign-up-for-visual-studio-online
  3. Create your publisher name - vsce create-publisher (publisher name)
  4. Create Extension manifest (package.json). More details at https://code.visualstudio.com/docs/extensionAPI/extension-manifest
  5. vsce publish // OR vsce publish major|minor|patch
  6. DONE. Your snippet is now up on VS Code's Extensions marketplace.
@motss
motss / find-custom-element-on-document.js
Last active January 16, 2017 15:26
Simple script to find custom elements on a page
var foundCustomElements = [];
var foundCustomElementNames = [];
// main function to deeply find all custom elements on a page.
function getAllCustomElements(nodes) {
nodes.forEach(el => {
if (el.shadowRoot) getAllCustomElements(node.shadowRoot.querySelectorAll('*'));
if (el.localName.includes('-') || el.getAttribute('is') && el.getAttribute('is').includes('-')) {
foundCustomElements.push(el);