Skip to content

Instantly share code, notes, and snippets.

View mcsee's full-sized avatar
🏠
Working from home

mcsee mcsee

🏠
Working from home
View GitHub Profile
import React from 'react';
// This is more closely related to real world
const InexistantCustomer = () => {
return (
<div>
<h2>Inexistant customer</h2>
<p>Sorry, we couldn't find any customer matching your criteria.</p>
</div>
);
import React from 'react';
const NullCustomer = () => {
return (
<div>
<h2>No customer found</h2>
<p>Sorry, we couldn't find any customer matching your criteria.</p>
</div>
);
};
import java.util.EmptyStackException;
import java.util.Stack;
public class SchrodingerStack<T> {
private Stack<T> stack;
private boolean isEmpty;
public SchrodingerStack() {
stack = new Stack<>();
isEmpty = true;
import java.util.EmptyStackException;
import java.util.Stack;
public class SchrodingerStack<T> {
private Stack<T> stack;
private boolean isEmpty;
public SchrodingerStack() {
stack = new Stack<>();
isEmpty = true;
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
memo = {}
def factorial_with_memo(n):
if n in memo:
return memo[n]
if n == 0:
return 1
result = n * factorial_with_memo(n-1)
memo[n] = result
return result
public const string FORMAT_JPG = "JPG";
public const string FORMAT_GIF = "GIF";
public const string FORMAT_PNG = "PNG";
// OR
public enum ImageFormat
{
JPG,
GIF,
public const FORMAT_JPG = 1;
public const FORMAT_GIF = 2;
public const FORMAT_PNG = 3;
<?
$sourceFile = 'C:\temp\source.txt';
$destination = 'C:\temp\destination :txt';
// The filename is simplified
// and might come from a programmatic construction
$copyWasSuccessful = copy($sourceFile, $destination);
if (!$copyWasSuccessful || !$file_exists($destination)) {
// Don't trust the function result. Handle the postcondition error
<?
$sourceFile = 'C:\temp\source.txt';
$destination = 'C:\temp\destination.txt';
$copyWasSuccessful = copy($sourceFile, $destination); // true
$destinationFileExists = file_exists($destination); // true
$sourceFile = 'C:\temp\source.txt';
$destination = 'C:\temp\destination :txt';
// The filename is simplified