Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* @author Michael Calcinai <michael@calcin.ai>
*/
class IteratorPropertySorterIterator implements \Iterator
{
/**
* @var \Iterator[]
@calcinai
calcinai / adc_gpio.php
Created September 6, 2017 23:51
Example for MCP3008 with PHPi
<?php
include __DIR__.'/../vendor/autoload.php';
use Calcinai\PHPi\Peripheral\SPI;
use Calcinai\PHPi\Pin\PinFunction;
use Calcinai\PHPi\External\ADC\Microchip\MCP3008;
$board = \Calcinai\PHPi\Factory::create();
<?php
$xero = new PrivateApplication($config);
/** @var Contact[] $contacts */
$contacts = $xero->load('Accounting\\Contact')->execute();
foreach($contacts as $contact){
//do something here
//this will give you the raw data without the object structure
@calcinai
calcinai / aggregate_reading.php
Created September 27, 2016 08:33
Time-series aggregate readings
<?php
public function getAggregateReadings(\DateTime $from, \DateTime $to, \DateInterval $interval) {
$from = clone $from;
$to = clone $to;
$seconds = date_create('@0')->add($interval)->getTimestamp();
//Round to the correct block.