Skip to content

Instantly share code, notes, and snippets.

@patcoll
patcoll / twig.php
Created March 2, 2010 15:53
Command-line script to process YAML frontmatter with Twig templates.
<?php
/**
* twig.php
*
* Command-line script to process YAML frontmatter with Twig templates.
* Inspired by Mustache <http://github.com/defunkt/mustache>.
*
* Example template file (test.html):
* ---
* people: [ {name: scott}, {name: laura} ]
Then /^I should be able to change the "(name|teaser_text|full_text)" of the ad with an inline editor$/ do |field|
require 'time'
selector = ".inline-edit em.text .#{field}"
old_value = find(selector).text
value = "New Value #{Time.now.to_i}"
find(selector).click
wait_until { find_field(field) }
fill_in(field, :with => value)
file_content = File.open(datafile).map do |line|
line = line.split(',').map { |n| n.strip }
line.each_index do |i|
line[i] = { labels[i][0] => line[i] }
end
line = line.inject({}) { |merged,n| merged.update(n) }
line = { line.delete('LOGRECNO') => line }
end
puts file_content.to_json
@patcoll
patcoll / gist:706951
Created November 19, 2010 18:56
config.ru
require 'rubygems'
require 'padrino'
class App < Padrino::Application
register Padrino::Mailer
register Padrino::Helpers
get("/") { "index" }
get("/index") { "index" }
get("/index", :provides => :html) { "index" }
@patcoll
patcoll / gist:742421
Created December 15, 2010 18:59
arduino_funnel_sinatra_app.rb
require 'rubygems'
require 'sinatra'
$: << '..'
# prepare for using the Funnel library
require 'funnel'
include Funnel
# configure pin(s) of the Arduino board
@patcoll
patcoll / gist:788526
Created January 20, 2011 20:01
php52-ubuntu-lucid.sh
#!/bin/bash
sed s/lucid/karmic/g /etc/apt/sources.list | tee /etc/apt/sources.list.d/karmic.list
aptitude update -y
cat > /etc/apt/preferences.d/php <<heredoc
Package: php5
Pin: version 5.2.*
Pin-Priority: 991
Package: php5-cli
Pin: version 5.2.*
#!/bin/bash
# installs latest PHPUnit
# use sudo if necessary
pear upgrade PEAR # newest phpunit needs pear 1.9.2
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
@patcoll
patcoll / copy_zf_files.sh
Created April 13, 2011 15:26
Copy only certain Zend Framework libs and their dependencies into a specified directory
#!/bin/bash
#
# Copy only certain Zend Framework libs and their dependencies into a specified directory.
#
# This script was created because copying the entire Zend Framework into an existing project
# is not really necessary if you only want to use part of it. However you fall into dependency
# hell because most sub-libraries use multi-purpose libs like Zend_Exception and Zend_Validate.
#
# Put this script in a fresh copy of ZF's `library` folder and run it as follows:
#
#define SYNC_INTERVAL 60
@interface AppDelegate : NSObject <UIApplicationDelegate> {
// ...
NSMutableDictionary *mocs;
NSMutableDictionary *mocThreads;
// ...
}
@property (nonatomic, retain) NSMutableDictionary *mocs;
@property (nonatomic, retain) NSMutableDictionary *mocThreads;
// I wanted a proof-of-concept for streaming binary data from a MongoDB document with Mongoose.
// I'm using express as web framework here but you should be able to pipe to anything that expects a stream.
// Based on https://gist.github.com/1403797
//// [ other express app stuff... ]
app.get('/files/:file', function(req, res, next) {
var queryfileId = req.params.file;
var GrabBinaryForField = require('./streamformatters').GrabBinaryForField;
// "buffer" is the field on my model that stores the binary data