Skip to content

Instantly share code, notes, and snippets.

View efarem's full-sized avatar

EFAREM efarem

  • London, UK
View GitHub Profile
@efarem
efarem / plesk-reload-domain
Last active August 29, 2015 14:00
Plesk - Reload domain/vhost config
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example-domain.com
@efarem
efarem / mysql-random-number
Created July 17, 2014 08:15
MySQL Random Number
(FLOOR( 100 + RAND( ) * 1000 ))
@efarem
efarem / ssl-generate-csr
Created September 9, 2014 09:21
SSL Generate CSR
sudo openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
@efarem
efarem / new-sftp-user
Created March 5, 2015 17:21
New SFTP User
useradd [username]
passwd [username]
usermod -g www-data -G [username] -d [home-directory] -s /usr/sbin/nologin [username]
Add this to bottom of /etc/ssh/sshd_config
Match User [username]
ChrootDirectory [home-directory]
PasswordAuthentication yes
X11Forwarding no
@efarem
efarem / gitautodeploy.sh
Created July 24, 2015 13:50
Git Auto Deploy init script for CentOS 6
#!/bin/bash
#
# /etc/init.d/gitautodeploy
#
# Service manager for GitAutoDeploy
#
# chkconfig: 345 70 30
# description: Git Auto Deploy is a simple HTTP server for accepting push notifications from GitLab
# processname: gitautodeploy
@efarem
efarem / WordPress Loop Shortcode
Last active December 15, 2015 07:19
WordPress loop shortcode, super useful for when you're faking post type archives using pages for SEO or for adding content above and below easily.
<?php
if (!class_exists('FRM_Loop'))
{
class FRM_Loop
{
public function __construct()
{
add_shortcode('loop', array(&$this, 'loop_shortcode'));
}
@efarem
efarem / Elapsed time string
Last active December 21, 2015 01:59
Convert a timestamp into a relative string e.g. 2 Hours ago
<?php
/**
* Convert a timestamp into a relative string e.g. 2 Hours ago
*
* @return string
*
* @param $time Timestamp
**/
function time_elapsed($time)
@efarem
efarem / Resize Image Canvas
Created September 25, 2013 18:30
Quick and dirty was to resize an image canvas, center original and fill white space
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
@efarem
efarem / Force HTTPS
Created September 30, 2013 08:57
Force HTTPS
if (!isset($_SERVER['HTTPS']))
{
header('Status-Code: 301');
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
else
{
header('Strict-Transport-Security: max-age=500');
}
@efarem
efarem / is_blog
Created October 1, 2013 15:45
WordPress function to tell if you're on a blog page, current page is a blog page
<?php
/**
* Are we on a blog page?
*
* @return bool
**/
function is_blog()
{
return (is_post_type_archive('post') || is_author() || is_category() || is_home() || is_singular('post') || is_tag()) ? true : false ;