Skip to content

Instantly share code, notes, and snippets.

View skipcloud's full-sized avatar

Skip Gibson skipcloud

View GitHub Profile
@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
@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 / 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 / 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 / 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-prepush.md
Last active January 27, 2020 14:03
Don't push to Master

Just had a fun moment where I didn't realise I was on the master branch of repo and was able to force push after a rebase (a dance I'm so used to during development I do it almost without thinking). If you're like me and don't want that to happen to you you can set up a safe guard to stop you ever being able to push to master. What you need in your life is a simple git hook. Here are the steps to create your own if you want

Tell git where to find your templates for new repos:

> git config --global init.templatedir $HOME/.git_template

Next, create that directory with a hooks directory inside it

> mkdir -p $HOME/.git_template/hooks
@skipcloud
skipcloud / vim-syntax.md
Created January 27, 2020 08:51
How about some colour in your git commits?

Most of you use vim everyday as it's the default editor that is opened when editing git commits. Instead of dealing with a wall of white text why not enable syntax highlighting? If you use vim as your editor or you have $EDITOR set to something else then this one isn't as useful for you.

Create a file .vimrc in your home directory with syntax on. This file is sourced everytime you start vim.

echo syntax on >> $HOME/.vimrc

There's a bunch of default colour schemes to choose from, to enable one just append colorscheme <name-of-color-scheme> to your .vimrc

blue
darkblue
@skipcloud
skipcloud / computers-and-dates.md
Last active January 28, 2020 09:26
Some information about computers, numbers, and dates.

Good morning! Couldn't think of a tip for you but still wanted to write something to spread some knowledge. This is about how computers handle numbers, specifically how it affects dates. This might be a little waffle-y.

Do you remember the Y2K problem? To understand why this was an issue we need to know a little about computers back when they were in their infancy, the 50s and 60s, when memory was at a premium. In 1965 the PDP-7 computer[1] had a whopping 9KB of memory, which could be expanded to a eye watering 144KB. As we got into the 70s memory improved but not by much, this meant that when programs were being written they had to be as economical as possible when it came to memory. One way of doing that is to store dates as two digits 00-99, after all this won't be an issue in the future because computers will improve and this code won't be running then, right? If you know anything about programming you know there is a lot of code running in production that has been there a long time.

The issue here is

@skipcloud
skipcloud / git-fixup.md
Last active February 5, 2020 04:52
Use fixup and autosquash to tidy up your commits

Git is a great tool, one that (when commits are created correctly) makes PRs easier to review and even makes life easier for developers in the future who might need to investigate your code. This isn't a post about what makes a good commit but generally you want to avoid things like "fixed typo" or "removed comment", these are of no use to anyone. But say you realise you need to make a change that's relevant to a commit that's a few commits down in your log, like this:

e8e6ecb (HEAD -> master) Change relevant to commit B
01d71d1 commit C
064b768 commit B
7519200 commit A

If that change was instead better suited to go with commit C then you could've added it to it with git add <files> && commit -v --no-edit --amend which will add it to your previous commit without seeing if you want to amend the commit message.

@skipcloud
skipcloud / cdr.md
Created February 5, 2020 08:15
Small bash function to cd back to the top level of your git projects

Have you ever been digging around in the bowels of a repo on the command line

app
├── spec
│   ├── base_application_spec.rb
│   ├── call_center
│   │   ├── consumer
│   │   │   ├── application_spec.rb
│   │   │   ├── areas
│   │   │   │   ├── account_spec.rb &lt;---- you are here