Skip to content

Instantly share code, notes, and snippets.

View stop_watch.cpp
#include <sys/time.h> // for gettimeofday()
class StopWatch {
timeval started;
std::string msg;
public:
StopWatch(const std::string& m): msg(m)
{ gettimeofday(&started, NULL); }
View app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path');
var app = express();
@mindriot101
mindriot101 / app.coffee
Created Jan 28, 2013
Raspberry pi server code
View app.coffee
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
@mindriot101
mindriot101 / extract.py
Created Feb 1, 2013
Code for flattening a paginated website
View extract.py
#!/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
View python-latex1.tex
\documentclass{article}
\usepackage{python}
\begin{document}
\begin{python}
print "Hello world from python!"
\end{python}
View python-latex2.tex
\begin{python}
import os
print "Current directory: {0}".format(os.getcwd())
\end{python}
View python-latex3.tex
\begin{python}[initialise.py]
print "Current directory: {0}".format(currentDir)
\end{python}
View gist:5019884
\begin{equation}
\chi^2 = \sum \left(\frac{x_i - m_i}{\sigma_i}\right)^2
\end{equation}
@mindriot101
mindriot101 / gist:5128283
Last active Dec 14, 2015
Cross server ajax workaround
View gist:5128283
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);