Skip to content

Instantly share code, notes, and snippets.

@grayside
Last active August 29, 2015 14:22
Show Gist options
  • Save grayside/410781322930d3333274 to your computer and use it in GitHub Desktop.
Save grayside/410781322930d3333274 to your computer and use it in GitHub Desktop.
A few functions for fun Phase2 content generation.
<?php
/**
* Fun little set of text generation functions originally created for some custom data volume generation.
*/
/**
* Generate an simple text address.
*
* - 43 Fable Lane, San Francisco, CA 39508
* - 219 Marketing Canyon, New York, NY 11672
* - 695 Client Services Way, San Francisco, CA 35635
* - 76 Bad Erik Gulch, Portland, OR 33381
*
* @return string
*/
function p2_generate_address() {
$places = array(
'city' => array(
'Alexandria, VA',
'San Francisco, CA',
'Portland, OR',
'New York, NY',
),
'street' => array(
'Analyst',
'Project Manager',
'Account Director',
'Developer',
'Sales',
'Client Services',
'Capabilities',
'Marketing',
'Bad Erik',
'Remobot',
'Atrium',
'Fable',
),
'type' => array(
'Road',
'Way',
'Avenue',
'Circle',
'Highway',
'Trail',
'Canyon',
'Street',
'Gulch',
'Court',
'Lane',
),
);
$city = $places['city'][rand(0, count($places['city']) - 1)];
$street = $places['street'][rand(0, count($places['street']) - 1)];
$type = $places['type'][rand(0, count($places['type']) - 1)];
return rand(1, 1500) . ' ' . $street . ' ' . $type . ', ' . $city . ' ' . rand(10000, 99999);
}
/**
* Generate a line of disease/condition research.
*
* - Terminal Respiratory Lesion Formation caused by Unknown Condition
* - Intense Cardiac Paralysis caused by Cellular Degeneration
* - Surprise Cardiac Discoloration caused by Infection
*
* @return string
*/
function p2_generate_disease_research() {
$content = array(
'modifier' => array(
'Extreme',
'Emergent',
'Mild',
'Surprise',
'Intense',
'Terminal',
),
'location' => array(
'Ocular',
'Dermal',
'Respiratory',
'Cardiac',
'Endocrine',
),
'symptom' => array(
'Lesion Formation',
'Paralysis',
'Hyper-activity',
'Degradation',
'Discoloration',
),
'problem' => array(
'caused by Virus',
'caused by Infection',
'caused by Unknown Condition',
'caused by Cellular Degeneration',
)
);
$name = array();
foreach ($content as $item) {
$key = rand(0, count($item) - 1);
$name[] = $item[$key];
}
return implode(' ', $name);
}
/**
* Generate a quick-and-dirty but human-readable unique identifier.
*
* - P2-2015-0601-42
* - P2-2015-0601-43
* - P2-2015-0601-44
* - P2-2015-0601-45
*
* @return string
*/
function p2_generate_identifier() {
static $counter;
if (!isset($counter)) {
$counter = 41;
}
$counter++;
return 'P2-' . date('Y') . '-' . date('md') . '-' . $counter;
}
/**
* Generate a unique medical organization name.
*
* - NYC - Sunset Medical Research (#003)
* - NYC - Morrison Bioservices (#002)
* - SFO - Hawthorne Agency (#003)
* - PDQ - Phase2 Office - Pelican Group (#001)
*
* @return string
*/
function p2_generate_org_name_medical() {
static $counter;
if (!isset($counter)) {
$counter = 0;
}
$names = array(
'main' => array(
'SFO',
'PDX',
'NYC',
'DC',
),
'room' => array(
'Empire',
'Crescent',
'Pelican',
'Columbian',
'Sunset',
'Diplomat',
'Pool Table',
'Bronx',
'Brooklyn',
'Manhattan',
'Staten Island',
'Hawthorne',
'Morrison',
'St. John',
'Main Conference',
),
'type' => array(
'Agency',
'Lab',
'Hospital',
'Institute',
'University',
'Laboratory',
'College of Medicine',
'Pharmaceuticals',
'Center',
'Technology',
'Corporation',
'Clinic',
'Network',
'Council',
'Bioservices',
'Associates',
'School of Medicine',
'Health System',
'Department of Public Health',
'Project',
'Medical Research',
'Systems',
'Group',
),
);
$counter++;
$main = $names['main'][rand(0, count($names['main']) - 1)];
$room = $names['room'][rand(0, count($names['room']) - 1)];
$type = $names['type'][rand(0, count($names['type']) - 1)];
return $main . ' - ' . $room . ' ' . $type . ' (#' . str_pad($counter, 3, '0', STR_PAD_LEFT) . ')';
}
/**
* Generate body text for any node.
*
* @return string
*
* @see http://stackoverflow.com/a/20633400
*/
function p2_generate_body_text() {
static $reuse;
static $content;
if (!isset($reuse)) {
$reuse = 0;
}
$reuse++;
if (!isset($content) || $reuse > 5) {
$content = file_get_contents('http://loripsum.net/api/decorate/ol/bq/headers/prude');
$reuse = 0;
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment