# Gemfile
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
gem 'capybara'
-
Include Weather Icons in your app: https://github.com/erikflowers/weather-icons
-
Include the below JSON in your application, for example purposes, lets assume it's a global named
weatherIcons. -
Make a request to OpenWeatherMap:
req = $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=?');| _ = require 'underscore' | |
| # Given an array of elements ELEM and a matching KEY value, | |
| # will build the apprpriate projection to generate sortable | |
| # weights for a mongo aggregator. | |
| # | |
| # ELEM: An array of values upon which to match against KEY | |
| # KEY: The document field key to match against | |
| # I: Default 0, index into array at which to begin | |
| # |
#Simple Authentication with Bcrypt
This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.
The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).
You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault
##Steps
| # UPDATE: Ruby 2.0.0 https://docs.ruby-lang.org/en/2.0.0/Kernel.html#method-i-__dir__ | |
| # $ ruby -v | |
| # ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] | |
| # $ pwd | |
| # /Users/dev/Documents/Github/Gists/awesome/ | |
| # $ echo "puts __dir__" > how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb | |
| # $ cat how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb | |
| # puts __dir__ | |
| # $ ruby how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb |
| # update application.rb | |
| # config.middleware.insert_before(ActionDispatch::Static, TracePoint::Middleware) | |
| class TracePoint | |
| class Middleware | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) |
| t = 236 # seconds | |
| Time.at(t).utc.strftime("%H:%M:%S") | |
| => "00:03:56" | |
| # Reference | |
| # http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time |
YARD CHEATSHEET http://yardoc.org
May 2020 - updated fork: https://gist.github.com/phansch/db18a595d2f5f1ef16646af72fe1fb0e
cribbed from http://pastebin.com/xgzeAmBn
Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.
| require 'rubygems' | |
| require 'yaml' | |
| # A demonstration of YAML anchors, references and handling of nested values | |
| # For more info, see: | |
| # http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/ | |
| stooges = YAML::load( File.read('stooges.yml') ) | |
| # => { | |
| # "default" => { |
| module BinaryTree | |
| class Node | |
| attr_reader :word, :count, :left, :right | |
| include Enumerable | |
| def initialize(word) | |
| @word, @count = word, 1 | |
| end |