Skip to content

Instantly share code, notes, and snippets.

@dalelane
dalelane / gist:5395554
Last active December 16, 2015 06:59
Stylish (http://userstyles.org/help/stylish) script to stop Remember The Milk being fixed width, and instead resize to the browser width
/* remove the fixed width from the overall page */
#content {
width : auto;
margin-left: 15px;
margin-right: 15px;
}
/* use proportion instead of pixels to specify size */
/* of main list and the right info boxes */
#listbox {
@dalelane
dalelane / DoubleParser.java
Last active December 29, 2015 19:49
An alternative to java.lang.Double.parseDouble which isn't synchronised like the Java implementation is. Explanation in http://dalelane.co.uk/blog/?p=2936
/**
* An alternative to java.lang.Double.parseDouble which isn't synchronised like
* the Java implementation is.
*
* Explanation in http://dalelane.co.uk/blog/?p=2936
*
* @author Dale Lane ([email protected])
*/
public class DoubleParser {
@dalelane
dalelane / generateswimics.py
Created January 19, 2014 22:55
Create an iCalendar file with the swimming sessions available at Fleming Park Leisure Centre by scraping the timetable on their site
#
# Create an ICS calendar with the sessions available at a DC Leisure Centre
# using the info found by scraping the timetable website
#
# http://dalelane.co.uk/blog/?p=3017
#
# Dale Lane
# [email protected]
#
@dalelane
dalelane / nodejs_simple_webserver.js
Last active August 29, 2015 14:02
node.js simple web server (from http://nodejs.org/)
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
@dalelane
dalelane / nodejs_simple_inmemory_db.js
Created June 15, 2014 20:49
Node.js with an SQLite in-memory database (from https://github.com/mapbox/node-sqlite3)
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE lorem (info TEXT)");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
@dalelane
dalelane / nodejs_simple_file_db.js
Created June 15, 2014 20:55
Node.js with a SQLite database (based on sample from https://github.com/mapbox/node-sqlite3)
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('data/demodb01');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS demo (runtime REAL)");
db.run("INSERT INTO demo (runtime) VALUES (?)", new Date().getTime());
db.each("SELECT runtime FROM demo", function(err, row) {
console.log("This app was run at " + row.runtime);
@dalelane
dalelane / nodejs_simple_express_api.js
Created June 15, 2014 21:02
Node.js and Express to make a few REST API endpoints (based on sample in http://expressjs.com/4x/api.html )
var express = require('express');
var app = express();
console.log("Registering endpoint: /");
app.get('/', function(req, res){
res.send('hello ROOT world');
});
console.log("Registering endpoint: /stubbed");
app.get('/stubbed', function(req, res){
@dalelane
dalelane / nodejs_db_with_restapi.js
Created June 15, 2014 21:09
Node.js, Express, and SQLite to wrap a REST API around an SQL database
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('data/demodb02');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS counts (key TEXT, value INTEGER)");
db.run("INSERT INTO counts (key, value) VALUES (?, ?)", "counter", 0);
});
@dalelane
dalelane / JaxbProblem.java
Last active August 29, 2015 14:03
JAXB problem... a simple re-create of a problem I'm having with unmarshalling using JAXB. Fixed working version is at https://gist.github.com/dalelane/983f278d2485d29a6ef4
package sandbox;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@dalelane
dalelane / JaxbSolution.java
Created July 3, 2014 11:45
JAXB solution - a solution to my problem with https://gist.github.com/dalelane/88df784c3cb74b214d5c - using JAXB to unmarshall fragments of XML from an XMLStreamReader
package sandbox;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;