Skip to content

Instantly share code, notes, and snippets.

ParseResult(scheme='http', netloc='example.com', path='/over/there', params='', query='field1=value1&field2=value2&field3=value3', fragment='')
[('field1', 'value1'), ('field2', 'value2'), ('field3', 'value3')]
@curzona
curzona / conftest.py
Last active February 16, 2024 16:26
pytest with monkeypatch __buildin__.open
import __builtin__
from StringIO import StringIO
import os
import ConfigParser
import pytest
class MockFileManager():
def __init__(self):
self.files = {}
@curzona
curzona / test_mock_open.py
Created January 22, 2015 06:04
unittest with mock __builtin__.open
import mock
import unittest
class TestOpen(unittest.TestCase):
def test_mock_open(self):
m = mock.patch('__builtin__.open',
mock.mock_open(read_data="some text"))
m.start()
with open('somefile.txt', 'rb') as fin:
@curzona
curzona / clock.py
Created August 7, 2014 06:03 — forked from wickman/clock.py
from abc import ABCMeta, abstractmethod
import threading
class ClockInterface(object):
__metaclass__ = ABCMeta
@abstractmethod
def time(self):
pass
@curzona
curzona / flatten.py
Created May 17, 2014 09:25
Python flatten implementation from p4python
def __flatten(self, args):
result = []
if isinstance(args, tuple) or isinstance(args, list):
for i in args:
result.extend(self.__flatten(i))
else:
result.append(args)
return tuple(result)
@curzona
curzona / execnet_rpc.py
Last active August 29, 2015 14:00
Remote procedure call with execnet
import execnet
import sys
# Boilerplate
def remote_call(gw, method, args, kargs):
module = sys.modules[__name__]
channel = gw.remote_exec(module)
channel.send((method, args, kargs))
@curzona
curzona / indexer.conf
Created April 21, 2014 04:13
Send a message to logstash in python
input {
udp {
port => 5959
format => 'json'
}
}
output {
stdout { }
elasticsearch {
@curzona
curzona / shell_session.py
Created April 21, 2014 03:45
Multiple command shell session with paramiko
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('HOST', port=22, username='USERNAME', password='PASSWORD')
channel = client.get_transport().open_session()
channel.invoke_shell()
while channel.recv_ready():
@-moz-document url-prefix("https://<TEAMCITY_SERVER>/viewLog.html") {
/* Timestamp */
.log .ts, .log .time, .log .ts_in {
color: #6C6C6C;
}
/* Messages */
.l0, .l1, .l2, .l3, .l4, .l5, .l6, .l7, .l8, .l9, .l10, .l11, .l12, .l13, .l14, .l15, .l16, .l17, .l18, .l19, .l20, .l21, .l22, .l23, .l24, .l25, .lDeep {
color: white;
}
@curzona
curzona / EnumUtils.cs
Created April 6, 2014 09:44
Adding Descriptions to your Enumerations
// From http://www.codeproject.com/Articles/13821/Adding-Descriptions-to-your-Enumerations
public class EnumUtils<T>
{
public static string GetDescription(T enumValue, string defDesc)
{
FieldInfo fi = enumValue.GetType().GetField(enumValue.ToString());
if (null != fi)
{