Skip to content

Instantly share code, notes, and snippets.

View Antnee's full-sized avatar

Anthony Chambers Antnee

  • Nottinghamshire
View GitHub Profile

#Rules #RULES #rules #md001

@Antnee
Antnee / is-even.php
Last active August 24, 2020 14:50
What is quicker to check if a number is even or not? Checking the bits, or performing a modulus operation?
<?php
/**
* Check if a number is even by examining the bit for 1 (ie the odd number 'flag')
*/
function isEvenBit(int $num): bool
{
return !($num & 0b1);
}
/**
@Antnee
Antnee / strace.txt
Last active November 19, 2019 16:43
Slow Xdebug 2.8.0 Strace
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
29.16 0.034135 2 20437 9 open
19.65 0.022995 1 20456 close
14.39 0.016840 1 25138 10055 access
8.61 0.010082 1 14542 poll
6.81 0.007972 1 5622 45 stat
4.65 0.005440 1 10127 17 lstat
4.26 0.004985 0 11774 write
4.08 0.004771 1 3333 getdents
@Antnee
Antnee / password_hash_cost_calculator.php
Created February 29, 2016 13:48
PHP password_hash() cost calculator
<?php
/**
* Password Hash Cost Calculator
*
* Set the ideal time that you want a password_hash() call to take and this
* script will keep testing until it finds the ideal cost value and let you
* know what to set it to when it has finished
*/
// Milliseconds that a hash should take (ideally)
@Antnee
Antnee / generator_return_types.php
Last active September 3, 2023 23:40
PHP 7 Generator Return Type
<?php
class Item {
private $id;
public function __construct(int $id)
{
$this->id = $id;
}
public function id() : int
{
@Antnee
Antnee / Vagrantfile
Last active November 23, 2017 02:01
Vagrant PHP 7 Apache 2.4 XDebug
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@Antnee
Antnee / php7_structs.php
Last active September 30, 2017 01:22
PHP7 Structs
<?php
/**
* Ideas for how I'd like to see structs implemented in PHP7
*
* In this example, structs are more like lightweight objects that have no
* methods, just properties. They can be "instantiated" and all properties will be
* null until defined later, as per classes. It is however not possible to set a
* value to a property that was not defined in the struct originally.
*
* Structs can extend other structs, much like classes can. Properties can also