Got an idea of a new assignment operator ?=
in PHP.
Instead of writing
if (!$x)
$x = $y;
one could use ?=
and write
$x ?= $y;
package main | |
import "fmt" | |
type H struct { seq int } | |
type O struct { seq int } | |
type H2O struct { | |
h1, h2 H | |
o O |
package main | |
import "fmt" | |
// Sends the sequence n, n+1, n+2, ... to the `out` channel | |
func from(n int, out chan<- int) { | |
for i := n; ; i++ { | |
out <- i | |
} |
package main | |
import "fmt" | |
const s="package main%cimport %cfmt%c%cconst s=%c%s%c%cfunc main() {fmt.Printf(s,10,34,34,10,34,s,34,10,10)}%c" | |
func main() {fmt.Printf(s,10,34,34,10,34,s,34,10,10)} |
class Safe | |
{ | |
protected $value; | |
public function __construct($value) { $this->value = $value; } | |
public function __call($method, $args) | |
{ | |
if (is_object($this->value) && method_exists($this->value, $method)) { | |
return new self(call_user_func_array([$this->value, $method], $args); |
class Rectangle | |
{ | |
protected double width, height; | |
constructor(double width, double height) | |
{ | |
this.width = width; | |
this.height = height; | |
} |
Got an idea of a new assignment operator ?=
in PHP.
Instead of writing
if (!$x)
$x = $y;
one could use ?=
and write
$x ?= $y;
function permutations(list) | |
{ | |
// Empty list has one permutation | |
if (list.length == 0) | |
return [[]]; | |
var result = []; | |
for (var i=0; i<list.length; i++) |
<?php | |
// Returns a cer encoded SSL certificate | |
function create_identity_cer( | |
$countryName, $stateOrProvinceName, $localityName, $organizationName, | |
$organizationalUnitName, $commonName, $emailAddress, $foafLocation) | |
{ | |
// Create the DN array for the openssl function calls | |
$fields = array( | |
'countryName', | |
'stateOrProvinceName', |