Skip to content

Instantly share code, notes, and snippets.

View ojhaujjwal's full-sized avatar

Ujjwal Ojha ojhaujjwal

View GitHub Profile
#!/usr/bin/env sh
set -eu
export GCP_PROJECT=my-gcp-project
export APP_NAME=cloudrun-node-app-demo
# Logging in to GCR using service account credentials placed on ./gcp-credentials.json
cat ./gcp-credentials.json | docker login -u _json_key --password-stdin https://gcr.io
<?php
function getLines($file): Generator {
$f = fopen($file, 'r');
if (!$f) throw new Exception();
while ($line = fgets($f)) {
yield $line;
}
fclose($f);
}
<?php
$lines = getLines('/path-to-file');
foreach ($lines as $line) {
if (SOME CONDITION) {
break;
}
echo $line. "\n";
}
<?php
function getLines($file): array {
$f = fopen($file, 'r');
if (!$f) throw new Exception();
$lines = [];
while ($line = fgets($f)) {
$lines[] = $line;
}
return $lines;
}
<?php
class FileIterator implements \Iterator {
protected $filePointer;
protected $data;
protected $key;
public function __construct($file) {
$this->filePointer = fopen($file, 'rb');
if (!$this->filePointer) {
<?php
function createLogger($file)): Generator {
$f = fopen($file, 'a');
while (true) {
$line = yield;
fwrite($f, $line. "\n");
}
}
$log = createLogger('/path-to-log/file.log');
<?php
function uploadImages(iterable $images) {
foreach ($images as $image) {
// code to upload image to somewhere
}
}
<?php
function uploadImages(array $images) {
foreach ($images as $image) {
// code to upload image to somewhere
}
}
@ojhaujjwal
ojhaujjwal / ddd_cqrs_event-sourcing_in_php.md
Last active December 4, 2018 01:24 — forked from jsor/ddd_cqrs_event-sourcing_in_php.md
DDD, CQRS and Event Sourcing in PHP

DDD, CQRS and Event Sourcing in PHP

  • ProophEventSourcing - Provides basic functionality for event-sourced aggregates
  • ProophServiceBus - PHP Enterprise Service Bus Implementation supporting CQRS and DDD
  • Broadway - Infrastructure and testing helpers for creating CQRS and event sourced applications
  • EventSauce - Pragmatic event sourcing for PHP
  • ProophEventMachine - The world's only CQRS / ES framework that lets you pick your Flavour ]* predaddy - Common DDD classes including an annotation driven message bus and tools for CQRS and Event Sourcing
  • mmasiukevich/service-bus - CQRS\Event Sourcing\Message based framework
@ojhaujjwal
ojhaujjwal / README.md
Last active August 13, 2018 14:40
Configure Xdebug with PHPStorm and Docker for Mac

Add the following xdebug.ini in your docker container:

zend_extension=/usr/lib/php/20170718/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=off
xdebug.idekey=debugit
xdebug.remote_host=docker.for.mac.localhost