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 / units.cs
Created November 30, 2021 07:16
Units of measure in C#
using System;
class Unit
{
public string Name {get; private set;}
protected Unit(string name)
{
Name = name;
}
public static readonly Unit DimensionLess = new Unit(" ");
@markusjohnsson
markusjohnsson / corruption.html
Created August 3, 2018 13:42
Corrupted label layer when using textures
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='/dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
@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
@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 / 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 / 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 / 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: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: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: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;