Skip to content

Instantly share code, notes, and snippets.

View cystbear's full-sized avatar
🚴‍♂️
🏄🏕️

Oleg Zinchenko cystbear

🚴‍♂️
🏄🏕️
View GitHub Profile
@cystbear
cystbear / curry.php
Created January 31, 2020 19:17
My PHP Currying implementation
<?php
function curry(\Closure $f) {
$rf = new \ReflectionFunction($f);
$arity = $rf->getNumberOfParameters();
function acc($f, $arity, $args=[]) {
return function(...$acc) use($f, $arity, $args) {
$acc = array_merge($args, $acc);
return (count($acc) >= $arity) ? $f(...$acc) : acc($f, $arity, $acc);
@cystbear
cystbear / curry.php
Last active January 31, 2020 19:12
My PHP Currying implementation
<?php
function curry(\Closure $f) {
$rf = new \ReflectionFunction($f);
$arity = $rf->getNumberOfParameters();
function acc($f, $arity, $args=[]) {
return function(...$acc) use($f, $arity, $args) {
$acc = array_merge($args, $acc);
return (count($acc) >= $arity) ? $f(...$acc) : acc($f, $arity, $acc);
@cystbear
cystbear / collatz.erl
Last active January 11, 2017 14:05
Academic problems solved with Erlang
%% https://en.wikipedia.org/wiki/Collatz_conjecture
-module(collatz).
-export([collatz/1]).
collatz(N) -> collatz(N,0,[N]).
collatz(1, C, Acc) -> {C, lists:reverse(Acc)};
collatz(N, C, Acc) ->
R = case is_even(N) of
<?php
class ErrorPreventer
{
private static $squatter;
public static function init()
{
static::$squatter = new \SplFixedArray(100000);
register_shutdown_function(array(__CLASS__, 'helpMe'));
@cystbear
cystbear / bind-to.php
Last active April 23, 2020 08:26
Shifter Domain -> DTO
<?php
class Domain
{
protected $foo;
protected $bar;
protected $baz;
public function setFoo($foo)
{
@cystbear
cystbear / ExceptionalClient.php
Created January 18, 2012 16:49 — forked from everzet/ExceptionalClient.php
View real exceptions in Behat output with Mink+SymfonyDriver in your Symfony2 feature suite
<?php
namespace Your\MainBundle;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class ExceptionalClient extends Client
{
static private $catchExceptions = true;