Skip to content

Instantly share code, notes, and snippets.

View scuerda's full-sized avatar

Sasha Cuerda scuerda

View GitHub Profile
@scuerda
scuerda / model_dump.py
Last active August 29, 2015 14:19
Dump model to CSV - poached from Ben Welsh and stored when his site was offline
import csv
from django.db.models.loading import get_model
def dump(qs, outfile_path):
"""
Takes in a Django queryset and spits out a CSV file.
Usage::
>> from utils import dump2csv
@scuerda
scuerda / ckanBasic.R
Created April 28, 2015 10:53
Ckan Helper File
require(RCurl)
require(rjson)
require(httr)
require(yaml)
# Load api key
ckanapi <- getOption('CkanAPIKey')
# slugger function for generating title
@scuerda
scuerda / benandjerrysflavors.py
Created June 29, 2015 00:46
Ben and Jerry's Flavors and Release Date
from bs4 import BeautifulSoup
import urllib2
import csv
html = urllib2.urlopen("http://www.benjerry.com/flavors")
soup = BeautifulSoup(html)
flavors = soup.select(".flavor-item")
flavors = flavors[1:]
flavorList = []
@scuerda
scuerda / setup_git_repo.yml
Last active November 5, 2015 21:28
Ansible play for dealing with private git repos
---
- name: Confirms directory for repo is present
file: path={{ project_path }} state=directory owner={{ ckan_user }}
- name: Creates directory
file: path=/home/{{ ckan_user }}/.ssh state=directory
### The key used here needs to not have a password associated with it ###
- name: Create the Github SSH public key file
# Simple python function to flatten a dict with a regular structure into a list of dicts
# This is essentially the inverse of a d3 roll-up, where we know that the deepest leaves will contain all necessary keys
def rollout(d, current_level=0, depth_to_flatten=0):
items = []
for k, v in d.items():
if current_level == depth_to_flatten:
if v == {}:
pass
else:
import csv
files = ['file1.csv', 'file2.csv', 'file3.csv']
rows = []
for file in files:
with open(file, 'r') as datafile:
reader = csv.DictReader(datafile)
for row in reader:
from __future__ import with_statement
from fabric.api import env, local, run, sudo, cd, hosts, get
from fabric.context_managers import prefix
import datetime
env.use_ssh_config = True
# Hosts
# env.hosts list references aliases in ~/.ssh/config or IP address. When using .ssh/config,
@scuerda
scuerda / capture.py
Created January 14, 2017 20:51
Capture full screen image of webpage
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def setup_phantom_browser():
user_agent = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36")
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
browser = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs',
@scuerda
scuerda / vagrant_resize.md
Last active February 24, 2017 20:27
How to deal w/ Vagrant boxes that are too small

This should do it

vagrant box add ubuntu/xenial64
cd ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170223.0.0/virtualbox/
VBoxManage clonehd ubuntu-xenial-16.04-cloudimg.vmdk tmp-disk.vdi --format vdi
VBoxManage modifyhd tmp-disk.vdi --resize 61440
VBoxManage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk
rm tmp-disk.vdi ubuntu-xenial-16.04-cloudimg.vmdk
mv resized-disk.vmdk ubuntu-xenial-16.04-cloudimg.vmdk