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 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;
@victorknust
victorknust / get_current_git_commit.php
Last active August 23, 2016 18:56 — forked from stevegrunwell/get_current_git_commit.php
Get current git HEAD using PHP
<?php
/**
* Get the hash of the current git HEAD
* @param str $branch The git branch to check
* @return mixed Either the hash or a boolean false
*/
function get_current_git_commit( $branch = 'master' )
{
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
return $hash;
<?php
class Connection
{
protected $link;
private $dsn, $username, $password;
public function __construct($dsn, $username, $password)
{
$this->dsn = $dsn;
$this->username = $username;
#!/bin/sh
THESITE= "SITE-NAME"
THEDB="DATABASE-NAME"
THEDBUSER="DATABASE-USER"
THEDBPW="DATABASE-USER-PASSWORD"
THEDATE=`date +%d%m%y%H%M`
# export database
mysqldump -u $THEDBUSER -p${THEDBPW} $THEDB | gzip > /var/www/_backups/dbbackup_${THEDB}_${THEDATE}.bak.gz
@victorknust
victorknust / wp-session.php
Last active July 18, 2016 14:17
WordPress Session
<?php
add_action( 'init', 'example_session_start', 1 );
add_action( 'wp_login', 'example_session_regenerate' );
add_action( 'wp_logout', 'example_session_end' );
function example_session_start() {
if ( !session_id() ) {
session_save_path( '/mnt/data/www/example.com/sessions' );
session_name( uniqid( 'example-', true ) );
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
Plugin Name: Plugin x
*/
add_action( 'wp_footer', 'example_plugin_name' );
<?php
// Render template
function tpl_set($template_name, $template_data = array()){
if(stristr($template_name, '.php') === FALSE) {
$template_name = $template_name . '.php';
}
// Create variables for each of sent data index
<?php
// Activate WordPress Maintenance Mode
function maintenance_mode(){
if(!current_user_can('edit_themes') || !is_user_logged_in()){
wp_die('<h1 style="color:red">Website under Maintenance</h1><br />We are performing scheduled maintenance. We will be back online shortly!');
}
}
add_action('get_header', 'maintenance_mode');