Skip to content

Instantly share code, notes, and snippets.

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

Ademola Ogunmokun Ademola101

🏠
Working from home
View GitHub Profile
@structuralartistry
structuralartistry / fading_flash_notice_rails
Created December 23, 2010 00:31
Simple fading flash[:notice] in Rails with jQuery
# I struggled with getting a fading flash[:notice] that would work both with standard served pages as well
# as ajax requests. I saw a number of posts online but did not have luck with or they seemed too
# complicated. This is what I ended up with from experimentation.
# Place the following code in application_helper.rb. Note that you need to either change or name your
# containers as I have in this code:
# application_helper.rb
module ApplicationHelper
@sumitasok
sumitasok / user.rb
Created April 24, 2012 09:35
accepts_nested_attributes_for - Rails association management using single form submit.
# model file
class User < ActiveRecord::Base
has_many :books
accepts_nested_attributes_for :books, :reject_if => lambda {|book| book[:name].blank? }, :allow_destroy => true
end
# :reject_if => it passes the whole hash passed from browser with book details into this Proc(lambda) and iterates over each book hash. The book record is not created if the condition given in the lambda block is satisfied.
# :allow_destroy => if set to true, then the book record that was passed from browser, while submitting User form, with a key-value pair :_destroy => 1 (or '1' or true or "true") will be destroyed
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@rayning0
rayning0 / gist:6724800
Last active October 28, 2021 22:29
My_Each method, using Yield
# Read about the yield keyword and ruby blocks.
# http://allaboutruby.wordpress.com/2006/01/20/ruby-blocks-101/
# http://ruby.about.com/od/beginningruby/a/Block-Parameters-And-Yielding.htm
# http://blog.codahale.com/2005/11/24/a-ruby-howto-writing-a-method-that-uses-code-blocks/
# http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
# Now that you know how the yield method works, try to write your
# own version of the each method without using the each method
# provided by ruby. As in, try to build my_each using only the
@rxaviers
rxaviers / gist:7360908
Last active June 26, 2024 16:59
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@jczaplew
jczaplew / herok_github.md
Last active January 11, 2023 10:41
Heroku + Github + Sensitive Data

Heroku + Github + Sensitive Data

Scenario: You deployed a Heroku project that contains sensitive data (password, API key, etc) but you want to share it on Github.

Problem: You need to commit all files necessary for the application to run on Heroku. However, pushing this to Github would reveal the sensitive info.

Solution: Have a production branch (for this example, master will be the production branch) and a Github branch. The latter contains a different .gitignore that ignores the sensitive files.

@cferdinandi
cferdinandi / terminal-cheat-sheet.txt
Last active June 19, 2024 03:05
Terminal Cheat Sheet
# Terminal Cheat Sheet
pwd # print working directory
ls # list files in directory
cd # change directory
~ # home directory
.. # up one directory
- # previous working directory
help # get help
-h # get help
@maxivak
maxivak / 00.md
Last active May 23, 2024 13:24
Sending emails with ActionMailer and Sidekiq

Sending emails with ActionMailer and Sidekiq

Send email asynchroniously using Sidekiq.

ActionMailer

Create your mailer us usual:

@akshaymohite
akshaymohite / sample-readme-for-a-rails-project.md
Created April 21, 2017 07:09
Sample README.md for a Rails Project
Prerequisites

The setups steps expect following tools installed on the system.

1. Check out the repository
@withoutwax
withoutwax / custom_fields_devise.markdown
Last active April 27, 2024 00:43
Adding Custom Fields to Devise

Adding Custom Fields to Devise

Before doing anything, please check the versions of the gem files:

gem 'rails', '~> 5.1.4'
gem 'devise', '~> 4.4.0'

Disclaimer - This solution may not work with older versions of rails and devise. Versions listed above were the latest versions of gems which I was using at the time of creation and tests. (10 Jan 2018)