Skip to content

Instantly share code, notes, and snippets.

View rarous's full-sized avatar
💭
I may be slow to respond.

Aleš Roubíček rarous

💭
I may be slow to respond.
View GitHub Profile
public OrderableService GetById(int id)
{
return (from service in SourceSet
where service.ID == id
select service).
FirstOrDefault();
}
using System;
using Xunit;
public class HelloWorldTests {
[Fact]
public void ShouldSayHello {
var listener = new Listener();
var helloWorld = new HelloWorld();
helloWorld.SayHello(listener.Listen);
Asser.Equal("Hello world", listener.ReceivedMessage)
public OrderableService GetById(int id)
{
return (from service in SourceSet
where service.ID == id
select service).
FirstOrDefault();
}
@rarous
rarous / gist:5625751
Last active September 8, 2024 22:39
rx-throttle directive for angular.js
directive('ngThrottle', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, elm, attr, ngModelCtrl) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input').unbind('keydown').unbind('change');
var disp = elm.keyupAsObservable().
throttle(attr.ngThrottle).
select(function(){ return elm.val() }).
<div ng-app="videoApp" ng-controller="VideoController">
<table>
<thead>
<th>Title</th>
<th>Length</th>
<th></th>
</thead>
<tbody>
<tr data-id="{{video.Id}}" ng-repeat="video in videos">
@rarous
rarous / rs.cljs
Last active December 17, 2015 10:39
(ns rx-cljs-demo.client
(:use [domina :only [by-id]]))
(def query (by-id "query"))
(def obs (Rx/Observable/fromEvent query "keyup"))
(-> obs
(.map #(.-value query))
(.filter #(> (count %) 3))
(.throttle 500)
public interface IStorage
{
Uri Save(Stream data, string name);
Task<Stream> LoadAsync(Uri dataUri);
}
static void Main()
{
var service = new MyService
{
ServiceName = ConfigurationManager.AppSettings["Service.Name"]
};
#if DEBUG
service.OnStart(null);
Console.WriteLine("Press Ctrl+C to exit.");
var sync = new System.Threading.ManualResetEventSlim(false);
@rarous
rarous / ParseEx.cs
Last active December 16, 2015 10:19
public static class ParseEx {
public delegate bool ParserDelegate<T>(string input, out T result);
public static Maybe<T> Parse<T>(string input, ParserDelegate<T> parser) {
T result;
bool isSuccess = parser(input, out result);
return isSuccess ? result.ToMaybe() : new Nothing<T>();
}
public static Maybe<DateTime> ParseDateTime(string input) {
// before
var bdayEl = el.Descendant("DatumNarozeni");
var birthday = bdayEl != null ? (DateTime?)Convert.ToDateTime(bdayEl.Value) : null;
// after Maybe
var birthday = from bday in el.Descendant("DatumNarozeni").ToMaybe()
select Convert.ToDateTime(bday.Value).ToMaybe();