Skip to content

Instantly share code, notes, and snippets.

View robcalcroft's full-sized avatar

Rob Calcroft robcalcroft

View GitHub Profile
@robcalcroft
robcalcroft / *angels-singing*.jsx
Last active July 16, 2019 20:53
Why render props mean messy code
function App(things) {
const newData = useGetNewData(things);
function handleClick() {
if (newData.length > 0)) {
// Woohoo
}
}
return (
@robcalcroft
robcalcroft / basicCipher.js
Last active April 13, 2019 20:29
A super basic character shift cipher
const alphabet = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
@robcalcroft
robcalcroft / createSha256CspHash.js
Created May 20, 2018 22:23
Create a sha256 hash of a string in Node.js to use in a CSP
const crypto = require('crypto');
function createSha256CspHash(content) {
return 'sha256-' + crypto.createHash('sha256').update(content).digest('base64');
}
@robcalcroft
robcalcroft / late-trains.js
Last active March 18, 2019 15:30
Lets you pass UK station codes to this script to view delays etc
let lateFlag = 0;
const isTrainLate = train => (train.sta !== train.eta && train.eta.toLowerCase() !== 'on time');
const processTrains = ({ trainServices }) => trainServices.some((train) => {
if (isTrainLate(train)) {
console.log(`The ${train.sta} won't arrive until ${train.eta} 😕`);
lateFlag = 1;
} else if (lateFlag) {
console.log('Subsequent trains are running fine');
lateFlag = 0;
@robcalcroft
robcalcroft / item-adder.js
Created April 2, 2018 00:43
XML podcast feed utility
const fs = require('fs');
const xml2js = require('xml2js');
const parser = new xml2js.Parser();
const builder = new xml2js.Builder();
const createFeedItem = ({
title,
filePath,
callback
@robcalcroft
robcalcroft / build.js
Created March 24, 2018 20:01
Super simple build tool for watching and running static builds - watches recursively unlike some watching tools out there
const fs = require('fs');
const build = () => {
console.info('Building');
// Run your build here
};
const watchAndBuild = () => {
console.info('Watching files for rebuild');
fs.watch('src', { recursive: true }, build);
@robcalcroft
robcalcroft / security.conf
Created November 5, 2017 01:28
A Nginx configuration file including security settings for server blocks
add_header X-Xss-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy no-referrer-when-downgrade;
add_header Strict-Transport-Security max-age=15768000;
add_header X-Frame-Options SAMEORIGIN;
proxy_hide_header X-Powered-By;
@robcalcroft
robcalcroft / .vimrc
Created August 23, 2017 14:51
My .vimrc file
sy on
set number
set hlsearch
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set autoindent
set cindent
set smartindent
@robcalcroft
robcalcroft / opsview-alexa.js
Last active July 17, 2017 19:53
Opsview Alexa skill
// Run `npm i --save alexa-sdk request` for dependencies
const Alexa = require('alexa-sdk');
const request = require('request');
const handlers = {
opsviewAuthenticate() {
request({
method: 'POST',
uri: '********/api/auth',