Skip to content

Instantly share code, notes, and snippets.

@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'
@cn007b
cn007b / ValueObject.static.php
Last active August 20, 2018 13:59
Value Object instead of Form - ValueObject static
<?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');
@cn007b
cn007b / Implementation1.controller.go
Last active September 24, 2018 20:16
eop - Implementation1 controller
// controller
func SignUp(username string) {
msg := "ok"
if err := service.SignUp(username); err != nil {
msg = err.Error()
}
fmt.Printf("[error] SignUp: %s \n", msg)
}
@cn007b
cn007b / Implementation1.service.go
Created September 24, 2018 20:19
eop - Implementation1 service
// service
func SignUp(username string) error {
if err := validation(username); err != nil {
return fmt.Errorf("validation failed, error: %s", err)
}
if err := signUpFacebook(username); err != nil {
return fmt.Errorf("facebook sign up failed, error: %s", err)
}
if err := signUpTwitter(username); err != nil {