Skip to content

Instantly share code, notes, and snippets.

View AlexandrBasan's full-sized avatar
:octocat:

Alexandr Basan AlexandrBasan

:octocat:
View GitHub Profile
@AlexandrBasan
AlexandrBasan / data_controller.rb
Created November 17, 2015 02:56
Rails autocomplete by data from URL
def index
@data = Company.all
respond_to do |format|
format.html
format.json { render :json => @data.to_json }
end
end
@AlexandrBasan
AlexandrBasan / 0_reuse_code.js
Created January 27, 2016 20:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@AlexandrBasan
AlexandrBasan / controller.rb
Last active June 26, 2022 08:05 — forked from joakimk/controller.rb
A way to lazy load partials in Rails 4
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end
@AlexandrBasan
AlexandrBasan / ruby_csr_example.rb
Last active December 19, 2016 21:12 — forked from mitfik/ruby_csr_example.rb
Ruby example of CSR with openssl
require 'openssl'
def create_fingerprint(string)
key = OpenSSL::PKey::RSA.new 2048
self.create_fingerprint(OpenSSL::Digest::SHA256.new(key.to_pem).to_s)
string.scan(/../).map{ |s| s.upcase }.join(":")
end
def gen_key(name)
key = OpenSSL::PKey::RSA.new 1048
@AlexandrBasan
AlexandrBasan / application.rb
Last active July 27, 2016 03:41
ExceptionDatabaseSaver middleware for Rails
require_dependency "lib/exception_database_saver.rb"
config.middleware.use ExceptionDatabaseSaver
@AlexandrBasan
AlexandrBasan / timeout.rb
Created December 19, 2016 21:27
Rails Timeout
require 'timeout'
begin
complete_results = Timeout.timeout(1) do
sleep(2)
end
rescue Timeout::Error
puts 'Print me something please'
end
@AlexandrBasan
AlexandrBasan / file.rb
Created April 5, 2017 21:25
Read config/settings.yml as a file and convert hash['key'] to hash.key in Ruby
def config_data
settings = ActiveSupport::OrderedOptions.new
data = settings.merge!(Rails.application.config_for(:settings).deep_symbolize_keys!)
data_private = data["data_#{self.id}"]
require 'ostruct'
correct = OpenStruct.new data_private
end