Ruby
Latest commit 9ed3b34 Jan 20, 2017 @equivalent note
Permalink
Failed to load latest commit information.
archive
assets/images
examples
notes
.gitignore
LICENSE
README.md
amazon_s3.md
angularJS.md notes Oct 29, 2015
aws_eb.md
aws_ec2_amazon.md
aws_s3_amazon.md
azure.md
bash.md
benchmark.md
bitcoin-mining.md
bootstrap.md
bundler_gems.md
capistrano-deployment.md
carrierwave.md test attachement upload May 9, 2016
code_theory.md
css_sass.md
csv_ruby.md csv Sep 27, 2016
cucumber.md selenium trick position" Mar 15, 2016
data_mapper.md train notes Jul 29, 2014
delayed_job.md
docker.md
elasticsearch.md
elixir.md
factory_girl.md
git.md
handlebarsjs.md
httparty.md notes Mar 18, 2016
iptables.md iptable Nov 16, 2016
jQuery-JavaScript-CoffeeScriipt.md
jenkins.md
linux.md
memcached.md Update memcached.md Aug 29, 2014
mini_test.md
mix.md notes Jan 20, 2017
mysql.md Update mysql.md Aug 8, 2014
net-http.md
nginx.md
nokogiri.md
paperclip.md
phoenix.md
postgresql.md
rails_action_controller.md
rails_action_dispatch_and_routing.md
rails_action_view.md
rails_active_model.md
rails_active_model_serializer.md
rails_active_record.md
rails_active_support.md
rails_caching.md
rails_config.md
rails_console_and_pry.md
rails_exceptions.md
rails_i18n_internationalization.md Update rails_i18n_internationalization.md Aug 19, 2014
rails_migrations_and_database.md
rake.md
raspberry_pi.md
rbenv.md
regex_regular_expressions.md
resque.md
rspec.md
rspec3.md
ruby.md notes Jan 6, 2017
ruby_interactive.md
ruby_rails_file_manipulation.md all models May 28, 2015
rvm.md
security_notes.md
sidekiq.md
simple_form.md
sketchup_ruby.md tomiho experiment Feb 16, 2016
theory-notes.md
travis-ci.md
unicorn.md
ux.md
vcr.md
vim.md
whenever-gem.md
windows.md Update windows.md Jan 28, 2015
xml.md
yaml.md tapas notes Jun 25, 2014

README.md

Gitten Open Thanks

Scrapbook2

Pure git/github version of my scrapbook on Ruby on Rails, web-development, linux system configuration.

##########################################################################
##                                                                      ##
##   Check individual .md files above for more information on topics    ##
##                                                                      ##
##########################################################################

Archive:

Web-development notes unsorted

Rails find session_id in rails console

#  `app` is variable  and `ENV` a constant loaded when you start rails console
a = Rails.application.config.session_store.new(app, Rails.application.config.session_options)
a.class # => ActionDispatch::Session::RedisStore
a.get_session(ENV, '07319b2485be9ac4850664cd47cede38')  # you can find session id inspecting
                                                        # your cookis via firefox or plugin

# or a.find_session(ENV, '07319b2485be9ac4850664cd47cede38')

generate ri documentation

rvm docs generate

to lunch ri Array

cowsay

require 'net/http'
require 'cgi'

class Cowsays
  def say(message)
    message = CGI.escape(message)
    Net::HTTP.get_print(URI.parse(http://www.cowsays.com/cowsay?message=#{message}))
  end
end

source: ruby tapas 30

rails all models

Rails.application.eager_load!
ActiveRecord::Base.descendants

include Rails helpers in cusom class

class Foo
  include Rails.application.routes.url_helpers
  # ... or you can Delegate methods it


  def home_macro
    h.link_to 'Home', root_path
  end

  private

  def h
    ActionController::Base.helpers
  end

end

note you can do include UrlHelper which includes link_to but this will work only for String based urls as this module was changed in Rails 4 ( check source code )

if you keep getting error arguments passed to url_for can't be handled ... your only chance is to use my former code

checkbox, radio input value to boolean

ActiveRecord::ConnectionAdapters::Column.value_to_boolean 'f'  # => false
ActiveRecord::ConnectionAdapters::Column.value_to_boolean 't'  # => true
ActiveRecord::ConnectionAdapters::Column.value_to_boolean '0'  # => false
ActiveRecord::ConnectionAdapters::Column.value_to_boolean '1'  # => true
ActiveRecord::ConnectionAdapters::Column.value_to_boolean nil  # => false

in Rails 4.2 and above this is depricated and replaced with

ActiveRecord::Type::Boolean.new.type_cast_from_database(value)

...works the same the only difference is that when nil is passed it returns nil and "y", "n" will give you deprication warning

https://gist.github.com/equivalent/3825916

Robots.txt examlpe

Dont chache content that is restricted

Tell browser not to cache content that hold harmfull data (e.g.: user settings, card details..>)

<meta http-equiv="Cache-control" content="no-cache no-store">

Memory stats simple method

def memstats
  `ps -o size= #{$$}`.strip.to_i
end

source: ruby tapas 42

grep tail

 tail -f log/production.log | grep "NoMethodError"

rails time to iso 8601 (javascript time)

"2010-10-25 23:48:46 UTC".to_time.iso8601

Gems