Skip to content

Instantly share code, notes, and snippets.

View olleharstedt's full-sized avatar

Olle Härstedt olleharstedt

View GitHub Profile
module Typestate
open FStar.Heap
open FStar.ST
type state =
| Open
| Closed
type file = {
<?php
$command = sprintf(
'echo -e "%s" | nc -U /var/run/docker.sock',
'GET /info HTTP/1.1\r\nHost: localhost\r\n'
);
echo '<pre>'; var_dump($command); echo '</pre>';
var_dump(exec($command));
<?php
$command = sprintf(
'echo -e "%s" | nc -U /var/run/docker.sock',
"GET /info HTTP/1.1\r\nHost: localhost\r\n"
);
echo '<pre>'; var_dump($command); echo '</pre>';
var_dump(exec($command));
<?php
$command = sprintf(
'echo -e "%s" | nc -U /var/run/docker.sock',
"GET /info HTTP/1.1\r\nHost: localhost\r\n"
);
echo '<pre>'; var_dump($command); echo '</pre>';
var_dump(exec($command));
<?php
$command = sprintf(
'echo -e "%s" | nc -U /var/run/docker.sock',
"GET /info HTTP/1.1\r\nHost: localhost\r\n\r\n"
);
echo '<pre>'; var_dump($command); echo '</pre>';
var_dump(exec($command));
@olleharstedt
olleharstedt / tmp.php
Created September 5, 2019 19:52
socket to browser
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (socket_bind($sock, '127.0.0.10', 888) === false) {
die('cannot bind' . PHP_EOL);
@olleharstedt
olleharstedt / WriteIO
Created August 21, 2020 18:52
Amphp and mocking
<?php
require __DIR__ . '/../vendor/autoload.php';
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Loop;
use Amp\ByteStream\ClosedException;
use Amp\File;
@olleharstedt
olleharstedt / amp_io.php
Created August 21, 2020 19:55
Mocking in Amphp, 2
<?php
require __DIR__ . '/../vendor/autoload.php';
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Http\Client\HttpClient;
use Amp\Loop;
use Amp\ByteStream\ClosedException;
use Amp\File\File;
@olleharstedt
olleharstedt / benchmark.js
Last active December 30, 2020 22:38
Clone benchmark
class Query {
constructor() {
this.select = '';
this.from = '';
this.where = '';
}
}
for (let i = 0; i < 1000000; i++) {
const q = new Query();

Pre-req: Functional core, imperative shell

Pre-req: Side-effects, purity, referential transparency

  • The functional core is more testable and more composable than the imperative shell or effectful code
  • Extending the functional core means making a bigger part of the software pure
  • Side-effects can in some cases easily be lifted out from a function, creating a more composable and testable unit
  • But sometimes, side-effects are tangled in business logic
  • Some side-effects can be delayed until end of request (e.g., updating user's name in database; exception at failure can still be thrown)
  • Example: Create dummy users