Skip to content

Instantly share code, notes, and snippets.

View simonespa's full-sized avatar

Simone Spaccarotella simonespa

View GitHub Profile
@simonespa
simonespa / file-watcher.js
Last active December 23, 2018 17:41
File watcher
#!/usr/bin/env node
const fs = require('fs');
const file = '/path/to/file.json';
fs.watch(file, (eventType, filename) => {
fs.readFile(file, 'utf8', function (err, data) {
if (err) throw err;
process.env.DATA = data;
@simonespa
simonespa / index.html
Last active December 23, 2018 17:39
Roma Homepage Example
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AS Roma | Official Website | Rome | Football | Soccer | Calcio</title>
<link rel="stylesheet" href="css/main.css">
<meta name="description" content="Thee AS Roma official website">
</head>
@simonespa
simonespa / git
Last active December 23, 2018 18:05
Dev Cheat Sheets
# INIT A NEW REPO
git init
git add .
git commit -m "first commit"
git remote add origin git@github.com:<REPO>.git
git push -u origin master
# SECURITY ON GIT
Remove Sensitive Data: https://help.github.com/articles/remove-sensitive-data/
Sensitive information can include, but is not limited to:
@simonespa
simonespa / server.js
Created November 6, 2019 11:52
NodeJS clustering with message passing from master to workers
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const express = require('express')
const app = express();
const port = 3000;
app.get('/', (req, res) => res.send('Hello World!'));
if (cluster.isMaster) {
@simonespa
simonespa / client.html
Created December 18, 2019 12:51
User-Agent override test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<title>User Agent Override</title>
</head>
<body>
let logger;
if (typeof window === 'undefined') {
logger = await import('./serverLogger');
} else {
logger = await import('./clientLogger');
}
export default logger;
@simonespa
simonespa / example.js
Last active September 14, 2020 08:50
AWS Embedded Metrics usage
const aws = require("aws-sdk");
const cloudwatchlogs = new aws.CloudWatchLogs({
region: "eu-west-1",
});
const m = {
requestMethod: 'get',
timestamp: 123432039483,
status: '200'
@simonespa
simonespa / costFunction.m
Created April 16, 2020 21:16
Linear Regression
function J = costFunction(X, y, theta)
% Compute cost for linear regression
% J = costFunction(X, y, theta) computes the cost of using theta as the
% parameter for linear regression to fit the data points in X and y
% Initialize some useful values
m = length(y); % number of training examples
% Compute the cost
J = sum((X * theta - y).^2) * 1/(2*m);
% =========================================================================
@simonespa
simonespa / PageSwitcher.jsx
Created April 17, 2020 11:36
React Router DOM - Page Switcher Listener
import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { Switch, Route, withRouter } from 'react-router-dom';
import HomePage from './HomePage';
import NotFoundPage from './NotFoundPage';
class PageSwitcher extends React.PureComponent {
static propTypes = {
location: PropTypes.object.isRequired
@simonespa
simonespa / command.txt
Last active October 5, 2020 18:45
Performance testing and Profiling
artillery quick --insecure --count 100 -n 50 https://domain.com
artillery run --insecure --output report.json --target https://example.co.uk config.yaml
https://clinicjs.org/
https://nodesource.com/
https://github.com/wg/wrk