Skip to content

Instantly share code, notes, and snippets.

Avatar

Frank Martin efarem

  • Improbable
  • London, UK
View GitHub Profile
@efarem
efarem / plesk-reload-domain
Last active Aug 29, 2015
Plesk - Reload domain/vhost config
View plesk-reload-domain
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example-domain.com
@efarem
efarem / mysql-random-number
Created Jul 17, 2014
MySQL Random Number
View mysql-random-number
(FLOOR( 100 + RAND( ) * 1000 ))
View ssl-generate-csr
sudo openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
View 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 Jul 24, 2015
Git Auto Deploy init script for CentOS 6
View gitautodeploy.sh
#!/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 Dec 15, 2015
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.
View WordPress Loop Shortcode
<?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 Dec 21, 2015
Convert a timestamp into a relative string e.g. 2 Hours ago
View Elapsed time string
<?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 Sep 25, 2013
Quick and dirty was to resize an image canvas, center original and fill white space
View Resize Image Canvas
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
View 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 Oct 1, 2013
WordPress function to tell if you're on a blog page, current page is a blog page
View is_blog
<?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 ;
You can’t perform that action at this time.