Skip to content

Instantly share code, notes, and snippets.

View MarcelMalik's full-sized avatar

Marcel MarcelMalik

View GitHub Profile
@aelij
aelij / -Usage.cs
Last active March 29, 2024 14:26
IAsyncEnumerable Bridge for Service Fabric Reliable Collections
class MyService : StatefulService
{
private Task<IReliableDictionary<int, string>> AccountNames => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountNames");
private Task<IReliableDictionary<int, string>> AccountData => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountData");
public async Task<List<Account>> SearchAccountsByNameAsync(string name)
{
using (var txn = StateManager.CreateTransaction())
{
var accountNames = await AccountNames;
@ebidel
ebidel / unregistered_custom_elements.bookmarklet.js
Last active May 30, 2019 19:17
Logs any custom elements on a page that are not registerd (e.g. missing an HTML import)
javascript:(function(){function isUnregisteredCustomElement(el){if(el.constructor==HTMLElement){console.error("Found unregistered custom element:",el);return true;}return false;}function isCustomEl(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}var allCustomElements=document.querySelectorAll('html /deep/ *');allCustomElements=Array.prototype.slice.call(allCustomElements).filter(function(el){return isCustomEl(el);});var foundSome=false;for(var i=0,el;el=allCustomElements[i];++i){if(isUnregisteredCustomElement(el)){foundSome=true;}}if(foundSome){alert('Oops: found one or more unregistered custom elements in use! Check the console.');}else{alert('Good: All custom elements are registered :)');}})();
@grenade
grenade / robocopy.ps1
Last active March 12, 2024 15:22
Wrap robocopy in powershell to get standard (0/1) exit codes.
<#
.Synopsis
Robocopy wrapper with standard 0 (success) and 1 (failure) exit codes.
.Parameter source
Defines the source folder
.Parameter target
Defines the target folder
.Parameter include
Defines the files to include. Accepts wildcards. Eg: -include *.dll,*.pdb
Optional, Default value is $null and will include all files from source.
@DamianEdwards
DamianEdwards / ChatHub.cs
Created January 10, 2013 06:10
SignalR peer-to-peer using class-less hubs idea
// This hub is optional, it's not required for the client to work.
// The client's call to "all.newMessage" will result in this Hub's
// NewMessage method being called so it can persist the message.
public class Chat : Hub
{
public void NewMessage(string message)
{
MyDataLayer.SaveMessage(message);
}
}
@DamianEdwards
DamianEdwards / gist:4499713
Created January 10, 2013 05:37
SignalR chat using Knockout sync models idea
<form data-bind="submit: sendMessage">
<input type="text" data-bind="value: newMessage" />
<input type="submit" value="Send" />
</form>
<ul data-bind="foreach: messages">
<li data-bind="text: $data"></li>
</ul>
<script src="Scripts/jquery-1.8.3.js"></script>
@anaisbetts
anaisbetts / KeyedOperationQueue.cs
Last active December 10, 2015 10:39
A non-blocking version of @praeclarum's SqliteAsync.cs using Rx
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using ReactiveUI;
namespace Akavache.Sqlite3
public IObservable<Unit> CreateRecursive(string path)
{
var paths = path.Split('\\');
var firstFolderThatExists = Observable.Range(0, paths.Length - 1)
.Select(x =>
StorageFolder.GetFolderFromPathAsync(String.Join("\\", paths.Take(paths.Length - x)))
.ToObservable()
.LoggedCatch(this, Observable.Empty<StorageFolder>()))
.Concat()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading;
@DamianEdwards
DamianEdwards / gist:4030394
Created November 7, 2012 09:31
Async site scraping in ASP.NET 4.5
public class SiteScrape : HttpTaskAsyncHandler
{
public override async Task ProcessRequestAsync(HttpContext context)
{
using (var http = new HttpClient())
{
var downloadTasks = new List<Task<string>> {
http.GetStringAsync("http://bing.com"),
http.GetStringAsync("http://google.com"),
http.GetStringAsync("http://oredev.org"),
using System;
using ReactiveUI.Routing;
using ReactiveUI.Xaml;
namespace ReactiveUI.Samples.Routing.ViewModels
{
public interface IWelcomeViewModel : IRoutableViewModel
{
ReactiveCommand HelloWorld { get; }
}