Skip to content

Instantly share code, notes, and snippets.

View jhargis's full-sized avatar

Jay Hargis jhargis

  • Heroku
  • Portland, OR
View GitHub Profile
# coding=utf-8
#
# Copyright 2014 Leo Moll
#
# Authors: Leo Moll and Contributors (see CREDITS)
#
# Thanks to Mark Johnson for btsyncindicator.py which gave me the
# last nudge needed to learn python and write my first linux gui
# application. Thank you!
#
# temporary hack to address bug with vagrant-vbguest installation
# https://github.com/mitchellh/vagrant/issues/4962
if awk "BEGIN {exit `vagrant -v` == "1.7.1" ? 0 : 1 }"
then
sudo sed -i .original 's/\*\*opts/opts/g' /opt/vagrant/embedded/gems/gems/vagrant-1.7.1/lib/vagrant/machine.rb
fi

Python Excel Mini Cookbook

Original post at: http://pythonexcels.com/python-excel-mini-cookbook/

To get you started, I’ve illustrated a number of common tasks you can do with Python and Excel. Each program below is a self contained example, just copy it, paste it and run it. A few things to note:

These examples were tested in Excel 2007, they should work fine in earlier versions as well after changing the extension of the file within the wb.SaveAs() statement from .xlsx to .xls If you’re new to this, I recommend typing these examples by hand into IDLE, IPython or the Python interpreter, then watching the effect in Excel as you enter the commands. To make Excel visible add the line excel.Visible = True after the excel =win32.gencache.EnsureDispatch('Excel.Application') line in the script These are simple examples with no error checking. Make sure the output files doesn’t exist before running the script. If the script crashes, it may leave a copy of Excel running in the background. Open the Windows T

@jhargis
jhargis / PostgreSQL Clarion date conversion.plsql
Last active August 29, 2015 14:17
Convert Clarion date values from 5 digit integers to DATE types in Postgresql with a custom function
# Convert Clarion date values from 5 digit integers to DATE types in Postgresql with a custom function
\d inv
Table "public.inv"
Column | Type | Modifiers
------------+---------------+--------------------------------------------------
create_dt | integer |
from psycopg2.extras import DictCursor
from django.db import connections
def get_cursor(alias='default', cursor_factory=None):
# map from django's ORM layer to the raw DB cursor.
wrapped_conn = connections[alias]
# hack to ensure connection is immediately opened:
if wrapped_conn.connection is None:
@jhargis
jhargis / django_bulk_export.py
Last active June 13, 2018 17:43
django and psycopg2 with server side cursors for memory efficient large bulk data exports
import uuid
import psycopg2
from psycopg2.extras import DictCursor
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
class classproperty(object):
@jhargis
jhargis / create_pls.py
Created May 16, 2015 12:03
create pls playlist files
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Create ``.pls`` playlists from music filenames.
Specify a path to be recursively searched for music files.
According to an `unofficial PLS format specification`__, the attribute
``NumberOfEntries`` can be placed *after* all entries. This allows to iterate
through filenames without keeping details for each entry in memory.
@jhargis
jhargis / mk_playlist.py
Created May 16, 2015 12:07
Convert Grooveshark playlist files into .pls files for import into soundiiz.com
#!/usr/bin/python
# -*- coding: utf-8 -*-
#"SongName","ArtistName","AlbumName"
"""Convert Grooveshark playlist into .pls file for import into any music
service supported by http://soundiiz.com
usage: put this file in the same directory as the playlist you want to
convert. rename the file to tracks.csv then
@jhargis
jhargis / serve.py
Last active August 29, 2015 14:21 — forked from nigma/serve.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import webbrowser
from threading import Timer
os.environ["DJANGO_SETTINGS_MODULE"] = "webapp.settings"
import cherrypy
@jhargis
jhargis / django-cherrypy.py
Created May 20, 2015 15:13
another way to run django on the cherrypy server
# http://www.defuze.org/archives/262-hosting-a-django-application-on-a-cherrypy-server.html
# Python stdlib imports
import sys
import logging
import os, os.path
# Third-party imports
import cherrypy
from cherrypy.process import wspbus, plugins
from cherrypy import _cplogging, _cperror