Download a single directory from a repo on github

I went looking for “how download a single directory from within a repo on github”. Here’s what I found in their documentation – https://developer.github.com/v3/repos/contents/#get-archive-link. Below is my interpretation of that doc, having spent a total of 30 seconds reading it. Maybe if I spend another 30 seconds at some point, I’ll find out how to actually get just a single folder, instead of the whole repository (just as an archive, so no .git history). But this is what I ended up doing.

1. Construct a url starting with https://api.github.com/repos/
2. Follow that with the repository owner, the name of the repo, and format you’d like to download
3. curl it

curl -L https://api.github.com/repos/Automattic/vip-go-mu-plugins/tarball > tarball.tar

After that, I used the somewhat lazy method of opening the directory in the finder and untarring it with Mac’s Archive utility, instead of using the command line, pulled out the folder I wanted, and deleted the rest.

Advertisements

grep has tons of great options, like

-F = fgrep; no regex – way faster
-v = as mentioned in the article
-o = print only matched input, not the entire line
-C = context, print lines before and after the match; can also be used partially with -A (after) and -B (before)

Recursively grep a directory

grep -r "texthere" .

#grep

Sometimes you don’t have a…

Sometimes you don’t have a debugger handy, but you have a function acting weird and you want to know where it’s being called. You can find out using the backtrace, like this –

echo debug_backtrace()[1]['function'];

And send that to /tmp/php-errors by using error_log.

error_log( "called by: " . debug_backtrace()[1]['function'] );

Tail error logs in VIP…

Tail error logs in VIP Go containers like this –

[/chroot/var/www $tail -F /chroot/tmp/php-errors -F /tmp/php-errors

I like using the command…

I like using the command line whenever I can. I had a GUI for editing my hosts file for development work. but I really disliked it. Way too clunky. I found a ruby script that does the job more easily. It’s at https://github.com/markjaquith/Localdev and you can install it on your Mac with sudo gem install localdev

The command is “localdev”, but even that is too much typing for me. I aliased it to ld, and the “add” command to ldadd, but the script defaults to using localhost as the ip address. To make my sandbox ip the default, I needed to add it to the alias, and also get an argument in between “add” and the ip. bash_profile allows functions for that kind of thing.

alias ld="localdev"
ldadd() { localdev add "$1" 192.0.95.13; }

The command needs sudo access which you can get around by adding this line to the sudoers file:

$sudo visudo -f /etc/sudoers
shannon ALL = NOPASSWD: /usr/bin/localdev

Restart the session to make sure it takes.

It’s annoying to type in…

It’s annoying to type in your svn password every time you want to svn up.

Try running SVNAUTHCACHE=1 svn up -N ~/public_html on the sandbox. Thanks Paul Kevan for the tip.

I made an Alfred workflow…

It’s documented elsewhere that HSTS can make sandboxes act weird sometimes. You get the https “unsafe site!” warning error, except in this case, you can’t click the “I know what I’m doing” button to get past it. Here’s the field guide page about it.

In Firefox there’s a way around it using the Dev edition. In Chrome you can visit chrome://net-internals/#hsts and delete the domain in question from the HSTS set, but that’s kind of annoying.

I made an Alfred workflow for flushing the HSTS cache with a keyword instead. Triggers on “fl {query}”.

On GitHub

on alfred_script(q)

    tell application "Google Chrome"
        open location "chrome://net-internals/#hsts"
    end tell
    delay 1
    
	tell application "Google Chrome"
        execute front window's active tab javascript         
        "document.getElementById('hsts-view-delete-input').value='" & q & "';"
delay 1
        "document.getElementById('hsts-view-delete-submit').click(); "
delay 1
        delete tab (active tab index of front window) of front window
    end tell

	tell application "Google Chrome"
        open location "http://" & q
    end tell
end alfred_script