Skip to content

Instantly share code, notes, and snippets.

@bongardino
Last active June 28, 2018 02:44
Show Gist options
  • Save bongardino/274067c0676f37d54653b3ebaeebe4d0 to your computer and use it in GitHub Desktop.
Save bongardino/274067c0676f37d54653b3ebaeebe4d0 to your computer and use it in GitHub Desktop.
daily introspection

TIL - Today I learned

6/17

You can chain `/*` after an `ls` to travrse child folders.

ex:
~ ❯ ls Movies/*
Movies/Final Cut Backups.localized:
Untitled

Movies/Motion Templates.localized:

Movies/Untitled.fcpbundle:
CurrentVersion.flexolibrary Lib                         Settings.plist              __Temp
CurrentVersion.plist        Motion Templates.localized  __Sync__                    fuhh
~ ❯ ls Movies/*/*
Movies/Untitled.fcpbundle/CurrentVersion.flexolibrary Movies/Untitled.fcpbundle/Settings.plist
Movies/Untitled.fcpbundle/CurrentVersion.plist        Movies/Untitled.fcpbundle/__Sync__

Movies/Final Cut Backups.localized/Untitled:
20170730_2014_EDT.fcpbundle Previous Versions.localized

Movies/Untitled.fcpbundle/Lib:
CurrentVersion.fcpevent Render Files            Shared Items
Original Media          Share                   Transcoded Media

Movies/Untitled.fcpbundle/Motion Templates.localized:

Movies/Untitled.fcpbundle/__Temp:

Movies/Untitled.fcpbundle/fuhh:
CurrentVersion.fcpevent Render Files            Transcoded Media
Original Media          Shared Items            fuuuuhhh

6/18

Sublime Hotkeys.

⌘+D hightlight the next instance of the current selection for easy edits
⌘+SHIFT+ENTER new line above current line
⌘+[``⌘+] indent left and right

6/19

Super Duper!

Using super to inherit initialize vars from other classes keeps you nice and dry. Also its easier

Because why not

Apparently this
Explosive.new(item_name: "Explosive Sheep", description: "Baahhhhd Dreams", cost: "18 silver")

is a valid hash in Ruby. Because it looks nice so it must be valid. Everything is optional!

6/20

Modules are kind of the best

  • Name Spacing
  • Inheritance
  • Wrapping
  • I get why modules are a thing now!

    Inheritence is useful but gets really gross really fast with Classes. Choosing what inherits from what quickly gets dicey. Enter modules! Inherit from modules into multiple classes to keep your code dry and less confusing. Wrap modules / classes in more modules to name space them

    6/21

    system "clear"

    It clears the screen.

    system "clear"

    That's it.
    IDK dude but it blew my mind

    6/24

    pop

    While trying to reverse an array without using .reverse, I was introduced to pop of the array instance method. This article eloquently accomplished what I was trying to do and explains the method nicely. (thanks to heatherkylee for the link)

    6/25

    rails db:seed

    Rails has a built in method (method?) to seed your database with info. Helpful for testing and play.

    To do this wonderful thing :

  • put a loop in your `$app/db/seeds.rb` file.
  • use faker for varience, and also fun.

    10.times do
      new_user = Contact.new( first_name: Faker::Name.first_name,
        last_name: Faker::Name.last_name, email: Faker::Internet.email,
        phone_number: Faker::PhoneNumber.phone_number, crazy: Faker::Boolean.boolean )
      new_user.save
    end
    

    then call the method. I think its a method. IDK I haven't gotten that far.

    cd $rails_app
    rails db:seed
    

    Boom! Fake data.

    6/26

    create!

    Replace Model.new / Model.save with create!
    Saves a step and fails loudly if you did it wrong.

    6/27

    routes?params/routes/params:

    You can pass data into your app with routes and params. I've been doing this via curl forever but the pieces didn't fit together quite so well until I learned this.

    query params:
    get /random_url/ => random#random_number_action "foo.com/random_url/?id=4"

    segment params:
    get /other_random_url/:params => random#other_random_number_action "foo.com/random_url/4"

    Are there other routes? Maybe! Oh man.

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