Skip to content

Instantly share code, notes, and snippets.

@stefpe
stefpe / multi_curl.php
Last active March 22, 2018 12:55
Multi curl
function multiRequest(array $requests = []): array
{
$std_options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5
];
$mh = curl_multi_init();
$handlers = [];
@stefpe
stefpe / main.go
Last active August 1, 2018 11:32
hello world go
package main
import "fmt"
func main() {
fmt.Println("Hello multi stage build")
}
@stefpe
stefpe / main.go
Created August 1, 2018 13:02
golang healthcheck example
package main
import (
"database/sql"
"encoding/json"
"fmt"
"net/http"
_ "github.com/go-sql-driver/mysql"
)
@stefpe
stefpe / sync.sh
Created August 6, 2018 20:23
Dropbox sync example
#!/usr/bin/env bash
readonly TOKEN=YOUR_APP_TOKEN
readonly DIR=/YOUR_DIR_PATH
FILE=$1
BASENAME=$(basename $FILE)
if [ -f "$FILE" ]; then
@stefpe
stefpe / Dockerfile
Created September 4, 2018 09:51
php 7 memcached installation
FROM php:7.2-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install memcached-3.0.4 \
&& docker-php-ext-enable memcached
@stefpe
stefpe / test.php
Last active September 4, 2018 12:39
Test memcached modula distribution algorithm
<?php
const KEY = 'foo';
const VALUE = 'bar';
$memcached = new Memcached();
$memcached->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_MODULA);
$memcached->addServers([
['memcached1', 11211],
['memcached2', 11211]
@stefpe
stefpe / Robofile.php
Created September 18, 2018 21:31
Robo basic start
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
/**
* Shows how to start with robo.
@stefpe
stefpe / datetime_compare.php
Last active April 17, 2019 19:44
DateTime comparison with spaceship operator
<?php
$list = [
new DateTime('yesterday'),
new DateTime('today'),
new DateTime('1 week ago'),
];
usort($list, function ($a, $b) {
return $a <=> $b;
@stefpe
stefpe / robo_fs.php
Last active January 21, 2019 13:34
FilesystemStack
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
/**
@stefpe
stefpe / robo_watcher.php
Created January 21, 2019 15:26
File watcher with robo
<?php
require_once './vendor/autoload.php';
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks