Skip to content

Instantly share code, notes, and snippets.

View geraldcroes's full-sized avatar

Gérald Croës geraldcroes

View GitHub Profile
@geraldcroes
geraldcroes / gist:6212423
Created August 12, 2013 16:17
Mongo insert bug with the magic add a _id even if the data is passed by copy
<?php
class EntityObject {
private $arData = array();
public function __construct ($initialValue) {
$this->setProperty($initialValue);
}
public function setProperty ($value) {
@geraldcroes
geraldcroes / response.json
Created December 3, 2017 11:11
REST 101 - Reservation collection
[
{
"reservation_id" : "R1",
"client_id" : "robert-id",
"date" : "2017-10-10",
"time" : "9:00pm",
"number_of_guests" : 10
},
{
"reservation_id" : "R2",
@geraldcroes
geraldcroes / sent.json
Created December 3, 2017 11:16
REST 101 - New reservation
{
"client_id": "my-id",
"date": "2017-12-12",
"time": "9:30pm",
"number_of_guests": 12
}
@geraldcroes
geraldcroes / response.json
Last active December 3, 2017 11:18
REST 101 - New reservation in collection
[
{
"reservation_id" : "R1",
"client_id" : "robert-id",
"date" : "2017-10-10",
"time" : "9:00pm",
"number_of_guests" : 10
},
{
"reservation_id" : "R2",
@geraldcroes
geraldcroes / response.json
Last active December 3, 2017 11:29
REST 101 - Single reservation
{
"reservation_id": "R3",
"client_id": "my-id",
"date": "2017–12–12",
"time": "9:30pm",
"number_of_guests": 12
}
@geraldcroes
geraldcroes / sent.json
Created December 3, 2017 11:31
REST 101 - Update a record
{
"client_id": "my-id",
"date": "2018–12–12",
"time": "9:00pm",
"number_of_guests": 2
}
@geraldcroes
geraldcroes / sent.json
Last active December 3, 2017 11:33
REST 101 - PATCH
{
"time": "9:30pm"
}
@geraldcroes
geraldcroes / FileParser.kt
Created December 9, 2017 16:46
FileParser interface
interface FileParser
@geraldcroes
geraldcroes / FileParsers.kt
Created December 9, 2017 16:47
FileParser implementations
class XmlFileParser : FileParser
class JsonFileParser : FileParser
@geraldcroes
geraldcroes / FileParserFactory.kt
Created December 9, 2017 16:48
StandardFileParserFactory
/* The concept of the factory -> creates a Product */
interface FileParserFactory {
fun createFromFileName(fileName: String): FileParser
}
/* Our specific Factory */
class StandardFileParserFactory : FileParserFactory {
override fun createFromFileName(fileName: String) =
when (fileName.substringAfterLast('.')) {
"xml" -> XmlFileParser()