Skip to content

Instantly share code, notes, and snippets.

@kbaum
kbaum / set_time_zone.js.coffee
Created March 12, 2013 22:17
Setting Browser TZone
window.BrowserTZone ||= {}
BrowserTZone.setCookie = ->
$.cookie "browser.timezone", jstz.determine().name(), { expires: 365, path: '/' }
jQuery ->
BrowserTZone.setCookie()
@kbaum
kbaum / set_time_zone.rb
Last active December 14, 2015 20:58
Set the timezone within an around filter
around_filter :set_time_zone
private
def set_time_zone
old_time_zone = Time.zone
Time.zone = browser_timezone if browser_timezone.present?
yield
ensure
Time.zone = old_time_zone
@kbaum
kbaum / building_traffic.rb
Last active December 19, 2015 12:49
Sidekiq and pusher presentation
class BuildingTrafficController < ApplicationController
def show
format.html{ render :show}
format.json do
Jobs::DashboardQueriesJob.perform_async dashboard_params
render json: :success
end
end
end
class Viewthespace.BuildingTrafficDashboard
constructor: (pusherKey, uniqueUserId) ->
pusher = new Pusher pusherKey
channel = pusher.subscribe "dashboard_results_#{uniqueUserId}"
dashboard = @
channel.bind 'top_traffic_sources', (trafficSources) ->
dashboard.refreshTopTrafficSources trafficSources
require 'webrick/https'
require 'rack/handler/webrick'
def run_ssl_server(app, port)
opts = {
:Port => port,
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new("./spec/support/server.key"),
Capybara.server_port = 3001
Capybara.app_host = "https://localhost:%d" % Capybara.server_port
#For selenium
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile.secure_ssl = false
profile.assume_untrusted_certificate_issuer = false
Capybara::Selenium::Driver.new(app, :browser => :firefox, profile: profile)
end
#For capybara-webkit:
@kbaum
kbaum / my_portfolio_eager_loading.rb
Last active December 30, 2015 23:39
Fragment caching optimization
class MyPortfoliosController < ApplicationController
before_filter :authenticate_user!
def show
@portfolio_properties = my_portfolio_filter.filtered_properties
.includes(:city, :submarket, :photos, :videos, :spaces)
.page(page)
.per(10)
.decorate
@kbaum
kbaum / show.html.haml
Created December 10, 2013 23:18
my portfolio show
- content_for :title, "My Portfolio - VTS"
= cache [ "v2", 'my_portfolio', current_user.all_properties_cache_key, current_user.all_spaces_cache_key ] do
.my_portfolio#main
= render partial: 'search_filters'
= render partial: 'multishare_bar'
#search-results
= render partial: 'search_results'
#footer-links
@kbaum
kbaum / gist:7902365
Created December 10, 2013 23:34
Eager load
(15.0ms) SELECT "spaces"."property_id" FROM "spaces" INNER JOIN "properties" ON "properties"."id" = "spaces"."property_id" LEFT OUTER JOIN "user_properties" ON "user_properties"."property_id" = "properties"."id" LEFT OUTER JOIN "user_spaces" ON "user_spaces"."space_id" = "spaces"."id" WHERE ((user_spaces.user_id = 2023 and spaces.lease_type = 'sublease') or (user_properties.user_id = 2023 and spaces.lease_type = 'direct')) AND (spaces.status!='removed') ORDER BY "spaces"."status", "spaces"."id"
Property Load (9.3ms) SELECT distinct properties.* FROM "properties" LEFT OUTER JOIN "user_properties" ON "user_properties"."property_id" = "properties"."id" LEFT OUTER JOIN "spaces" ON "spaces"."property_id" = "properties"."id" AND spaces.status != 'removed' LEFT OUTER JOIN "user_spaces" ON "user_spaces"."space_id" = "spaces"."id" WHERE "properties"."id" IN (142, 143, 207, 208, 214, 304, 297, 305, 349, 351, 352, 353, 453, 454, 456, 457, 459, 461, 482, 483, 490, 508, 534, 536, 567, 596, 597, 598, 622, 621, 665, 67