Skip to content

Instantly share code, notes, and snippets.

@PetrKaleta
PetrKaleta / gist:704639f9e9bf8798b815
Last active August 29, 2015 14:03
Strange microseconds issue when querying by time
# Please have a look, how updated_at timestamp is represented in generated SQL
# In this example everything is OK
Event.where(Sequel.expr(:updated_at) > Time.at(1405338941.821000)).sql
# => "SELECT * FROM \"events\" WHERE (\"updated_at\" > '2014-07-14 13:55:41.821000+0200')"
# In this example, there's a precision issue (see microseconds), why?
Event.where(Sequel.expr(:updated_at) > Time.at(1405341161.918000)).sql
# => "SELECT * FROM \"events\" WHERE (\"updated_at\" > '2014-07-14 14:32:41.917999+0200')"
@PetrKaleta
PetrKaleta / Rakefile
Last active August 29, 2015 14:01
Heroku deploy rake tasks with hooks. Demonstrates how to trigger Sidekiq to quiet or terminate via API before deploy
# List of environments and their heroku git remotes (id: 'remote_name')
HEROKU_ENVIRONMENTS = {
staging: 'staging-remote-name',
production: 'production-remote-name'
}
namespace :deploy do
# Create rake tasks to deploy on Heroku environments
# $ rake -T deploy
# rake deploy:production # Deploy to production
@PetrKaleta
PetrKaleta / classic_worker.rb
Last active December 10, 2015 15:08
This code demonstrates how you can create queue_classic worker which will do concurrent requests to 3rd party APIs.
# This code is demonstrating a default queue_classic worker.
# The biggest issue is, that requests made by its jobs are blocking
require 'rubygems'
require 'queue_classic'
require 'typhoeus'
trap('INT') { exit }
trap('TERM') { worker.stop }
@PetrKaleta
PetrKaleta / gist:4434069
Last active December 10, 2015 12:28
Custom Typhoeus based QC Worker Note: I've never tested this code, its just an example
require 'queue_classic'
require 'typhoeus'
trap('INT') { exit }
trap('TERM') { worker.stop }
# Generic consumer
class TyphoeusConcurrentJob
@PetrKaleta
PetrKaleta / config.ru
Created March 20, 2012 14:27
The Rack::TryStatic middleware delegates requests to Rack::Static middleware trying to match a static file
# config.ru
# The Rack::TryStatic middleware delegates requests to Rack::Static middleware
# trying to match a static file
#
# Inspired by original code from rack-contrib
# http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
#
module Rack
@PetrKaleta
PetrKaleta / Caffeinated.coffee
Created January 8, 2012 21:38
Micro JavaScript library written in CoffeeScript to solve my needs when creating mobile web apps for iOS.
###
Caffeinated.js 1.0.1
(c) 2012 Petr Kaleta, @petrkaleta
Caffeinated.js is freely distributable under the MIT license.
Micro JavaScript library written in CoffeeScript to make my life easier when creating mobile web apps for iOS.
I don't like extending built-in JavaScript objects, so I've created this lib as an separate object.
I used underscore identifier to make its calls short as possible. So please do not mess this lib with gorgeous
Underscore.js lib by Jeremy Ashkenas, DocumentCloud Inc.
Some methods are inspired or borrowed from popular JavaScript frameworks like jQuery, Underscore.js and Prototype.js
@PetrKaleta
PetrKaleta / gist:1557073
Created January 3, 2012 21:38
How to work properly with event listeners in CoffeeScript classes
class SomeClass
constructor: ->
@message = 'Page scrolled'
window.addEventListener 'scroll', @onPageScrolled, no
# note I'm using a fat arrow (check how the compiler handle it)
onPageScrolled: =>
alert @message
@PetrKaleta
PetrKaleta / gist:1548614
Created January 1, 2012 23:13
How to append rendered Hogan.js template into some DOM element
# use pre-compiled template
piicHTML = HoganTemplates.piic.render { link: '#', url: 'http://foo.bar/image.jpg' }
# used just for htmlString => DOMElement conversion
el = document.createElement 'span'
el.innerHTML = piicHTML
# append all first childs
@piicsContainer.appendChild el.firstChild while el.firstChild
@PetrKaleta
PetrKaleta / gist:1527710
Created December 28, 2011 11:57
Simple OOP pattern
log = (o) -> console.log o
# -------------- CLASS DEFINITIONS -------------
# Private methods are starting with underscore, but this is just for better readability
class SimpleOOPPattern
@classProperty: 'le class property'
@classMethod: ->
'le class method'
publicProperty: 'le public property'
@PetrKaleta
PetrKaleta / gist:1084214
Created July 15, 2011 06:46
mini_magick error
Command ("identify -ping /var/folders/Y6/Y6ctKVyOFjCFdBR1qX2zuU+++TI/-Tmp-/mini_magick20110715-72476-oai3or-0.jpg") failed: {:status_code=>127, :output=>"sh: identify: command not found\n"}