Skip to content

Instantly share code, notes, and snippets.

View akmalhazim's full-sized avatar

Akmal Hazim akmalhazim

View GitHub Profile
@akmalhazim
akmalhazim / index.js
Created March 9, 2022 14:13
Algo playground
const arr = [2, [4, 3, [7, 6]]];
const flatArr = [];
const flat = arr => {
if (!Array.isArray(arr)) {
flatArr.push(arr);
return
}
@akmalhazim
akmalhazim / postcodes.json
Created June 25, 2021 21:03
Get short-formed state by post code - useful for calculating shipping price via external provider
{"1750":"pls","5110":"kdh","5330":"kdh","7520":"kdh","8170":"kdh","10000":"png","10020":"png","10050":"png","10100":"png","10110":"png","10150":"png","10160":"png","10200":"png","10250":"png","10300":"png","10350":"png","10400":"png","10420":"png","10450":"png","10460":"png","10470":"png","10500":"png","10502":"png","10503":"png","10504":"png","10505":"png","10506":"png","10508":"png","10512":"png","10514":"png","10516":"png","10518":"png","10520":"png","10524":"png","10534":"png","10538":"png","10540":"png","10542":"png","10546":"png","10550":"png","10551":"png","10552":"png","10558":"png","10560":"png","10564":"png","10566":"png","10570":"png","10576":"png","10578":"png","10582":"png","10590":"png","10592":"png","10593":"png","10594":"png","10596":"png","10600":"png","10604":"png","10609":"png","10610":"png","10612":"png","10620":"png","10622":"png","10626":"png","10628":"png","10634":"png","10646":"png","10648":"png","10660":"png","10661":"png","10662":"png","10668":"png","10670":"png","10672":"png","10673
@akmalhazim
akmalhazim / cote-performance-test.js
Last active December 16, 2019 10:58
CoteJS performance test
const cote = require('cote');
const requester = new cote.Requester({
name: 'test caller',
key: 'test'
});
const responder = new cote.Responder({
name: 'test responder',
key: 'test'
});
responder.on('ping', (req, cb) => {
@akmalhazim
akmalhazim / projekiot-unit-test-review-second.js
Created September 7, 2019 04:12
ProjekIoT Unit Test Review Second Revision
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const { should, expect } = chai;
chai.should();
chai.use(chaiAsPromised);
const { User } = require('../models/index');
const AuthController = require('../controllers/auth');
@akmalhazim
akmalhazim / projekiot-unit-test-review.js
Created September 6, 2019 10:27
ProjekIoT Unit Test Review
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const { should, expect } = chai;
chai.should();
chai.use(chaiAsPromised);
const { User } = require('../models/index');
const AuthController = require('../controllers/auth');
<?php
namespace App\Services;
use App\Traits\Braintree\Helpers;
use App\Traits\Braintree\Base;
use App\User;
use App\PaymentMethod;
use App\Jobs\PaymentMethod\DeleteCard;
<?php
namespace App\Contracts;
use App\User;
use App\Card;
interface PaymentGateway {
public function getPaymentMethodNonce( User $user );
public function createCustomer( User $user );
<?php
namespace App\Modules;
use App\User;
use App\Services\BraintreeService;
class BillingModule {
<?php
namespace App\Providers;
use App\Modules\AccountModule;
use App\Modules\SubscriptionModule;
use App\Modules\BillingModule;
use App\Modules\ProjectModule;
use App\Modules\RecordModule;
use App\Modules\SensorModule;
public function removePaymentMethod( PaymentMethod $paymentMethod, User $user ) {
dispatch(new DeleteCard($paymentMethod, $user));
// delete local db.
$paymentMethod->delete();
return;
}