4 de agosto de 2015

Pimp my GIT: Improving GIT command line (cli) interface and usage

Aloha!


Following up yesterday's post, here goes another set of tricks I have done to my GIT setup.

To begin with, add this code to yhe .git/config file of your git repo clone:



Once you do that, you'll see things like colors when running a "git status":




You'lll also be able to use git command shortcuts, like:

- "git st" instead of "git status"
- "git ci" instead of "git commit"
(etc!)


Logs will look much more sexy and colorful.

You'll see diffs with colors and with a much more user-friendly format:





When running "git branch", you'll see the current branch highlighted and the local branches clearly marked in yellow:



And remote branches in green:




That's all for today, folks!


Cheers!

3 de agosto de 2015

Setting sail towards an awesome GIT experience

Here goes a bundle of tricks and treats for a better GIT experience:

Some years ago I found something like that I'm going to show you and, eventually, I assembled a series of scripts (some things I did, some things that I found on the web); they do various things with bash, which are sweet.

What things?


  • Automatically detects if you are in a folder belonging to a git repo, and, in the case it is, the prompt display relevant information that is repo: branch and state. Example:




In this case depicted, I was on the branch "master" and I had modified files (hence the "m") and files I deleted (hence the "d").


  •  Another cool thing is to have tab completion (that pressing the tab key with a half-written command you get all the options to complete the command -or the command being automatically completed if there was just one choice-).


Imagine that applied to branch names, git commands and Django commands (like "python manage.py runserver" for example). Sweet, isn't it?


  • Some other sweetnesses included:
    • Increase the size of the history of bash, but eliminating duplicates, so to do "ctrl r" in the console, we can look at the history of the commands that we did and found interesting results.
    • A long list of colors defined to directly save them in defining the prompt.
    • Etc!

The scripts, give me the scripts!

The first two put them right into your home folder.
The third file, call it the way your system get it right. For me it is .bash_profile. Put it right in your home with this name or copy its contents to your existing bash config file.
If you use Linux, you can do the same with .bashrc.

Note that the files have an underscore in the beginning of their filenames. Remove this underscore when placing the files, letting the names begin with a dot, as they are hidden files.


Cheers and May the bash be with you!!

19 de mayo de 2015

REST with Python: awesome API development tools and docs


Here goes a collection of links I find very useful to keep handy regarding RESTful APIs and Python:



Frameworks/libraries


Videos/blog posts/Tutorials


Others


Dealing with speed

  • json, from the Python standard library, is slow and performance can be improved using ujson
  • SQLAlchemy has an option to cache connections: connection pool.


Special thanks to Juan Norris for creating and letting me share the original document here.

9 de marzo de 2015

Reset the DNS cache in OS X

Reset the DNS cache in OS X

Learn how to reset (flush) the DNS cache.

About the DNS cache

OS X keeps a local cache of resolved DNS queries for a time defined by the DNS server. Sometimes it might be necessary to reset the cache immediately and re-query a DNS server. For example, you might need to do this if you are a network or server administrator and an entry on your DNS server has recently changed.
If your Mac isn't using the latest DNS entries from your server, you can restart your Mac to update its cached information. If you need to update DNS entries on a server using OS X and you can't restart the server, use the terminal commands below for the version of OS X you're using.

OS X Yosemite

Use the following Terminal command to reset the DNS cache:
sudo discoveryutil mdnsflushcache

OS X Mavericks, Mountain Lion, and Lion

Use the following Terminal command to reset the DNS cache:
sudo killall -HUP mDNSResponder

Mac OS X v10.6

Use the following Terminal command to reset the DNS cache:
sudo dscacheutil -flushcache

16 de octubre de 2014

How to undo a git rebase / squash / fixup? (a.k.a. "we all poop it sometimes")



Today I had a bit of a mess in one of my PRs by doing an interactive rebase (git rebase -i HEAD~) and a fixup / squash.

Now: What to do now, after doing the wrong squash?

Good news: virtually everything can be undone in GIT :)

"git reflog" was what I was looking for to put thing where they were before:

$ git reflog

At this point you'll see a long list of commits like this one:

 $ git reflog
e074e05 HEAD@{0}: rebase: aborting
b3885fe HEAD@{1}: rebase -i (start): checkout HEAD~7
e074e05 HEAD@{2}: pull origin master: Merge made by the 'recursive' strategy.
b3885fe HEAD@{3}: rebase -i (finish): returning to refs/heads/ticket
b3885fe HEAD@{4}: rebase -i (pick): something
....

Then you need to pick the action you want to go back to and reset to it with this command:

$ git reset --hard HEAD@{N}

Where "N" is the number between curly braces from the list of commits displayed by git reflog.

Et voilà!

26 de septiembre de 2014

Get file extension from filename with Python


Several times I had to put some code together some Python code to get the extension from a filename.

It was required for it to work OK with complex extensions, like ".tar.gz", and remain functional when you have dots in the filename, like in this case: "some.filename.1.v2.tar.gz".

After trying several options, the one that did the trick was using regular expressions, wrapped in a little function.

Here the case for keeping the ".", and getting the extension in the fashion ".tar.gz" or ".png":



Here the case for not keeping the ".", and getting the extension in the fashion "tar.gz" or "png":




Et voilà! :D