Skip to content

Instantly share code, notes, and snippets.

View flash-gordon's full-sized avatar
🔪
Working on sharp tools

Nikita Shilnikov flash-gordon

🔪
Working on sharp tools
View GitHub Profile
def yield_and_ensure
yield
ensure
'ensure'
end
def yield_and_return_ensure
yield
ensure
return 'ensure'
class Foo
def self.method_added(method_name)
super
create_wrapper_for(method_name)
end
def self.create_wrapper_for(method)
wrap_module.class_eval <<-RUBY
def #{method}(*)
p '#{method} called!'
@flash-gordon
flash-gordon / oracle_nested_tables.sql
Created October 24, 2013 21:26
oracle nested tables example
create or replace type id_list as table of number
/
create table test_nested(
id number primary key,
ids id_list
)
nested table ids store as nested_ids
/
insert into test_nested(id, ids)
values (1, id_list(1, 2, 3))
declare
cursor c_t is
select *
from dual;
procedure remember_about_cursor
as
begin
if c_t%isopen then
close c_t;
FUNCTION FETCH_NEXT_SERVICE
RETURN BOOLEAN
AS
num_Rows NUMBER;
BEGIN
rc_ServiceRow := NULL;
rc_OverlappingRow := NULL;
OPEN c_NextService;
@flash-gordon
flash-gordon / oracle_locks.sql
Last active August 29, 2015 14:04
ora_locks
SELECT sn.username, m.sid, m.type,
DECODE(m.lmode, 0, 'None',
1, 'Null',
2, 'Row Share',
3, 'Row Excl.',
4, 'Share',
5, 'S/Row Excl.',
6, 'Exclusive',
lmode, ltrim(to_char(lmode,'990'))) lmode,
DECODE(m.request,0, 'None',
2.2.2 :001 > fiber = Fiber.new {}
=> #<Fiber:0x007fc04b891f58>
2.2.2 :002 > Thread.new {fiber.resume}.join
FiberError: fiber called across threads
from (irb):2:in `resume'
from (irb):2:in `block in irb_binding'
module TestCV
def value=(val)
@@value = val
end
def value
@@value
end
end
define_method :create do |field, &block|
define_method "#{field}=" do |arg|
instance_variable_set(:"@#{field}", arg)
end
define_method "#{field}" do
puts instance_exec(&block)
instance_variable_get(:"@#{field}")
end
end
A = Class.new do
module CommandPlugins
module ActiveRecordTimestamps
def insert(tuples)
now = Time.zone.now
tuples_with_timestamps = tuples.map do |tuple|
tuple.merge(created_at: now, updated_at: now)
end
super(tuples_with_timestamps)
end