Skip to content

Instantly share code, notes, and snippets.

View andreasonny83's full-sized avatar
:octocat:
<Coding />

Andrea Z. andreasonny83

:octocat:
<Coding />
View GitHub Profile
@andreasonny83
andreasonny83 / sw.js
Last active January 18, 2017 14:27
Service Worker
// https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
// app.js
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', { scope: '/sw-test/' }).then(function(reg) {
if(reg.installing) {
console.log('Service worker installing');
} else if(reg.waiting) {
console.log('Service worker installed');

start http-server to serve a project folder:

http-server -a localhost -p 8000 -c-1 ./dist

For Angular1-2 project, use lite-server instead

Running the server in the background and run protractor test using that server:

@andreasonny83
andreasonny83 / pr.md
Created June 15, 2016 17:26 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@andreasonny83
andreasonny83 / tostring.js
Created April 6, 2016 19:18
Using toString() to detect object class
// Using toString() to detect object class
// toString() can be used with every object and allows you to get its class. To use the Object.prototype.toString() with every object, you need to call Function.prototype.call() or Function.prototype.apply() on it, passing the object you want to inspect as the first parameter called thisArg.
var toString = Object.prototype.toString;
toString.call(new Date); // [object Date]
toString.call(new String); // [object String]
toString.call(Math); // [object Math]
@andreasonny83
andreasonny83 / commands.sh
Last active January 24, 2018 16:13
Bash commands
-r: recursive
-i: ignore case sensitive
-w: match the full words
-B: prints the specified N lines before the match
-A: prints the specified N lines after the match
-C: shows N lines in both the side(before & after) of match
grep -r h[1-6] ./*.css | wc -l
grep -ir color=auto h[1-6] ./*.css | wc -l
@andreasonny83
andreasonny83 / index.html
Last active February 26, 2016 10:06
JavaScript nested functions
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Javascript nested functions">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<a href="https://jsbin.com/viposub/edit?html,js,output">Jsbin available here</a>
function test(val) {
var n = val || 0;
document.write(n, '<br>');
function add(addN) {
addN = addN || 0;
document.write('[add ', addN, ']<br>');
n += addN;