Skip to content

Instantly share code, notes, and snippets.

View jlstr's full-sized avatar

José Estrella-Campaña jlstr

View GitHub Profile
@jlstr
jlstr / insert.js.coffee
Created December 11, 2012 17:33
Insert text at cursor position
insertAtCaret = (areaId, text) ->
txtarea = $("#t1").get(0)
scrollPos = txtarea.scrollTop
strPos = 0
br = ((if (txtarea.selectionStart or txtarea.selectionStart is "0") then "ff" else ((if document.selection then "ie" else false))))
if br is "ie"
txtarea.focus()
range = document.selection.createRange()
range.moveStart "character", -txtarea.value.length
strPos = range.text.length
@jlstr
jlstr / _sidebar.html.erb
Created November 27, 2012 19:24
SideBar!
<%= search_form_for @q, :url => home_path, :html => { :method => :get } do |f| %>
<div class="widget" id="price_container">
<h3><%= t :general, scope: :sidebar %></h3>
<div class="box">
<div class="item">
<h4><%= t :price, scope: :sidebar %></h4>
<span class="left">0 $</span>
<span class="right">10.000.000 $</span>
<div id="slider-range_1" class="slider_wrap"></div>
</div>
@jlstr
jlstr / layout_scripts.js.coffee
Created November 27, 2012 19:23
New Sliders file!
jQuery ->
new Sliders()
class Sliders
constructor: ->
_self = this
if typeof $.fn.checkbox isnt 'undefined'
$('input[type=checkbox]').checkbox(cls:'jquery-safari-checkbox')
if typeof $.fn.selectBox isnt 'undefined'
@jlstr
jlstr / layout_scripts.js.coffee
Created November 27, 2012 18:08
Slider responding to change callback
jQuery ->
if typeof $.fn.jCarouselLite isnt 'undefined'
$("#slider_1").jCarouselLite
btnNext: "#slider_1 .next"
btnPrev: "#slider_1 .prev"
visible: 1
jQuery ->
if $.fn.jCarouselLite?
$("#slider_1").jCarouselLite
btnNext: "#slider_1 .next"
btnPrev: "#slider_1 .prev"
visible: 1
@jlstr
jlstr / _widget_price.html.erb
Created November 27, 2012 14:38
price widget slider
<div class="widget" id="price_container">
<h3><%= t :general, scope: :sidebar %></h3>
<div class="box">
<div class="item">
<h4><%= t :price, scope: :sidebar %></h4>
<span class="left">0 $</span>
<span class="right">2.000000$</span>
<%= f.text_field :price_gteq, value: [params[:q][:price_gteq], params[:q][:price_lteq]].join(';') %>
</div>
<div class="item">
@jlstr
jlstr / _sort_navbar.html.erb
Created November 5, 2012 21:27
Sorting using Ransack
<%= search_form_for @q, :url => home_path, :html => { :method => :get } do |f| %>
<%= f.sort_fields do |s| %>
<%= s.sort_select %>
<% end %>
<%= f.submit "Sort" %>
<% end %>
@jlstr
jlstr / controller
Created November 5, 2012 21:25
Sorting using Ransack
class LandingController < ApplicationController
layout "landing2"
def index
@zones = Zone.all
@zone_id ||= 1
@q = Property.search(params[:q])
@q.build_sort if @q.sorts.empty?
end
end
@jlstr
jlstr / parallel.rb
Created October 24, 2012 20:13
Parallel
def crawl_in_parallel(urls=[], type, subcategory)
hydra = Typhoeus::Hydra.new(:max_concurrency => 5)
urls.each do |url|
request = Typhoeus::Request.new(url,
timeout: 7000,
follow_location: true,
)
request.on_complete do |response|
@jlstr
jlstr / calc
Created March 23, 2012 01:32
First Feature from Cuke book
Given /^the input "([^"]*)"$/ do |input|
@input = input
end
When /^the calculator is run$/ do
@output = "ruby calc.rb #{@input}"
raise "Command failed!" unless $?.success?
end
Then /^the output should be "([^"]*)"$/ do |arg1|