Skip to content

Instantly share code, notes, and snippets.

View romul's full-sized avatar

Roman Smirnov romul

View GitHub Profile
@romul
romul / ichebnik-keyboard-input.user.js
Last active May 30, 2017 08:43
Добавляет возможность проходить задания в ichebnik.ru при помощи клавиатуры.
// ==UserScript==
// @name Ichebnik Keyboard Input
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Добавляет возможность проходить задания в ichebnik.ru при помощи клавиатуры.
// @author Roman Smirnov
// @match http://ichebnik.ru/*/*
// @match https://ichebnik.ru/*/*
// ==/UserScript==
defmodule MacroHelpers do
@doc """
Converts block AST to a list
You could pass function names which results should be included to the list
Examples:
block_to_list(ast, [:column])
"""
def block_to_list(block, search_for \\ []) do
@romul
romul / rpn.ex
Created May 3, 2016 10:44
Reverse polish notation parser implemented in Elixir
defmodule RPN do
@binary_ops ~w(+ - / * ^)
@unary_ops ~w(+ - sqrt ln)
@ops @binary_ops ++ @unary_ops
def convert(str) do
str |> String.split(" ") |> Enum.reduce([], &convert_rpn(&1, &2)) |> hd
end
defp convert_rpn(op, [a, b | tail]) when op in @binary_ops do
@romul
romul / observer.md
Created November 13, 2015 12:51 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
defmodule Morgue.Repo do
use Ecto.Repo, otp_app: :my_awesome_app
def log(entry) do
result = super(entry)
time = (entry.query_time + entry.queue_time) / 1_000
:ok = :exometer.update ~w(tracker ecto query_exec_time)a, time
:ok = :exometer.update ~w(tracker ecto query_count)a, 1
result
end
@romul
romul / README.md
Last active December 23, 2017 00:56
Using Postres hstore with Elixir, Ecto & Postgrex

To use hstore in Ecto schemas you have to create own Ecto type. To do this, follow these steps:

  1. Create files hstore.ex & hstore_extension.ex inside your lib folder
  2. Open your database settings and add the following line

extensions: [{MyApp.HStoreExtension, nil}],, for example

config :my_app, MyApp.Repo,
 adapter: Ecto.Adapters.Postgres,
@romul
romul / faye.ex
Created June 24, 2015 09:22
Draft implementation of Faye Client in Elixir
defmodule MyApp.Faye do
@name __MODULE__
@unconnected 1
@connecting 2
@connected 3
@disconnected 4
@handshake_params %{
channel: "/meta/handshake",
version: "1.0",
supportedConnectionTypes: ["long-polling"]
@romul
romul / gist:1687744
Created January 27, 2012 08:12
The way to use Kaminari with Cell (or with Apotomo)
# 1) Run rails g kaminari:views default to generate copy of kaminari views inside your app
# 2) Override Kaminari::Helpers::Tag#to_s as shown here:
module Kaminari
module Helpers
class Tag
def to_s(locals = {}) #:nodoc:
@template.render :partial => "../views/kaminari/#{@theme}#{self.class.name.demodulize.underscore}", :locals => @options.merge(locals)
end
end
end
@romul
romul / delayed_tasks.markdown
Created March 28, 2011 09:50
Running rake tasks in background
  1. Add gem 'delayed_job', '2.1.4' to your Gemfile

  2. Run bundle install

  3. Run rails g migration create_delayed_jobs

  4. Edit the created migration to contain:

     class CreateDelayedJobs < ActiveRecord::Migration
       def self.up
         create_table :delayed_jobs, :force => true do |table|
           table.integer  :priority, :default => 0      # jobs can jump to the front of
    

table.integer :attempts, :default => 0 # retries, but still fail eventually

@romul
romul / gist:820448
Created February 10, 2011 12:37
Refinery CMS: Transliterate page titles in URLs

Ты не знаешь как включить транслитерацию URL в Refinery CMS 0.9.9, а русские символы в виде шестнадцатеричных последовательностей в URL тебя бесят? Тогда ты нашёл нужный gist.

Включить транслитерацию достаточно не сложно, после кропотливого изучения кода ;-)

Итак:

  1. Установи и подключи gem russian
  2. Создай initializer со следующим содержимым:

Добавить поддержку русского языка в Bobosa