Giter Site home page Giter Site logo

scrapbook2's Introduction

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

In rails 5.x you need to do

ActiveModel::Type::Boolean.new.cast('true')

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

scrapbook2's People

Contributors

aried3r avatar bmalets avatar equivalent avatar ivan-leschinsky avatar limeblast avatar rdunlop avatar serixscorpio avatar tom-lord avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.