Skip to content

Instantly share code, notes, and snippets.

View jhargis's full-sized avatar

Jay Hargis jhargis

  • Heroku
  • Portland, OR
View GitHub Profile
@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 |

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

# 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
# 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!
#
@jhargis
jhargis / UPnP-client.py
Created November 20, 2014 03:57
UPnp or NAT-PMP client
# NAT Traversal via UPnP Port Mapping
# Written by Nikos Fotoulis <nikofot at gmx.com>
# This code is public domain.
#
# Tested on Thomsom TG858v7 modem router.
# UPnP is hairy. May not work with other routers
# Feedback is welcome.
import re, thread, socket, traceback as tb, random
from time import sleep
@jhargis
jhargis / keybase.md
Created November 13, 2014 19:43
keybase.md

Keybase proof

I hereby claim:

  • I am jhargis on github.
  • I am jhargis (https://keybase.io/jhargis) on keybase.
  • I have a public key whose fingerprint is 0FCF 328B 353D 9282 C929 80EA 8620 C622 7D44 B2EA

To claim this, I am signing this object:

@jhargis
jhargis / bottle_flash2.py
Last active June 20, 2021 21:09
bottle-flash2 - Fixed up abandoned bottle-flash[https://pypi.python.org/pypi/bottle-flash/]. Made api ver 2 ready. Plugin enables flash messages in bottle similar to django and flask.
from bottle import request, response, PluginError
class FlashMsgPlugin(object):
"""Usage:
from bottle import Bottle
from bottle_flash2 import FlashMsgPlugin
app = Bottle()
COOKIE_SECRET = 'your_secret_key'
app.install(FlashPlugin(secret=COOKIE_SECRET))
@jhargis
jhargis / __init__.py
Last active November 18, 2018 22:00
using jinja2 with cherrypy - example
# -*- coding: utf-8 -*-
# http://docs.cherrypy.org/en/latest/advanced.html?highlight=jinja2#html-templating-support
import os.path
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
@jhargis
jhargis / guncorn-example
Created May 1, 2014 17:56
Debian init script for virtualenv'd gunicorn_django
#! /bin/sh
### BEGIN INIT INFO
# Provides: gunicorn-initscript
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $nginx
# Default-Start: 30 2 3 4 5
# Default-Stop: 70 0 1 6
# Short-Description: virtualenv + gunicorn + nginx debian init script
# Description: virtualenv + gunicorn + nginx debian init script
@jhargis
jhargis / mclarens.js
Created February 22, 2014 17:43 — forked from nikhilm/mclarens.js
/*
* Mclarens Bar: Redis based Instant Messaging
* Nikhil Marathe - 22/04/2010
* A simple example of an IM client implemented using
* Redis PUB/SUB commands so that all the communication
* is offloaded to Redis, and the node.js code only
* handles command interpretation,presentation and subscribing.
*
* Requires redis-node-client and a recent version of Redis