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 / 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;

@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('б', 'β', 'Ъ', 'Ь', 'ب'),
@victorknust
victorknust / gist:49f48fbfc72b344ea4c16a4ff64a2512
Created May 10, 2016 13:17 — forked from kerstner/gist:252c0346a3f52f6d8252
Generate 6 Character Random Bit.ly like ID for a URL with PHP and MySQL
// Set number of shortcodes to generate
$shortcodes = 10000000;
// Loop through and create unique shortcodes
while ($shortcodes) {
$shortcode = generateShortcode();
$checkSQL = "SELECT shortcode FROM shortcodes WHERE shortcode = '" . $shortcode . "'";
$checkResult = $mysqli->query($checkSQL);
// If doesn't exist, insert into database
@victorknust
victorknust / update_moodle_photo.php
Created April 27, 2016 20:02 — forked from dangtrinhnt/update_moodle_photo.php
Update moodle user's photo programmatically
#!/usr/bin/php
<?php
// USAGE:
// $ php update_moodle_photo.php <user-id-number>
//
// to be able to run this file as command line script
define('CLI_SCRIPT', true);
// include config.php from your moodle's docroot
require_once('/var/www/moodle/config.php');
@victorknust
victorknust / nginx-mamp-macports.txt
Created March 18, 2016 13:57 — forked from raamdev/nginx-mamp-macports.txt
These are the steps to get Nginx running alongside MAMP on a Mac.
# These steps will get nginx installed on your Mac for local development and
# testing purposes, to be used alongside MAMP (which already includes Apache).
# The following steps assume that you're running MAMP and that you already
# have php-cgi in /Applications/MAMP/bin/php/php5.4.10/bin/php-cgi.
# The start-nginx and stop-nginx scripts created at the end do not
# start or stop MySQL because it is assumed that you normally run MAMP
# with Apache + MySQL turned on and that you occasionally want to switch
# your web server to Nginx for testing purposes and that you leave MySQL running.
# This process was tested successfully on OS X 10.9.
@victorknust
victorknust / ts-ewrcm.php
Created March 1, 2016 18:15
Editing WordPress registration confirmation message
<?php
// Editing WordPress registration confirmation message
// http://wp.me/p1Ehkq-gn
add_filter( 'gettext', 'ts_edit_password_email_text' );
function ts_edit_password_email_text ( $text ) {
if ( $text == 'A password will be e-mailed to you.' ) {
$text = 'If you leave password fields empty one will be generated for you. Password must be at least eight characters long.';
}
return $text;
@victorknust
victorknust / ts-anwpuspr.php
Created March 1, 2016 18:15
Allowing new WordPress users to select password when they register
<?php
// Add Password, Repeat Password and Are You Human fields to WordPress registration form
// http://wp.me/p1Ehkq-gn
add_action( 'register_form', 'ts_show_extra_register_fields' );
function ts_show_extra_register_fields(){
?>
<p>
<label for="password">Password<br/>
<input id="password" class="input" type="password" tabindex="30" size="25" value="" name="password" />
@victorknust
victorknust / ts-swpdr.php
Created March 1, 2016 18:12
Storing WordPress user-selected password into database on registration
<?php
// Storing WordPress user-selected password into database on registration
// http://wp.me/p1Ehkq-gn
add_action( 'user_register', 'ts_register_extra_fields', 100 );
function ts_register_extra_fields( $user_id ){
$userdata = array();
$userdata['ID'] = $user_id;
if ( $_POST['password'] !== '' ) {