Skip to content

Instantly share code, notes, and snippets.

View 7even's full-sized avatar

Vsevolod Romashov 7even

View GitHub Profile
@7even
7even / gist:5088892
Created March 5, 2013 08:52
EM-based pubsub
require 'eventmachine'
require 'awesome_print'
class Channel
def initialize
@sockets = []
end
def subscribe(socket)
@sockets << socket
git log --pretty=format:'%C(auto)%h%d%Creset %s %C(green)(%cr) %C(bold blue)<%an>' --graph --all
@7even
7even / .psqlrc
Last active August 29, 2015 13:56
psql settings
\set QUIET 1
\x auto
\timing
\set PROMPT1 '%[\x1b[33m%]%n%[\x1b[0m%]@%[\x1b[32m%]%/%[\x1b[0m%] > '
\pset null '(null)'
\set QUIET 0
@7even
7even / message-test.rb
Last active August 29, 2015 13:56 — forked from ozgg/message-test
# controller
class UsersController < ApplicationController
def send_recovery
user = User.find_by(email: params[:email].to_s.downcase)
if user.nil?
flash[:message] = t('email_not_found')
redirect_to recover_form_users_path
else
send_recovery_code user
redirect_to recover_users_path
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}[%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)%{$fg_bold[yellow]%}$(work_in_progress)%{$reset_color%}$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
@7even
7even / url_creator.rb
Last active August 29, 2015 14:01 — forked from foxweb/url_creator.rb
# Класс создатель объектов Url и связанных сущностей.
class UrlCreator
attr_reader :uri, :domain, :url_path, :query_string, :url
# Инициирует модель Url на основе полного URL.
#
# @param [String] full_url какой-то URL (http://www.linux.org.ru/forum/talks/8623652)
#
def initialize(full_url)
@uri = URI.parse(full_url)
def post_author(properties_or_obj = {})
# Теперь пользователь может передать свой объект или просто хэш с параметрами
author = if properties_or_obj.respond_to?(:author)
properties_or_obj.to_author
else
properties_or_obj
end
raise ArgumentError unless author.is_a?(Hash)
@7even
7even / gist:79609a787a7781209ffc
Last active August 29, 2015 14:18
Exercises from "7 languages in 7 weeks".
;; Macros
(defmacro unless-else
[cond if-true if-false]
(list 'if cond if-false if-true))
(macroexpand '(unless-else false (println "false") (println "true")))
;;=> (if false (println "true") (println "false"))
(unless-else false (println "false") (println "true"))
@7even
7even / .pryrc
Created November 13, 2015 14:05
def generate_password(length: 20)
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
length.times.map { chars.sample }.join
end
@7even
7even / Guardfile
Created September 19, 2017 14:27
Guardfile for guard-rspec in Hanami application
guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)
dsl.watch_spec_files_for(%r{apps/(.*)\.rb})