Skip to content

Instantly share code, notes, and snippets.

/**
* Define Dog class using supertype Animal
* Use safeguard annotation.
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.test(); // Dog
}
<?php
/**
* Given the users $role and access $rights ...
* Check if Mike has admin rights and downgrade him
* Wrong approach:
* if ($is_admin && $can_edit_articles ...
*/
$rights = (object) ["read"=>1, "write"=>2, "readwrite"=>16, "admin"=> 32];
$role = (object) ["jim"=>96, "mike"=>32];
@minte9
minte9 / index.php
Last active April 14, 2021 07:24
Php / Basics / Reference
<?php
/**
* array_map()
*
* Round up array values
* Use array_map() with built-in ceil functions
* The result array $mapped will be [2, 3, 4]
*/
<?php
/**
* Define getMaxValue() method
* Use static syntax
*/
class MyClass {
const MAX_VALUE = 100;
@minte9
minte9 / index.php
Last active April 14, 2021 08:19
Php / Basics / Integers / Decimal 2 Ocatal - https://www.minte9.com/php/basics-integers-13
<?php
/**
* Compose $m octal value using myFunc() recursively
* Use reminder and quontient values
*
* 97 (decimal) = 141 (octal)
* 97 % 8 => reminder 1
* 12 % 8 => reminder 4
* 1 % 8 => reminder 1
<?php
/**
* Define $output on multiple $lines
* Use Herodoc syntax.
*
* output =
* She said "This is John's test"
* on multiple rows
*/
/**
* Define a string s1 = "1"
* Define a number n1 = 2
* Display the sum of s1 + n1 = 3
* (convert the string to number)
*/
class App {
public static void main(String[] args) {
/**
* Declare Number no as float 22.23 ...
* Use object's shortValue() method and ...
* Display no as 22
*/
class App {
public static void main(String[] args) {
/**
/**
* Make a for-each loop and ...
* Output all names
*/
class LearningApp {
public static void main(String[] args) {
String[] names = {"John", "Marry", "Ana"};
/**
* Declare showInfo() method ...
* The method should display "Cooper is 3 age old" ...
* The method must have no return type
*/
class App {
public static void main(String[] args) {