Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Script from http://www.cyberciti.biz/tips/howto-linux-unix-write-to-syslog.html
result=$(echo -e "ping\n\r" | nc localhost 6082|grep PONG|wc -l);
if [ "${result}" -lt "1" ];
then
/etc/init.d/varnish stop;
sleep 5;
@andybeak
andybeak / wordpress_update.sql
Created May 5, 2015 15:02
Update Wordpress posts when moving domains (e.g.: deploying)
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE instr(meta_value, 'http://www.olddomain.com') > 0;
UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE instr(guid, 'http://www.olddomain.com') > 0;
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE instr(post_content, 'http://www.olddomain.com') > 0;
@andybeak
andybeak / nginx_laravel.conf
Last active March 17, 2016 12:33
Laravel Nginx config
# Read
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart#
# http://tautt.com/best-nginx-configuration-for-security/
#
# Generate your key with: openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# Generate certificate: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
server_tokens off;
@andybeak
andybeak / get_post_from_body.php
Created May 21, 2015 12:49
Get post from body in Laravel
/**
* getPostFromBody
*
* Returns an array obtained from reading and decoding the post body
* Optionally supply an array of fields that are required to be present
*
* @version 1.0.0
* @author Andy Beak
* @since 1.0.0
@andybeak
andybeak / memcached_large_values.php
Last active October 21, 2020 16:20
Storing large values in Memcached
/**
* store
*
* Stores a large array into memcache as a number of key=>values in order to overcome the limitation placed
* on memcache. You'll need to use discretion when choosing to do this.
*
* The principle is to split the data into several smaller chunks. The original key is used to store an
* index array which provides retrieveBigCacheValue() with information on where to look for the data.
*
* See retrieveBigCacheValue for the inverse
@andybeak
andybeak / s3 bucket policy
Last active August 29, 2015 14:21
Amazon S3 allow global access to read bucket
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@andybeak
andybeak / cli-config.php
Created June 3, 2015 12:56
Client config for Doctrine
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = ['/home/andy/development/metagrated/poc/restengine/app/Lib/Domain/Mappings'];
require_once __DIR__.'/../../../../bootstrap/autoload.php';
$paths = [ __DIR__ ];
@andybeak
andybeak / dummy3_reverse_proxy.conf
Last active January 9, 2024 15:51
Nginx reverse proxy with SSL config example
# Read
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart#
# http://tautt.com/best-nginx-configuration-for-security/
# https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
#
# Generate your key with: openssl dhparam -out /etc/nginx/ssl/dhparam.pem 4096
# Generate certificate: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
server {
@andybeak
andybeak / LoggingMiddleware.php
Last active August 29, 2015 14:26
Laravel request logging middleware
<?php namespace App\Http\Middleware;
use Auth;
use Closure;
use Config;
use Log;
class LoggingMiddleware {
/**
@andybeak
andybeak / xml2array.php
Created August 12, 2015 08:31
xml2array() will convert the given XML text to an array in the XML structure.
<?php
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
* $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
* Return: The parsed XML in an array form. Use print_r() to see the resulting array structure.
* Examples: $array = xml2array(file_get_contents('feed.xml'));
* $array = xml2array(file_get_contents('feed.xml', 1, 'attribute'));