Skip to content

Instantly share code, notes, and snippets.

View af23me's full-sized avatar
👋

Evghenii M af23me

👋
View GitHub Profile
@af23me
af23me / paperclip_cleaner.rb
Created February 26, 2017 22:26
Paperclip old styles (resolutions) cleaner.
require 'fileutils'
class PaperclipCleaner
class << self
def clean(parent_resource_id)
book_images = ImageModel.where(parent_resource_id: parent_resource_id).to_a
images.each do |image_object|
@af23me
af23me / merge_hash_recursively.rb
Created March 23, 2017 16:24
Merge hash recursively
def merge_hash_recursively(first_hash, second_hash)
first_hash.merge(second_hash) { |key, a_item, b_item| merge_hash_recursively(a_item, b_item) }
end
@af23me
af23me / encode_hash.rb
Last active June 26, 2017 13:27
Deep encode hash
def encode_hash(hashie)
Hash[
hashie.collect do |k, v|
if (v.is_a?(Hash))
[ k, encode_hash(v) ]
elsif (v.respond_to?(:encoding))
[ k, v.dup.force_encoding('UTF-8').encode('UTF-16', {invalid: :replace, undef: :replace, replace: '?'}).encode('UTF-8') ]
elsif (v.respond_to?(:to_utf8))
[ k, v.to_utf8 ]
else
@af23me
af23me / bootstrap-popover-extension.css
Created December 14, 2017 13:48
Extend Bootstrap 3 Popover positions
.popover.topLeft {
margin-top: -10px;
}
.popover.topLeft .arrow {
bottom: -11px;
left: 20%;
margin-left: -11px;
border-top-color: #999999;
border-top-color: rgba(0, 0, 0, 0.25);
@af23me
af23me / letsencrypt_2017.md
Created December 20, 2017 08:45 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

$.ajax({
type: 'POST',
url: "https://sandbox-api.didww.com/v3/orders",
data: JSON.stringify({
data: {
type: "orders",
attributes: {
allow_back_ordering: false,
items: [{
type: "did_order_items",
@af23me
af23me / .rubocop.yml
Created March 27, 2019 12:21 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@af23me
af23me / measure.rb
Created May 22, 2019 08:15 — forked from camertron/measure.rb
Measure the memory taken by a Ruby object (by Robert Klemme)
#!/bin/env ruby
# lazy hack from Robert Klemme
module Memory
# sizes are guessed, I was too lazy to look
# them up and then they are also platform
# dependent
REF_SIZE = 4 # ?
OBJ_OVERHEAD = 4 # ?
@af23me
af23me / request_logger.rb
Created December 30, 2019 23:32 — forked from jugyo/request_logger.rb
Rack middleware for logging all rails request
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
@af23me
af23me / gist:5bad131506766a69b1749b6b818408fc
Created February 6, 2020 19:37 — forked from caok/gist:4065758
Deploy from a git tag with capistrano
ref: http://nathanhoad.net/deploy-from-a-git-tag-with-capistrano
Deploy from a Git tag with Capistrano
Are you using Capistrano and Git and want to easily deploy from Git tags? It couldn't be simpler
Using Git, tag a new release:
git tag -a 09.10.02.01 -m "Tagging a release"
You can use git tag to list your tags: