Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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,
Installed Packages
ConsoleKit.i686 0.4.2-3.fc14 @updates
ConsoleKit-libs.i686 0.4.2-3.fc14 @updates
ConsoleKit-x11.i686 0.4.2-3.fc14 @updates
GConf2.i686 2.31.91-1.fc14 @fedora
GConf2-gtk.i686 2.31.91-1.fc14 @fedora
ImageMagick.i686 6.6.4.1-16.fc14 installed
ModemManager.i686 0.4.998-1.git20110706.fc14 installed
ORBit2.i686 2.14.19-1.fc14 @fedora
SDL.i686 1.2.14-11.fc14 @updates
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
;
mongoose.connect('mongodb://localhost/test_update_getters_setters_defaults');
var Fooschema = new Schema ({
name : { type: String, default: 'foo', required: true }
, date : Date
@danmactough
danmactough / gist:2041678
Created March 15, 2012 03:24
Bash one-liner to create JSON { shorturl: longurl } from a directory of Adjix redirects
grep "rel=\"canonical\"" * | awk '{ OFS = ""; ORS = ","; file = substr($1, 0, 4); href = match($0, /http:\/\/[^\"]+/); print "\"", file, "\": \"", substr($0, RSTART, RLENGTH), "\""}' | awk '{ OFS = ""; ORS = ""; len = length($0); print "{", substr($0, 1, len - 1), "}" }'
@danmactough
danmactough / includes.jade
Created September 28, 2011 20:08
Jade Issue #354
html
body
h1 My Site
p Welcome to my super lame site.
include template.jqtl
@danmactough
danmactough / index.js
Created September 26, 2011 00:54 — forked from aheckmann/index.js
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_535');
console.error('mongoose version', mongoose.version);
var OID = mongoose.Types.ObjectId;
var ASchema = new mongoose.Schema({
square: mongoose.Schema.ObjectId
, task: Number
});
Model.post('init', function() {
if (!this.isNew) {
var my = this
, activePaths = Object.keys(this._activePaths.states.init);
Object.keys(my._doc).forEach(function(path){
if (activePaths.indexOf(path) === -1) {
delete(my._doc[path]);
}
});
this._doc = my._doc;
@danmactough
danmactough / express-form-alt.js
Created July 20, 2011 14:36
Alternative to Connect - Multipart
/*!
* Alternative to Connect - Multipart
* Copyright(c) 2010, 2011 TJ Holowaychuk <[email protected]>, Dan MacTough <[email protected]>
* MIT Licensed
*/
/**
* Module dependencies.
*/