Skip to content

Instantly share code, notes, and snippets.

@vkobel
vkobel / WSServer.cs
Last active August 29, 2015 13:57
Basic structure for a WebSocket communication (multitask ready) with C# / Alchemy
using System;
using System.Collections.Concurrent;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Alchemy;
using Alchemy.Classes;
namespace WebSocketsDemo {
class WSServer {
@vkobel
vkobel / base.html.twig
Last active August 29, 2015 13:58
Essential snippets for pjax + nprogress (YouTube like navigation) to work along with Silex/Symfony2
{# parent template for every standard (non-pjax) requests #}
(...)
<link href="{{ res }}/css/nprogress.css" rel="stylesheet" media="screen" />
<script src="{{ res }}/js/jquery-2.1.0.min.js"></script>
<script src="{{ res }}/js/jquery.pjax.js"></script>
<script src="{{ res }}/js/nprogress.js"></script>
open System.Threading
let workThenWait() =
async {
do! Async.Sleep(1000)
printfn "work done"
}
let demo() =
printfn "started"
@vkobel
vkobel / seqjoin.fs
Created April 24, 2014 13:19
Join / combine 2 seq into one in F#
let joinseq seq1 seq2 =
seq {
yield! seq1
yield! seq2
}
@vkobel
vkobel / AgentsSimple.fs
Created April 24, 2014 15:30
Simple F# agents (MailboxProcessor) example. Try it here: http://www.tryfsharp.org/create/vkobel/Agent.fsx
type CounterMessage =
| Update of float
| Reset
let inbox = MailboxProcessor.Start(fun agent ->
// Function that implements the body of the agent
let rec loop sum count = async {
// Asynchronously wait for the next message
let! msg = agent.Receive()
match msg with
@vkobel
vkobel / Lexer.fs
Last active August 29, 2015 14:01
Simple lexer for a minimalist asm-like language
module Lexer
open System
open System.IO
open System.Text.RegularExpressions
type Register =
| A // 8 bits
| B // 8 bits
| D // 16 bits (A + B)
@vkobel
vkobel / async_await.cs
Last active August 29, 2015 14:02
Simple Async Await remainder
using System;
using System.Threading.Tasks;
namespace AsyncAwaitTest {
class Program {
async static void DoIt() {
Console.WriteLine("Enter DoIt!");
await Task.Delay(2000);
Console.WriteLine("DoIt has ended!");
@vkobel
vkobel / KobInjector.cs
Last active August 29, 2015 14:05
Simple Dependency Injector (contructors only) in .NET C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace KobInjector {
/// <summary>
/// Simple Exeption to be thrown if a paramter cannot be resolved, it displays the whole injection stack
/// </summary>
public class InjectionStackException : Exception {
@vkobel
vkobel / links.js
Last active August 29, 2015 14:05
Retrieve links (ajax created) on a website for further processing using PhantomJS (http://phantomjs.org/)
@vkobel
vkobel / groupbytimespan.cs
Created October 9, 2014 11:24
Group datetimes by duration. Here it will make 3 groups of 15 minutes each
using System;
using System.Linq;
namespace GroupbyTimespan {
class Program {
static void Main(string[] args) {
DateTime[] dateTimes = new[]{
new DateTime(2010, 8, 24, 0, 5, 0),
new DateTime(2010, 8, 24, 0, 10, 0),