Skip to content

Instantly share code, notes, and snippets.

View jystewart's full-sized avatar

James Stewart jystewart

View GitHub Profile
@jystewart
jystewart / automongodbbackup.sh
Created July 12, 2011 13:19
Basic script to do mongodb backups a la automysqlbackup
#!/bin/bash
#
# A very quick, dirty script for doing daily and weekly mongodb backups
# using mongodump. Probably not the best way to do the backups, but it's
# a stopgap until we build in more redundancy via slaves, etc.
#
# Mostly stolen from automysqlbackup - http://sourceforge.net/projects/automysqlbackup/
BACKUPDIR="/var/lib/automongodbbackup"
DBNAMES="guides_staging"
@jystewart
jystewart / optimize_tables.sql
Created May 21, 2011 15:01
Query to generate OPTIMIZE TABLE statements for all fragmented tables
SELECT CONCAT('OPTIMIZE TABLE ', TABLE_SCHEMA,'.',TABLE_NAME, ';'), Data_free from information_schema.TABLES where TABLE_SCHEMA NOT IN ('information_schema','mysql') and Data_free > 0 AND ENGINE NOT IN ('INNODB', 'MEMORY');
@jystewart
jystewart / jangomail-sync.php
Created June 9, 2010 11:33
A slightly saner interface for JangoMail Sync than the one they supply
<?php
/**
* A slightly saner interface for JangoMail Sync than the one they supply
*
* This is a demonstration of how to produce a more security-aware interface for JangoMail's
* web database synchronisation system. It is not guaranteed in any way and is not meant
* to be seen as an example of best practice on any level. It does, however, demonstrate how
* the flaws in that system can be worked around to build a reasonable JSON-based interface
* when working with recent versions of PHP.
# to move data to drupal
require 'activerecord'
class ActiveRecord::Drupal < ActiveRecord::Base
self.abstract_class = true
establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "",
:database => "nm_drupal"
#!/usr/bin/ruby -w
#
# Paypal CSV to QIF
# By James Stewart - james@ketlai.co.uk
#
# A really simple script attempting to get data from my paypal account (multi currency)
# into Xero. More adjustment will be needed to handle the multiple currencies, but I've
# not found good documentation of how to bake that into the QIF file yet.
#
# (I know paypal do qif output, but it seems to only send transactions from one currency)
# Superseded by http://github.com/jystewart/wp_ar
require 'html2textile'
first_block = <<END
<div class="column span-3">
<h3 class="storytitle entry-title" id="post-312">
<a href="http://jystewart.net/process/2007/11/converting-html-to-textile-with-ruby/" rel="bookmark">Converting HTML to Textile with Ruby</a>
</h3>
<p>
<span>23 November 2007</span>
#!/usr/bin/ruby
#
# Facebook allows you to specify an RSS feed to poll to get new 'notes' for personal
# profiles, but no similar mechanism to feed a feed in as a group's "news" (possibly
# because of the awful data model around groups...)
#
# This is a quick mechanize script to update the 'news' box for a group you are an
# admin of. It's very basic, but works, and could be developed with an RSS reader
# or as an activerecord callback to send a new blog entry/news story to facebook, or...
#
require 'rubygems'
require 'hpricot'
require 'open-uri'
# Extract a list of currently available hotels for SxSWi
# and produce a simple list of "name - 1 person price - map URL"
# The intention was to then plot them on a map, but I found
# what I needed and moved on
doc = Hpricot(open("http://www.sxsw.com/hotels"))
hotel_list = doc.search("ul#hotel_list li")