Skip to content

Instantly share code, notes, and snippets.

@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 / devcon_examples.bat
Created August 15, 2015 07:16
DevCon examples
set DEVCON="C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe"
REM DevCon hwids - https://msdn.microsoft.com/en-us/library/windows/hardware/ff544772(v=vs.85).aspx
%DEVCON% hwids invalid > devcon_hwids_invalid.txt 2>&1
%DEVCON% hwids * > devcon_hwids_star.txt 2>&1
%DEVCON% hwids =AudioEndpoint > devcon_hwids_class.txt 2>&1
%DEVCON% hwids MMDEVAPI\AudioEndpoints > devcon_hwids_hwid.txt 2>&1
%DEVCON% hwids @SWD\MMDEVAPI\{0.0.0.00000000}.{32247EDD-EAC6-46F8-BEFB-44448BDBC8D3} > devcon_hwids_instanceid.txt 2>&1
REM DevCon classes - https://msdn.microsoft.com/en-us/library/windows/hardware/ff544712(v=vs.85).aspx
@curzona
curzona / TeamCityDisableAgent.cs
Created April 6, 2014 09:43
Disable a TeamCity agent through the REST API in C# http://devnet.jetbrains.com/message/5462246#5462246
string address = "http://<TEAMCITY>/httpAuth/app/rest/agents/id:1/enabled";
byte[] data = Encoding.UTF8.GetBytes("false");
using (var client = new System.Net.WebClient())
{
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("<USER>", "<PASSWORD>");
byte[] response = client.UploadData(address, "PUT", data);
}
@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():
@curzona
curzona / levenshtein.py
Created March 8, 2014 17:49
Python implementation of the Levenshtein distance with edits
# Calculates the levenshtein distance and the edits between two strings
def levenshtein(s1, s2, key=hash):
rows = costmatrix(s1, s2, key)
edits = backtrace(s1, s2, rows, key)
return rows[-1][-1], edits
# Generate the cost matrix for the two strings
# Based on http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Python
def costmatrix(s1, s2, key=hash):
@curzona
curzona / .travis.yml
Last active July 17, 2017 10:56
Comparison of config files
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints
language: php
# list any PHP version you want to test against
php:
# using major version aliases
# aliased to 5.2.17
- 5.2
# aliased to 5.3.29
@-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 / retry.py
Created June 22, 2015 00:55
retry utility for Python
import time
import inspect
import types
def _assert(func):
if not func():
if isinstance(func, types.FunctionType):
raise AssertionError(inspect.getsource(func).strip())
else:
raise AssertionError()
Collecting attrdict
1 location(s) to search for versions of attrdict:
* https://pypi.python.org/simple/attrdict/
Getting page https://pypi.python.org/simple/attrdict/
Looking up "https://pypi.python.org/simple/attrdict/" in the cache
Current age based on date: 96
Freshness lifetime from max-age: 600
Freshness lifetime from request max-age: 600
The response is "fresh", returning cached response
600 > 96