Skip to content

Instantly share code, notes, and snippets.

View md2perpe's full-sized avatar

Per Persson md2perpe

View GitHub Profile
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);
@md2perpe
md2perpe / Shapes
Created June 23, 2015 19:36
Square as a subclass of Rectangle
class Rectangle
{
protected double width, height;
constructor(double width, double height)
{
this.width = width;
this.height = height;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@md2perpe
md2perpe / gist:9683372
Last active August 29, 2015 13:57
Idea of new operator in PHP

Got an idea of a new assignment operator ?= in PHP.

Instead of writing

if (!$x)
    $x = $y;

one could use ?= and write

$x ?= $y;
@md2perpe
md2perpe / permutations.js
Created January 1, 2014 18:54
Function for generating permutations of a list.
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',

Merry Christmas in different languages

Spanish
English Merry Christmas