Skip to content

Instantly share code, notes, and snippets.

@ryaz
ryaz / oracle_mac
Created April 10, 2015 12:01
oracle support for mac os x
1. download from https://docs.oracle.com/cd/E11882_01/install.112/e38228/inst_task.htm#BJFHJIBH
- instantclient-basic-macos.x64-11.2.0.3.0.zip
- instantclient-sqlplus-macos.x64-11.2.0.3.0.zip
- instantclient-sdk-macos.x64-11.2.0.4.0.zip
2. unpack and place to /opt/oracle/instantclient_11_2
3. set proper permissions
4. in ~/.bash_profile
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/oracle/instantclient_11_2
export DYLD_LIBRARY_PATH
PATH=$PATH:/oracle/instantclient_11_2/
@ryaz
ryaz / serilize accessors
Created April 6, 2015 13:20
serilize accessors
serialize :preferences
#helper for using serialized values in form
def self.serialized_attr_accessor(*args)
args.each do |method_name|
eval "
def #{method_name}
(self.preferences || {})[:#{method_name}]
end
def #{method_name}=(value)
@ryaz
ryaz / oracle_queries
Last active August 29, 2015 14:16
oracle sys_dba stuff
### Open cursors
select max(a.value) as highest_open_cur, p.value as max_open_cur
from v$sesstat a, v$statname b, v$parameter p
where a.statistic# = b.statistic#
and b.name = 'opened cursors current'
and p.name = 'open_cursors'
group by p.value;
### Find out the session that is causing the error by using the following SQL statement:
select a.value, s.username, s.sid, s.serial#
require 'excon'
Excon.defaults[:ssl_verify_peer] = false
Excon.defaults[:ssl_ca_path] = ' /usr/lib/ssl'
CarrierWave.configure do |config|
if Rails.env.production? || Rails.env.staging?
config.storage = :fog
config.fog_credentials = {
provider: 'AWS',
@ryaz
ryaz / gist:6d953e7a7959c870e9fd
Created October 28, 2014 21:28
relink brew
brew list -1 | while read line; do brew unlink $line; brew link $line; done
@ryaz
ryaz / Reservation
Created October 14, 2014 11:13
Reservation
Write a migration and ActiveRecord model that tracks restaurant reservations. Assume there is a table in your relational database named "reservations". Reservations have a start time, an end time and a table number.
Write some ActiveRecord validations that check new reservations for overbooking of the same table in the restaurant. For example, table #10 cannot have 2 reservations for the same period of time. This validation(s) should check time overlap for both record creation and updates.
Unit tests are a must to make sure your double booking validations are working. (rspec and unittests)
@ryaz
ryaz / migrate_to_s3
Last active August 29, 2015 14:04
migrate_from_file_storage_to_s3
namespace :paperclip_migration do
desc "migrate files from file storage to s3"
task :migrate_to_s3 => :environment do
puts "Migrating... carrierwave..."
Asset1.find_each do |record|
path = record.avatar.path.to_s
if path != record.avatar.default_url
file_path = (Rails.root.join('public', path)
if File.exists?(file_path)
file = File.open(file_path)
def dice_rand
(1..10).inject(10) {|s,i| s + rand(6)}
end
def count_dice_avg(number)
res = Hash.new(0)
number.times { x = dice_rand; res[x] += 1}
res.sort_by {|k,v| v}.reverse
end
@ryaz
ryaz / API.md
Last active August 29, 2015 13:57
api for kostia/jquery.li18n.js

API

$.li18n.currentLocale = locale

Set the current locale.

Default is 'en'.

$.li18n.currentLocale = 'de';