Skip to content

Instantly share code, notes, and snippets.

public static bool None<TSource>(this IEnumerable<TSource> source)
{
return !source.Any();
}
public static bool None<TSource>(this IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
return !source.Any(predicate);
}
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using System;
using System.Threading.Tasks;
namespace YourNameSpace
{
public class VaultAccess
{
public async Task<string> GetSecretKey(string secretKeyEndPoint)
//HttpRequest
byte[] bytesInStream = new byte[req.ContentLength.GetValueOrDefault()];
req.Body.Read(bytesInStream, 0, bytesInStream.Length);
//HttpRequestMessage
using (Stream requestStream = await req.Content.ReadAsStreamAsync())
{
byte[] bytesInStream = new byte[requestStream.Length];
requestStream.Read(bytesInStream, 0, (int)bytesInStream.Length);
int firstDuplicate(int[] a) {
for (int i = 0; i < a.Length; i++) {
if (a[Math.Abs(a[i])-1] >= 0)
a[Math.Abs(a[i])-1] = -a[Math.Abs(a[i])-1];
else
return Math.Abs(a[i]);
}
return -1;
}
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unit Test</Title>
<Author>Rusty Divine</Author>
<Description>Unit Test Template with 3 Parts</Description>
<HelpUrl>https://msdn.microsoft.com/en-us/library/ms165394.aspx</HelpUrl>
<SnippetTypes />
<Keywords />
@davidbreyer
davidbreyer / FileServiceController.cs
Last active May 2, 2016 13:47
Return a PDF to the browser in the form of a byte array.
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
public class FileServiceController : ApiController
{
[Route("api/fileservice/{docId}")]
public HttpResponseMessage Get(string docId)
@davidbreyer
davidbreyer / sleep.js
Created March 22, 2016 20:15
Sleep Function for JavaScript found at http://www.phpied.com/sleep-in-javascript/
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
@davidbreyer
davidbreyer / Solar System Simulator 2.0 Pure CSS.markdown
Created March 11, 2016 00:25
Solar System Simulator 2.0 Pure CSS

Solar System Simulator 2.0 Pure CSS

I have done it again.. This time, using Haml and SCSS.

Version 1 was pretty filthy in terms of syntax, it was raw html and css, but now I just used algorithms to (hopefully) get everything pixel perfect. I added the glowing stars, which are really just circles 2x2 spawned in random positions increasing in opacity every couple of seconds.

Didn't think I'd be making another solar system, but after seeing how easy everything else was using a preprocessor, I thought why the hell not.

Also I finally worked out how to make the ring for saturn, also the moon is much better.

@davidbreyer
davidbreyer / DateTimeLibrary.cs
Last active August 29, 2015 14:27
Get DateTimeOffset for a specified time zone.
public static DateTimeOffset GetCurrentDateTimeForTimeZone(string TimeZoneStandardName)
{
try
{
//Find specified time zone
var timeZone = TimeZoneInfo.FindSystemTimeZoneById((TimeZoneStandardName));
//Convert UTC time to a specified local time.
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZone);
@davidbreyer
davidbreyer / ProfilingInterceptionBehavior.cs
Last active August 29, 2015 14:24
Unity Interceptor to log the elapsed time of a method.
public class ProfilingInterceptionBehavior : IInterceptionBehavior
{
[Dependency]
public ILog Log { get; set; }
public IMethodReturn Invoke(IMethodInvocation input,
GetNextInterceptionBehaviorDelegate getNext)
{
//This behavior will record the start and stop time
//of a method and will log the method name and elapsed time.