Skip to content

Instantly share code, notes, and snippets.

View jystewart's full-sized avatar

James Stewart jystewart

View GitHub Profile
module PaperclipMigrations
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def add_paperclip_fields(table, prefix)
add_column table, "#{prefix}_file_name", :string
add_column table, "#{prefix}_content_type", :string
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")
#!/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 '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>
# Superseded by http://github.com/jystewart/wp_ar
#!/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)
# 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"
@jystewart
jystewart / team-repo-list.rb
Last active September 4, 2015 18:17
Generate YAML file of teams' github repositories suitable for generating pages with github pages
# Generate YAML file of teams' github repositories suitable for generating pages
# with jekyll/github pages and upload it to a github repository.
#
# Requires the 'octokit' gem
#
# Usage
# export TOKEN=my-github-personal-token
# export ORG=my-org
# ruby team-repo-list.rb
# export TOKEN=
@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.