Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Who reads this?

Bogdan Bujdea thewindev

💭
Who reads this?
View GitHub Profile
@thewindev
thewindev / TextToAudioProfileConverter.cs
Created May 16, 2013
converter from text to AudioType useful in Windows 8 apps so you can bind something to an AudioType property like this: <Page.Resources> <converters:TextToAudioQualityConverter x:Key="TextToAudioQuality"></converters:TextToAudioQualityConverter> </Page.Resources> ... <TextBox Text="{Binding Converter={StaticResource TextToAudio}}" />
View TextToAudioProfileConverter.cs
public class TextToAudioProfileConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
AudioType audioType = (AudioType)value;
switch (audioType)
{
case AudioType.Mp3:
return "MP3";
case AudioType.M4a:
@thewindev
thewindev / ViewModelBase.cs
Created Jun 8, 2013
ViewModelBase class for Windows 8 caliburn micro project
View ViewModelBase.cs
public abstract class ViewModelBase : Screen
{
private readonly INavigationService _navigationService;
protected ViewModelBase(INavigationService navigationService)
{
_navigationService = navigationService;
}
public void GoBack()
@thewindev
thewindev / windows8
Last active Dec 18, 2015
Full share contract snippet
View windows8
#region ShareContract
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
UnregisterForShare();
}
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
@thewindev
thewindev / App.xaml.cs
Created Jan 28, 2014
Clean App.xaml.cs file for Windows Phone 8
View App.xaml.cs
namespace BudgetPlanner.WP8
{
using System.Diagnostics;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Controls;
public partial class App
{
public static PhoneApplicationFrame RootFrame { get; private set; }
@thewindev
thewindev / App.xaml
Last active Jan 4, 2016
App.xaml file with Caliburn.Micro Bootstrapper
View App.xaml
<Application
x:Class="BudgetPlanner.WP8.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wp8="clr-namespace:BudgetPlanner.WP8">
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:BudgetPlanner.WP8" x:Key="LocalizedStrings"/>
<wp8:AppBootstrapper x:Key="Bootstrapper"></wp8:AppBootstrapper>
</Application.Resources>
@thewindev
thewindev / MainViewModel
Created Jan 28, 2014
Simple ViewModel for Windows Phone 8
View MainViewModel
namespace BudgetPlanner.WP8.ViewModels
{
public class MainViewModel
{
public MainViewModel()
{
PageName = "It worked!";
}
public string PageName { get; set; }
@thewindev
thewindev / commit-msg
Last active May 15, 2017
Git hook for enforcing a commit message that includes project name and JIRA ticket number
View commit-msg
#!/bin/sh
#read https://gist.github.com/thewindev/feb728495b31eda499230c1fda04addd for instructions
excluded_branches="develop master" #the branches where you don't want commit message validation
project_name="MyAwesomeProject" #the name of the project in JIRA
current_branch="$(git rev-parse --abbrev-ref HEAD)"
for e in $excluded_branches
do [[ "$e" == "$current_branch" ]] && exit 0; done #if you're on an excluded branch then we don't check the message
commit_regex='(project-[0-9])'
View MembersSortAnalyzer.cs
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace MembersSort
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class MembersSortAnalyzer : DiagnosticAnalyzer
{
@thewindev
thewindev / AnalyzeSymbol.cs
Created Apr 3, 2018
Reporting an error from Roslyn analyzer
View AnalyzeSymbol.cs
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var classSymbol = context.Symbol as INamedTypeSymbol;
if (classSymbol?.TypeKind != TypeKind.Class)
return; //we only need classes, not other types like enum, struct, etc.
var members = GetMembersFromClass(classSymbol); //retrieve only methods and properties
var unorderedMember = GetUnorderedMember(members); //then find the first member that is out of order
if (unorderedMember != null)
{
var rule = new DiagnosticDescriptor(DiagnosticId, Title, $"Move {unorderedMember.Name} lower in the file", Category,
@thewindev
thewindev / MembersSortAnalyzer.cs
Created Apr 3, 2018
Roslyn analyzer for member accessibility order
View MembersSortAnalyzer.cs
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Net.Http.Headers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace MembersSort
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]