Skip to content

Instantly share code, notes, and snippets.

@cn007b
cn007b / superSimpleGOExamples.md
Last active April 17, 2020 09:45
Super simple GO examples

Super simple GO examples

Super simple golang code examples:

cli.go:

package main

import (
@cn007b
cn007b / websockets.html
Created August 2, 2018 23:10
Super simple PHP WebSocket example - websockets.html
<html>
<body>
<div id="root"></div>
<script>
var host = 'ws://0.0.0.0:12345/websockets.php';
var socket = new WebSocket(host);
socket.onmessage = function(e) {
document.getElementById('root').innerHTML = e.data;
};
</script>
@cn007b
cn007b / websockets.php
Last active June 20, 2023 23:17
Super simple PHP WebSocket example - websockets.php
<?php
$address = '0.0.0.0';
$port = 12345;
// Create WebSocket.
$server = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($server, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($server, $address, $port);
socket_listen($server);
@cn007b
cn007b / EuropeanUnion.php
Last active August 3, 2018 14:34
Namespace Dependency Injection - src/Domain/Interfaces/VISA/EuropeanUnion.php
<?php
namespace Domain\Interfaces\VISA;
interface EuropeanUnion
{
public function approve() : string;
}
@cn007b
cn007b / EuropeanUnion.php
Last active August 3, 2018 14:31
Namespace Dependency Injection - src/Infrastructure/VISA/Review/EuropeanUnion.php
<?php
namespace VISA;
use Domain\Interfaces\VISA\EuropeanUnion as VISAInterface;
class EuropeanUnion implements VISAInterface
{
public function approve(): string
{
@cn007b
cn007b / EuropeanUnion.php
Last active August 3, 2018 14:31
Namespace Dependency Injection - src/Infrastructure/VISA/Free/EuropeanUnion.php
<?php
namespace VISA;
use Domain\Interfaces\VISA\EuropeanUnion as VISAInterface;
class EuropeanUnion implements VISAInterface
{
public function approve(): string
{
@cn007b
cn007b / index.php
Created August 3, 2018 14:31
Namespace Dependency Injection - index.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
$eu = new VISA\EuropeanUnion();
$result = $eu->approve();
var_export($result);
@cn007b
cn007b / composer.json
Last active August 3, 2018 14:33
Namespace Dependency Injection - composer.json #1
{
"autoload": {
"psr-4": {
"Domain\\": "src/Domain",
"VISA\\": "src/Infrastructure/VISA/Review"
}
}
}
@cn007b
cn007b / composer.json
Created August 3, 2018 14:33
Namespace Dependency Injection - composer.json #2
{
"autoload": {
"psr-4": {
"Domain\\": "src/Domain",
"VISA\\": "src/Infrastructure/VISA/Free"
}
}
}
@cn007b
cn007b / index.php
Last active August 3, 2018 19:14
Benchmarking ElasticSearch vendors for PHP - index.php
<?php
/**
* PHP benchmarking ElasticSearch vendors.
*
* README:
*
* This is a simple example which provides different options
* how to receive data from ElasticSearch into PHP.
* In this test, we have simple `type` inside ElasticSearch `index` which contains 1K records,
* @see https://github.com/cn007b/my/blob/master/ed/php/examples/elasticsearch/comparison/import.sh