Skip to content

Instantly share code, notes, and snippets.

View TsuiAnthonYVR's full-sized avatar

Anthony Tsui TsuiAnthonYVR

  • Voleo
  • Vancouver, Canada
View GitHub Profile
@TsuiAnthonYVR
TsuiAnthonYVR / AppServiceProvider.php
Last active November 18, 2016 21:21
Adding custom macros into Laravel
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
class AppServiceProvider extends ServiceProvider
{
/**
@TsuiAnthonYVR
TsuiAnthonYVR / MailingListBaseDecorator.php
Last active February 16, 2017 18:10
Use decorator without making type hinting mad
<?php
namespace App;
use App\Contracts\MailingListService;
abstract class MailingListBaseDecorator implements MailingListService
{
protected $mailingList;
@TsuiAnthonYVR
TsuiAnthonYVR / BelongsToMany.php
Created July 19, 2017 13:07
How to get Laravel to fire model attach/detach events
<?php namespace App\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class BelongsToMany extends \Illuminate\Database\Eloquent\Relations\BelongsToMany {
/**
* Attach a model to the parent.
*
* @param mixed $id
@TsuiAnthonYVR
TsuiAnthonYVR / day8.php
Last active December 10, 2017 07:25
Advent of Code day 8
<?php
$max = 0;
$qk =0;$qt =0; $t =0; $hfh =0; $js =0; $b =0; $uoc =0; $yg =0; $iyu =0;$gy =0; $gif =0; $nwe =0; $itw =0; $ih =0; $hm =0; $cp =0; $x =0; $fi =0; $tc =0; $j =0; $xly =0; $yr =0; $ioe =0; $bi =0; $bhp = 0;
if ( $qk > -10 ) $ioe -= 890 ; $max = max($max, $b, $bhp, $bi, $cp, $fi, $gif, $gy, $hfh, $hm, $ih, $ioe, $itw, $iyu, $j, $js, $nwe, $qk, $qt, $t, $tc, $uoc, $x, $xly, $yg, $yr); ;
if ( $qt <= 7 ) $gif += -533 ; $max = max($max, $b, $bhp, $bi, $cp, $fi, $gif, $gy, $hfh, $hm, $ih, $ioe, $itw, $iyu, $j, $js, $nwe, $qk, $qt, $t, $tc, $uoc, $x, $xly, $yg, $yr); ;
if ( $t != 0 ) $itw -= 894 ; $max = max($max, $b, $bhp, $bi, $cp, $fi, $gif, $gy, $hfh, $hm, $ih, $ioe, $itw, $iyu, $j, $js, $nwe, $qk, $qt, $t, $tc, $uoc, $x, $xly, $yg, $yr); ;
if ( $hfh < -2 ) $nwe += 486 ; $max = max($max, $b, $bhp, $bi, $cp, $fi, $gif, $gy, $hfh, $hm, $ih, $ioe, $itw, $iyu, $j, $js, $nwe, $qk, $qt, $t, $tc, $uoc, $x, $
@TsuiAnthonYVR
TsuiAnthonYVR / Day7.swift
Created December 13, 2017 00:19
Advent of Code Day 7
//: Playground - noun: a place where people can play
import Foundation
let inputString: String = """
pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
@TsuiAnthonYVR
TsuiAnthonYVR / Day 2 Part 2.php
Created December 13, 2017 00:22
Day 2 Part 2
$rows = explode("\n", $xml);
$checksum = 0;
foreach ($rows as $row) {
$cells = [];
foreach (explode("|", $row) as $cell) {
$cells[] = intval($cell);
}
sort($cells);
for ($outer = 0; $outer < count($cells); $outer++) {
for ($inner = $outer + 1; $inner < count($cells); $inner++) {
@TsuiAnthonYVR
TsuiAnthonYVR / Day 1 Part 2.php
Created December 13, 2017 00:23
Day 1 Part 2
<?
$original = str_split($inputString);
$characters = array_merge($original, $original);
$total = 0;
$stepsHalfWay = intval(count($original) / 2);
for ($i = 0; $i < count($original); $i++) {
$char = $characters[$i];
$match = $characters[$i + $stepsHalfWay];
if ($char === $match) {
$total += intval($char);
@TsuiAnthonYVR
TsuiAnthonYVR / Day 1 Part 1.php
Created December 13, 2017 00:25
Day 1 Part 1
<?
$inputString = "599452122679583848618887218995255147535292914535728498346367894477722813939811764912984385383712422835368955117812935354833177978374291536134322914153833468825481971481366443926879197821555367777283885332883534548471122976747772994847339122877648645668626511487568653692649863449569569225215937397163154359465695449411714929464887666115753485193893395478761214643657118314449467995245232598921248121913968613813931491585277462871844353241552477664287713176335941382298661931286288968947239777696866214875318776779376265413342934951532433387778792546554158858498882713667637612888781916167246714257926199548273187897928457324653368883522635269112216984783294351375892419423234598872674178924737918431978238775761313874281782631637623344352185788167822869486368197144544266325142318417762897789996391999752946835495354861296669952671864913278992258452455669771513316337646325622518183325769282133166553268128821694945127684441915424542343414183491395185455125333978553339594981511562281156599925255523494455
@TsuiAnthonYVR
TsuiAnthonYVR / gist:73e5e8cbc1ea2d0f75fd6865bbecb8ee
Last active January 27, 2018 06:20
Live Blogging Canaccord Blockchain Day
anthony [12:47]
Live blogging the Canaccord thing here
[12:48]
Met some Bitcoin Teller Machines up front, CEO is a friend.
Apparently they use Gemini exchange and is despirate to shorten the cash-to-bitcoin time because it takes 5 days for them
[12:49]
He is talking to some miners to get fresh coins to reduce transaction fees
@TsuiAnthonYVR
TsuiAnthonYVR / BluzelleService.php
Created May 17, 2018 03:54
Consuming a WebSocket API inside synchronous code
<?php
namespace App;
use React\EventLoop\Factory;
use React\Socket\Connector as SocketConnector;
use Ratchet\Client\Connector as ClientConnector;
use Clue\React\Block;
class BluzelleService