Skip to content

Instantly share code, notes, and snippets.

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

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
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)
[skin]
description=Ajnasz Blue Theme. Midnight Commander skin from Ajnasz.
[Lines]
horiz=─
vert=│
lefttop=┌
righttop=┐
leftbottom=└
rightbottom=┘
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
@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
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
class Foo
def self.foo
"foo"
end
def foo
"ifoo"
end
def true_foo
Foo.foo
end
@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
defmodule HttpRequester do
use GenServer.Behaviour
def start_link(_) do
:gen_server.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
:gen_server.cast(server, {:fetch, url})
end