Mostrando entradas con la etiqueta software development. Mostrar todas las entradas
Mostrando entradas con la etiqueta software development. Mostrar todas las entradas

8 de febrero de 2017

Advanced AJAX / REST debugging tricks


When you are debugging or working with API interactions, you may find yourself making and monitoring a bunch of request from the browser console.

Like this:


You may've noticed the blue line there (plus the url). First trick :)

To get a line like this for every request the site you are looking / debugging performs, as well as one for every AJAX request you make "by hand" (usually, those requests don't get logged by the browser, not they appear on the Network or Timeline tabs), right click on the console and click the "Log XMLHttpRequests" option:




Good one, yet nothing too crazy. Right?

Well, here's where the plot thickens:

Now that you can get all and every each of the requests logged, let's try clicking on the url on the right-side of the blue text and see where it gets us:


Network activity! Things look promising. Ours is the last one. (here comes the second trick).

Let's right-click the last line -> Copy -> Copy as cURL:


Getting and idea of where this is going? :)

Let's now open Postman:

Import -> Paste raw text, paste:


Click import and now you have the request the site (or you) made, exported and put together in Postman, all bit and pieces included (yep, all headers too):



Neat, right? :)


I found this extremely useful when debugging API interactions and request to and from 3rd party sites with unclear APIs (or not APIs at all). Also very useful to simulate form posting from scripts.


Cheers!


19 de febrero de 2016

From the ground up with GIT


A continuación el contenido, materiales y otras yerbas de la Tech Meetup "From the ground up with GIT", que di en el Tech Pub de Santex America, en febrero de 2016:

Link al evento: http://www.meetup.com/Tech-Meetup-Santex-Cordoba-Argentina/events/228759107/

Link a las slides: link

Link a las notas:

Link al video de la charla: link

Link a las scripts para generar conflictos: link

Graciasmiles a todos/as los/as asistentes por venir y por la tan activa participación, que volvió la charla en algo mucho más divertido y enriquecedor (al menos para mi :) ).


¡Salud!

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.

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

7 de abril de 2014

Installing MySQL-Python in Mac OS X Mavericks

If you are in Mac OS X Mavericks and while trying to install MySQL-Python you run into this error:



This is a what makes the trick:



Then, pip works its way towards installing MySQL-Python OK:



Voilà!

26 de marzo de 2014

Create a global GIT hook to check Flake8 before each commit

First, let's install Flake8:




Note It is important to set the right version when installing Flake8, as there there are some versions that are bugged and will prevent the GIT hook to work (like the 2.1.0 version).

Now, let's setup global git commit hooks:

1. Enable git templates:



This tells git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init

2. Create a directory to hold the global hooks:



3. Write your hooks in ~/.git-templates/hooks.

For example, here's a post-commit hook (located in ~/.git-templates/hooks/post-commit):



4. Make sure the hook is executable.



5. Re-initialize git in each existing repo you'd like to use this in:




NOTE if you already have a hook defined in your local git repo, this will not overwrite it.

Now, let's create a global git pre-commit hook:


Finally, let's take it for a spin!

Go to some of your repos and re-initialize it to take the pre-commit hook:


Now edit some of your Python files, introducing some violation (like a >80 columns line, only one blank line between function/class definitions, etc.) and try to commit it:


Voilà!



8 de enero de 2014

Custom sorting function as parameter to sorted() in Python


So, I am working with Python and I come across a list of image names,  and I'd like to have them sorted. So, I call the sorted function with this list:



HA! It doesn't work as I would have liked it to. So, what can we do to achieve the sorting of the list as we want it?

Python's standard library sorted function, as you can see here, has an optional cmp parameter, through which you can pass a custom comparison function.

Going back to my example, I needed the images to be compared by the number in their name. I made this little function to achieve this goal:



And now let's put altogether:



TA DA!

27 de noviembre de 2013

How to setup you repo GIT and local instance (like for GitLab) and not to fall in despair

How to setup you repo GIT and local instance (like for GitLab) and not to fall in despair

For a while now, while collaborating with several projects, I noticed that having issues to generated and setup the public keys and configuring the access to GIT repositories was giving a bit of a harsh time to lots of people.

And when in comes to recurring problems there’s nothing better suited than a little reference tutorial to blaze the trail. So, let’s get to it!

#1: generate your SSH key-pair and set it up


Step #1: Check if you don’t already have a key pair


Open a terminal and run the following command:

1
2
3
cd ~/.ssh
ls
# Lists the files in your .ssh directory



Check the directory listing to see if you have a file named either id_rsa.pub or id_dsa.pub. If you don't have either of those files go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.

Step #2: Generate new SSH keys

To generate a new SSH key, enter the code below in the terminal. We want the default settings so when asked to enter a file in which to save the key, just press enter.

1
2
3
4
5
$ ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
ssh-add id_rsa





Now you need to enter a passphrase.

