Skip to content

Instantly share code, notes, and snippets.

@therealplato
therealplato / gist:6346624
Created August 26, 2013 21:03
express error handling middleware
// example based on @AriPorad Expressjs - All Routes Are 404
// http://stackoverflow.com/questions/18406591/expressjs-all-routes-are-404/18407658#18407658
// custom error handler
// put this at the end of your middleware chain and handle errors however you want
app.use(function (err, req, res, next) {
if (err.message
&& (~err.message.indexOf('not found')
|| (~err.message.indexOf('Cast to ObjectId failed')))) {
res.status(404).render('404', { url: req.originalUrl })
@therealplato
therealplato / gist:5954112
Created July 9, 2013 02:06
google places result - `details.opening_hours`
// Output for this code:
// http://stackoverflow.com/a/17538819/1380669
// Output for a restaurant with 7 periods
{
"open_now": true,
"periods": [
{
"close": {
"day": 2,
"time": "0000"

@Gavin Andresen says:

There is a non-voluntary, hard-to-change, 1,000,000-bytes-of-transactions-per-block limit that needs to be raised.

And there is… uhh, “vigorous”… debate over when and how to change it.

I wasn't aware this was up for change. I was surprised that Gavin says we need to change the block size cap. As Gavin is the lead dev, what Gavin says arguably goes and I hope he is making his decisions with the fullest possible

var url = 'https://dominion.isotropic.org/gamelog/201302/24/game-20130224-103117-6c8c2cb8.html';
var regex = /^https?:\/\/dominion\.isotropic\.org\/gamelog\/\d*\/\d\d\/game\-(\d*)\-([^.]*)\.html$/;
var result = url.match(regex);
//console.log(result);
if(result){
console.log('date: '+result[1]);
console.log('id: '+result[2]);
};
/* Annotated
/*
To size fonts we have to take into account the screen width and pixel density.
Assorted screen sizes and pixels per inch:
x_px y_px PPI
-----------------
G1 320 480 180
Nexus S 480 800 233
Iphone 4S 640 960 326
Iphone 5 640 1136 326
Ipad 2 768 1024 132
/*
To size fonts we have to take into account the screen width and pixel density.
Assorted screen sizes and pixels per inch:
x_px y_px PPI
-----------------
G1 320 480 180
Nexus S 480 800 233
Iphone 4S 640 960 326
Iphone 5 640 1136 326
Ipad 2 768 1024 132
@therealplato
therealplato / plato-mediaquery.css
Created February 6, 2013 17:52
pixel density media query problem
/*
To size fonts we have to take into account the screen width and pixel density.
Assorted screen sizes and pixels per inch:
x_px y_px PPI
-----------------
G1 320 480 180
Nexus S 480 800 233
Iphone 4S 640 960 326
Iphone 5 640 1136 326
Ipad 2 768 1024 132
// Example code by plato demonstrating fs and async
// Before running this: Create a file foo.txt in the same directory as this
// Additionally, run npm install async
var async = require('async');
var fs = require('fs');
handleimg = function(callback){
var raft={}; // to float down the waterfall
raft.meta = {size:50, name:"foo.txt"};
async.waterfall(
@therealplato
therealplato / nano_.js
Created June 4, 2012 16:57
leading underscore in documents fails nano's validation
nano = require('nano')('http://localhost:5984');
nano.db.create('underscore', function(err){
data = {foo:'bar', _ISNEW:true};
couchdb = nano.use('underscore');
couchdb.insert(data, function(err,body) {
console.log('err:\n'+err+'\nbody:\n'+body);
console.log('JSON.stringify(err):\n'+JSON.stringify(err,null,2));
});
});
JReviews user form creation problem
I'm debugging a Joomla site that uses JReviews to store user reviews. The JReviews code has apparently been modified into a broken state.\
User forms are not being saved to the database when the user clicks Submit at the bottom of the form. I'm not sure if the server is receiving the data.
I'm using JReviews 2.3.12.203 and PHP 1.5. Unfortunately I'm running on godaddy hosting so I don't have access to php console error logs.
Details: