Skip to content

Instantly share code, notes, and snippets.

View victorknust's full-sized avatar
🏠
Working from home

Victor knust victorknust

🏠
Working from home
View GitHub Profile
<?php
function days_of_this_week()
{
$data = strtotime(date('Y-m-d'));
$ano = date('o', $data);
$semana = date('W', $data);
for($i = 1; $i <= 7; $i++) {
$dias[] = date("m/d/Y l", strtotime($ano . 'W' . $semana . $i));
}
@victorknust
victorknust / readme.md
Created January 18, 2017 11:45 — forked from xeoncross/readme.md
140 byte PHP routing framework (well, it's just a function actually)

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;

<?php
class Router
{
public $routes = array();
public function route( $method, $pattern, $callback )
{
$pattern = '/^' . str_replace( array('/', ':id'), array('\/', '([0-9]+)'), $pattern ) . '$/';
$this->routes[$method][$pattern] = $callback;
<?php
class Generica {
private $dados = array();
public function __set( $chave, $valor ) {
$this->dados[$chave] = $valor;
@victorknust
victorknust / .htaccess
Created October 27, 2016 12:54 — forked from dhrrgn/.htaccess
NPSR - PSRs? We don't need to stinkin' PSRs.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?_uri=$1 [L]
@victorknust
victorknust / slug.php
Created October 26, 2016 16:20 — forked from astrocosa/slug.php
Function slug
<?php
function slug($str, $cat=false) {
$ene = ($cat === true) ? 'ny' : 'n';
$str = (function_exists('mb_strtolower')) ? mb_strtolower($str, 'UTF-8') : strtolower($str);
$str = preg_replace('(à|á|â|ã|ä|å)', 'a', $str);
$str = preg_replace('(è|é|ê|ë)', 'e', $str);
$str = preg_replace('(ì|í|î|ï)', 'i', $str);
$str = preg_replace('(ò|ó|ô|õ|ö|ø|ō)', 'o', $str);
$str = preg_replace('(ù|ú|û|ü|ū)', 'u', $str);
@victorknust
victorknust / slug.php
Created October 26, 2016 15:49 — forked from Heolink/slug.php
Slug
function slug($title, $separator = '-', $removeUnsupported = true)
{
$charsArray = array(
'a' => array(
'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą',
'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ',
'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ',
'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ'),
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب'),
<?php
// GUID v4
public function guid() {
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
<?php
$app->get('',
function ( ) {
echo 'Hello!';
}
);
$app->get('user/{id}/profile',
function ( $id ) {
<?php
// development
// testing
$environment = 'production';
//-------------------------------------------
$config = [