Skip to content

Instantly share code, notes, and snippets.

View gudata's full-sized avatar
🏢
Working from office

gudata

🏢
Working from office
View GitHub Profile
@gudata
gudata / log.rb
Created July 15, 2011 11:52
example of normal faceting
URL: http://user:[email protected]/v1/properties/?facet.mincount=1&facet.sort=count&f.sale_price.facet.sort=index&filter.city=London&facet.limit=-1&f.area_sqft.facet.sort=index&facet.field=sale_price&facet.field=property_types&facet.field=bedrooms&facet.field=bathrooms&facet.field=modified_at&facet.field=area_sqft&f.property_types.facet.sort=index&f.bedrooms.facet.sort=index&f.modified_at.facet.sort=index&f.area_sqft.facet.buckets=0%2C500%2C800%2C1000%2C1500%2C2000%2C2500%2C3000%2C4000%2C5000%2C%2A&sort=city+asc%2Csale_price+desc&filter.transaction=buy&f.bathrooms.facet.sort=index&f.sale_price.facet.buckets=0%2C100000%2C200000%2C300000%2C500000%2C750000%2C800000%2C1000000%2C1500000%2C2000000%2C%2A&f.modified_at.facet.buckets=2011-01-12T11%3A06%3A29Z%2C2011-04-14T12%3A06%3A29Z%2C2011-06-14T12%3A06%3A29Z%2C2011-07-01T12%3A06%3A29Z%2C2011-07-08T12%3A06%3A29Z%2C2011-07-12T12%3A06%3A29Z%2C2011-07-14T12%3A06%3A29Z%2C2011-07-15T12%3A06%3A29Z
Here is a readable dump of the URL
12:06:31 action_view http://l
@gudata
gudata / _manufacturer.erb.html
Created December 22, 2011 14:47 — forked from sanaumair/_manufacturer.erb.html
code logic review
<%= simple_form_for @search, :as => :search_manufacturer, :url => search_index_url(:search => @search.to_hash), :html => {:novalidate => true, :method => :get} do |search_form|%>
<% SimpleForm.wrapper_tag = nil %>
<!-- Center everything -->
<div class="center-content" itemscope itemtype ="http://schema.org/Product">
<article>
<!-- 1 column box with tabs -->
<div class="tabs">
<nav>
<%= render_filter search_form, @search.filter("boat_manufacturer") %>
</nav>
def validate params
raise OURERROR if !(self.manufacturer == params[:manufacturer] and self.country_code and params[:country_code] and self.model == params[:model])
end
def validate params
[:manufacturer, :model, :country_code].each do |field|
incoming_param = params[field].blank? ? '' : params[field]
field_value = self.send(field).blank? ? '' : self.send(field)
if field_value != incoming_param
error = Api::Errors::BadRequest.new('Bad Request it should be like manufacturer-country_code-model')
raise error
end
end
end
@gudata
gudata / product-image-zoom.xml
Created April 9, 2012 14:28
Magic zoom plus - work with more tempaltes
diff --git a/vqmod/xml/product-image-zoom.xml b/vqmod/xml/product-image-zoom.xml
index 3af73b8..936c8b9 100644
--- a/vqmod/xml/product-image-zoom.xml
+++ b/vqmod/xml/product-image-zoom.xml
@@ -3,13 +3,13 @@
<version>2</version>
<vqmver>2.0</vqmver>
<author>www.backonoc.com</author>
- <file name="catalog/view/theme/default/template/common/header.tpl">
+ <file name="catalog/view/theme/*/template/common/header.tpl">
@gudata
gudata / _page.html.slim
Created July 18, 2012 14:41
Easy implementation of nestedSortable with rails preserving the sort order http://mjsarfatti.com/sandbox/nestedSortable/
- class_for_root_only = ((root_ol rescue true) ? 'sortable' : @first_call = '')
ol class=class_for_root_only data-sort-url=sort_website_pages_path(@website)
li id="list_#{page.id}"
.handle
= link_to page.name, edit_website_page_path(@website, page)
'
= active_icon(page, :published)
.btn-group.pull-right
= link_to t('View'), website_page_path(@website, page), :class => 'btn btn-mini'
@gudata
gudata / ransack.rb
Last active December 11, 2015 07:08
real life searching with ransack including search in field concatation and sorting on virtual columns
Models
class User
ransacker :full_name, :formatter => proc {|v| UnicodeUtils.downcase(v) } do |parent|
Arel::Nodes::NamedFunction.new('LOWER',
[Arel::Nodes::NamedFunction.new('concat_ws', [' ', parent.table[:first_name], parent.table[:middle_name], parent.table[:last_name]])]
)
end
end
@gudata
gudata / sync_to_schema_migrations.rake
Created February 6, 2013 07:30
Rails with Joomla Integration. This is when you have two databases and want to use the migrations. Use this code until you get rid of Joomla
desc "Sync the schema_migrations tables on both databases"
task :sync_schema_migrations => :environment do
class JoomlaSchemaMigrations < ActiveRecord::Base
establish_connection "joomla_#{Rails.env}"
self.table_name = 'schema_migrations'
self.inheritance_column = :sti_type
attr_accessible :version
end
class RailsSchemaMigrations < ActiveRecord::Base

Sublime Text 2 – Useful Shortcuts (Windows)

General

Ctrl+KB toggle side bar
Ctrl+Shift+P command prompt
Ctrl+` python console
Ctrl+N new file

Editing

class SampleJob
def perform
begin
# do all your work in the begin block.
puts "hello world"
rescue Exception => e
# rescue any errors so that you know something went wrong. Email yourself the error if you need.
error_msg = "#{Time.now} ERROR (SampleJob#perform): #{e.message} - (#{e.class})\n#{(e.backtrace or []).join("\n")}"
puts error_msg
ensure