Skip to content

Instantly share code, notes, and snippets.

@noelworden
Last active August 8, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noelworden/3bcfa71da8a0de00dc6293a9f29d4f25 to your computer and use it in GitHub Desktop.
Save noelworden/3bcfa71da8a0de00dc6293a9f29d4f25 to your computer and use it in GitHub Desktop.
'little' things to make life easier, #helpers

VIM

VSCode

Change language

  • ctrl + shift + L

Extra Empty Characters Before a String

  • Problem output

    • \uFEFFvendor_id
  • Use xxd to confirm

  • Check that you have xxd

    • which xxd
  • Run xxd

    • head -n 4 ~/downloads/newmappings.csv| xxd
  • Example output (note the three dots)

    • 00000000: efbb bf76 656e 646f 725f 6964 2c6e 616d ...vendor_id,nam
  • One solution

    • pbcopy < path/to/newmappings.csv & pbpaste > path/to/newmappings.csv
  • Another solution

    • tail -c +4 < path/to/newmappings.csv

Git

When this error comes up:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> nw/CVS-119/MetroNorth

Run this: git pull origin nw/CVS-119/MetroNorth

Fixup into existing commit (last commit)

$ git add ...                           # Stage a fix
$ git commit --fixup=a0b1c2d3           # Perform the commit to fix broken a0b1c2d3
$ git rebase -i --autosquash a0b1c2d3~1 # Now merge fixup commit into broken commit

Fixup into a commit other than last commit

$ git add ...                           # Stage a fix
$ git commit --fixup 8ebb3bd            # Use the SHA from commit to be added to
$ git rebase -i master                  # Stage a fix

Once in the interactive console, the new commits should be under the commit to be added to. Change the new commit from pick to fixup

acts_as_list gem

  • Repo: Beekman
  • Problem: When using acts_as_list on offer model, and scoping with published_at previously working tests starting failing
  • Solution: Add add_new_at: nil, so the entire acts_as_list markup looks like this:
    acts_as_list scope: [:published_at], add_new_at: nil
    
  • Explanation: When testing, acts_as_list was including a position with each item created for the testing, this would then trigger other components of the offer.rb model. It would also give any new item created in the CMS a position, which didnt necessarily break anything, but is not proper behavior.

Lodash

JavaScript utility library https://lodash.com/

Rake Task

  • Building custom rake tasks

  • files live in lib/tasks

  • This is a rake task to update each Club with its timezone

    namespace :time_zone do
      desc 'Populate club time_zones'
      task populate_time_zones: :environment do
        puts ' - updating club time_zones'
        Club.find(1).update_attribute(:time_zone, "Central Time (US & Canada)")
        Club.find(2).update_attribute(:time_zone, "Eastern Time (US & Canada)")
        Club.find(3).update_attribute(:time_zone, "Eastern Time (US & Canada)")
        Club.find(4).update_attribute(:time_zone, "Eastern Time (US & Canada)")
        ...
        Club.find(185).update_attribute(:time_zone, "Mountain Time (US & Canada)")
        puts ' - club time_zones update complete'
      end
    end
    
    • namespace -> Used to group multiple, similar rake tasks (not applicable in this example, not actually needed for this one)
    • desc -> Description so one doesnt have to read the code, also displays when using rake -T to see all available tasks
    • task -> Name of the task
    • :environment -> Loads the environment, to have access to Club
    • call with rake time_zone:populate_time_zones
  • A more automated rake task:

    namespace :users do
      desc 'Recalculates Badges for All Users'
      task recalculate_badges: :environment do
        User.find_each do |user|
    
          puts "#{user.first_name} #{user.last_name} - #{user.email}"
          RecalculateBadges.new(user).all
    
        end
      end
    end
    
    • Utilizing an each function for a more automated script
  • Resources:

Postgres Import

  • confirm db and user by using the psql interface
    • psql
    • \l <- lists out all the databases and associated users
  • psql -U noelworden crunch_class_development < /Users/noelworden/crunch_class_development.pgsql
  • psql -U noelworden <- user
  • crunch_class_development <- DB to be imported into
  • /Users/noelworden/crunch_class_development.pgsql <- location of the DB dump

Postgres DB being used accessed

  • if this error occurs

    • PG::ObjectInUse: ERROR: database "crunch_class_development" is being accessed by other users
  • run this command, with the appropriate db after grep

    • ps ax | grep crunch
  • should get something like this:

    6186   ??  S      0:00.78 spring server | crunch-class | started 93 hours ago
    6187   ??  Ss     6:55.65 spring app    | crunch-class | started 93 hours ago | development mode
    97841   ??  Ss     0:00.15 postgres: root crunch_class_development ::1(61095) idle
    
  • pick an ID (first column) and run:

    • kill 6168
  • middleman freeze

    • lsof -i tcp:4567
    • kill -9 "PID"

Git

  • reset branch to master
    • git reset --hard origin/master

Adding to Branch

  • commit as normal, message does not matter
  • git rebase -i master
  • pick fixup for whatever commit should be added to the branch

Clear local browser

  • localStorage.clear()
    • (in the dev tools console)

JS Dropdown in front of next div

  position: absolute;
  z-index: 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment