Skip to content

Instantly share code, notes, and snippets.

@colorstain
colorstain / copy.yml
Last active July 18, 2016 15:58
Copy SSH Keys to remote servers
---
- name: Copy SSH key
hosts: all
serial: "{{ serial|default(1) }}"
tasks:
- name: Get the name of the user running the script
local_action: command whoami
register: username_on_host
- name: Copy ssh key to server
@colorstain
colorstain / table.py
Created April 8, 2016 16:15
CLI helpers
def table(rows, add_index=False):
"""
Generates a table from a list of lists. The first row should contain the
headers.
"""
rows = [list(row) for row in rows]
headers = rows[0]
body = rows[1:]
if add_index:
headers.insert(0, '#')

Keybase proof

I hereby claim:

  • I am colorstain on github.
  • I am colorstain (https://keybase.io/colorstain) on keybase.
  • I have a public key whose fingerprint is 757A F248 BBD0 A7CD 1F7E ACF1 9461 7797 FB66 89A4

To claim this, I am signing this object:

@colorstain
colorstain / test.py
Last active August 29, 2015 14:08
googleads error
# Import appropriate modules from the client library.
from googleads import dfp
# Set the line item ID and creative IDs to associate.
LINE_ITEM_ID = 'INSERT_LINE_ITEM_ID_HERE'
CREATIVE_IDS = ['INSERT_CREATIVE_IDS_HERE']
def main(client, line_item_id, creative_ids):
# Initialize appropriate service.
@colorstain
colorstain / gist:10776676
Created April 15, 2014 21:21
autocommit off decorator
from functools import wraps
from django.db import transaction
def autocommit_off(func):
"""
Decorator to turn autocommit off inside a function, function should commit or rollback before returning.
:param func: Function to be decorated
:return: decorated function
"""
@colorstain
colorstain / gmail_chat_extractor.py
Created February 7, 2013 00:17
Small program that extracts chat logs from gmail and saves them in a csv file.
__author__ = 'colorstain@gmail.com'
import email
from datetime import datetime, timedelta
from imapclient import IMAPClient
from bs4 import BeautifulSoup #make sure it's the latest version
import csv
def parse_chats(xml):
soup = BeautifulSoup(xml, features='xml')