Skip to content

Instantly share code, notes, and snippets.

@matthewlmcclure
matthewlmcclure / requestascurl.py
Created July 12, 2013 01:25
Return a curl command string view of a Requests PreparedRequest
def headers_as_curl(headers):
header_args = [
" -H '{key}: {value}'".format(key=key, value=value)
for key, value in headers.iteritems()
]
return ''.join(header_args)
def request_as_curl(preparedrequest):
body = preparedrequest.body if preparedrequest.body else ''
return (
@matthewlmcclure
matthewlmcclure / gist:6124117
Created July 31, 2013 17:22
Log information about the objects replaced by Python Mock, patch. Combine with similar logging in your application to debug patching.
--- mock.py~ 2013-07-31 13:20:48.000000000 -0400
+++ mock.py 2013-07-31 13:19:57.000000000 -0400
@@ -32,9 +32,12 @@
__version__ = '0.8.0'
+import logging
import pprint
import sys
@matthewlmcclure
matthewlmcclure / mock.py.diff
Last active December 20, 2015 11:29
Log information about the objects replaced by Python Mock, patch. Combine with similar logging in your application to debug patching.
--- mock.py~ 2013-07-31 13:20:48.000000000 -0400
+++ mock.py 2013-07-31 17:43:13.000000000 -0400
@@ -32,9 +32,12 @@
__version__ = '0.8.0'
+import logging
import pprint
import sys
@matthewlmcclure
matthewlmcclure / kill-processes-orphaned-by-jenkins.sh
Last active January 3, 2016 12:09
Kill processes orphaned by Jenkins
#! /bin/bash
# Kill processes orphaned by Jenkins
# Work around Java's use of SIGTERM rather than SIGKILL and
# Jenkins's lack of any workaroud in the box.
# Suggested usage:
#
# $ crontab -l
@matthewlmcclure
matthewlmcclure / 0_reuse_code.js
Created January 18, 2014 15:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
$ cat ./notes-invalid-json.csv
User,name,title,owner,ownedByMe,JSON
user@example.com,notes/placeholder-id,,user@example.com,True, {"body": {"text": {"text": "\\""}}, "createTime": "2022-03-10T13:10:00Z", "name": "notes/placeholder-id", "ownedByMe": true, "owner": "user@example.com", "permissions": [{"email": "user@example.com", "name": "notes/placeholder-id/permissions/placeholder-id", "role": "OWNER", "user": {"email": "user@example.com"}}], "trashTime": "Never", "updateTime": "2022-03-10T13:10:00Z"}
$ gam csv ./notes-invalid-json.csv quotechar " " gam user user@example.com create note json "~JSON" copyacls
2022-03-10T13:17:09.932+00:00,0/1,Using 1 process...
Command: gam user user@example.com create note json >>>"{"body": {"text": {"text": "\\""}}, "createTime": "2022-03-10T13:10:00Z", "name": "notes/placeholder-id", "ownedByMe": true, "owner": "user@example.com", "permissions": [{"email": "user@example.com", "name": "notes/placeholder-id/permissions/placeholder-id", "role": "OWNER", "user": {"email": "us