Skip to content

Instantly share code, notes, and snippets.

View Talha5's full-sized avatar
🏠
Working from home

Talha Meh Talha5

🏠
Working from home
View GitHub Profile
@radavis
radavis / instructions.md
Last active August 29, 2018 19:48 — forked from jacksy40/instructions.md
Capybara/RSpec/Poltergeist. How to run javascript in your Rails test suite.

install phantomjs

brew install phantomjs

Gemfile:

group :test do
  gem 'poltergeist'
 gem 'database_cleaner'
# This works with steak 0.3.x and rspec 1.x
# For steak --pre and rspec 2 see this fork: http://gist.github.com/448487
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Spec::Runner.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if options[:js]
end
@gssbzn
gssbzn / yarm.config
Last active October 30, 2018 18:57
Elastic Beanstalk Rails+Webpacker extension
# Copyright 2018 SwiftComply.com
commands:
01_node_install:
test: "[ `node --version` != 'v8.10.0' ]"
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
02_yarn_repo:
test: "[ ! -f /etc/yum.repos.d/yarn.repo ]"
command: "curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo"
03_yarn_install:
test: "[ ! -x /usr/bin/yarn ]"
@robdodson
robdodson / crawler.rb
Created June 20, 2012 07:06
Crawl a page full of links with Mechanize
require 'mechanize'
# Create a new instance of Mechanize and grab our page
agent = Mechanize.new
page = agent.get('http://robdodson.me/blog/archives/')
# Find all the links on the page that are contained within
# h1 tags.
post_links = page.links.find_all { |l| l.attributes.parent.name == 'h1' }
@ayrton
ayrton / taggable.rb
Last active September 29, 2020 20:42
Testing Active Support concerns with rspec in isolation. See first comment for more information.
module Taggable
extend ActiveSupport::Concern
included do
attr_accessible :tags
after_save :set_tags
after_destroy :unset_tags
end
@pmarreck
pmarreck / complex_password_validation.rb
Created May 2, 2014 16:47
Example of using regex to check a complex password validation requirement ("use at least 1 character from 3 sets of characters out of a total of 4 sets of characters")
PASSWORD_VALIDATOR = /( # Start of group
(?: # Start of nonmatching group, 4 possible solutions
(?=.*[a-z]) # Must contain one lowercase character
(?=.*[A-Z]) # Must contain one uppercase character
(?=.*\W) # Must contain one non-word character or symbol
| # or...
(?=.*\d) # Must contain one digit from 0-9
(?=.*[A-Z]) # Must contain one uppercase character
(?=.*\W) # Must contain one non-word character or symbol
| # or...
@Andrew8xx8
Andrew8xx8 / Gemfile
Created June 14, 2013 10:32
Example of API with ransack search and kaminari paginate.
gem 'kaminari'
gem 'ransack'
@anotheruiguy
anotheruiguy / web-fonts-asset-pipeline.md
Last active May 24, 2023 22:08
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@kinopyo
kinopyo / custom_logger.rb
Created October 11, 2011 15:40
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@roberto
roberto / _flash_messages.html.erb
Created August 13, 2012 22:47
Rails flash messages using Twitter Bootstrap
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>