Skip to content

Instantly share code, notes, and snippets.

@winkel
winkel / gist:760149
Created December 30, 2010 19:07
Prime numbers
class Sieve
{
public static List<int> GetPrimeNumbers(int maxValue)
{
List<int> primeNumbers = new List<int>(new int[] { 2, 3, 5 });
for (var testValue = primeNumbers.Max() + 1; testValue <= maxValue; testValue++)
{
int sqrtTestValue = (int)Math.Floor(Math.Sqrt(testValue));
bool isPrime = true;
@winkel
winkel / MazoviaEncoding.cs
Created April 23, 2012 21:46
Mazovia Encoding class
using System;
using System.Collections.Generic;
using System.Text;
namespace System.Text
{
/// <summary>
/// This class was generated by a tool. For more information, visit
/// http://www.hardcodet.net/2010/03/silverlight-text-encoding-class-generator
/// </summary>
@winkel
winkel / AttachedCommands.cs
Last active December 18, 2015 10:40
WinRT AttachedCommands
public static class AttachedCommands
{
public static readonly DependencyProperty ControlTappedCommandProperty =
DependencyProperty.RegisterAttached("ControlTappedCommand",
typeof(ICommand), typeof(AttachedCommands),
new PropertyMetadata(null, new PropertyChangedCallback(AttachOrRemoveUIElementTappedEvent)));
public static ICommand GetControlTappedCommand(DependencyObject obj)
{
return (ICommand)obj.GetValue(ControlTappedCommandProperty);
@winkel
winkel / gist:5344489
Created April 9, 2013 09:48
FindVisualChild in WinRT
private T FindVisualChild<T>(DependencyObject obj)
where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is T)
return (T) child;
else
@winkel
winkel / CommandMap.cs
Last active February 6, 2016 01:36
CommandMap
// THIS SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS
// MEANS NO EXPRESS, IMPLIED OR STATUTORY WARRANTY, INCLUDING
// WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY OR FITNESS
// FOR A PARTICULAR PURPOSE OR ANY WARRANTY OF TITLE OR
// NON-INFRINGEMENT.
//
// MICROSOFT WILL NOT BE LIABLE FOR ANY DAMAGES RELATED TO
// THE SOFTWARE, INCLUDING DIRECT, INDIRECT, SPECIAL,
// CONSEQUENTIAL OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT
// THE LAW PERMITS, NO MATTER WHAT LEGAL THEORY IT IS
git gc --prune=now --aggressive
@winkel
winkel / gist:5946926
Created July 8, 2013 07:41
NTP: GetNetworkTime
public static DateTime GetNetworkTime()
{
//default Windows time server
const string ntpServer = "time.windows.com";
// NTP message size - 16 bytes of the digest (RFC 2030)
var ntpData = new byte[48];
//Setting the Leap Indicator, Version Number and Mode values
ntpData[0] = 0x1B; //LI = 0 (no warning), VN = 3 (IPv4 only), Mode = 3 (Client Mode)
@winkel
winkel / uninstall.bat
Created July 9, 2013 08:29
How to uninstall all ClickOnce apps
rundll32 dfshim CleanOnlineAppCache
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
namespace SharpGIS.Metro.Controls
@winkel
winkel / LockHolder.cs
Created October 16, 2013 18:06
LockHolder
// http://www.informit.com/articles/article.aspx?p=1231461
public sealed class LockHolder<T> : IDisposable where T : class
{
private T handle;
private bool holdsLock;
public LockHolder(T handle, int milliSecondTimeout)
{
this.handle = handle;