Skip to content

Instantly share code, notes, and snippets.

@luke0x
Last active August 29, 2015 13:56
Show Gist options
  • Save luke0x/8981781 to your computer and use it in GitHub Desktop.
Save luke0x/8981781 to your computer and use it in GitHub Desktop.
Dev Notes

Dev Notes

Rename App

Rename Postgresql user

psql template1 -c 'ALTER USER "keezy-api" RENAME TO "keezy-web"';

Rename Postgresql database

psql template1 -c 'ALTER DATABASE "keezy-api_development" RENAME TO "keezy-web_development"';

psql template1 -c 'ALTER DATABASE "keezy-api_test" RENAME TO "keezy-web_test"';

Sort shell output by number in the first column

cat lines |sort -n -k1,1

See 404s in Rails development environment

In config/development.rb:

config.consider_all_requests_local = false

Best monospaced fonts

  1. Inconsolata-dz
  2. Inconsolata
  3. Consolas
  4. Menlo

Style Atom scrollbar

::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: none;
}
::-webkit-scrollbar-thumb {
  background: rgb(106, 107, 108);
}

Style Atom Tree View

.tree-view {
  font-size: 12px;
}

Change Atom line height

.editor {
  line-height: 1.6;
}
.editor .cursor {
  line-height: 1.6;
}

Style Atom Find And Replace

.preview-pane .results-view .preview {
  font-family: Inconsolata-dz;
  font-size: 13px;
}

Fix Homebrew node package

#!/bin/bash

for man in 1 3 5 7; do
  ln -sf /usr/local/lib/node_modules/npm/man/man${man}/* /usr/local/share/man/man${man}
done

ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

npm update npm -g

Uninstall node.js

#!/bin/sh
(( ${#} > 0 )) || {
  sudo ${0} sudo
  exit $?
}

[ -e /var/db/receipts/org.nodejs.pkg.bom ] || {
  echo 'Nothing to do.'
  exit 0
}

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
  rm /usr/local/${i}
done

rm -rf /usr/local/lib/node \
  /usr/local/lib/node_modules \
  /var/db/receipts/org.nodejs.*

exit 0

Match the beginning and end of Ruby strings

  • Match the beginning of a string: \A
  • Match the beginning of a line: ^
  • Match the end of a line: $
  • Match the end of a string: \Z

Choose a specific version of a file during a git rebase

  • Prefer the current branch's file: git checkout --ours file
  • Prefer the other branch's file: git checkout --ours file
  • Revert to the conflicted merge file provided by rebase: git checkout --conflict=merge file

Merge strategy for merging highly-divergent git branches

With git you have the opportunity to do it the way it should have originally been done, after the fact. There is still work to do with the merge, but it is work that would have been needed to be done along the way anyhow. The cost isn't over-paid, it's just paid late.

  • Revert to the last commit on master where all branches diverged
  • Merge the most-divergent feature branch onto master
  • For each other branch, rebase it onto master and merge it into master

Set a default Heroku app for a Git repository

Configure a default remote for the heroku command per git repository:

git config heroku.remote heroku-remote-name

Deploy to Heroku takes a long time

This is a limited problem and occurs when a large number of files change. The Herkou deploy script runs rake assets:precompile to precompile files indicated in config.assets.precompile. These files are included in the Heroku slug and copied to the dyno /app/public/assets/ directory. The dyno filesystem keeps the 3 most-recent versions of each file on disk. Only new and changed files are compiled and copied, so the time required is typically low but occasionally more.

Search a tree for files not having an extension in an array

find . -type f |grep -vE "\.(js|css|html)$"
  • v negates the match
  • E uses a regex

Rails asset pipeline precompilation fails on files lacking extensions

  • Sprockets known issue, won't fix: sstephenson/sprockets#347
  • Workaround with Heroku step 2 only: https://gist.github.com/afeld/5704079
  • config.assets.precompile defaults to all .js and .css files
  • Verify this will get all the files we need (this is what I actually incrementally used to review the list of files): find . -type f |grep -vE "\.(js|css|html|css|html|erb|haml|png|gif|jpg|jpeg|svg|eot|otf|svc|woff|ttf|coffee|yml|md|ico|ai|eps|pdf|map|ts|map|sh|txt|rb|gemspec|php)$" |grep -vE "(README|gitignore|bower.json|LICENSE|Makefile|Rakefile|MANIFEST)"
@jackrusher
Copy link

That's a whole lotta grep right there.

$ find . -type f | grep -E ".(js|html)$"

@jarodl
Copy link

jarodl commented Feb 27, 2014

re: Match the beginning and end of Ruby strings
http://rubular.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment