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
class Array
def complect(n)
each_slice((length.to_f / n).ceil).map {|a| a.inject(:+)}
end
end
# Nginx+Unicorn best-practices congifuration guide.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@flash-gordon
flash-gordon / deterministic_test.sql
Created October 26, 2012 21:22
deterministic test
create or replace
function get_ref_name(
num_n_ref_id si_ref.n_ref_id%type,
num_n_lang_id si_ref.n_lang_id%type := sys_context('MAIN', 'N_LANG_ID')
)
return si_ref.vc_name%type
is
vch_vc_name si_ref.vc_name%type;
begin
select nvl(l.vc_name, r.vc_name)
@flash-gordon
flash-gordon / hupo.rb
Created November 15, 2012 23:28
clients_stuff/hupo.rb
module ClientsStuff
class Hupo < ::Rails::Engine
delegate :application, to: :Rails
initializer 'clients_stuff.hupo.append_assets' do
append_paths('assets')
end
initializer 'clients_stuff.hupo.append_widgets_paths', before: 'hupo_widget.load_all_widgets' do
append_paths('widgets')
@flash-gordon
flash-gordon / concat_strings.sql
Created January 12, 2013 11:51
wm_concat/listagg alt (10gR2) no benchmarks
create or replace function concat_strings (
c_list sys_refcursor)
return varchar2
as
vch_result varchar2(4000);
vch_string varchar2(4000);
begin
loop
fetch c_list into vch_string;
exit when c_list%notfound;
@flash-gordon
flash-gordon / object.rb
Created January 26, 2013 09:20
Little object extension that provide method calling tracking
class Object
# class MyObject
# end
#
# obj = MyObject.new
# obj.ring_it! # Start tracking
# # Logs will appear in rails log (tweak as you wish)
# # Do not use in production! Only for debug
def ring_it!
return if @__ringed__
CREATE OR REPLACE FUNCTION parse_ipv6(src varchar2)
RETURN RAW
AS LANGUAGE JAVA
NAME 'sun.net.util.IPAddressUtil.textToNumericFormatV6(java.lang.String) return java.lang.Byte[]';
/
begin
dbms_output.put_line(rawtohex(parse_ipv6('::1')));
end;
/
before_save :check_comment_size, if: :max_comment_size
class << self
def max_comment_size
return @max_comment_size if defined? @max_comment_size
@max_comment_size = comment_field.try(:[], :data_length)
end
def comment_field
put_procedure = procedure_methods[:put][:procedure]
@flash-gordon
flash-gordon / magic_hash.rb
Created July 8, 2013 16:54
Infinite hash example
recursive_lambda = proc {|h, k| h[k] = Hash.new(&recursive_lambda)}
Hash.new(&recursive_lambda)
CREATE TABLE invoices (
id NUMBER PRIMARY KEY,
strategy_id NUMBER
);
CREATE OR REPLACE TYPE base_strategy AS OBJECT (
id number,
not final member procedure do(d date)
) NOT FINAL;
/