Skip to content

Instantly share code, notes, and snippets.

@tylerflint
tylerflint / gist:1302094
Created October 20, 2011 19:37
apache redirect www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
@tylerflint
tylerflint / gist:1289742
Created October 15, 2011 15:51
php fibbonaci
function fib( $n ) {
// PRE: $n >= 0
if( $n < 2 ) {
return $n;
} else {
return fib( $n-1 ) + fib( $n-2 );
}
}
for( $i=0; $i<5000; $i++ ) {
@tylerflint
tylerflint / gist:1285319
Created October 13, 2011 19:51
gross output
Parsing instructions from Boxfile
Executing deploy
> Building deployable template
> Init git submodules
> Init git submodules --recursive
> Init writable directories on storage cluster
> Mounting writable directories
> Finalizing image
> Building php web component environment
> Building php web component network
@tylerflint
tylerflint / gist:1270560
Created October 7, 2011 15:37
baker_http_supervisor
-module(baker_http_supervisor).
-include("baker.hrl").
-export([start_link/0]).
start_link() ->
WorkerCount =
case os:getenv("HTTP_LISTENER_COUNT") of
false -> ?DEFAULT_HTTP_LISTENER_COUNT;
@tylerflint
tylerflint / gist:1217271
Created September 14, 2011 18:00
erlang function to add a shard with simple error handling
add_shard(Master, Slave) ->
ErrorMsg = "unable to add shard",
case ?NEW_SHARD_KEY of
{error, _Msg} ->
{error, ErrorMsg};
ShardId ->
case ?SHARD_KEY_FOR_MEMBERS(ShardId) of
{error, _Msg} ->
{error, ErrorMsg};
ShardKey ->
@tylerflint
tylerflint / gist:1217217
Created September 14, 2011 17:42
erlang function to add a shard
add_shard(Master, Slave) ->
ShardId = ?NEW_SHARD_KEY,
ShardKey = ?SHARD_KEY_FOR_MEMBERS(ShardId),
Members = ?ENCODE_MASTER_SLAVE(Master,Slave),
?REDIS(["SET",ShardKey,Members]),
{ok,ShardId}.
@tylerflint
tylerflint / gist:1199151
Created September 6, 2011 22:12
eunit ets functionality
-module(baker_shard_tests).
-include_lib("eunit/include/eunit.hrl").
-include_lib("baker.hrl").
baker_shard_test_() ->
{
setup,
fun() ->
ets:new(services, [named_table, set, public, {keypos, 2}]),
@tylerflint
tylerflint / php.conf
Created August 31, 2011 23:16
web1 apache php.conf
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
#
@tylerflint
tylerflint / httpd.conf
Created August 31, 2011 23:12
web1 httpd.conf
#############################################
# Base Apache Server Configuration #
#############################################
User apache
Group apache
ServerAdmin root@localhost
ServerTokens OS
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 300
@tylerflint
tylerflint / gist:1154813
Created August 18, 2011 18:46
sample boxfile w/ component names
web:
type: php
db:
type: mysql
web:
type: php
name: api