Skip to content

Instantly share code, notes, and snippets.

@alexh225
alexh225 / timeline.vue
Created August 23, 2021 13:20 — forked from Bottelet/timeline.vue
Horizontal Calendar with VueJS and Vis.js
<template>
<div class="wrapper">
<p>
Timeline test 2
</p>
<div id="visualization"></div>
</div>
</template>
<script>
@alexh225
alexh225 / axios-catch-error.js
Created June 22, 2021 10:39 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
// will ignore console.log statements in IE and Firefox w/o Firebug ---
var debugging = false; // or true
if (typeof console == "undefined") var console = { log: function() {} };
else if (!debugging || typeof console.log == "undefined") console.log = function() {};
// npm i axios
const axios = require('axios').default;
axios.interceptors.request.use( x => {
// to avoid overwriting if another interceptor
// already defined the same object (meta)
x.meta = x.meta || {}
x.meta.requestStartedAt = new Date().getTime();
return x;
@alexh225
alexh225 / nice-scale.js
Created July 21, 2020 17:39 — forked from igodorogea/nice-scale.js
Javascript - Algorithm for Optimal Scaling on a Chart Axis (Nice Numbers for Graph Labels)
function NiceScale (lowerBound, upperBound, _maxTicks) {
var maxTicks = _maxTicks || 10;
var tickSpacing;
var range;
var niceLowerBound;
var niceUpperBound;
calculate();
@alexh225
alexh225 / linearScale.js
Created February 7, 2020 15:21 — forked from vectorsize/linearScale.js
Quick linear scale inspired by d3.js scales, based on the processing.org map() function. takes in an object with a domain array and a rage array, gives you back a function that receives a value and returns the scaled value.
// based on http://processing.org/reference/javadoc/core/processing/core/PApplet.html#map(float, float, float, float, float)
var scale = function(opts){
var istart = opts.domain[0],
istop = opts.domain[1],
ostart = opts.range[0],
ostop = opts.range[1];
return function scale(value) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
const net = require('net');
const server = net.createServer();
const config = {
host: '0.0.0.0',
port: 9670,
exclusive: true,
}
server.on('connection', (socket) => {
console.log('New client connected')
@alexh225
alexh225 / nodejs-tcp-example.js
Created February 19, 2019 21:09 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@alexh225
alexh225 / pi_stats.js
Created February 5, 2019 16:15 — forked from sidwarkd/pi_stats.js
Python and NodeJS example code for getting memory and cpu usage information on the Raspberry Pi
'use strict'
// A very simple nodeJS script that demonstrates how you can access
// memory usage information similar to how free -m works on the
// Raspberry Pi. Goes with µCast #14. http://youtu.be/EqyVlTP4R5M
// Usage: node pi_mem.js
// Example Output
//
@alexh225
alexh225 / box-shadow.html
Created October 30, 2018 09:43 — forked from ocean90/box-shadow.html
CSS3 Box Shadow, only top/right/bottom/left and all
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;