Skip to content

Instantly share code, notes, and snippets.

View AlexandrBasan's full-sized avatar
:octocat:
Building an effective team which works from home full-time

Alexandr Basan AlexandrBasan

:octocat:
Building an effective team which works from home full-time
View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / 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 / Never expiring Facebook Page Access Token.txt
Last active August 22, 2017 20:20
Never expiring Facebook Page Access Token
https://www.rocketmarketinginc.com/blog/get-never-expiring-facebook-page-access-token/
additional 3.3.1
@AlexandrBasan
AlexandrBasan / text
Created July 10, 2015 08:22
Installing Nokogiri on Yosemite
If you have attempted to install the Nokogiri gem and encountered errors similar to the output below… I feel your pain and have a solution.
The Pain
➜ z gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension.
/Users/mariozig/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150318-11691-1hlore5.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
@AlexandrBasan
AlexandrBasan / knockout
Created July 1, 2015 21:58
KnockoutJS if value != blank than show value in other case show Text
<div data-bind="text: fqdn5() === '' ? 'Default Value' : fqdn5 "></div>