Skip to content

Instantly share code, notes, and snippets.

View akshaymohite's full-sized avatar

Akshay Mohite akshaymohite

View GitHub Profile

Advanced JavaScript Learning Resources

This is a list of advanced JavaScript learning resources from people who responded to this [Tweet][13] and this [Tweet][20].

  • [You Don't Know JS][3]

  • [Frontend Masters courses by Kyle Simpson][12]

  • [@mpjme][6]'s [YouTube videos][5]

@akshaymohite
akshaymohite / devise_parameter_sanitizer.rb
Created July 22, 2017 13:03
devise_parameter_sanitizer method
# Set up a param sanitizer to filter parameters using strong_parameters. See
# lib/devise/parameter_sanitizer.rb for more info. Override this
# method in your application controller to use your own parameter sanitizer.
def devise_parameter_sanitizer
@devise_parameter_sanitizer ||= Devise::ParameterSanitizer.new(resource_class, resource_name, params)
end
@akshaymohite
akshaymohite / pg_stat_statements
Created July 20, 2017 17:13 — forked from troyk/pg_stat_statements
enable postgres pg_stat_statements
1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql
@akshaymohite
akshaymohite / user-image-attachment.rb
Last active July 19, 2017 12:18
ActiveStorage: Image upload
user = User.create!(name: 'Akshay')
user.image.attach(io: File.open(Rails.root.join("public", "nature.jpeg")), filename: 'nature.jpg' , content_type: "image/jpg")
#(0.2ms) BEGIN
# SQL (0.4ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["key", "jd7L8dydnt11tXpsWWX9AXbw"], ["filename", "nature.jpg"], ["content_type", "image/jpg"], ["byte_size", 10055], ["checksum", "A5p01Zn3Rq3lG1gU8eji0w=="], ["created_at", "12:17:47.164687"]]
# (1.0ms) COMMIT
# (0.1ms) BEGIN
# SQL (0.3ms) INSERT INTO "active_storage_attachments" ("name", "record_gid", "blob_id", "created_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["name", "image"], ["record_gid", "gid://activestorage-demo/User/1"], ["blob_id", 2], ["created_at", "12:17:47.168074"]]
# (0.3ms) COMMIT
@akshaymohite
akshaymohite / activestorage-boot-error.log
Created July 19, 2017 11:48
ActiveStorage: Boot Error Log
➜ activestorage-demo git:(master) ✗ rails console
(erb):11:in `<main>': Cannot load `Rails.config.active_storage.service`:
undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/akshay/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/erb.rb:896:in `eval'
from /Users/akshay/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/erb.rb:896:in `result'
from /Users/akshay/.rvm/gems/ruby-2.4.0/gems/activestorage-0.1/lib/active_storage/railtie.rb:37:in `block in <class:Engine>'
from /Users/akshay/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.2/lib/active_support/lazy_load_hooks.rb:43:in `execute_hook'
@akshaymohite
akshaymohite / storage_services.yml
Created July 19, 2017 11:45
ActiveStorage: storage_services.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
amazon:
service: S3
@akshaymohite
akshaymohite / activestorage_tables.rb
Created July 19, 2017 11:04
ActiveStorage: Migration
class ActiveStorage::CreateTables < ActiveRecord::Migration[5.1]
def change
create_table :active_storage_blobs do |t|
t.string :key
t.string :filename
t.string :content_type
t.text :metadata
t.integer :byte_size
t.string :checksum
t.time :created_at
@akshaymohite
akshaymohite / database.yml
Created July 19, 2017 10:37
ActiveStorage: database.yml
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: activestorage-demo-development
test:
@akshaymohite
akshaymohite / user.rb
Created July 19, 2017 10:10
ActiveStorage: User Model
class User < ApplicationRecord
has_one_attached :image
end
@akshaymohite
akshaymohite / create_users.rb
Created July 19, 2017 10:06
ActiveStorage: Create Users
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :name
t.file :image
t.timestamps
end
end
end