Skip to content

Instantly share code, notes, and snippets.

@cn007b
cn007b / superSimpleGOExamples.md
Last active Apr 17, 2020
Super simple GO examples
View superSimpleGOExamples.md

Super simple GO examples

Super simple golang code examples:

cli.go:

package main

import (
@cn007b
cn007b / websockets.html
Created Aug 2, 2018
Super simple PHP WebSocket example - websockets.html
View 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 Aug 2, 2018
Super simple PHP WebSocket example - websockets.php
View 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 Aug 3, 2018
Namespace Dependency Injection - src/Domain/Interfaces/VISA/EuropeanUnion.php
View EuropeanUnion.php
<?php
namespace Domain\Interfaces\VISA;
interface EuropeanUnion
{
public function approve() : string;
}
@cn007b
cn007b / EuropeanUnion.php
Last active Aug 3, 2018
Namespace Dependency Injection - src/Infrastructure/VISA/Review/EuropeanUnion.php
View 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 Aug 3, 2018
Namespace Dependency Injection - src/Infrastructure/VISA/Free/EuropeanUnion.php
View 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 Aug 3, 2018
Namespace Dependency Injection - index.php
View 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 Aug 3, 2018
Namespace Dependency Injection - composer.json #1
View composer.json
{
"autoload": {
"psr-4": {
"Domain\\": "src/Domain",
"VISA\\": "src/Infrastructure/VISA/Review"
}
}
}
@cn007b
cn007b / composer.json
Created Aug 3, 2018
Namespace Dependency Injection - composer.json #2
View composer.json
{
"autoload": {
"psr-4": {
"Domain\\": "src/Domain",
"VISA\\": "src/Infrastructure/VISA/Free"
}
}
}
@cn007b
cn007b / index.php
Last active Aug 3, 2018
Benchmarking ElasticSearch vendors for PHP - index.php
View 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