curl -X PURGE <url of cached badge image here>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def authorize_for_my_action(child_record) | |
| raise Pundit::NotAuthorizedError unless ParentPlociy.new(pundit_user, child_record).my_action? | |
| skip_authorization | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.sample = function() { | |
| return this[Math.floor(Math.random() * this.length)] | |
| }; | |
| Array.prototype.remove = function(element) { | |
| var index = this.indexOf(element); | |
| if (index > -1) { | |
| this.splice(index, 1); | |
| } | |
| return this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Slighty adapted from: stackoverflow.com/a/10478008 | |
| using System; | |
| using System.Collections; | |
| using System.Linq; | |
| using System.Collections.Generic; | |
| using System.Reflection; | |
| using System.Text; | |
| public class ObjectDumper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def extract_values_striped(hash, *keys) | |
| hash.values_at(*keys).map { |value| value.respond_to?(:strip) ? value.strip : value } | |
| end | |
| # test case ... | |
| test "#extract_values_striped helper takes a hash & keys list, then return their values stripe" do | |
| my_collection = { book: 'the pragmatic programmer', language: 'ruby', hoppy: 'swimming' } | |
| values = extract_values_striped(my_collection, :book, :hoppy, :toy) |
# Runs assert_difference with a number of conditions and varying difference
# counts.
#
# Call as follows:
#
# assert_differences([['Model1.count', 2], ['Model2.count', 3]])
#
def assert_differences(expression_array, message = nil, &block)
b = block.send(:binding)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Extend in your test_helper.rb or any other `/supprot` setup you have. | |
| class ActiveSupport::TestCase | |
| ## | |
| # === NOTICE: | |
| # Ensure you have `ActionMailer::TestHelper` in the test class .. | |
| # | |
| # This method performs any enqueued job during tests manually, | |
| # Helpful when testing the queueing of your jobs then the result of their execution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## Depends on ActiveSupport | |
| ## | |
| # Initial imple: stackoverflow.com/a/32279088 | |
| def greeting_phrase | |
| now = Time.zone.now | |
| today = Date.current.to_time | |
| morning = today.beginning_of_day | |
| noon = today.noon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewControllerExtension.swift | |
| // VirtualTourist | |
| // | |
| // Created by Abdullah on 2/15/17. | |
| // | |
| import UIKit | |
| extension UIViewController { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Convert string to a proper formatted date type. | |
| // | |
| // Swift 3.0 | |
| private func stringToDate(dateString: String?) -> Date? { | |
| if let str = dateString { | |
| let formatter = DateFormatter() | |
| formatter.dateFormat = "MMM dd, yyyy h:mm a" | |
| formatter.amSymbol = "AM" |