Skip to content

Instantly share code, notes, and snippets.

View bogdanbujdea's full-sized avatar
💭
Who reads this?

Bogdan Bujdea bogdanbujdea

💭
Who reads this?
View GitHub Profile
@bogdanbujdea
bogdanbujdea / TextToAudioProfileConverter.cs
Created May 16, 2013 21:37
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}}" />
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:
@bogdanbujdea
bogdanbujdea / ViewModelBase.cs
Created June 8, 2013 13:45
ViewModelBase class for Windows 8 caliburn micro project
public abstract class ViewModelBase : Screen
{
private readonly INavigationService _navigationService;
protected ViewModelBase(INavigationService navigationService)
{
_navigationService = navigationService;
}
public void GoBack()
@bogdanbujdea
bogdanbujdea / windows8
Last active December 18, 2015 11:38
Full share contract snippet
#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)
{
@bogdanbujdea
bogdanbujdea / App.xaml.cs
Created January 28, 2014 22:34
Clean App.xaml.cs file for Windows Phone 8
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; }
@bogdanbujdea
bogdanbujdea / App.xaml
Last active January 4, 2016 20:59
App.xaml file with Caliburn.Micro Bootstrapper
<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>
@bogdanbujdea
bogdanbujdea / MainViewModel
Created January 28, 2014 22:40
Simple ViewModel for Windows Phone 8
namespace BudgetPlanner.WP8.ViewModels
{
public class MainViewModel
{
public MainViewModel()
{
PageName = "It worked!";
}
public string PageName { get; set; }
@bogdanbujdea
bogdanbujdea / commit-msg
Last active May 15, 2017 08:38
Git hook for enforcing a commit message that includes project name and JIRA ticket number
#!/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])'
@bogdanbujdea
bogdanbujdea / MembersSortAnalyzer.cs
Created April 3, 2018 23:00
MembersSortAnalyzer
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace MembersSort
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class MembersSortAnalyzer : DiagnosticAnalyzer
{
@bogdanbujdea
bogdanbujdea / AnalyzeSymbol.cs
Created April 3, 2018 23:46
Reporting an error from Roslyn analyzer
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,
@bogdanbujdea
bogdanbujdea / MembersSortAnalyzer.cs
Created April 3, 2018 23:48
Roslyn analyzer for member accessibility order
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)]