Skip to content

Instantly share code, notes, and snippets.

View markusjohnsson's full-sized avatar

Markus Johnsson markusjohnsson

  • Infviz AB
  • Sweden
View GitHub Profile
@markusjohnsson
markusjohnsson / gist:5486979
Created April 30, 2013 06:41
Creates an observable that, when subscribed to, will subscribe to the underlying observable, but will not dispose that subscription when its own subscription is disposed.
using System;
using System.Reactive;
using System.Reactive.Linq;
namespace RxFireAndForget
{
public static class RxExtensions
{
/// <summary>
/// Creates an observable that, when subscribed to, will subscribe to the underlying observable,
@markusjohnsson
markusjohnsson / gist:6013785
Last active December 19, 2015 20:29
LINQ meta operator. Wraps each element in a meta object also containing the index in the sequence and whether the element is first and if it is last in the sequence.
public class MetaElement<T>
{
public MetaElement(T value, bool isLast, bool isFirst, int index)
{
this.Value = value;
this.IsLast = isLast;
this.IsFirst = isFirst;
this.Index = index;
}
public int Index { get; private set; }
@markusjohnsson
markusjohnsson / gist:8705473
Created January 30, 2014 09:49
IObservable.FirstOrDefaultObservable() - a non-blocking FirstOrDefault for IObservable
public static class ObservableExtensions
{
public static IObservable<T> FirstOrDefaultObservable<T>(this IObservable<T> source)
{
return Observable
.Create<T>(
observer =>
{
bool hasFired = false;
@markusjohnsson
markusjohnsson / gist:d7124998cd766b143db7
Created October 7, 2014 15:20
Kendo view model with ES5 properties
/// <reference path="../Kendo/typescript/kendo.web.d.ts"/>
/// <reference path="../Scripts/typings/jquery/jquery.d.ts"/>
class ViewModel extends kendo.data.ObservableObject {
private _text = "asd";
public set theText(v: string) {
if (this._text == v) return;
this._text = v;
@markusjohnsson
markusjohnsson / gist:20090ba9cf7c4132cabb
Last active August 29, 2015 14:13
Month View Calendar...
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
public class Program
{
public static void Main()
{
var today = DateTime.Today;
@markusjohnsson
markusjohnsson / gist:484802537b90b51e6e89
Created January 26, 2015 15:53
Illustrating the problem with named parameters and interfaces
using System;
class Coord : ICoord
{
public void Print(double lat, double lon)
{
Console.WriteLine("Lon: {0}, Lat: {1}", lon, lat);
}
}
@markusjohnsson
markusjohnsson / gist:af1a5c651f453621e217
Created January 29, 2015 11:04
Linq: lists of lists
using System;
using System.Linq;
using System.Collections.Generic;
public static class EnumerableExtractRangeEx
{
public static IEnumerable<IEnumerable<T>> ExtractRanges<T>(this IEnumerable<T> source, Func<T, bool> rangePredicate)
{
using (var enumerator = source.GetEnumerator())
{
@markusjohnsson
markusjohnsson / SetNoCache.cs
Created March 16, 2016 14:18
Setting a property (CacheControl) to all blobs in a Azure blob storage container
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Linq;
namespace SetNoCache
{
class Program
{
static void Main(string[] args)
@markusjohnsson
markusjohnsson / DownloadAllBlobs.cs
Created March 16, 2016 14:20
Backup (download) all blobs in a Azure blob storage container
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Linq;
using System.IO;
namespace DownloadAllBlobs
{
class Program
{
@markusjohnsson
markusjohnsson / react-binding.js
Created August 25, 2017 10:58
React knockout binding
function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
ko.bindingHandlers.react = {
init: function () {
return {
controlsDescendantBindings: true