Skip to content

Instantly share code, notes, and snippets.

@mpilquist
mpilquist / philosophers.scala
Last active April 28, 2023 23:31
Dining Philosophers with FS2
/*
scalaVersion := "2.12.7"
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "co.fs2" %% "fs2-core" % "1.0.1-SNAPSHOT"
*/
import cats._
import cats.implicits._
import cats.effect._
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active May 28, 2024 19:14
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

The Borrow Checker

This pass has the job of enforcing memory safety. This is a subtle topic. This docs aim to explain both the practice and the theory behind the borrow checker. They start with a high-level overview of how it works, and then proceed to dive into the theoretical background. Finally, they go into detail on some of the more subtle aspects.

Table of contents

@robertklep
robertklep / clientserver.js
Created May 2, 2013 07:57
client -> socket.io server 1 (clientserver.js) -> socket.io server 2 (serverserver.js)
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
server.listen(3012);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});