ln -s “/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl” /usr/local/bin/sublime
Faster npm install – Disable progress bar
$ npm set progress=false
$ npm install #faster
RuboCop – commands
Installing Rubocop and Overcommit
Install gems
$ gem install rubocop $ gem install overcommit
sets up githooks
$ overcommit –install
Sign changes to overcommit.yml
$ overcommit –sign
Run Rubocop against project
Displays Filename, line and description of error
$ rubocop
Rubocop Output
Symbol Description
. No issues
C Convention
E Error
F Fatal error
W Warning
Output offense name and count
$ rubocop –format offenses
Show cop definition
$ rubocop –show-cop Style/ZeroLengthPredicate
List all cops with description, key/values and link to style guide
$ rubocop –show-cops
Output offense name and count
$ rubocop –format offenses
Run a specific cop against project
$ rubocop –only Style/StringLiterals
Check a specific file with all cops
$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb
Check a specific file with all cops
$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb –only Style/StringLiterals
Check a specific file output errors as json
$ rubocop –format json app/models/app_namespace/api/v1/project.rb
Auto-correct with a specific cop
$ rubocop –auto-correct –only RedundantParentheses
Output offenses w formatted suggestion,
url to additional comments / example
$ rubocop –display-style-guide
Displays Filename, line and description of error
With url to documentation for this cop
$ rubocop –display-style-guide –display-cop-names
Show code correctness
$ rubocop –lint
List Files
$ rubocop –list-target-files
In the instance of a Merge, it may be required to Skip RuboCop
$ SKIP=RuboCop git commit -am “Merge”
Generate todo list / Turn off all cops
$ rubocop –auto-gen-config
Demystify Rails Class Methods – Get all Methods available on a class
Get all methods on a class.
It’s a long list..
puts ClassName.methods.sort.join("\n").to_s+"\n\n"
Rails / Ruby – Check db for table or column
Does table exist
def self.table_exists?(name)
ActiveRecord::Base.connection.tables.include?(name)
end
Does column exist
if table_exists?(:profile) && !TableName.column_names.include?("url")
add_column :profile, :url, :string
end
Git – list branches by date modified
When you don’t remember the branch name.. 🙁
$ git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
Search for Deleted Code via Git Command Line
$ git log -p --all -S 'string to search'
$ git log -p --all -G '(reg-ex-to-use.*)'
Postgres – psql – Find column name in any table
Find implementation of ancestry or other gems that alter the db.
select column_name, table_name FROM information_schema.columns WHERE column_name like 'parent_id'
Use Postgres to check for missing foreign keys – psql
select Distinct column_name, t1.tablename FROM information_schema.columns, (select * from pg_tables where schemaname='public' AND tablename = 'products') t1 WHERE table_name = 'projects' and column_name like '%_id' and column_name not in (
(SELECT
(SELECT a.attname FROM pg_attribute a WHERE a.attrelid = m.oid AND a.attnum = o.conkey[1] AND a.attisdropped = false) AS source_column
FROM
pg_constraint o LEFT JOIN pg_class c ON c.oid = o.conrelid
LEFT JOIN pg_class f ON f.oid = o.confrelid LEFT JOIN pg_class m ON m.oid = o.conrelid
WHERE
o.contype = 'f' AND o.conrelid IN (SELECT oid FROM pg_class c WHERE c.relkind = 'r') AND m.relname = 'products'))
postgres doesn’t start after restart. postmaster.pid may be blocking startup.
psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”?
$ rm /usr/local/var/postgres/postmaster.pid
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Note: the path to postgres may be different.