Skip to content

Instantly share code, notes, and snippets.

View learntoswim's full-sized avatar

Karl Stanton learntoswim

View GitHub Profile
@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);
@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
@jonnyreeves
jonnyreeves / testrunner.html
Created June 2, 2012 13:32
Unit Testing Promises with Sinon.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<!-- when.js Promises implementation -->
<script src="https://raw.github.com/cujojs/when/master/when.js"></script>
<!-- Unit testing and mocking framework -->
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 3, 2024 19:09
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@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
#!/bin/bash
set -o errexit
set -o nounset
if [[ ${#} -ne 1 ]]
then
echo "Usage: ${0} upstart-conf-file" >&2
exit 1
fi
@webgio
webgio / app.coffee
Last active December 10, 2023 10:24
Marionette.js module to manage authentication. Needs a server method that checks credentials returning true or false. Started from this blog post code: http://clintberry.com/2012/backbone-js-apps-authentication-tutorial/
App = new Marionette.Application();
App.addRegions {
"headerRegion": "#header"
"topMenuRegion": "#top-menu"
"mainRegion" : "#main"
}
App.on 'initialize:after', ->
Backbone.history.start()
@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
// 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")));