Skip to content

Instantly share code, notes, and snippets.

@cn007b
cn007b / import.sh
Created Aug 3, 2018
Benchmarking ElasticSearch vendors for PHP - import.sh
View import.sh
#!/bin/bash
curl -s -XPUT http://localhost:9200/somecorp -d '{
"mappings": {
"employee": {
"properties": {
"id": {
"type": "integer"
},
"first_name": {
@cn007b
cn007b / expectedResult.md
Created Aug 14, 2018
PostgreSQL vs MongoDB - expected result
View expectedResult.md
396, 4d509b2bc497b54455aac7e4863ce7dac3e1c898, NonMattis.avi
396, 4d509b2bc497b54455aac7e4863ce7dac3e1c898, VenenatisTurpis.xls
395, 65864917b1548aa1b4520a5a40511dc4e4e4af12, AmetErosSuspendisse.tiff
395, 65864917b1548aa1b4520a5a40511dc4e4e4af12, PlateaDictumst.gif
394, b738398a474808da2a9c9c0e00abecabba22acd4, AFeugiatEt.xls
394, b738398a474808da2a9c9c0e00abecabba22acd4, Amet.mp3
394, b738398a474808da2a9c9c0e00abecabba22acd4, At.avi
394, b738398a474808da2a9c9c0e00abecabba22acd4, AtVelit.png
394, b738398a474808da2a9c9c0e00abecabba22acd4, CondimentumId.xls
@cn007b
cn007b / postgres.sql
Created Aug 14, 2018
PostgreSQL vs MongoDB - postgres
View postgres.sql
# table storage
id | sha1 | count
----+------------------------------------------+-------
17 | dc9793d8f2379b73c4932d33a14c75eefa849fda | 64
# table file
id | storage_id | name
-----+------------+-----------------------
113 | 17 | OdioCondimentumId.avi
114 | 17 | Venenatis.png
@cn007b
cn007b / mongo.json
Created Aug 14, 2018
PostgreSQL vs MongoDB - mongo
View mongo.json
{
"_id": 17,
"sha1": "dc9793d8f2379b73c4932d33a14c75eefa849fda",
"count": 64,
"files": [
{
"id": 1,
"name": "OdioCondimentumId.avi"
},
{
@cn007b
cn007b / postgresQuery.sql
Created Aug 14, 2018
PostgreSQL vs MongoDB - postgres query
View postgresQuery.sql
SELECT s.id, s.sha1, f.name
FROM storage s
JOIN file f ON s.id = f.storage_id
WHERE s.count > 0
ORDER by id DESC, name ASC
OFFSET 1000 LIMIT 10
@cn007b
cn007b / mongoQuery.js
Created Aug 14, 2018
PostgreSQL vs MongoDB - mongo query
View mongoQuery.js
db.file_storage.aggregate([
{$match: {"count": {$gt: 0}}},
{$unwind: "$files"},
{$project: {_id: 1, sha1: 1, "name": "$files.name"}},
{$sort: {_id: -1, "name": 1}},
{$skip : 1000},
{$limit : 10},
])
@cn007b
cn007b / Form.php
Last active Aug 16, 2018
Value Object instead of Form - Form
View Form.php
<?php
class Form
{
protected $name;
public function getName()
{
return $this->name;
}
@cn007b
cn007b / ValueObject.php
Last active Aug 16, 2018
Value Object instead of Form - ValueObject
View ValueObject.php
<?php
class ValueObject
{
protected $name;
public function __construct(array $args)
{
if (!isset($args['name']) || $args['name'] === '') {
throw new InvalidArgumentException('name cannot be blank');
@cn007b
cn007b / ga.sh
Created Aug 16, 2018
Google Analytics - track custom event
View ga.sh
#!/bin/bash
tid='UA-109851522-1'
cid=`php -r 'echo rand();'`
curl -i 'https://www.google-analytics.com/collect?v=1&t=event&tid='$tid'&cid='$cid'&ec=shellClick&ea=click.shell&el=cli&ev=1'
@cn007b
cn007b / ValueObject.static.php
Last active Aug 20, 2018
Value Object instead of Form - ValueObject static
View ValueObject.static.php
<?php
class ValueObject
{
protected $name;
private function __construct()
{}
public static function fromArray(array $args)
{
if (!isset($args['name']) || $args['name'] === '') {
throw new InvalidArgumentException('name cannot be blank');