Skip to content

Instantly share code, notes, and snippets.

@agmcleod
agmcleod / xmlparse.rb
Created September 16, 2011 14:44
Parses an xml file with the given Object node name
# If you have an xml representation of a data entity, and need to convert to CSV, this script works pretty well.
# Specify the file name of an xml file, and the node name of the object. So if you have an XML file of <Person> objects that has all the fields in child elements.
# Specify the Person node, and it will iterate through to create a csv. Each person will be a separate row.
require 'rubygems'
require 'nokogiri'
puts 'type xml file name'
xml_name = gets.chomp
f = File.open(xml_name)
@agmcleod
agmcleod / sparkup.rb
Created September 13, 2011 01:16
Sparkup changes
module Redcar
class Sparkup
def self.plugin_dir
File.join(File.dirname(__FILE__), "..")
end
attr_accessor :indent_spaces
@agmcleod
agmcleod / example.scss
Created September 12, 2011 15:56
SCSS Optimization
@mixin content-middle {
width:1100px;
margin:0 auto;
}
.top {
height:123px;
background-color:#fff;
.content {
@include content-middle;
@agmcleod
agmcleod / simplecssreset.css
Created September 12, 2011 15:35
My own css reset
* { margin:0;padding:0;}
h1,h2,h3,h4,h5,p,li,a { font-size:12px;font-weight:normal;}
button, img { border:0; }
body {
font-family:Arial, sans-serif;
}
@agmcleod
agmcleod / gist:1201092
Created September 7, 2011 16:53
markdown example
# AB Testing in pagetorrent
## Limitations of Test and target
- Cross domain requests
- Can cause tracking issues when clicking outbound links. The request doesnt finish before the link does.
- Difficulty tracking periodical tests.
- Expensive license
## Pluses of Test and target
@agmcleod
agmcleod / model.php
Created September 6, 2011 15:20
Model base class
<?php
class Model
{
private $id;
private $data = Array();
private $fieldNames = Array();
public static function find($id)
{
$tn = self::getTableName();
@agmcleod
agmcleod / after.js
Created August 16, 2011 16:55
Ajax CSRF issue
$.ajax({
url: '/combat_instance',
type: 'post',
beforeSend: function(jqXHR, settings) {
jqXHR.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
},
success: function(data) {
Game.CombatInstance.parseCreateData(data);
}
});
# used to quickly build a sql where condition to copy and paste.
"1
2
3
4
5
6
7
8
9".split(/\n/).collect { |c| "id='#{c}'" }.join(' OR ')
@agmcleod
agmcleod / add_doc_steps.rb
Created July 29, 2011 23:12
There's got to be a better way to do this cucumber step
# Document being an active record model, and the test_data method returning a string.
# Is there a smarter way to organize this? Should i just use a local method in this step def file?
When /^I copy and paste a document$/ do
fill_in "content", Document.test_data
end
@agmcleod
agmcleod / gist:1060926
Created July 2, 2011 15:54
test_sort.rb
require 'benchmark'
class Student
attr_accessor :name, :age
def initialize(args)
args.each do |k, v|
send("#{k}=".to_sym, v)
end
end