Skip to content

Instantly share code, notes, and snippets.

@danmactough
danmactough / create_tables.sql
Created April 6, 2012 13:46
Example MySQL schemas for multi-user feed reader
CREATE TABLE `postmeta` (
`post_id` char(16) NOT NULL,
`user_id` bigint(20) unsigned NOT NULL,
`postmeta_read` bit(2) NOT NULL DEFAULT b'0',
`postmeta_starred` bit(2) NOT NULL DEFAULT b'0',
`postmeta_liked` bit(2) NOT NULL DEFAULT b'0',
`postmeta_shared` bit(2) NOT NULL DEFAULT b'0',
`postmeta_lastupdated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`postmeta_cache` longtext,
`postmeta_annotation` longtext,
@danmactough
danmactough / cleanup.sql
Created April 6, 2012 13:55
Run daily to remove read posts older than 14 days
DELETE `posts`,`postmeta` FROM `posts` LEFT JOIN `postmeta` USING (`post_id`)
WHERE `postmeta_read` IS NULL OR
(`postmeta_read`=b'10'
AND `postmeta_liked`<1
AND `postmeta_starred`<1
AND `postmeta_shared`<1
AND DATEDIFF(CURDATE(),FROM_UNIXTIME(`posts`.`post_pubdate`)) > 14);
OPTIMIZE TABLE `posts`,`postmeta`;
@danmactough
danmactough / .gitignore
Last active October 3, 2015 06:27
How do I add an empty directory to a git repository
# Ignore everything in this directory
*
# Except this file
!.gitignore
@danmactough
danmactough / sanitizeQuerystring.js
Created May 17, 2012 20:41
Sanitize Querystring
function sanitizeQuerystring (url){
var Url = require('url');
var u = Url.parse(url, true);
delete u.search;
for (var key in u.query){
/^utm_/.test(key) && delete u.query[key];
}
return Url.format(u);
}
[{"title":"Techmeme","xmlUrl":"http://www.techmeme.com/feed.xml"},{"title":"Sam Ruby","xmlUrl":"http://intertwingly.net/blog/index.atom"},{"title":"Lethal Librarian","xmlUrl":"http://www.lethal-librarian.net/?feed=rss2"},{"title":"inessential.com","xmlUrl":"http://inessential.com/xml/rss.xml"},{"title":"Amyloo","xmlUrl":"http://hosting.opml.org/amyloo/blog/rss.xml"},{"title":"bits & bytes & pixels & sprites","xmlUrl":"http://www.bitsbytespixelssprites.com/blog/feed/"},{"title":"Bad Gods","xmlUrl":"http://badgods.com/rss.xml"},{"title":"Geek's Guide to the Galaxy","xmlUrl":"http://io9.com/podcast.xml"},{"title":"Writing (3)","xmlUrl":"http://www.quicktopic.com/36/H/QaFaSkQcyBG.rss"},{"title":"Ficlets Blog","xmlUrl":"http://ficlets.com/blog/feed"},{"title":"Achewood","xmlUrl":"http://achewood.com/rss.php"},{"title":"Achewood","xmlUrl":"http://www.achewood.com/rss.php"},{"title":"Auralgasms News","xmlUrl":"http://www.auralgasms.com/AuralgasmsNews.xml"},{"title":"100 Word Stories","xmlUrl":"http://100wordstories.
@danmactough
danmactough / git-changelog.sh
Created October 22, 2012 02:34
Custom git-changelog
#!/bin/sh
DATE=`date +'%Y-%m-%d'`
HEAD="\nn.n.n / $DATE \n==================\n\n"
function gcl () {
version=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1))
if test -z "$version"; then
git log --no-merges --pretty="format: * %s (%an)"
else
@danmactough
danmactough / chain.js
Created January 10, 2013 20:30
Simple function chaining function
var chain = module.exports = function(x, fns){
for (var i=0, l=fns.length; i < l; i++){
x = fns[i](x);
}
return x;
};
@danmactough
danmactough / localStorageExport.js
Created March 26, 2013 21:00
Save a copy of your Little Outline
var $target = $('div.divExplanation:first');
var $dl = $('<div></div>', { 'class': 'divExplanation' });
$dl.prepend($('<a></a>', {
'class': 'saveCopy', // IE 8 bug with the "class" attr requires quotes
href: '#',
title: 'Click here to save a copy of your Little Outline',
download: 'myLittleOutline.opml',
text: 'Download Your Litte Outline'
}));
$dl.insertBefore($target);
#! /usr/bin/env node
var feedparser = require( 'feedparser' );
var request = require( 'request' );
var feedTest = function (url){
var object = {};
object.articles =[];
request( url, {timeout: 20000}, function(error, resp, body){
if (error){
@danmactough
danmactough / index.js
Created July 1, 2013 14:23
Example of using feedparser v0.16.x with a string input
var fs = require('fs')
, feedparser = require('feedparser');
var str = fs.readFileSync('./rss2sample.xml', 'utf-8')
, parser = new feedparser();
parser.on('error', console.error)
.on('readable', function () {
var stream = this, item;
while (item = stream.read()) {