Skip to content

Instantly share code, notes, and snippets.

@tonysm
tonysm / tests_Unit_PropertyBasedTest.php
Created March 24, 2020 14:39
Property based testing in PHP with DataProviders, Generators, and Faker
<?php
namespace Tests\Unit;
use Faker\Factory;
use PHPUnit\Framework\TestCase;
class PropertyBasedTest extends TestCase
{
public function propertyBaseData()
var awsIot = require('aws-iot-device-sdk');
// Replace this with the DEVICE ID
let thingName = 'DEVICE_ID';
var thingShadow = awsIot.thingShadow({
keyPath: __dirname + '/custom-certs/aws_rsa_private.pem',
certPath: __dirname + '/custom-certs/aws_rsa_cert.pem',
caPath: __dirname + '/AmazonRootCA1.pem',
clientId: 'myFakeClientId',
@tonysm
tonysm / iot-actions-builder.php
Created March 18, 2020 13:41
AWS IoT, pipeline actions, and builder pattern
<?php
class AwsIotProvider implements IotProvider
{
public function createDevice(DeviceId $deviceId, Certificate $rootCertificate): void
{
(new Pipeline(app()))
->send(
Aws\Tasks\CreateIotDeviceTask::forDeviceId($deviceId)
->withPolicyName(config('iot.providers.aws.devices.policy_name'))
@tonysm
tonysm / concurrent-pool.php
Last active November 1, 2023 13:08
Concurrent Requests
<?php
// 1. Register the routes
Route::get('test/{lorem}', function ($lorem) {
sleep(3);
return response()->json([
'message' => $lorem,
'token' => Str::random(),
]);
@tonysm
tonysm / dijkstra.php
Created January 27, 2020 14:17
Djikstra Algo in PHP
<?php
$graph = [
"start" => [
"a" => 6,
"b" => 2,
],
"a" => [
"end" => 1
],
<template>
<a :href="`/services?serviceId=${service.id}`">Link</a>
</template>
<script>
export default {
data() {
return {
service: {
id: 123,
import TurbolinksAdapter from 'vue-turbolinks';
document.addEventListener('turbolinks:load', () => {
var vueapp = new Vue({
el: "#hello",
template: '<App/>',
mixins: [TurbolinksAdapter],
components: { App }
});
});
@tonysm
tonysm / example.js
Last active December 8, 2019 19:19
websockets with Larvel Echo and React Hooks
import React, { useEffect, useReducer } from 'react';
import Layout from "@/Components/Layout";
const CONNECTION_STATUSES = {
ONLINE: 'ONLINE',
OFFLINE: 'OFFLINE',
};
const actions = {
@tonysm
tonysm / 01-message-passing.rb
Last active November 23, 2019 18:54
oop and fp article examples
class Deployment
def mark_as_finished
# ...
end
def mark_as_timedout
# ...
end
def cancel
@tonysm
tonysm / eager.php
Created May 6, 2019 14:24
lazy-loading vs eager-loading
<?php
class BuildingsController
{
public function index(
ListBuildingsRequest $request,
BuildingsRepository $buildings
) {
// Not sure how to return data here. For instance, we can return 'users_count'
// of Buildings, but a Building has many Organisations which has many users