Skip to content

Instantly share code, notes, and snippets.

View saboco's full-sized avatar

Santiago Botero saboco

View GitHub Profile
@charlesastaylor
charlesastaylor / -sna86.asm
Last active June 26, 2024 06:42
8086 assembly snake game!
; -------------------------------------------------------------------
; Sna86.
; An 8086 simulator snake!
; -------------------------------------------------------------------
;
; Assembly program intended to run in an 8086 simulator with functionaliy equal* to one made for homeworks
; up to Part 1 Episode 10 of the Peformance-Aware Programming Series (https://www.computerenhance.com/)
; by Casey Muratori. Demo - https://youtu.be/s_S4-QHeFMc.
;
; * mov, add, sub, cmp, je and jne was the target instructions. However I also added loop for convenience,
@Horusiath
Horusiath / Fiber.fs
Last active May 17, 2024 15:09
Custom fibers implementation in F#
/// MIT License
///
/// Copyright (c) 2024 Bartosz Sypytkowski
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@Tarmil
Tarmil / Directory.Build.targets
Last active November 20, 2019 13:38
Override NuGet/Paket package references with local projects
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!--
Override NuGet (or Paket) references with a set of local projects.
Usage:
* Add this file at the root above all your projects, so that they all gain the capability to override a package.
* In a solution where you want to override a package, add a file Directory.Build.props like the following:
<?xml version="1.0" encoding="utf-8"?>
<Project>
@mrange
mrange / README.md
Last active April 16, 2024 14:09
[F#] Implementing Coroutines (async/await) using continuations

[F#] Implementing Coroutines (async/await) using continuations

Coroutines or async/await is not a new concept as it was named in 1958 by Melvin Conway. Coroutines had support in languages such as Simula(1962), Smalltalk(1972) and Modula-2(1978) but I think one can argue that coroutines came into mainstream with C# 5(2012) when Microsoft added async/await to C#.

The problem with subroutines

A thread can only execute a single subroutine at a time as a subroutine starts and then runs to completion. In a server environment subroutines can be problematic as in order to service connections concurrently we would usually would start a thread per connection, this was the idiom a few years ago. A thread depending on the operating system and settings needs about 1 MiB of user stack space meaning 1,024 threads needs 1 GiB of for just user stack space. In addition there's the cost of kernel stack space, book-keeping and scheduling of threads. This drives cost of VM/hardwa

@mrange
mrange / 1.md
Last active August 2, 2023 16:43

Thinking about Async/Await

A couple of weeks ago I listened to .Net Rocks! #1433 about Visual Studio 17 with Kathleen Dollard. A very good episode interest but with stuck with me was Kathleen's comment that after all these years she sees very smart people still struggle with async. This is my and others experience as well.

A few years ago I wrote a blog post on why I thought async in C# isn't that great. I took it down a bit later even though it was popular it was also divisive and my understanding of async had grown which made me want to rewrite the whole piece into something better and less divisive.

I used to think that the implicit coupling in async to the SynchronizationContext is a major problem for async but today I think that it's a minor problem for most developers. The reason is that if you are writing ASP.NET you will always have the ASP.NET SynchronizationContext and that gives particular but consistent async behavior. If y

@mrange
mrange / full_coroutine.fs
Last active January 23, 2019 18:03
full_coroutine.fs
module Continuum =
open System
open System.Collections.Generic
open System.Diagnostics
open System.Net
open System.Threading
open System.Threading.Tasks
module Common =
let inline tid () = Thread.CurrentThread.ManagedThreadId
open System
open System.Diagnostics
open System.Net
open System.Threading
open System.Threading.Tasks
module Common =
let clock =
let d = float Stopwatch.Frequency / 1000000.
let sw = Stopwatch ()
type Next<'T> =
| Done of 'T
| Jump of Trampoline<'T>
and Trampoline<'T> = unit -> Next<'T>
module Trampoline =
let Return v : Trampoline<'T> =
fun () ->
Done v
// ----------------------------------------------------------------------------
open System
open System.Threading
open System.Collections.Generic
// ----------------------------------------------------------------------------
type Continuation<'T> = 'T -> unit
type Coroutine<'T> = Continuation<'T> -> unit
// ----------------------------------------------------------------------------
module Coroutine =
let Bind (t : Coroutine<'T>) (fu : 'T -> Coroutine<'U>) : Coroutine<'U> =
@joelverhagen
joelverhagen / RedirectingHandler.cs
Last active January 16, 2024 05:04
RedirectingHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Knapcode.Http.Handlers
{