Skip to content

Instantly share code, notes, and snippets.

#include <sys/time.h> // for gettimeofday()
class StopWatch {
timeval started;
std::string msg;
public:
StopWatch(const std::string& m): msg(m)
{ gettimeofday(&started, NULL); }
@simonrw
simonrw / app.js
Last active December 11, 2015 15:18
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path');
var app = express();
@simonrw
simonrw / app.coffee
Created January 28, 2013 14:39
Raspberry pi server code
express = require 'express'
http = require 'http'
path = require 'path'
app = express()
public_path = path.join __dirname, 'public'
app.configure ->
app.set 'port', process.env.PORT || 3000
@simonrw
simonrw / extract.py
Created February 1, 2013 16:27
Code for flattening a paginated website
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import requests
def analyse_page(url):
r = requests.get(url)
assert r.status_code == 200
\documentclass{article}
\usepackage{python}
\begin{document}
\begin{python}
print "Hello world from python!"
\end{python}
\begin{python}
import os
print "Current directory: {0}".format(os.getcwd())
\end{python}
\begin{python}[initialise.py]
print "Current directory: {0}".format(currentDir)
\end{python}
import os
currentDir = os.getcwd()
@simonrw
simonrw / gist:5019884
Created February 23, 2013 14:04
Latex example
\begin{equation}
\chi^2 = \sum \left(\frac{x_i - m_i}{\sigma_i}\right)^2
\end{equation}
@simonrw
simonrw / gist:5128283
Last active December 14, 2015 18:19
Cross server ajax workaround
var allowedHost = {
// Add your allowed hosts here
'http://localhost:3001': true,
'http://localhost:7357': true
};
var allowCrossDomain = function(req, res, next) {
// If the domain is allowed, set the response headers to reflect this. Otherwise reject the authentication
if(allowedHost[req.headers.origin]) {
res.header('Access-Control-Allow-Credentials', true);