Skip to content

Instantly share code, notes, and snippets.

View bzikarsky's full-sized avatar

Benjamin Zikarsky bzikarsky

View GitHub Profile
@bzikarsky
bzikarsky / check_oneplus_stock.bash
Created January 23, 2017 11:07
Desperate measures for ordering a OnePlus 3T )
#!/bin/bash
# Check for availability of a OnePlus stock item (405 == OnePlus 3T 128GB EU)
# and notify over pushover.net
#
# Background: https://www.oneplusstock.net/ revealed that you do not get
# an instant notification as soon as it goes back on stock...so this might
# help...
#
@bzikarsky
bzikarsky / example.php
Last active August 29, 2015 14:13
Resolvable generators
<?php
// this is our generator, dns\* and socket\* are assumed
// to be async functions returning promises
function read_data_from($hostname, $port) {
$ip = yield dns\resolve($hostname);
$socket = yield socket\connect($ip, $port);
echo yield socket\read(1024);
};
#!/bin/bash
DB="test"
COL="tz"
ZONES="London Berlin Istanbul"
DATE="2000-01-01"
echo "System timezone: $(date -R)"
echo ""
@bzikarsky
bzikarsky / test.bash
Last active August 29, 2015 14:10
Test timezone behavior with PHP and Mongo
#!/bin/bash
DB="test"
COL="tz"
ZONES="London Berlin Istanbul"
DATE="2000-01-01"
echo "System timezone: $(date -R)"
echo ""
@bzikarsky
bzikarsky / mongo_session_bench.php
Created November 20, 2014 07:30
Benchmark session lifetime condition: Mongo vs PHP
<?php
$mongo = new MongoClient();
$db = $mongo->test;
$collection = $db->selectCollection('session');
$sessionCount = $argv[1];
$sampleCount = $argv[2];
$samples = [];
// Setup collection
<?hh
async function stream_check(resource $stream, string $mode, int $usec): Awaitable<void>
{
$r = $w = $e = null;
do {
if ($mode == "r") {
$r = Vector{$stream};
}
@bzikarsky
bzikarsky / integer_overflow.php
Created December 29, 2013 22:05
Test PHP integer overflow
<?php
echo "var_dump(...)\n";
echo "\n";
echo "PHP_INT_MAX : ";
var_dump(PHP_INT_MAX);
echo "PHP_INT_MAX + 1 : ";
var_dump(PHP_INT_MAX + 1);
@bzikarsky
bzikarsky / ValueObject.php
Last active December 31, 2015 23:39
Immutable ValueObject example
<?php
class ValueObject
{
protected $checked;
protected $value;
protected $exists;
@bzikarsky
bzikarsky / Bcrypt.php
Created August 11, 2012 11:34
Simple Bcrypt class
<?php
namespace Zikarsky\Util;
class Bcrypt
{
const ALGO_ID = "2y";
const ALGO_ID_PRE_5_3_7 = "2a";
<html>
<head>
<title>VM</title>
<style type="text/css">
body {
font-family: "Courier New";
font-size: .8em;
}