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
@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 = [
<?php
$access_key = "iam-user-access-key"; //Access Key
$secret_key = "iam-user-secret-key"; //Secret Key
$my_bucket = "mybucket"; //bucket name
$region = "us-east-1"; //bucket region
$success_redirect = 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; //URL to which the client is redirected upon success (currently self)
$allowd_file_size = "1048579"; //1 MB allowed Size
//dates
<?php
function generate_uuid(){
$charid = md5(uniqid(rand(), true));
$uuid = substr($charid, 0, 8) . "-"
.substr($charid, 8, 4) . "-"
.substr($charid,12, 4) . "-"
.substr($charid,16, 4) . "-"
.substr($charid,20,12);
return $uuid;
<?php
function generate_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
mt_rand( 0, 0xffff ),
mt_rand( 0, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
@victorknust
victorknust / Person.php
Created August 23, 2016 19:49
Callback
<?php
class Person {
private $name;
private $age;
private $id;
function __construct( $name, $age ) {
$this->name = $name;
$this->age = $age;
<?php
class Connection
{
protected $link;
private $dsn, $username, $password;
public function __construct($dsn, $username, $password)
{
$this->dsn = $dsn;
$this->username = $username;