Skip to content

Instantly share code, notes, and snippets.

@lorenzoaiello
lorenzoaiello / xml2array
Created December 30, 2013 22:31
php xml2array
<?php
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
<?php
/**
USAGE
php file.php CONTAINERNAME
NOTE
By Default Softlayer has a limit of 100 file return. To change it
<?php
/**
USAGE
php file.php containers list
php file.php containers create CONTAINERNAME
php file.php containers delete CONTAINERNAME
php file.php cdn enable CONTAINERNAME
$array = json_decode(json_encode((array) simplexml_load_string($xml_string)),1);
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"elasticache:*",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcs",
"ec2:DescribeAccountAttributes",
"ec2:DescribeSecurityGroups",
@lorenzoaiello
lorenzoaiello / Dockerfile
Created October 14, 2016 13:19
LAMP Stack (PHP 5.6) with Xdebug for PHPStorm
FROM php:5.6-apache
RUN a2enmod rewrite vhost_alias
# install the PHP extensions we need
RUN apt-get update
RUN apt-get install -y libpng12-dev libjpeg-dev libpq-dev imagemagick libxml2-dev libldap2-dev unzip libicu-dev libmcrypt-dev libfreetype6-dev
RUN rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr --with-freetype-dir=/usr --enable-gd-native-ttf
@lorenzoaiello
lorenzoaiello / plex.conf
Created December 9, 2018 23:54
Plex NGINX Sample Configuration
#Must be set in the global scope see: https://forum.nginx.org/read.php?2,152294,152294
#Why this is important especially with Plex as it makes a lot of requests http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html / https://www.peterbe.com/plog/ssl_session_cache-ab
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#Upstream to Plex
upstream plex_backend {
server 127.0.0.1:32400;
keepalive 32;
}
$ cat provider.tf
provider "aws" {
region = "us-west-2"
}
$ cat dns.tf
resource "aws_route53_zone" "main" {
name = "dc34vo.com"
tags = {
# apply from https://gist.github.com/lorenzoaiello/bcb5e57d3f1da2bdc43c2c808565f6e9
$ docker run -it -v $(pwd):/workspace -v $HOME/.aws:/home/.aws -e "HOME=/home" -w /workspace hashicorp/terraform:light apply
aws_route53_zone.main: Refreshing state... [id=Z1XB1I9YEXBEWV]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
function fixJSON( $j ){
$j = trim( $j );
$j = ltrim( $j, '(' );
$j = rtrim( $j, ')' );
$a = preg_split('#(?<!\\\\)\"#', $j );
for( $i=0; $i < count( $a ); $i+=2 ){
$s = $a[$i];
$s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s );
$a[$i] = $s;
}