Navigation Menu

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
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';
$copyWasSuccessful = copy($sourceFile, $destination); // true
$destinationFileExists = file_exists($destination); // true
$sourceFile = 'C:\temp\source.txt';
$destination = 'C:\temp\destination :txt';
// The filename is simplified
<?
$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
class CreditCard {
private String number;
private MonthOfYear expiryDate;
// expiryDate is the role
// MonthOfYear is the type
}
class MonthOfYear {
private Month month;
private Year year;
const pets = '😺🐶😺';
const justDogs = pets.replaceAll('😺', '🐩');
// Or
const justDogs = pets.replace(/😺/g, '');
const catsArePresent = justDogs.includes('😺');
// returns false
const pets = '😺🐶😺';
const justDogs = pets.replace('😺', '🐩');
const catsArePresent = justDogs.includes('😺');
// returns true
import java.util.Date;
public class CreditCard {
private String cardNumber;
private Date expiryDate;
public CreditCard(String cardNumber, Date expiryDate) {
// Not a complete date
this.cardNumber = cardNumber;
this.expiryDate = expiryDate;
public class CreditCard {
private String cardNumber;
private int expiryMonth;
private int expiryYear;
public CreditCard(String cardNumber, int expiryMonth, int expiryYear) {
this.cardNumber = cardNumber;
this.expiryMonth = expiryMonth;
this.expiryYear = expiryYear;
// No validations on number ranges?
def calculate(mathOperand, firstArgument, secondArgument):
if mathOperand == '+':
return firstArgument + secondArgument
elif mathOperand == '-':
return firstArgument - secondArgument
elif mathOperand == '*':
return firstArgument * secondArgument
elif mathOperand == '/':
if secondArgument != 0:
return firstArgument / secondArgument