Skip to content

Instantly share code, notes, and snippets.

@Servana
Servana / split_string.php
Created July 13, 2011 11:08
Split string by spaces exception on spaces in braces and quotes
$str = '3021e69d9d2569db27ce7b74ccaa98496007de09a1f4b94e45f48203d8727ac6 test.com [05/Jul/2011:07:28:57 +0000] 126.97.98.19 3021e69d9d2569db27ce7b74ccaa98496007de09a1f4b94e45f48203d8727ac6 70706DF22A809F33 REST.GET.OBJECT 1as21/foldera/file.png "GET //folder/test.php?AWSAccessKeyId=45dsgrg$5f&Expires=1310388787&Signature=Yehn847BhdsaiuernYmjne= HTTP/1.1" 206 - 47972352 209316737 54194091 7 "http://test.info/?url=http://ns.in/54325" "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" -';
$regex = <<<REGEX
/"((?:[^"]*|)++)\"
|\[((?:[^\]]*|)++)\]
|[\s]
/x
REGEX;
$out = preg_split($regex,$str, 0, PREG_SPLIT_DELIM_CAPTURE );
<?php
/**
* A CakePHP datasource for the mongoDB (http://www.mongodb.org/) document-oriented database.
*
* This datasource uses Pecl Mongo (http://php.net/mongo)
* and is thus dependent on PHP 5.0 and greater.
*
* Original implementation by ichikaway(Yasushi Ichikawa) http://github.com/ichikaway/
*
* Reference:
@Servana
Servana / jsongrep.rb
Created February 25, 2011 18:42
STDIN JSON parser
require 'rubygems'
require 'fcntl'
require 'json'
block = ""
# Set $stdin to be non-blocking
$stdin.fcntl(Fcntl::F_SETFL,Fcntl::O_NONBLOCK)
begin
$stdin.each_line { |line|
block << line
}
@Servana
Servana / gist:843787
Created February 25, 2011 13:40
BASH export arch
if [ $(uname -m) = 'x86_64' ]; then
export arch=x86_64
else
export arch=i386
fi
@Servana
Servana / Lithium SkyScript
Created November 5, 2010 12:11
Use this script to bootstrap your Lithium project.
#!/bin/bash
#OLOH SOURCE=http://www.ohloh.net/p/lithium/download?filename=lithium-0.9.5.tar.gz
SOURCE=http://d10xg45o6p6dbl.cloudfront.net/projects/l/lithium/lithium-0.9.5.tar.gz
NAME=lithium-0.9.5
DB_NAME=lithium_test
DB_USER=lithium_user
VPATH=/var/www/example.com
#DB_PWD=`cat /opt/skystack/bootstrapper/etc/.mysql.lithium_user.shadow`
@Servana
Servana / gist:663986
Created November 5, 2010 11:08
Install mod_pagespeed on Ubuntu with Skystack
#!/bin/bash
arch=$(uname -m)
if [ $arch = 'x86_64' ]; then
SOURCE=https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb
NAME=mod-pagespeed-beta_current_amd64.deb
else if [ $arch = 'i686' ]; then
@Servana
Servana / wordpress_skyscript
Created October 21, 2010 18:53
Installs Wordpress
#!/bin/bash
# == Synopsis
# This is a SkyScript launched by Skystack, it was adapted from the StackScript used at Linode.
#
# == Website
# http://skystack.com
# == Author
# Tass Skoudros
#
# == Parameters