Skip to content

Instantly share code, notes, and snippets.

View owen2's full-sized avatar

Owen Johnson owen2

View GitHub Profile
@owen2
owen2 / enforcessl.php
Created July 18, 2012 18:33
Enforce ssl automatically in PHP
if ($_SERVER['HTTPS'] != "on") {
$url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: $url");
exit;
}
@owen2
owen2 / softap.cmd
Created October 15, 2012 19:18
How to turn on software access point in windows 7
netsh wlan set hostednetwork mode=allow ssid=NetworkName key=Password
netsh wlan start hostednetwork
@owen2
owen2 / DataGridBoundTemplateColumn.cs
Created March 4, 2014 19:51
DataGridBoundTemplateColumn
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace OwensWpfFunStuff
{
public class DataGridBoundTemplateColumn : DataGridBoundColumn
{
public DataTemplate CellTemplate { get; set; }
public DataTemplate CellEditingTemplate { get; set; }
@owen2
owen2 / EnumToItemsSourceConverter.cs
Last active August 29, 2015 14:16
MagicComboBoxEnumConverter
public class EnumToItemsSourceConverter : IValueConverter
{
public EnumToItemsSourceConverter() : base() { }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || !(value is Enum))
{
return new object[] { };
@owen2
owen2 / AsyncGeneratorCache.cs
Created March 6, 2015 20:32
A cache for your async tasks so that you can await the same result multiple times
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DataStructures
{
public class AsyncGeneratorCache<TKey, TValue>
{
private Func<TKey, Task<TValue>> _generate;
private Dictionary<TKey, Task<TValue>> _promises = new Dictionary<TKey, Task<TValue>>();
@owen2
owen2 / ChangeNotificationObject.cs
Created March 13, 2015 19:38
The closest thing to magic change notification on automatic properties without using proxies or postcompilers.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace ViewModelBase
{
/// <summary>
@owen2
owen2 / ListBoxExtensions.cs
Last active December 1, 2016 16:12
Bind to all of the SelectedItems in a ListBox set to multiple select mode.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@owen2
owen2 / displaynames.txt
Created April 6, 2016 21:02
Add [DisplayName] to C# properties
public\s([\w?]*)\s(\w*)\s{ get; set; }
[DisplayName("$2")]\r\n\t\tpublic $1 $2 { get; set; }
@owen2
owen2 / App.xaml.cs
Created December 12, 2016 22:21
Auto-Implemented Back Button Windows 10
// Stole this from http://devcenter.wintellect.com/jprosise/handling-the-back-button-in-windows-10-uwp-apps
sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
@owen2
owen2 / EF Code First Association Table.cs
Last active April 7, 2017 12:16
EF Code First Association Table
//From Model Builder
modelBuilder.Entity<ThisTable>().
HasMany(c => c.OtherTable).
WithMany(p => p.AssocTable).
Map(
m =>
{
m.MapLeftKey("ThisId");
m.MapRightKey("OtherId");
m.ToTable("AssocTable");