Skip to content

Instantly share code, notes, and snippets.

View sabman's full-sized avatar
😀
Building, Shiping, Sharing!

Shoaib Burq sabman

😀
Building, Shiping, Sharing!
View GitHub Profile
@sabman
sabman / gml_helper.rb
Created November 5, 2009 02:44
gml_helper.rb
require 'rubygems'
require 'geo_ruby'
include GeoRuby::SimpleFeatures
module GmlHelper
def parse_gml(gml_str)
doc = Hpricot(gml_str)
coords = doc.search('gml:coordinates').inner_html.split(',')
unless coords.empty? or coords.nil?
if doc.search("gml:point").size == 1
@sabman
sabman / georuby_sdo_geometry.rb
Created November 22, 2009 11:19
georuby_sdo_geometry.rb
require 'geo_ruby'
GeoRuby::SimpleFeatures::Point.class_eval do
def as_sdo_geometry
"MDSYS.SDO_GEOMETRY(#{sdo_gtype},#{sdo_srid},SDO_POINT_TYPE(#{sdo_ordinate_array}),NULL,NULL)"
end
# dl01 see http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_objrelschema.htm#g1013735
def sdo_gtype
d = @with_z ? 3 : 2
l = @with_m ? (d==2 ? 3 : 4) : 0
@sabman
sabman / test_crud_sdo_geometry.rb
Created November 22, 2009 11:20
test_crud_sdo_geometry.rb
require 'schema_dev.rb'
require '../utils/sdo_geometry.rb'
include GeoRuby::SimpleFeatures
ProdDb.connection.execute("ALTER SESSION set NLS_DATE_FORMAT ='DD-MON-FXYYYY'")
params = {
:eno=>455129,
:sampleid=>'GA2476/006CAM002',
:geom_original => nil,
@sabman
sabman / mars_helper.rb
Created November 25, 2009 08:11
mars_helper.rb # ausome helper for my MARS :-)
module MarsHelper
def self.convert_params_spatial_values_to_georuby(h)
geom = nil
r = h
if h[:start_lat] and h[:end_lat] and h[:start_long] and h[:end_long] # linestring
if r[:start_depth]
geom = LineString.from_coordinates([[r[:start_long], r[:start_lat],r[:start_depth].abs*-1],[r[:end_long], r[:end_lat], r[:end_depth].abs*-1]], 8311, true)
else
geom = LineString.from_coordinates([[r[:start_long], r[:start_lat]], [r[:end_long], r[:end_lat]]], 8311)
end
@sabman
sabman / sample.rb
Created December 2, 2009 12:27
sample.rb
module Prod
class Sample < ProdDb
set_table_name :samples
set_sequence_name :autogenerated
set_primary_key :sampleno
set_date_columns :entrydate, :qadate, :acquiredate, :confid_until, :lastupdate
belongs_to :survey, :foreign_key => :eno
has_many :sampledata, :foreign_key => :sampleno
comma :sampledata do
@sabman
sabman / gitc
Created February 12, 2010 09:07
git clone from behind a proxy
#!/bin/bash
repo_url=$1
read -s -p "Enter Password: " password
echo "Saving original proxy ... "
orig_proxy=$HTTP_PROXY
echo "getting username: $USERNAME"
echo "seeding the proxy with sweet love ..."
echo -ne '##### (33%)\r'
sleep 1
script/generate nifty_scaffold tile url:string file:string lon:decimal lat:decimal zoom:decimal
class AddTiles < ActiveRecord::Migration
def self.up
Tile.create(:file => '1.jpg', :lon => 134, :lat => -26, :zoom => 1)
Tile.create(:file => '2.jpg', :lon => 122, :lat => -26, :zoom => 2)
Tile.create(:file => '3.jpg', :lon => 145, :lat => -26, :zoom => 2)
end
def self.down
Tile.delete_all
end
class Tile < ActiveRecord::Base
attr_accessible :url, :file, :lon, :lat, :zoom, :url_params
def url_params
"?lon=#{lon}&lat=#{lat}&zoom=#{zoom}"
end
end
<% title "Tiles" %>
<table>
<tr>
<th>Tile Url</th>
</tr>
<% for tile in @tiles %>
<tr>
<td><%=link_to "#{tiles_path}/show/#{tile.url_params}", "#{tiles_path}/show/#{tile.url_params}" %></td>
</tr>