Skip to content

Instantly share code, notes, and snippets.

@codebubb
codebubb / commandline_exercises.txt
Created November 3, 2020 19:31
Command Line Exercises
Pipes---
1.Download the contents of "Harry Potter and the Goblet of fire" using the command line from here
wget https://raw.githubusercontent.com/bobdeng/owlreader/master/ERead/assets/books/Harry%20Potter%20and%20the%20Goblet%20of%20Fire.txt
1. Print the first three lines in the book
2.Print the last 10 lines in the book
3. How many times do the following words occur in the book?
@codebubb
codebubb / click-events.js
Created October 28, 2020 09:20
Beacon and PageVisibility API
window.addEventListener('click', event => {
window.events.push({ type: 'Click', x: event.clientX, y: event.clientY });
});
@codebubb
codebubb / index.html
Created October 28, 2020 09:18
Beacon and PageVisibility API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Beacon API</title>
</head>
<body>
<script>
window.events = [];
@codebubb
codebubb / app.js
Created October 28, 2020 09:16
Beacon and PageVisibility API
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.text());
app.use(express.static('public'));
app.post('/log', (req, res) => {
console.log('Received Beacon: ', JSON.parse(req.body));
});
app.listen(3000, console.log('App listening...'));
@codebubb
codebubb / visibility-change.js
Created October 28, 2020 09:15
Beacon and PageVisibility API
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
window.navigator.sendBeacon('/log', 'session ended');
}
});
@codebubb
codebubb / beacon-02-sendBeacon.js
Last active October 28, 2020 09:11
Beacon and Page Visibility API
window.addEventListener('unload', () => {
navigator.sendBeacon('/log', JSON.stringify({ data: 'test' });
});
@codebubb
codebubb / beacon-01-request-onunload.js
Last active October 28, 2020 09:13
Beacon and Page Visibility API
window.addEventListener('unload', async () => {
await fetch('/log', { method: 'POST', body: JSON.stringify({ data: 'test' }) });
});
@codebubb
codebubb / index.html
Created October 16, 2020 12:52
ParcelJS TypeScript HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ParcelJS</title>
<link rel="stylesheet" href="scss/styles.scss">
</head>
<body>
<h1>Hello from Parcel!</h1>
@codebubb
codebubb / app.ts
Created October 16, 2020 12:51
ParcelJS TypeScript
import { BtnEvent } from './Button';
let btnElem: HTMLElement;
btnElem = document
.getElementById('btn');
btnElem.addEventListener('click', BtnEvent);
@codebubb
codebubb / index.html
Created October 16, 2020 12:33
Parcel JS Index output
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>ParcelJS</title><link rel="stylesheet" href="/styles.173a965c.css"></head><body> <h1>Hello from Parcel!</h1> <button id="btn">Click Me</button> <script src="/app.700f0921.js"></script>
</body></html>