This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$value = 0; | |
if ($_POST) { | |
$value = (int) $_POST['value']; | |
if (isset($_POST['inc'])) { | |
$value++; | |
} elseif (isset($_POST['dec'])) { | |
$value--; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CsvIterator extends FileIterator | |
{ | |
/** | |
* @var string | |
*/ | |
protected $_delimiter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO(/* connection details */); | |
$query = ' | |
SELECT * | |
FROM table | |
WHERE col1 = :value1 | |
AND col2 = :value2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filename = 'data.txt'; | |
$delimiter = "\t"; | |
$file = new SplFileObject($filename, 'r'); | |
$file->setFlags(SplFileObject::READ_CSV); | |
$file->setCsvControl($delimiter); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuthService implements AuthServiceInterface { | |
private Logger logger; | |
// ... | |
public void setLogger(Logger logger) { | |
this.logger = logger; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DigitsIterator implements Iterator { | |
private $num; | |
private $radix; | |
private $temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function match($string, $pattern) { | |
$automata = new Automata($pattern); | |
return $automata->match($string); | |
} | |
function get_chars($string) { | |
for ($i = 0; $i < strlen($string); $i++) { | |
yield $string[$i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function * permutations(str) { | |
var length = str.length; | |
if (length <= 1) { | |
yield str; | |
} else { | |
for (var i = 0; i < length; i++) { | |
var ch = str[i], substr = str.substr(0, i) + str.substr(i + 1); | |
for (var permutation of permutations(substr)) { | |
yield ch + permutation; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wixpress.quotes.common | |
import java.util.UUID | |
object CQRS { | |
//////////////////////////////////////////////////////////////////////////////// | |
// Example application | |
//////////////////////////////////////////////////////////////////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Node(value: Int, | |
left: Option[Node] = None, | |
right: Option[Node] = None) | |
object Serializer { | |
private val pattern = """^(\d+)\((.*)\)$""".r | |
private val treeOpen = '(' | |
private val treeClose = ')' | |
private val separator = ',' | |
private val separatorLength = 1 |
OlderNewer