Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Andrey Koleshko ka8725

🏠
Working from home
View GitHub Profile
View ruby_closures1.rb
def foo
puts 'hello from foo'
end
def bar(f)
f()
end
bar(foo) # => NoMethodError (undefined method `f' for main:Object)
View ruby_closure.rb
class SMSGateway
# @param phone [String]
# @param message [String]
def self.send_message(phone, message)
puts "Hello #{phone}, #{message}"
end
end
User = Struct.new(:phone, :active)
View ruby.rb
class Base
end
class A < Base
def foo
puts 'foo'
end
end
class A < Base
View magic.ru
params = {a: 1, b: "2", n: {c: 3}}
struct = Magic.new(params)
struct.a # => 1
struct.b # => "2"
struct.c # => undefined method "c"
struct[] # => undefined method "[]"
struct.a = 2 # => undefined method "a ="
View gist:551daaf4ea9256706393
Running 30s test @ http://127.0.0.1:3000/users
1 threads and 16 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 321.24ms 37.67ms 794.62ms 93.10%
Req/Sec 49.87 6.95 60.00 67.80%
1491 requests in 30.08s, 13.32MB read
Requests/sec: 49.56
Transfer/sec: 453.51KB
View cache_pool.rb
class User
end
class UserChild < User
end
def cache
@cache ||= {}
end
View cache.rb
@semaphore = Mutex.new
def cache
@cache ||= {}
end
def get_y
sleep 1
Object.new
end
View migrations.txt
Timeline
production state ->|
|
|<- migration that changes User entities, developer #1, no tests for the migration
|
|<- migration that renames User to Customer, developer #2, no tests for the migration
|
|
deploy -> |
|
View finalize.rb
1 module HasFinalize
2 def self.included(base)
3 base.class_eval do
4 private
5
6 def finalize(&block)
7 ObjectSpace.define_finalizer(self, &block)
8 end
9 end
10 end
View qsort.erl
% **Quicksort**
% The head of the list is taken as the pivot; the list is then split according to those elements smaller
% than the pivot and the rest. These two lists are then recursively sorted by quicksort, and joined together,
% with the pivot between them.
-module(test).
-export([qsort/1]).
reverse(List) ->
reverse(List, []).
You can’t perform that action at this time.