Skip to content

Instantly share code, notes, and snippets.

View scarfacedeb's full-sized avatar
👀

Andrew Volozhanin scarfacedeb

👀
View GitHub Profile
module RetryableTyphoeus
require 'typhoeus'
include Typhoeus
DEFAULT_RETRIES = 1
class Request < Typhoeus::Request
def original_on_complete=(proc)
@original_on_complete = proc

Chapter 1 - Object Oriented Design

The purpose of design is to allow you to do design later, and it's primary goal is to reduce the cost of change.

SOLID Design:

  • Single Responsibility Principle: a class should have only a single responsibility
  • Open-Closed Principle: Software entities should be open for extension, but closed for modification (inherit instead of modifying existing classes).
  • Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
  • Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.
@scarfacedeb
scarfacedeb / 1.form.html.haml
Last active January 18, 2023 22:35
Form with multiple button in rails
/ Form excerpt
= f.button t(".save"), class: "btn"
= f.button t(".publish"), class: "btn", name: "publish"
= f.button t(".test"), class: "btn", name: "test"
@scarfacedeb
scarfacedeb / inspect_container.sh
Last active August 29, 2015 14:05
A shortcut to access docker container without sshd
#!/usr/bin/env bash
# A shortcut to access docker container without sshd
#
# See: http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/
#
# Usage: inspect_docker 7361ceaf8cd3 # container ID
# inspect_docker pensive_turing # container name
if ! [[ $1 ]]; then
echo "You need to specify container ID"
@scarfacedeb
scarfacedeb / svg_helper.rb
Last active August 29, 2015 14:04
Svg helper to reference icons
def svg_icon(icon, view_box: nil, css_class: "")
view_box = view_box.join(" ") if view_box # no need by default, because we use symbols with viewBox
element_id = "icon-#{icon}"
css_class << " icon "
css_class << element_id
content_tag :svg, class: css_class, viewBox: view_box do
content_tag :use, nil, :"xlink:href" => "##{element_id}"
end
end
@scarfacedeb
scarfacedeb / carrierwave.rb
Last active August 29, 2015 14:02
A quick and dirty way to download files from s3 to local for development
CarrierWave.configure do |config|
if Rails.env.development? || Rails.env.test?
config.storage = :file
else
config.storage = :fog
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: Rails.application.secrets.aws_access_key_id,
aws_secret_access_key: Rails.application.secrets.aws_secret_access_key
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
require 'mina/unicorn'
require 'mina/whenever'
# Basic settings:
# domain - The hostname to SSH to.
@scarfacedeb
scarfacedeb / httpcors
Last active August 29, 2015 14:00 — forked from gkatsev/httpcors
#!/usr/bin/env python
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
@scarfacedeb
scarfacedeb / theming.scss.erb
Created May 3, 2014 09:03
A way to use helpers in stylesheets
/*
*= require rails_admin/ra.globalize_tabs
*/
<% environment.context_class.instance_eval { include DecorationsHelper } %>
.well .order-items-images img {
max-width: 150px;
}
@scarfacedeb
scarfacedeb / foundation_breadcrumbs.rb
Last active August 29, 2015 13:59
Custom simple-nav renderer for foundation 5
# Renders an ItemContainer as a <ul> element and its containing items as
# <li><a> elements.
# It only renders 'selected' elements.
#
# It's suited to work with foundation 5 out of the box
class FoundationBreadcrumbs < SimpleNavigation::Renderer::Base
# logic from SimpleNavigation::Renderer::List
def render(item_container)
if skip_if_empty? && item_container.empty?