Skip to content

Instantly share code, notes, and snippets.

@cn007b
cn007b / composer.json
Created August 3, 2018 19:14
Benchmarking ElasticSearch vendors for PHP - composer.json
{
"require": {
"ruflin/elastica": "^5.1",
"elasticsearch/elasticsearch": "^5.1"
}
}
@cn007b
cn007b / import.sh
Created August 3, 2018 19:15
Benchmarking ElasticSearch vendors for PHP - 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 August 14, 2018 08:36
PostgreSQL vs MongoDB - expected result
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 August 14, 2018 08:42
PostgreSQL vs MongoDB - postgres
# 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 August 14, 2018 11:22
PostgreSQL vs MongoDB - mongo
{
"_id": 17,
"sha1": "dc9793d8f2379b73c4932d33a14c75eefa849fda",
"count": 64,
"files": [
{
"id": 1,
"name": "OdioCondimentumId.avi"
},
{
@cn007b
cn007b / postgresQuery.sql
Created August 14, 2018 11:24
PostgreSQL vs MongoDB - postgres query
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 August 14, 2018 11:25
PostgreSQL vs MongoDB - mongo query
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 August 16, 2018 12:43
Value Object instead of Form - Form
<?php
class Form
{
protected $name;
public function getName()
{
return $this->name;
}
@cn007b
cn007b / ValueObject.php
Last active August 16, 2018 13:09
Value Object instead of Form - ValueObject
<?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 August 16, 2018 16:08
Google Analytics - track custom event
#!/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'