Skip to content

Instantly share code, notes, and snippets.

@vajradog
vajradog / .gitignore
Created December 5, 2013 15:22
Global .gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@vajradog
vajradog / secret_token.rb
Created December 5, 2013 15:33
Hiding secret_token.rb on GitHub public repository.
require 'securerandom'
def secure_token
token_file = Rails.root.join('.secret')
if File.exist?(token_file)
# Use the existing token.
File.read(token_file).chomp
else
# Generate a new token and store it in token_file.
token = SecureRandom.hex(64)
@vajradog
vajradog / application.rb
Last active January 1, 2016 16:49
bootstrap-sass compatibility in Rails 4.0
# As of Rails 4.0 we need to add a line to config/application.rb to make bootstrap-sass compatible with the asset pipeline
require File.expand_path('../boot', __FILE__)
.
.
.
module YourApp
class Application < Rails::Application
.
.
@vajradog
vajradog / application.html.erb
Created January 15, 2014 18:01
Rails, navigation buttons 'selected' stage
#...
<ul class="nav">
<li class="<%= 'active' if current_page?(root_path) %>"><%= link_to "Home", root_path %></li>
<li class="<%= 'active' if current_page?(about_path) %>"><%= link_to "About", about_path %></li>
<li class="<%= 'active' if current_page?(contact_path) %>"><%= link_to "Contact", contact_path %></li>
</ul>
#<%= yield %>
#...
@vajradog
vajradog / rack-zippy
Created January 21, 2014 19:27
Rack-zippy replaces the ActionDispatch::Static middleware used by Rails, which is not capable of serving the gzipped assets created by the rake assets:precompile task. rack-zippy will serve non-gzipped assets where they are not available or not supported by the requesting client.
gem 'rack-zippy'
bundle install
Add this line to config/application.rb
config.middleware.swap(ActionDispatch::Static, Rack::Zippy::AssetServer)
Push to Heroku and you’re done.
@vajradog
vajradog / Date formatting in rails
Created March 14, 2014 16:09
formatting date to words in rails
<%= applicant.start_date %> gives out 2014-04-14
<%= applicant.start_date.strftime("%B %d, %Y") %> gives out April 14, 2014
<%= applicant.start_date.strftime("%B #{applicant.start_date.day.ordinalize}, %Y") %> gives out April 14th, 2014
@vajradog
vajradog / rails_nav.md
Last active August 29, 2015 14:07
Set pages as header and footer navigations in Rails.

##Set pages as header and footer navigations in Rails.

I am not sure if this is the best solution, I made this up while working on a project but I hope it helps someone.

Assuming you already have a page model and can CRUD pages.

rails g migration add_nav_to_pages
@vajradog
vajradog / auto_expiration.md
Last active April 5, 2021 22:33
Set auto expiration for rails models

##Set auto expiration for rails models.

This is a simple view logic that moves objects based on a predetermined date.

Let's say we have a bunch of events(or posts) on our index page and we want to sort out which of these are still active and which are not (based on the time).

We want the active ones to be clickable and prominent, we want the non-active ones to be greyed-out or even hidden. So how do we do this?

Rails provide a simple yet powerful method: future?()

@vajradog
vajradog / capybara_cheat_sheet.md
Last active October 9, 2017 23:34
capybara cheat sheet (capybara (2.4.4): May 2015)

Created this cheat-sheet for personal reference on May 17, 2015. For detailed documentation and updates you should visit https://github.com/jnicklas/capybara

###Navigating

visit('/projects') or visit '/projects'
visit(post_comments_path(post)) or visit post_comments_path(post)

###Clicking links and buttons click_link('id-of-link') click_link('Link Text')

@vajradog
vajradog / index.html
Created February 17, 2023 11:34
xxaGYGj
<!--
Audio player courtesy of Ivan
https://codepen.io/k-ivan/pen/pJMLmJ
-->
<div class="audio-player">
<div class="player-head">
<div class="player-image">
<img src="https://images.unsplash.com/photo-1542438408-abb260104ef3?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1935&q=80" alt="" />
</div>