Skip to content

Instantly share code, notes, and snippets.

View styx's full-sized avatar
🌴
¯\_(ツ)_/¯

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
@styx
styx / gist:9187773
Created February 24, 2014 12:48 — forked from thijsc/gist:1391107
def select_from_chosen(item_text, options)
field = find_field(options[:from])
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("$('##{field[:id]}').val('#{option_value}')")
end
class Foo
def self.foo
"foo"
end
def foo
"ifoo"
end
def true_foo
Foo.foo
end
defmodule FibAgent do
def start_link do
cache = Enum.into([{0, 0}, {1, 1}], HashDict.new)
Agent.start_link(fn -> cache end)
end
def fib(pid, n) when n >= 0 do
Agent.get_and_update(pid, &do_fib(&1, n))
end
@styx
styx / .vimrc
Created May 26, 2014 07:49 — forked from knewter/.vimrc
augroup elixir
au!
au BufNewFile,BufRead *.ex,*.exs noremap <buffer> <leader>t :!mix test %<cr>
au BufNewFile,BufRead *_test.exs noremap <buffer> <leader>t :!mix test %<cr>
augroup END
defmodule FibAgent do
defstruct cache: nil, highest_n: 0
def start_link do
initial_cache = Enum.into([ {0, 0}, {1, 1}], HashDict.new)
state = %__MODULE__{cache: initial_cache, highest_n: 1}
Agent.start_link(fn -> state end, name: __MODULE__)
end
[skin]
description=Ajnasz Blue Theme. Midnight Commander skin from Ajnasz.
[Lines]
horiz=─
vert=│
lefttop=┌
righttop=┐
leftbottom=└
rightbottom=┘
defmodule Curried do
defmacro defc({name, _, args}, [do: body]) do
curried_args = Enum.map(Enum.with_index(args), fn({_, index}) ->
Enum.take(args, index + 1)
end)
for a <- curried_args do
if a == Enum.at(curried_args, Enum.count(curried_args) - 1) do
quote do
def unquote(name)(unquote_splicing(a)) do
unquote(body)
@styx
styx / active_record_introspection.rb
Created June 1, 2012 05:59 — forked from german/active_record_introspection.rb
adding introspection to all ActiveRecord methods (putting method's name when it's invoked)
module ActiveRecord
Base.singleton_methods.each do |m|
Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
end
@styx
styx / method_logger.rb
Created September 25, 2012 07:02 — forked from nhance/method_logger.rb
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo