Skip to content

Instantly share code, notes, and snippets.

View LiamChapman's full-sized avatar

Liam Chapman LiamChapman

View GitHub Profile

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@LiamChapman
LiamChapman / commit_format_examples.txt
Created February 21, 2019 10:30 — forked from mutewinter/commit_format_examples.txt
Examples of my commit format.
chore: add Oyster build script
docs: explain hat wobble
feat: add beta sequence
fix: remove broken confirmation message
refactor: share logic between 4d3d3d3 and flarhgunnstow
style: convert tabs to spaces
test: ensure Tayne retains clothing
@LiamChapman
LiamChapman / express_robots.js
Last active October 11, 2018 13:51
node express hide from robots.txt
app.get('/robots.txt', function (req, res) {
res.type('text/plain');
res.send("User-agent: *\nDisallow: /");
});
@LiamChapman
LiamChapman / README.md
Created September 7, 2018 14:35 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@LiamChapman
LiamChapman / ExcelFormulas.js
Created August 26, 2018 21:07 — forked from pies/ExcelFormulas.js
Few Excel formulas - PMT, PPMT, XIRR - expressed in Javascript
/* Based on
* - EGM Mathematical Finance class by Enrique Garcia M. <[email protected]>
* - A Guide to the PMT, FV, IPMT and PPMT Functions by Kevin (aka MWVisa1)
*/
var ExcelFormulas = {
PVIF: function(rate, nper) {
return Math.pow(1 + rate, nper);
},
@LiamChapman
LiamChapman / reduxLocalStorage.js
Created August 21, 2018 15:17
Redux localStorage
// https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
export const loadState = () => {
console.log( "State Loaded");
try {
const serialisedState = localStorage.getItem('state');
if (serialisedState === null) {
return undefined;
}
return JSON.parse( serialisedState );
@LiamChapman
LiamChapman / draw_polygon.js
Last active July 5, 2018 15:55
Canvas Draw Polygon
// ctx and RAD defined globally etc
function drawPolygon(x,y, rot, radius, sides, colour) {
ctx.fillStyle = colour;
ctx.beginPath();
var step = (360 / sizes) + rot;
var tx, ty;
for(var i = 0; i < sides; i++ ) {
tx = radius * Math.cos((step * i) / RAD);
ty = radius * Math.sin((step * i) / RAD);
}
@LiamChapman
LiamChapman / httpStatus.js
Last active March 7, 2018 21:21
Check if a file exists with it's http status (200) with a promise
window.httpStatus = (address) => {
return new Promise( (resolve, reject) => {
let client = new XMLHttpRequest();
client.onload = function () {
if (this.status === 200) resolve(this.status);
if (this.status !== 200) reject(this.status);
};
client.open("HEAD", address, true);
client.send();
});
@LiamChapman
LiamChapman / googleMaps.js
Created February 19, 2018 10:56
Google map code. Currently set to London and colours are purple.
// https://maps.googleapis.com/maps/api/js?key=API_KEY (include)
/**
* Google Maps
**/
var GoogleMaps = (function(google, document) {
try {
// Params for offsetting map
var desktopWidth = 768;
@LiamChapman
LiamChapman / element_count_size.css
Created February 16, 2018 14:36
CSS for changing dimensions depending on the amount of elements in HTML
/* one item */
li:first-child:nth-last-child(1) {
width: 100%
}
/* two items */
li:first-child:nth-last-child(2),
li:first-child:nth-last-child(2) ~ li {
width: 50%;
}