Skip to content

Instantly share code, notes, and snippets.

@dougn
dougn / jsons2csv.py
Created February 6, 2018 21:52
convert a bunch of json files into a csv file
import argparse
import csv
import json
parser = argparse.ArgumentParser(
description="""
Convert a number of json files into a single CSV file with each file as a row.""",
epilog="""
Example:
@dougn
dougn / argutil.py
Created October 18, 2017 18:21
Wrapper to argparse which provides decorator interface for command based commandlines
import argparse
import functools
def _call(func, args):
# RED_FLAG: add nargs
kwds = dict((name, getattr(args, name, None)) for name in func._arguments)
return func(**kwds)
def _command(subparsers, defaults, passthrough, description, **kwds):
def subcommand(parsers, defaults, passthrough, description, kwds, func):
@dougn
dougn / hack.py
Created February 25, 2017 07:44
Get the file diff's included in the perforce P4Python api structured data
## The Perforce P4Python api and p4 -G (marshalled data) do not return the diff data shown when you use the 'p4 describe'
## command to describe a changeset. You need to run the P4Python API in untagged mode. But then you have to parse things yourself.
## But the untagged data is partially structured. Each piece of data is included with embedded newlines. The file diff section has each
## header and then the diff data. The tagged data returned from the P4Python API has each file's data split into independent lists.
## So you get the file names and revisions each as independent lists. But the file diff section may not include all files. Some
## might be binary, some might be too large to diff (by server settings), etc. So you want to add two new lists to the tagged
## output, one for the headers and one for the diff raw data, but you want them to be aligned with the depotFiles listing.
## and using '' has sentinal place holders. So here we go:
import P4
from setuptools import setup, find_packages
from setuptools import Extension
from setuptools.command.install import install
from setuptools import Command
from setuptools.dist import Distribution
from wheel.bdist_wheel import bdist_wheel
class BinaryDistribution(Distribution):
def is_pure(self):
return False
@dougn
dougn / gist:adf1eff92f8d5e34d17d
Created May 12, 2014 18:48
Python3 cat example
## in answer to Armin Ronacher's http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/
import sys
import shutil
for filename in sys.argv[1:]:
f = sys.stdin.buffer
if filename != '-':
try:
@dougn
dougn / html5_wiki_video.js
Created June 10, 2013 05:10
FogBugz Customization to insert HTML5 video player in wiki pages
name: Wiki Embed Video
description: Makes .mp4 and .m4v video attachments HTML5 playable
author: Napoleone, Doug
version: 1.0.0.0
js:
// TODO: Fill this in
if ($('#idEditArticle')) {
var videos = $('a[href$=".m4v"], a[href$=".mp4"]');
@dougn
dougn / auto_fill_custom.js
Created June 10, 2013 05:07
FogBugz Customization to allow for URL filling of custom fields
name: Auto Fill Custom Fields
description: Find any arguments on in the URL for a new case which start with 'custom_' and attempt to fill that field with the value.
author: Doug Napoleone
version: 1.0.0.0
js:
// based on inspiration from:
// http://fogbugz.stackexchange.com/questions/2427/feature-request-pre-fill-custom-fields-on-new-case-edit-page-via-url-parameter
// But only 1 line remains from that origional.
@dougn
dougn / case_title_summary.js
Last active December 18, 2015 07:29
FogBugz Customization to create a case summary text to be cut&pasted into checkin comments
name: Case Title Summary
description: Add a cut&pasteable form of the case in the form of 'Category:1234 ("title here")' to cases.
author: Napoleone, Doug
version: 1.0.0.0
js:
// TODO: Fill this in
if (!window.goBug || !$("#bugviewContainer").length || $("#miniBugList").length)
return; // Don't do anything unless we're looking at a single bug :-(
@dougn
dougn / split_filters_menu.js
Last active December 18, 2015 07:29
FogBugz Customization to split the Filters Menu into My Filters and Shared Filters
name: Menus: Shared Filters and My Filters
description: Menu: Split 'Filters' Menu into 'Shared Filters' and 'My Filters' Menues
author: Doug Napoleone
version: 1.0.0.0
js:
/*
Based on this plugin by Jon Ericson:
http://fogbugz.stackexchange.com/questions/6471/how-to-create-a-custom-menu-in-the-menu-bar
@dougn
dougn / view_unread.js
Last active December 18, 2015 07:29
FogBugz Customization to open all unread cases in tabs
name: View All Unread Cases
description: Adds a link to the titlebar (if there is one) to open all unread cases in new windows.
author: Daniel Jalkut, Doug Napoleone
version: 1.0.0.0
js:
// Based on original code by Daniel Jalkut: https://gist.github.com/danielpunkass/5612389
// but not one line of code survived.
if ($('div.viewMoreOptions')) {