Skip to content

Instantly share code, notes, and snippets.

View ktopping's full-sized avatar

Kieran Topping ktopping

  • Unbound, and self
  • Dublin, Ireland
View GitHub Profile
class Event < ActiveRecord::Base
...
has_many :options, :class_name => "EventOption", ...
...
end
class EventOption < ActiveRecord::Base
...
belongs_to :event
...
function flushThis(id){
var msie = 'Microsoft Internet Explorer';
var tmp = 0;
var elementOnShow = document.getElementById(id);
if (navigator.appName == msie){
tmp = elementOnShow.parentNode.offsetTop + 'px';
}else{
tmp = elementOnShow.offsetTop;
}
}
use strict;
use mySociety::GeoUtil qw/national_grid_to_wgs84/;
use CAM::DBF;
my $filename = $ARGV[0];
my $dbf = CAM::DBF->new($filename);
# Double-check the data is as we expect.
my @fieldnames = $dbf->fieldnames();
die if $fieldnames[0] ne "PC1" || $fieldnames[6] ne "X" || $fieldnames[7] ne "Y";
use strict;
use mySociety::GeoUtil qw/national_grid_to_wgs84/;
while (<>) {
my @x=split(/,/); # split csv
my ($pc, $east, $north) = ($x[0], $x[10], $x[11]);
$pc=~s/\"//g; # remove quotes around postcode
my ($lat, $lng) = national_grid_to_wgs84($east, $north, "G"); # "G" means Great Britain
print "$pc,$lat,$lng\n";
}
# mod_rewrite preamble:
RewriteEngine On
RewriteBase /shop
# The following rule omits anything that actually really maps to a file or folder.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
# Anything that's not the above, we route to index.php with the path in "readablePath"
RewriteRule (.*) index.php?readablePath=$1 [L,QSA]
production:
solr:
# Kieran's laptop's (obfuscated!) ip address.
# I'm lazy. I usually ascertain it from http://whatismyip.com/
hostname: 86.00.00.000
port: 8980
log_level: WARNING
[kieran@localhost myapp]$ # Build docs
[kieran@localhost myapp]$ rake doc:app
[kieran@localhost myapp]$ # The following line shows you where to browse to
[kieran@localhost myapp]$ # in order to view your docs
[kieran@localhost myapp]$ echo "Find your docs here: file:///$PWD/doc/app/index.html"
test "sunspot available" do
begin
# Search for instances of "String". The String class will always
# exist, so I use it in order to make this test simpler. It then
# has no dependency on my application classes.
s = Sunspot.search(String) {}
rescue
assert false, "Cannot connect to solr server #{Sunspot.config.solr.url}\n#{$!}"
end
end
query.adjust_solr_params do |params|
params[:"f.#{Sunspot::Setup.for(MyModel).dynamic_field_factory(:custom).build(:my_field).indexed_name}.facet.prefix"] = my_leading_str
end
[kieran@localhost myapp]$ script/console
Loading development environment (Rails 2.3.2)
>> c = Content.new(:xml => '<content><field1>abc</field1><field2>def</field2></content>')
>> c.save
=> true
>> Content.search.results
=> []
>> Sunspot.commit
=> {"responseHeader"=>{"status"=>0, "QTime"=>33}}
=> Content.search.results