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
function test(val) {
var n = val || 0;
document.write(n, '<br>');
function add(addN) {
addN = addN || 0;
document.write('[add ', addN, ']<br>');
n += addN;
@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>
@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 / 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 / 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:

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 / 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');
@andreasonny83
andreasonny83 / Bash-Scripts.bash
Last active March 26, 2020 10:49
Find and delete bunch of files from terminal
find app/ -name '*.map' -exec sh -c 'rm "{}" ' \; # Remove all the .map files inside app/
find . -name node_modules -exec rm -rf {} \; # Remove all node_modules from inside current folder and subfolders
ssh-add -L # Print Git ssh credentials
ssh-add ~/.ssh/id_rsa # Activate SSH credentials
@andreasonny83
andreasonny83 / README.md
Last active September 17, 2024 15:00
Readme template

npm version code style: prettier

Project Name

Write a project description

Prerequisites

This project requires NodeJS (version 8 or later) and NPM.

@andreasonny83
andreasonny83 / .gitignore
Last active November 12, 2024 22:07
Gitignore template for JavaScript projects
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# Runtime data
pids
*.pid