Working Ninja
# Simple List
', '.join([ for author in authors])

# Django
', '.join([ for author in book.author_set.all()])

Both will output "Author Name, Author 2 Name, ..., Author x Name"


Let's say you add an element to the DOM via jQuery:

$("<button class="delete">Delete</button>").appendTo("foo");

And want to later remove it via a jQuery event. Calling $('.delete').on('click') will not fire the event. This is because .on() only looks for elements that were loaded initially with the DOM. To resolve you can use .live() for older version of jQuery or if you're using later versions of jQuery (1.7+), the following:

$(document).on("click", ".delete", function() { ... });

Since "document" existed when the DOM loaded a click on it will fire an event. Furthermore, since we specified the ".delete" CSS class for the selector arguement for the .on() event, the event will search through its descendents to find any elements with the ".delete" CSS class and execute our function.



Using IUS (Inline with Upstream Stable)--a nifty repository provided by EPEL--we can upgrade beyond PHP 5.4 by first removing our current version of PHP, installing our preferred version (5.6 in our case), and then restarting Apache:

$ sudo yum remove php-cli mod_php php-common

$ sudo yum install mod_php56u php56u-cli php56u-mysqlnd

$ sudo apachectl restart



Renewing an SSL but can't recall exactly how it was filled out last time? Try the following:

openssl req -text -in request.csr

The above command will decode the CSR file and output its contents in human readable text. Enjoy!

More here:


I just started my first Django project with Python 3 in earnest. One of the first things I have noticed is that reload isn't available by default from the Django shell. It needs to be imported:

>>> from importlib import reload
>>> reload(<module>)

This became a pretty tedious process and didn't always reload the module as expected. So, instead of reloading the shell and the module to run a command, I moved the commands that I was running into a custom Django management command. No more reloading =)


The following code allows us to monkey patch the json() method that is returned by

import requests
from mock import MagicMock

@mock.patch.object(requests, 'post')
def my_function(self, post):
    attrs = {'json.return_value': {'id': 1}}
    post.return_value = MagicMock(**attrs)

    r =


from sqlalchemy.sql import text
from sqlalchemy import create_engine

import secrets

engine = create_engine(
        secrets.username, secrets.password
conn = engine.connect()

s = text("SELECT * FROM users WHERE name = :name")
result = conn.execute(s, name=name).fetchall()
print result

For further information on installing and configuring unixODBC (requirement for pyodbc) on Linux:

Connecting to Microsoft SQL Server with pyodbc:

function sendWebhook($data) {
    $url = 'https://url/';
    $jsonDataEncoded = json_encode($data);
    $webhook = curl_init($url);
    curl_setopt($webhook, CURLOPT_POST, 1);
    curl_setopt($webhook, CURLOPT_POSTFIELDS, $jsonDataEncoded);
    curl_setopt($webhook, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($webhook);

$data = array(
    'key' => 'value'




Sometimes it is necessary to resize partitions (e.g. updates to GitLab require additional space on /opt). Here's what we need to do. If you have an LVM parition, you're in luck! Things are pretty straightforward.

  1.   Run vgdisplay (Volume Group Display) to verify we have space to expand our partition.
    •     The line PE Free / Size should have space available.
  2.   Next, add space to the parition with lvresize (Logical Volume Resize):
    sudo lvresize --size +100M /dev/mapper/opt
  3.   Now that the volume has been expanded, let's commit those changes to the filesystem:
    sudo xfs_growfs /dev/mapper/opt



Here's a simple way to count lines of code via the command line that I recently used for a Django project:

find . -name '*.py' -not -path "*/migrations/*" | xargs wc -l


wc -l **/*.py