Skip to content

Instantly share code, notes, and snippets.

@jamie94bc
jamie94bc / cm-tomorrow-night-eighties
Created May 6, 2013 18:21
Quick implementation of the Tomorrow Night Eighties theme (https://github.com/chriskempson/tomorrow-theme) for Code Mirror 2
.cm-s-tomorrow-night-eighties.CodeMirror { background: #2d2d2d; color: #cccccc; }
.cm-s-tomorrow-night-eighties .CodeMirror-selected { background: #515151 !important; }
.cm-s-tomorrow-night-eighties .CodeMirror-gutters { background: #2d2d2d; border-right: 0; }
.cm-s-tomorrow-night-eighties .CodeMirror-linenumber { color: #7C7C7C; }
.cm-s-tomorrow-night-eighties .CodeMirror-cursor { border-left: 1px solid #A7A7A7 !important; }
.cm-s-tomorrow-night-eighties .CodeMirror-matchingbracket { border-bottom: 1px solid #999999; color: #cccccc !important; }
.cm-s-tomorrow-night-eighties .CodeMirror-nonmatchingbracket { color: red !important; }
.cm-s-tomorrow-night-eighties .cm-keyword { color: #cc99cc; }
.cm-s-tomorrow-night-eighties .cm-atom { color: #f99157; }
@jamie94bc
jamie94bc / DateTimeExtensions.cs
Last active February 24, 2016 22:03
MomentJS style .NET DateTime extensions
public static class DateTimeExtensions {
#region Day
public static DateTime StartOfDay(this DateTime d) {
return d.Date;
}
public static DateTime EndOfDay(this DateTime d) {
return new DateTime(d.Year, d.Month, d.Day, 23, 59, 59);
}
@jamie94bc
jamie94bc / CollectionViewSource .cs
Last active January 21, 2016 13:54
A early (largely untested), simple implementation of CollectionViewSource for use view models in portable class libraries.Does not yet support grouping
/// <summary>
/// A simple implementation of CollectionView / CollectionViewSource
/// for portable class libraries.
/// </summary>
/// <remarks>
/// Unfortunately due some Windows 8 oddness, we had to resort to using
/// an <see cref="ObservableCollection{T}"/> as the view. Probably something
/// to do with ObservableMap but ItemsControls and the inherited versions
/// don't subscribe to the <see cref="INotifyCollectionChanged.CollectionChanged"/>
/// event.
@jamie94bc
jamie94bc / DependsOn.cs
Last active December 22, 2015 23:49
A quick helper to call the `PropertyChanged` event for properties with getters which depend on other properties which must raise `PropertyChanged`. Unfortunately this does require making `RaisePropertyChanged()` public.
/// <summary>
/// An attribute used to dynamically
/// call RaisePropertyChanged for the applied
/// property when the dependent property is changed.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class DependsOnAttribute : Attribute {
public IEnumerable<string> DependentPropertyNames { get; private set; }
public DependsOnAttribute(params string[] dependentPropertyNames) {
@jamie94bc
jamie94bc / ExpandingMvxListView.cs
Created October 9, 2013 07:47
A list view which expands to fit it's content rather than scrolling (for MonoDroid + MvvmCross).
/// <summary>
/// A list view which expands to fit
/// it's content rather than scrolling.
/// </summary>
public class ExpandingMvxListView : MvxListView {
public ExpandingMvxListView(Context context, IAttributeSet attrs) : base(context, attrs) {}
public ExpandingMvxListView(Context context, IAttributeSet attrs, IMvxAdapter adapter) : base(context, attrs, adapter) { }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Calculate entire height by providing a very large height hint.
@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; }
@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 / 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());
}
}
/// <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 / 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;