Skip to content

Instantly share code, notes, and snippets.

@jamie94bc
jamie94bc / git-delete-merged
Created May 6, 2021 09:55
Script to delete merged branches in git
git for-each-ref --format '%(refname:short)' refs/heads/ | grep -v master | xargs git branch -d
@jamie94bc
jamie94bc / DbModelBuilderExtensions.cs
Created January 17, 2016 13:50
Things EntityFramework 6's DbModelBuilder is missing or could be more succinct.
/// <summary>
/// Things <see cref="DbModelBuilder"/> is missing or could be more succinct.
/// </summary>
public static class DbModelBuilderExtensions {
/// <summary>
/// Configures the primary key property for this entity type.
/// </summary>
/// <typeparam name="TEntityType"></typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <param name="keyExpression">A lambda expression representing the property to be configured.</param>
@jamie94bc
jamie94bc / ExamplePlatformPresenter.cs
Created August 13, 2015 08:50
Prettier presentation hint handling in MvvmCross
public class YourPlatformSpecificPresenter : PlatformSpecificMvxPresenter, IMvxViewPresenterWithDelegate {
public MvxViewPresenterDelegate Delegate { get; } = new MvxViewPresenterDelegate();
public YourPlatformSpecificPresenter() {
this.AddPresentationHintHandler<MyPresentationHint>(hint => {
// Do something
});
}
public override void ChangePresentation(MvxPresentationHint hint) {
@jamie94bc
jamie94bc / MonoDroidHelper.cs
Created April 20, 2015 14:03
Helper methods for Xamarin.Android to check if IJavaObjects are still alive in the Java VM. Useful for MVVM.
public static class MonoDroidHelper {
/// <summary>
/// Returns true if the current <paramref name="javaObj"/>
/// does not have a <see cref="IJavaObject.Handle"/> to the
/// object in the Java VM.
/// </summary>
public static bool IsInMonoLimbo<T>(this T javaObj) where T : class, IJavaObject {
return javaObj.Handle == IntPtr.Zero;
}
@jamie94bc
jamie94bc / DateTimeFormat.cs
Last active August 29, 2015 14:13
A workaround for Xamarin.Android date/time format bug https://bugzilla.xamarin.com/show_bug.cgi?id=23544
public static class DateTimeFormat {
public static bool Is24Hour {
get { return CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern.Contains("H"); }
}
}
@jamie94bc
jamie94bc / DateTimeEx.cs
Created September 26, 2014 14:50
A workaround for a bug in Mono for DateTime.Now for people who also use MvvmCross.
public static class DateTimeEx {
private static IDateTimeProvider _provider;
public static DateTime Now {
get {
if (_provider == null && !Mvx.TryResolve(out _provider)) {
return DateTime.Now;
}
return _provider.Now;
/// <summary>
/// Like an MvxImageView, but with a transition.
///
/// Set the background drawable to your placeholder
/// image.
/// </summary>
public class MslImageView : ImageView {
private readonly IMvxImageHelper<Bitmap> _imageHelper;
private int _transitionDuration = 300;
@jamie94bc
jamie94bc / App.cs
Created March 23, 2014 11:19
A more "MvvmCross" implementation of https://github.com/paulcbetts/ModernHttpClient.
public class App : Cirrious.MvvmCross.ViewModels.MvxApplication {
public override void Initialize() {
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, DefaultHttpClientFactory>();
RegisterAppStart(new AppStart());
}
}
@jamie94bc
jamie94bc / gist:8247780
Created January 3, 2014 22:19
Use case for '&' in Less
/**
* defaults.less
*/
div.my-class-name {
padding: 15px;
form {
padding: 10px;
}
@jamie94bc
jamie94bc / IUpgrade.cs
Created October 16, 2013 09:51
Interfaces for an upgrade service to handle changes between versions on an application. If required, IUpgradeService should be implemented in a PCL with the CurrentAppVersion left as abstract to implement on a per device basis.
/// <summary>
/// Defines an interface which upgrades
/// the application from a version which is great
/// or equal to <see cref="IUpgrade.FromVersion"/>
/// and before <see cref="IUpgrade.ToVersion"/>.
/// </summary>
public interface IUpgrade {
Version FromVersion { get; }
Version ToVersion { get; }