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 / gist:949a774243c1c5d3a1e6
Created April 9, 2015 04:03
Ruby parser (schema.rb)
<% a = File.open("db/schema.rb") %>
<% a.each do |out| %>
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/) %>
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') == 'created_at' || out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') == 'updated_at' %>
<% else %>
:<%= out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') %>,
<% end %>
<% elsif out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/)%>
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/).join(', ') == 'created_at' || out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/).join(', ') == 'updated_at' %>
<% else %>
@AlexandrBasan
AlexandrBasan / gist:582cde2677be0f41beee
Created April 9, 2015 04:05
Credit card check using REGEX
def card_number_format
case card_type.downcase
when 'visa'
/^4\d{3}\d{4}\d{4}\d{4}$/
when 'mastercard'
/^5[1-5]\d{2}\d{4}\d{4}\d{4}$/
when 'american express'
/^3[4,7]\d{13}$/
end
end
@AlexandrBasan
AlexandrBasan / gist:9e1260477bf54f6c44e4
Last active November 15, 2015 22:26
REGEX for find trailing whitespace
Ruby function for delete leading and trailing white-spaces:
2.1.5 :001 > " clean up my edges ".strip
=> "clean up my edges"
Regex for trailing white-spaces:
[ \t]+$
@AlexandrBasan
AlexandrBasan / mailers_controller.rb
Created June 11, 2015 03:55
Mailer Viewer inside Rails application
class MailersController < Admin::BaseController
def render_layout
# received params
# params[:mailer_type]
# params[:email_template]
# params[:email_format]
mailer_type = params[:mailer_type].camelize
mailer_template = params[:email_template]
type_class = mailer_type.classify.safe_constantize
@AlexandrBasan
AlexandrBasan / app.js
Created June 12, 2015 02:18
Left sliding menu for website.
$('.icon-menu').click(function() {
$('.menu').animate({
left: "0px"
}, 200);
$('body').animate({
left: "285px"
}, 200);
});
@AlexandrBasan
AlexandrBasan / _error_messages.erb
Created June 24, 2015 04:49
Add custom error using standard Rails error Model
<% if object and object.errors.any? %>
<div class="error_explanation">
<h2><%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.model_name.human.downcase %> from being saved:</h2>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
Open Rails console in jruby:
jruby -S bundle exec rails console
jRuby RailsCast
http://railscasts.com/episodes/376-jruby-basics
@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>
@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 / 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