This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
public static class Math | |
{ | |
/// <summary> | |
/// Floating-point epsilon value. | |
/// </summary> | |
public const float FLT_EPSILON = 1.192092896e-07f; | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected MyImmutableObject(IDictionary<string, object> parameters) | |
{ | |
foreach (var field in GetType().GetFields().Where(x => parameters.Keys.Contains(x.Name))) | |
{ | |
if (parameters[field.Name] is Dictionary<string, object>) | |
{ | |
var ctor = field.FieldType.GetConstructor(new[] { typeof(Dictionary<string, object>) }); | |
var instance = ctor.Invoke(new object[] { parameters[field.Name] }); | |
field.SetValue(this, instance); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
public abstract class DataObject | |
{ | |
public override bool Equals(object obj) | |
{ | |
var dataObj = obj as DataObject; | |
if (dataObj == null) return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string csvPath = "..."; | |
string xmlPath = "..."; | |
using (StreamReader streamReader = new StreamReader(new FileStream(csvPath, FileMode.Open))) | |
{ | |
// snag headers | |
string[] headers = streamReader.ReadLine().Split(','); | |
// col0="{0}" col1="{1}" coln="{n}" | |
string attributesFormat = string.Join(" ", headers.Select((colStr, colIdx) => string.Format("{0}=\"{{{1}}}\"", colStr, colIdx))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import csv | |
parser = argparse.ArgumentParser(description="Converts a CSV file to an XML file") | |
parser.add_argument("csv", help="the path to the .CSV file") | |
parser.add_argument("xml", help="the path to the .XML file") | |
parser.add_argument("--root", help="root tag name", default="root") | |
parser.add_argument("--row", help="row tag name", default="row") | |
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") | |
args = parser.parse_args() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static List<List<T>> GetPermutations<T>(List<T> values) | |
{ | |
if (values.Count <= 1) return new List<List<T>>() { values }; | |
var results = new List<List<T>>(); | |
var perms = GetPermutations(values.Skip(1).ToList()); | |
foreach (var perm in perms) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import heapq | |
# construct initial collection | |
initial_col = [1, 5, 3, 9, 4] | |
# construct heap | |
heap = [] | |
# assemble the heap, store tuples as such: (original_value, original_index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum DaysOfTheWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; | |
var tues = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), "Tuesday"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
################################################################################ | |
# Installing Redis on CentOS | |
# with lots of help from: | |
# * https://gist.github.com/coder4web/5762999 | |
# * http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/ | |
# * https://coderwall.com/p/ypo94q | |
# * https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server | |
################################################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' invoke vsvars32.bat. just do it. | |
call "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat" | |
' temporary environment variables assignment | |
' set ENV_VAR = value | |
' temporary path modification | |
set path=%path%;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE | |
' launch visual studio |
OlderNewer