Skip to content

Instantly share code, notes, and snippets.

View DotNetNerd's full-sized avatar

Christian Holm Diget DotNetNerd

View GitHub Profile
@DotNetNerd
DotNetNerd / typeahead.ts
Last active December 14, 2017 12:47
Type(Script)Ahead
interface ITypeaheadArgs
{
minChars?: number,
onSelect?: () => void
}
async function typeahead(
field: HTMLInputElement,
search: (text: string) => Promise<string[]>,
args: ITypeaheadArgs) {
@DotNetNerd
DotNetNerd / AzureServiceBus.cs
Created May 24, 2013 08:53
Basic sample of using Azure service bus
/* Init */
string connectionString = "Endpoint=sb://xxx.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=xxx";//CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
/* Setup */
if (!namespaceManager.TopicExists("TestTopic"))
@DotNetNerd
DotNetNerd / PhantomRunner.cs
Created May 23, 2013 11:20
Grabbing a site in C# using phantomJS
class Program
{
static void Main(string[] args)
{
var grabby = new Grabby();
string output = grabby.Grab("http://www.dotnetnerd.dk/cv");
Console.WriteLine(output);
File.WriteAllText("c:\\test.html", output);
}
@DotNetNerd
DotNetNerd / ShadowDOM
Created May 22, 2013 08:55
Use of shadow DOM
<html>
<body>
<template id="nameTagTemplate">
<style>
.outer {
border: 2px solid pink;
border-radius: 1em;
font-size: 20pt;
@DotNetNerd
DotNetNerd / CustomElements
Created May 22, 2013 08:54
Use of custom elements with Polymer
<html>
<body>
<style>
element {
display:none;
}
</style>
<script src="CustomElements/custom-elements.js"></script>
@DotNetNerd
DotNetNerd / App.xaml
Created May 13, 2013 08:02
WPF IOC wireup
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_OnStartup">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="20" />
</Style>
</Application.Resources>
@DotNetNerd
DotNetNerd / App.xaml
Created May 10, 2013 12:32
Sample of a viewmodel with Reactive UI
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml" xmlns:local="clr-namespace:WpfApplication1.ViewModels">
<Application.Resources>
<local:ApplicationViewModel x:Key="MyApplicationViewModel" />
</Application.Resources>
</Application>
@DotNetNerd
DotNetNerd / F# ExtensionMethods
Created May 8, 2013 08:54
Sample of extension method in F#
namespace ExtensionFSharp
module CollectionExtensions =
type System.Collections.Generic.IEnumerable<'a> with
member this.ForEach(f:'a -> unit) =
for item in this do
f item
@DotNetNerd
DotNetNerd / Unity with F#
Created May 8, 2013 08:48
Sample of using Unity from F#
open Microsoft.Practices.Unity
type IRepository =
abstract member FindPhoneNumber : string -> string
type Repository() =
interface IRepository with
member this.FindPhoneNumber(name) = match name with "John" -> "87654321" | _ -> ""
let container = new UnityContainer() :> IUnityContainer
@DotNetNerd
DotNetNerd / JsRx buffer clicks
Created May 8, 2013 08:15
Shows buffering of clicks using Reactive extentions in JavaScript
.Add("/scripts/libs/rx.min.js")
.Add("/scripts/libs/rx.time.min.js")
.Add("/scripts/libs/rx.jquery.min.js")
var observer = $(e.target).clickAsObservable().bufferWithTime(200)
.subscribe(function (events) {
console.log(events.length);
var $item = $(e.target).closest('.productItem');
var quantity = parseInt($.trim($item.find('.qty').html())) + events.length + 1;