Skip to content

Instantly share code, notes, and snippets.

View Sohair63's full-sized avatar
🎯
Focusing

Sohair Ahmad Sohair63

🎯
Focusing
View GitHub Profile
# frozen_string_literal: true
module ControllerMacros
def login_user
before(:each) do
@request.env['devise.mapping'] = Devise.mappings[:user]
current_collaborator = FactoryBot.create(:account_collaborator, :admin)
current_account = current_collaborator.account
@Sohair63
Sohair63 / http_url_validator.rb
Created January 24, 2018 12:39
ActiveModel HttpUrlValidator
# frozen_string_literal: true
module Validators
class HttpUrlValidator < ActiveModel::EachValidator
GENERIC_URI_FORMAT = /^((ftp|http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
def validate_each(record, attribute, value)
uri = parse_uri(value)
record.errors.add(attribute, :bad_uri, options) unless uri
end
@Sohair63
Sohair63 / checkbox_dynamic_selection_with_foundation_dropdown.html.erb
Created August 2, 2017 06:31
This gist provides bulk selection; after bulk selection there appear a dropdown which shows count of selected resources and an action button that submit to the form Update/Delete/ etc.
<script type="text/javascript">
// JAVASCRIPT
function bind_bulk_toggle(resource_toggle_id, form_id) {
return $(resource_toggle_id).click(function() {
if ($(resource_toggle_id).is(':checked')) {
$(form_id + ' input:checkbox').prop('checked', true);
return $(form_id + ' input:checkbox').each(function() {
return $(this).val($(this).parents('tr').find('.selected_ids').val());
});
@Sohair63
Sohair63 / gist:bf9eb0f85e2614c140c033874ee13375
Created June 8, 2017 09:10 — forked from jvenator/gist:9672772a631c117da151
PDFtk Server Install Workaround for Mac OS X

Installing PDFtk Server edittion on your Mac

This workaround install is necessary because PDFtk was pulled from homebrew-cask due to issues with it aggressively overwriting file permissions that could impact other installed libraries. See this homebrew-cask issue.
The following steps worked on Mac OS X 10.10.1 with a standard brew installation for the PDFtk Mac OS X server libary version 2.02.
All Terminal commands separated by a full line space. Some commands wrap into multiple lines.

Download and extract the Mac OS X server install pacakge

@Sohair63
Sohair63 / en.yml
Created May 24, 2017 05:24 — forked from adamico/en.yml
Rails 4 with I18n working interpolations
en:
errors: &errors
messages:
bad_uri: is an invalid url
bad_protocol: must start with %{protocols}
activemodel:
errors:
<<: *errors
activerecord:
errors:
@Sohair63
Sohair63 / email_validation_service.rb
Created May 18, 2017 19:10
This is custom email format validation service that hold all the cases.
require 'resolv.rb'
class EmailValidationService
DOMAIN_LENGTH = 255
LOCAL_LENGTH = 64
LOCAL_PART_SPECIAL_CHAR = /[\!\#\$\%\&\'\*\-\/\=\?\+\-\^\_\`\{\|\}\~]/
def self.valid_email_format?(email)
begin
@Sohair63
Sohair63 / bulk_checkbox_selection.html.erb
Created May 18, 2017 19:06
this gist includes javascript/coffee with ruby on rails form to bulk / individual checkbox selection
<script type="text/javascript">
// JAVASCRIPT
window.bind_bulk_resources_checkbox_toggle = function() {
return $('#bulk_toggle_checkbox').click(function() {
if ($('#bulk_toggle_checkbox').is(':checked')) {
$('#bulk_form input:checkbox').prop('checked', true);
return $('#bulk_form input:checkbox').each(function() {
return $(this).val($(this).parents('tr').find('.selected_ids').val());
@Sohair63
Sohair63 / custom_logger.rb
Last active May 18, 2017 19:23
Rails Logging with Custom Logger
module Logging
class CustomLogger
DEFAULTS = {
level: :info
}
LEVELS = %w(debug info warn error fatal unknown).map(&:to_sym)
def self.log(*tags, **params)
level = determine_log_level(**params)