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
function getURLParameter(name) { | |
return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]); | |
} | |
function hideURLParams() { | |
//Parameters to hide (ie ?success=value, ?error=value, etc) | |
var hide = ['success','error']; | |
for(var h in hide) { | |
if(getURLParameter(h)) { | |
history.replaceState(null, document.getElementsByTagName("title")[0].innerHTML, window.location.pathname); | |
} |
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
//Get a range of numbers between two numbers | |
//Usage: [1, 10].range returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
Object.defineProperty(Array.prototype, "range", { | |
get: function () { | |
var range = [this[0]], i; | |
for (var i = this[0], len = this[1]; i < len; range.push(++i)); | |
return range; | |
} | |
}); | |
// Golfed TypeScript: |
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
<svg class="loader" width="60" height="60" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<ellipse ry="25" rx="25" cy="30" cx="30" stroke-width="5" stroke="#000" fill="none"/> | |
</g> | |
</svg> |
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
void Main() | |
{ | |
var path = @"R:\test.txt"; | |
const int MAX_LINE_LENGTH = 15; | |
const int MAX_LINE_COUNT = 15; | |
using (var stream = GetTruncatedFile(path, MAX_LINE_LENGTH, MAX_LINE_COUNT)) | |
using (var reader = new StreamReader(stream)) | |
{ |
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
void Main() | |
{ | |
foreach (var file in Directory.GetFiles(@"X:\Scott\Projects\Test XML Files", "*.xml")) | |
{ | |
var doc = XDocument.Load(file); | |
var expando = XmlToDict.Convert(doc.Root.Elements(), new LibertyTransformer()); | |
expando.Dump(20); | |
JsonConvert.SerializeObject(expando, Newtonsoft.Json.Formatting.Indented).Dump(); |
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
void Main() | |
{ | |
var bytes = new byte[] { 0, 0, 1, 0, 255, 64 }; | |
var reader = new ByteReader(bytes); | |
reader.Read<int>().Dump(); | |
reader.Read<byte>().Dump(); | |
reader.Read<sbyte>().Dump(); | |
reader.Read<byte>(4).Dump(); | |
} |
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
void Main() | |
{ | |
string input = Console.ReadLine(); | |
input.EatHorror("abcdefg"); | |
input.Dump("Eaten"); | |
(input + " - Appended").Dump("Fix?"); | |
"hello".Dump("Try entering \"hello\""); | |
} |
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
public static class Benchmark | |
{ | |
/// <summary> | |
/// Returns the total number of milliseconds elapsed running a function [iterations] times. | |
/// </summary> | |
/// <see cref="http://stackoverflow.com/a/1048708/382456" /> | |
public static double Run(int iterations, Action func) | |
{ | |
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; | |
Thread.CurrentThread.Priority = ThreadPriority.Highest; |
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
/// <summary> | |
/// An in-memory repository of T. | |
/// </summary> | |
/// <typeparam name="T">Type of entities to emulate.</typeparam> | |
public class FakeRepository<T> : IRepository<T> | |
where T : class | |
{ | |
private readonly PropertyInfo _key; | |
private readonly Dictionary<int, T> _entities; |
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
// ES3 | |
var getParams = function() { | |
var results = [], parts = window.location.search.slice(1).split("&"), i, len; | |
for (i = 0, len = parts.length; i < len; ++i) results.push(parts[i].split("=")); | |
return results; | |
}; | |
console.log(getParams()); | |
// ES6 | |
const getParams = () => window.location.search.slice(1).split("&").map(q => q.split("=")); |
NewerOlder