Skip to content

Instantly share code, notes, and snippets.

View skipcloud's full-sized avatar

Skip Gibson skipcloud

View GitHub Profile
@skipcloud
skipcloud / pry.md
Last active January 27, 2020 08:46
Working with Pry

This one is for the Ruby users. irb is the REPL that comes with Ruby, there is another one called Pry which is very popular. In fact when you SSH into Orderweb this is the REPL you get put into. It has some fun tricks that make poking around in code much easier. In my code examples >> is the pry prompt.

Editing code [1]

This one is better explained with a video but the basics of it is if you have the EDITOR environment variable set export EDITOR=vim or set it in your .pryrc Pry.config.editor = 'vim' you can then edit code. the edit command will open your text editor at a blank file saved in /tmp and you can write some ruby, save it and exit and it will bring you back to pry where your code will have been loaded in. If you edit again it will open the tmp file back up. The cool thing is you can edit specific methods with edit <method>. This one won't work on production containers but it's handy for local development.

>> edit

*inside vim*
def hi
@skipcloud
skipcloud / git-standup.md
Created January 27, 2020 08:44
Git tip!

Can't remember what you did yesterday and stand up is a few minutes away? I gotchu

> git log --author=$USER --since='9am yesterday' --format='%s'

ct-1234: WIP dear god please work
ct-1234: download extra RAM
ct-1234: add artificial sleep to make it look like service is doing work
ct-1234: hidden cat gif in the codebase
@skipcloud
skipcloud / zsh-history-expansions.md
Created January 27, 2020 08:43
A few tips around zsh history/argument expansion

Good morning, let's keep this tip train a-moving. This one is for the zsh users. History expansion is pretty cool, that section in the zsh manual is quite extensive[1] but I'm only really going to talk about one aspect of it here

I'm sure most of you are aware that !! references the previous command

> echo hi
hi
> !! <tab>
> echo hi

Well you can go back farther using this syntax !-n where n is how far back in your history you would like to go

@skipcloud
skipcloud / temporal-git-commands.md
Last active January 27, 2020 08:40
A small git tip

A friend of mine tweeted recently about how they got into such a git mess that they deleted the entire repo and re-cloned it. I know I've done that in the past so I thought I would share a neat git feature that isn't widely known: git can understand temporal strings.

For example say you are working on a branch for an hour and you completely mess it up, knowing an hour ago you were in a good place you could issue this command git reset --hard @{'1 hour ago'} . You can use all sorts of temporal langauge e.g. hours, minutes, seconds, weeks, months, years. You can even combine them git reset --hard @{'1 year 3 months 5 hours ago'}.

@skipcloud
skipcloud / readline.md
Last active January 27, 2020 09:20
Some shell shortcuts.

I've always been quite the fan of keyboard shortcuts, after all why move your hand to the mouse to dick around clicking things if you can just do the same thing without moving your fingers from the home row. In my eyes the arrow keys might as well be on the other side of the room. Did you know your shell has a bunch of shortcuts to make your life a little easier? A library called readline[1] is responsible and I think all of these work on Mac too but your milage may vary.

  • Move back through your history with ctrl-p
  • Move forward through your history with ctrl-n
  • Need to incrementally search through your history? ctrl-r has got you, you can keep pressing ctrl-r to see it's suggestions. Slight sidebar, if you have fzf[2] installed it extends this functionality showing you what it has found.
  • Are there a bunch of commands that you ran in a sequence before that you want to run again? Before I used to keep pressing up up up until I found what I needed, pressed enter, then repeated this ho