spec
|--- apis #do not put into controllers folder.
|--- your_api_test_spec.rb
|--- controllers
|--- models
|--- factories
|--- views
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
| require 'rspec' | |
| class Array | |
| def custom_group_by(&block) | |
| results = {} | |
| each do |e| | |
| (results[block.call(e)] ||= []) << e | |
| end |
#!/bin/ruby --verion => 2.0.0-p353
In Ruby, self is a special variable that always references the current object.
- Inside class or module definition, self refer to the Class or Module object.
- Inside instance method, self refer to future instance object.
- Inside class method, self refer to the class.i
Install ImageMagick for image conversion:
brew install imagemagick
Install tesseract for OCR:
brew install tesseract --all-languages
Or install without --all-languages and install them manually as needed.
It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.
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
| const memoize = (fn) => { | |
| let cache = {}, key; | |
| return (...args) => { | |
| key = JSON.stringify(args); | |
| return cache[key] || (cache[key] = fn.call(null, ...args)); | |
| } | |
| }; |
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
| const memoize = (fn) => { | |
| let cache = {}, key; | |
| return (...args) => { | |
| key = JSON.stringify(args); | |
| return cache[key] || (cache[key] = fn.call(null, ...args)); | |
| } | |
| }; |
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
| # autoload concerns | |
| module YourApp | |
| class Application < Rails::Application | |
| config.autoload_paths += %W( | |
| #{config.root}/app/controllers/concerns | |
| #{config.root}/app/models/concerns | |
| ) | |
| end | |
| 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
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| gempaths = Gem::default_path | |
| puts | |
| puts "Scanning paths in Gem::default_path for RubyGems with native extensions ..." | |
| puts |
OlderNewer