(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
module OS | |
def OS.windows? | |
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil | |
end | |
def OS.mac? | |
(/darwin/ =~ RUBY_PLATFORM) != nil |
#!/usr/bin/env node | |
// todo: try to require jshint here, instead of spawning process, then fallback to spawning process. | |
var jshint = nrequire('jshint'); | |
if (jshint) return process.exit(0); | |
// jshint not installed locally, spawn process instead. | |
// basically the same, but less pretty. | |
var exec = require('child_process').exec; |
Initially, I found bitmasking to be a confusing concept and found no use for it. So I've whipped up this code snippet in case anyone else is confused: | |
<?php | |
// The various details a vehicle can have | |
$hasFourWheels = 1; | |
$hasTwoWheels = 2; | |
$hasDoors = 4; | |
$hasRedColour = 8; |
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Listen for XDebug - Remote", | |
"type": "php", | |
"request": "launch", | |
"port": 9000, | |
"pathMappings": { | |
"/var/www/html/your_app_on_server": "${workspaceFolder}", |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import React from "react" | |
import { Route, Switch } from "react-router-dom" | |
const AppRoute = ({ component: Component, layout: Layout, ...rest }) => ( | |
<Route {...rest} render={props => ( | |
<Layout> | |
<Component {...props} /> | |
</Layout> | |
)} /> | |
) |
<?php declare(strict_types=1); | |
namespace App\Factory; | |
use Psr\Http\Message\RequestInterface; | |
use Psr\Http\Message\ResponseInterface; | |
use Tuupola\Middleware\Cors; | |
use Zend\Diactoros\Response; | |
use Zend\Diactoros\Response\JsonResponse; | |
use Zend\ProblemDetails\ProblemDetailsResponseFactory; | |
use Zend\Stratigility\Middleware\CallableMiddlewareWrapper; |
<?php | |
/** | |
* This script performs a full dump of a database query into | |
* CSV format and pipes it directly to the browser. | |
* | |
* - YES, the browser will save the CSV file to disk | |
* - YES, it should support large files without using massive amounts of memory | |
* - YES, it compresses the request using GZIP to reduce download time | |
*/ |
<?php | |
function discountRateByMembershipType($userId) { | |
//$date = getCurrentDateFromLocalTimeOrRemoteTimeServer(); //with remote time server, we can't fake date | |
//if (is_not_black_friday($date) return 0; // we can't not test CORE BUSINESS if add this spec | |
$membershipType = getMemberShipTypeFromDatabaseOrRemoteApi($userId); | |
//CORE BUSINESS need coverage by unit test or manual test | |
if ('platinum' === $membershipType) return 0.15; | |
if ('gold' === $membershipType) return 0.1; | |
if ('slive' === $membershipType) return 0.05; | |
throw new UnknowMembershipTypeException('invalid membership type'); |
<?php | |
function test_with_platinum_member_will_discount_fifteen_percent() { | |
if ( 0.15 === discountRateByMembershipType('platinum') { | |
echo 'Test Done'; | |
} else { | |
echo 'Test Fail'; | |
} | |
} |