Skip to content

Instantly share code, notes, and snippets.

View rsim's full-sized avatar

Raimonds Simanovskis rsim

View GitHub Profile
@rsim
rsim / gist:d11652a8336137832df9
Created April 7, 2015 08:01
How to get the current Unix timestamp in SQL

Get the current Unix timestamp (seconds from 1970-01-01T00:00:00Z) in SQL.

  • MySQL: UNIX_TIMESTAMP()
  • PostgreSQL: CAST(EXTRACT(epoch FROM NOW()) AS INT)
  • MS SQL: DATEDIFF(s, '1970-01-01', GETUTCDATE())
  • Oracle: (CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE) - DATE'1970-01-01') * 86400
@rsim
rsim / 01_thread.rb
Created March 26, 2013 21:15
Code examples from my "Using threads in Ruby applications" presentation in our local Ruby meetup http://www.meetup.com/ruby-on-rails-latvia/events/105142132/
Thread.new do
sleep 5
puts "finished"
end
thread = Thread.new do
sleep 5
puts "finished"
end
thread.join
@rsim
rsim / speaker.md
Created July 1, 2012 15:44 — forked from matiaskorhonen/speaker.md
Frozen Rails Talk Proposal Template (http://2012.frozenrails.eu/)
@rsim
rsim / jasmine_config.rb
Created January 21, 2011 21:41
Adds CoffeeScript support for jasmine gem (rake jasmine task), uses barista gem to compile CoffeScript files to JavaScript before running Jasmine tests.
# put this file in spec/javascripts/support directory
require 'barista'
require 'logger'
require File.join(Rails.root, 'config/initializers/barista_config')
Barista.configure do |c|
c.env = 'test'
c.logger = Logger.new(STDOUT)
c.logger.level = Logger::INFO
def rank(arr)
count = {}
arr.each{|item| count[item] = (count[item]||0) + 1}
rank = 1 # initial ranking
ranking = {}
count.keys.sort.reverse.each{|item| ranking[item] = rank; rank += count[item]}
arr.map{|item| ranking[item]}
end
Spec::Runner.configure do |config|
config.extend(DataMapper::Spec::AdapterHelpers)
config.include(DataMapper::Spec::PendingHelpers)
config.after :all do
# global model cleanup
descendants = DataMapper::Model.descendants.to_a
while model = descendants.shift
descendants.concat(model.descendants.to_a - [ model ])
Spec::Runner.configure do |config|
config.extend(DataMapper::Spec::AdapterHelpers)
config.include(DataMapper::Spec::PendingHelpers)
config.after :all do
# global model cleanup
descendants = DataMapper::Model.descendants.to_a
while model = descendants.shift
descendants.concat(model.descendants.to_a - [ model ])
require "rubygems"
gem "activerecord", "= 2.3.5"
gem "activerecord-oracle_enhanced-adapter", "= 1.2.3"
require "active_record"
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection( :adapter => "oracle_enhanced",
:database => "orcl", :username => "hr", :password => "hr")
ActiveRecord::Base.connection.instance_eval do
def define_equivalent_method(methods)
respond_to = []
equivalent = []
methods.each do |method|
respond_to << "other.respond_to?(#{method.inspect})"
equivalent << "#{method} == other.#{method}"
end
class_eval <<-RUBY, __FILE__, __LINE__ + 1
1)
'DataMapper::Query#difference with mysql with other having a limit should put each query into a subquery and AND them together, and negate the other' FAILED
expected: #<DataMapper::Query::Conditions::AndOperation:0x6a22a6bb @operands=#<Set: {#<DataMapper::Query::Conditions::EqualToComparison @subject=#<DataMapper::Property @model=User @name=:name> @dumped_value="Dan Kubb" @loaded_value="Dan Kubb">, #<DataMapper::Query::Conditions::NotOperation:0x5f44426c @operands=#<Set: {#<DataMapper::Query::Conditions::InclusionComparison @subject=#<DataMapper::Associations::OneToMany::Relationship:0xc00a029 @reader_visibility=:public, @query={}, @child_repository_name=#<DataMapper::Repository @name=default>, @parent_model=User, @max=Infinity, @options={:min=>0, :max=>Infinity, :child_key=>[:name], :parent_key=>[:name], :child_repository_name=>#<DataMapper::Repository @name=default>, :parent_repository_name=>#<DataMapper::Repository @name=default>}, @min=0, @parent_repository_name=#<DataMapper::Repository @name=default>,