Skip to content

Instantly share code, notes, and snippets.

View thgs's full-sized avatar
👻

Theo Gotsopoulos thgs

👻
View GitHub Profile
@thgs
thgs / rfp.php
Created February 26, 2015 05:33
Script to randomly pick a file and echo it, or return the filename
<?php
/*
* Script to randomly pick a file and echo it, or return the filename
*
*/
# data
$_helpScreen = <<<OUT
Random File Picker Help
-=-=-=-==-=-=--==-=-=-=-
@thgs
thgs / tedious.php
Created February 26, 2015 05:34
Simple script to return php configuration
<?php
/*
* tedious version 0.1
*
* Simple script to return php configuration
*/
#settings
$password = 'ablabla';
// some password protection
if ($_GET['pass'] != $password)
@thgs
thgs / ats.php
Created November 17, 2015 09:08
Array pretty printer for PHP
<?php
function arrToStr(array $a)
{
if (empty($a)) return '[]';
foreach($a as $k => $v)
{
if (is_array($v))
$a[$k] = arrToStr($v);
@thgs
thgs / HomeController.php
Created January 27, 2016 23:22
laravel-5 wrapper
<?php namespace App\Http\Controllers;
use File;
use App\Http\Requests;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
@thgs
thgs / with.php
Last active February 22, 2016 07:59
with for PHP
<?php
/* with operator for PHP */
function with(&$obj, $properties)
{
foreach ($properties as $property => $value)
{
$obj->$property = $value;
}
@thgs
thgs / mvc.php
Created June 6, 2020 15:50
Tiny MVC in PHP
<?php
/*
Usage: MVC_ROUTE_FILE=routes.php php -S localhost:8000 mvc.php
Need to move into views/ directory those files named views_*
*/
foreach (require getenv('MVC_ROUTE_FILE') as $routePattern => $dispatch) {
if (preg_match($routePattern, $_SERVER['REQUEST_URI'], $arguments)) {
$dispatch(...$arguments);
exit(0);
@thgs
thgs / flipFlopExample.php
Created December 5, 2022 12:54
Flip Flop example
<?php
function flipFlop2(): \Generator
{
$switch = false;
while (true) {
$value = yield;
// condition1
@thgs
thgs / flipFlopReduce.php
Created December 5, 2022 13:24
FlipFlop example with array_reduce
<?php
$a = range(1, 4);
$example = [1,2,3,4,5,6,3,7];
$a = $example;
print_r(array_reduce(
$a,
// (..) ==1, ==1
function ($carry, $item) {