1
2
Enter passphrase (empty for no passphrase): [Type a passphrase]# Enter same passphrase again: [Type passphrase again]



Which should give you something like this:

1
2
3
4
Your identification has been saved in /Users/you/.ssh/id_rsa.# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com



Step #3: Add your SSH key to GitLab

  1. Go to your account settings:
  1. Now go to the SSH keys section:

  1. Click “Add SSH key”
  1. Give it a title you like (in the “Title” field) and paste your public key in the bigger “Key” field:
  1. Click “Add key” and we are done with loading the SSH public key in GitLab!

Step #4: Check everything worked

Now we should have the key pair generated and set up locally and the public key loaded in GitLab. Let’s now make sure this is the case and that everything went fine.

To achieve such a certainty, run the following command:

1
$ ssh -T git@git.santexgroup.com




If everything went well, you should see an output like this:

1
2
$ ssh -T git@git.santexgroup.com
Welcome to GitLab, !




#2: Some extra hints

Now we have the keys and our GitLab repo set up and ready to work. Now you should be able to clone, push/pull and do all sorts of thing with your GIT repos without being prompted for your username and password. If GIT, after making a command, asks you for your username or password, it means something at some point went wrong.

Go back and make sure you didn’t miss any steps or ask someone for help.

Done with this and want to learn some new tricks? Take a look at this link!

Hope this saves you of annoyances and frustrations in the future!

5 de noviembre de 2013

List merge conflicts with GIT


Made a merge, particularly, a big one and you want to know which where the files that had conflicts?

Then, this command might come handy:



You can also make a GIT alias this way:



and then use it like this:

25 de septiembre de 2013

Unix exit status code reference

0    # successful termination 
64   # base value for error messages 
64   # command line usage error 
65   # data format error 
66   # cannot open input     
67   # addressee unknown     
68   # host name unknown 
69   # service unavailable 
70   # internal software error 
71   # system error (e.g., can't fork) 
72   # critical OS file missing 
73   # can't create (user) output file 
74   # input/output error 
75   # temp failure; user is invited to retry 
76   # remote error in protocol 
77   # permission denied 
78   # configuration error

24 de septiembre de 2013

Where to start to learn GIT

Many times I was asked: Where to start to learn GIT?

It is not usual to have a good answer to questions like this in the area of software engineering.

But when it comes to the case of GIT, there is one. This is a great place to start: http://try.github.io/

This is the official GitHub "Got 15 minutes and want to learn Git?" Git tutorial.

Pimp my GIT: mejorando la interfaz para el uso de GIT

Siguiendo con el post de ayer, acá les comparto otras cosas del setup que tengo para git.

El setup este, y va dentro del .git/config de su clone git:


Con esto seteado, verán, por ejemplo, los git status con colores:




Podrán usar abreviaciones de los comandos, como:

- "git st" en vez de "git status"
- "git ci" en vez de "git commit"

Podrán ver un log más interesante y con colores con git log.

Verán los diff coloreados y con formato piola:



Git branch muestra coloreado el branch actual (los branches locales aparecen en amarillo):



Y los branches remotos aparecen en verde:

Inline image 4


Saludos!

23 de septiembre de 2013

Mostrar el branch de GIT y el status actual en el shell prompt y más!

Algunos trucos para configurar nuestro setup local de GIT:

Hace algunos años encontré algo como eso y, con el tiempo, armé una serie de scripts (algunas cosas que hice yo, algunas cosas que fui encontrando en la web), que hacen varias cosas con bash, que están piolas.

¿Qué cosas?

- que se detecte automáticamente si se está en una carpeta perteneciente a un repo git, y que, en el caso que sí lo sea, el prompt muestre información relevante del repo en que se está: branch y estado. Ejemplo:



en ese caso, estoy en el branch "master" y tengo archivos modificados (por eso la "m") y archivos que borré (por eso la "d").

- otra cosa muy piola es tener tab completion (que al apretar tab, con un comando a medio escribir, se muestren opciones para completar ese comando -o que se completen, si hubiera una opción posible). Imaginen eso aplicado a nombres de branch, comandos git y comandos de django (como "python manage.py runserver", por ejemplo).

- Algunas cosas más, como:
-- aumentar el tamaño del history de bash, pero eliminando duplicados, para que al hacer "ctrl r" en la consola, podamos buscar en el historial de los comandos que hicimos y encontrar resultados interesantes.
-- Una larga lista de colores definidos, para directamente poder usarlos en la definición del prompt.

Etc!

Les paso adjuntas las scripts para hacer todo esto:


Las dos primeras las ponen derecho en el home. El .profile pueden ponerlo derecho en el home (si usan Mac y no tienen otro .profile armado) o copiar su contenido a su .profile existente. Si usan Linux, pueden hacer esto mismo con el archivo .bashrc.
(notar que tienen un underscore los archivos, a propósito, para que no sobreescriban cosas sin querer y para que no los tome el file browser como archivos ocultos).


Un abrazo y may the bash be with you (?),