Skip to content

Instantly share code, notes, and snippets.

View learntoswim's full-sized avatar

Karl Stanton learntoswim

View GitHub Profile
// Timer to continue counting while using bcrypt.
// Demonstrates that the bcrypt functions are asynchronous.
;(function() {
console.log('start timer');
var x = 1;
setInterval(function() {
console.log('Timer: ' + x);
x++;
}, 1000);
}());
function onlyStatic (middleware) {
return function (req, res, next) {
var match = /(\.css|\.eot|\.gif|\.html|\.js|\.png|\.svg|\.ttf|\.woff|\.jpg)($|\?.*$)/ig.exec(req.originalUrl);
if (!match) return next();
middleware(req, res, next);
};
}
//usage
this.use(onlyStatic(express.static(__dirname + "/public")));
@ezekielchentnik
ezekielchentnik / devServer.js
Last active August 2, 2016 21:51
webpack dev config with dev server, for react, latest greatest hot module reloading. Also uses postcss to compile our css (sass compatible), and image optimization
var WebpackDevMiddleware = require('webpack-dev-middleware');
var WebpackHotMiddleware = require('webpack-hot-middleware');
var historyApiFallback = require('connect-history-api-fallback');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var app = express();
var compiler = webpack(config);
@bradleyg
bradleyg / Dockerfile
Created October 26, 2016 12:46
Dockerfile for Wagtail on GAE
# docker build -t wagtail .
# docker run -it -v $(pwd):/app -p 0.0.0.0:8080:8080 wagtail
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python python-pip python-dev libmysqlclient-dev
ADD https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-131.0.0-linux-x86.tar.gz /tmp/cloudsdk.tar.gz
RUN tar -zxvf /tmp/cloudsdk.tar.gz -C /tmp
RUN /tmp/google-cloud-sdk/install.sh
@Integralist
Integralist / Description.md
Last active April 25, 2020 16:20
This is how BBC News currently implements it's Image Enhancer for responsive images. Note: this is a completely rebuilt version of the code so the BBC's original source code doesn't actually look anything like the below example.

The BBC has a server-side image service which provides developers with multiple sized versions of any image they request. It works in a similar fashion to http://placehold.it/ but it also handles the image ratios returned (where as placehold.it doesn't).

The original BBC News process (and my re-working of the script) follows roughly these steps...

  • Create new instance of ImageEnhancer
  • Change any divs within the page (which have a class of delayed-image-load) into a transparent GIF using a Base64 encoded string.
    • We set the width & height HTML attributes of the image to the required size
    • We know what size the image needs to be because each div has custom data-attr set server-side to the size of the image
    • We then set a class of image-replace onto each newly created transparent image
  • We use a 250ms setTimeout to unblock the UI thread and which calls a function resizeImages which enhances the image-replace images so their source is now set to a URL whe
@catalinbostan
catalinbostan / clear-net-ports.sh
Created September 8, 2017 11:10
Clears out port collisions for VMWare guests in Vagrant env.
#!/bin/bash
##
# Show the user what we're looking to remove from the network configs.
##
printf "\nWe've located the following entries matching the associated port argument. \n"
grep "add_nat_portfwd" /Library/Preferences/VMware\ Fusion/networking | grep $1
grep $1 /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
##
@chrisyco
chrisyco / fixext.py
Created May 23, 2011 04:05
Recursively rename UPPERCASE filename extensions to lowercase
#!/usr/bin/env python
"""Epic script to rename scary uppercase extensions (like .JPG) to
more friendly lowercase (like .jpg).
How to use
==========
Recursively rename all files in the current directory::
fixext
#!/bin/bash
set -o errexit
set -o nounset
if [[ ${#} -ne 1 ]]
then
echo "Usage: ${0} upstart-conf-file" >&2
exit 1
fi
@vorandrew
vorandrew / blackscholes.js
Created September 4, 2012 16:44 — forked from joaojeronimo/blackscholes.js
Black-Scholes in Javascript: A rewrite of http://www.espenhaug.com/black_scholes.html
/*
PutCallFlag: Either "put" or "call"
S: Stock Price
X: Strike Price
T: Time to expiration (in years)
r: Risk-free rate
v: Volatility
This is the same one found in http://www.espenhaug.com/black_scholes.html
but written with proper indentation and a === instead of == because it's
@aasmith
aasmith / javascript option stuff.js
Created August 14, 2010 22:34
black scholes & IV in javascript
/* Returns probability of occuring below and above target price. */
function probability(price, target, days, volatility) {
var p = price;
var q = target;
var t = days / 365;
var v = volatility;
var vt = v*Math.sqrt(t);
var lnpq = Math.log(q/p);