Skip to content

Instantly share code, notes, and snippets.

@curzona
curzona / DateTimeEx.cs
Created March 8, 2014 17:48
DateTime to simple string descriptions like Today, Tomorrow, Someday, etc.
// Extended DateTime constants and strinify
class DateTimeEx
{
public static DateTime NextYear { get { return DateTime.Today.AddDays(-DateTime.Today.DayOfYear + 1).AddYears(1); } }
public static DateTime NextMonth { get { return DateTime.Today.AddDays(-DateTime.Today.Day + 1).AddMonths(1); } }
public static DateTime NextWeek { get { return DateTime.Today.AddDays(7 - (DateTime.Today.DayOfWeek - CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)); } }
public static DateTime Tomorrow { get { return DateTime.Today.AddDays(1); } }
public static DateTime Now { get { return DateTime.Now; } }
public static DateTime Today { get { return DateTime.Today; } }
public static DateTime Yesterday { get { return DateTime.Today.AddDays(-1); } }
@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 / hamming.py
Created March 8, 2014 17:50
Python implementation of the Hamming distance with edits
# Calculates the hamming distance and the edits between two strings
def hamming(s1, s2, key=hash):
assert len(s1) == len(s2)
dist = 0
edits = []
for i in xrange(len(s1)):
if s1[i] == s2[i]:
edits.append({'type':'match', 'i':i, 'j':i})
@curzona
curzona / error.txt
Last active August 29, 2015 13:57
Build error from https://github.com/tianocore/edk2 with short path to build directory
(Python 2.7.3 on linux2) Traceback (most recent call last):
File "/vagrant/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 1828, in Main
MyBuild.Launch()
File "/vagrant/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 1595, in Launch
self._MultiThreadBuildPlatform()
File "/vagrant/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 1402, in _MultiThreadBuildPlatform
self.Progress
File "/vagrant/edk2/BaseTools/Source/Python/AutoGen/AutoGen.py", line 130, in __new__
if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):
File "/vagrant/edk2/BaseTools/Source/Python/AutoGen/AutoGen.py", line 300, in _Init
@curzona
curzona / config.txt
Last active August 29, 2015 13:58
logstash failure after standby on windows
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7601 Service Pack 1 Build 7601
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04, mixed mode)
@curzona
curzona / config.txt
Last active August 29, 2015 13:58
logstash eventlog failure on windows
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7601 Service Pack 1 Build 7601
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04, mixed mode)
@curzona
curzona / logstash-indexer.conf
Last active August 29, 2015 13:58
Centralized logging on Windows with nxlog, logstash, elasticsearch and kibana
input {
udp {
port => 5959
type => "Win32-EventLog"
format => "json"
}
}
output {
stdout {
@curzona
curzona / teamcity_disable_agent.py
Created April 6, 2014 09:42
Disable a TeamCity agent through the REST API in Python http://devnet.jetbrains.com/message/5462246#5462246
import urllib2
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request('http://<TEAMCITY>/httpAuth/app/rest/agents/id:1/enabled', data='false')
request.add_header('Content-Type', 'text/plain')
request.get_method = lambda: 'PUT'
url = opener.open(request)
@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 / 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)
{