This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'eventmachine' | |
| require 'awesome_print' | |
| class Channel | |
| def initialize | |
| @sockets = [] | |
| end | |
| def subscribe(socket) | |
| @sockets << socket |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git log --pretty=format:'%C(auto)%h%d%Creset %s %C(green)(%cr) %C(bold blue)<%an>' --graph --all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \set QUIET 1 | |
| \x auto | |
| \timing | |
| \set PROMPT1 '%[\x1b[33m%]%n%[\x1b[0m%]@%[\x1b[32m%]%/%[\x1b[0m%] > ' | |
| \pset null '(null)' | |
| \set QUIET 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Класс создатель объектов 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}) |