Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2011 19:25
Show Gist options
  • Save khrome/1498504 to your computer and use it in GitHub Desktop.
Save khrome/1498504 to your computer and use it in GitHub Desktop.
The Soup Talker
$soups = array("Avgolemono ", "Borscht ", "Caldo verde ", "Fasolada ",
"Goulash soup", "Islensk Kjotsupa ", "Kimchi jjigae ", "Lentil soup",
"Menudo", "Mulligan Stew", "Philadelphia Pepper Pot ", "Pho",
"Sundubu jjigae ", "Snert ", "Solyanka ", "Tomato soup", "Cold borscht",
"Dashi soup ", "Okroshka", "Sour cherry soup", "Vichyssois", "Ginataan",
"Naengmyeon ", "Fruktsuppe", "Cioppino ", "Fanesca ", "Lan Sikik ",
"Sliced fish soup", "Ukha or Lohikeitto", "Bird's nest soup", "Fuhn",
"Mian", "Ramen", "Saimin", "French onion soup", "Tinola", "Crab bisque",
"Chestnut bisque", "Cream of Crab Soup", "Clam chowder", "Chupe",
"Maryland Crab Soup ", "Brown Veal", "Fumet", "White Veal",
"Cream of mushroom soup", "Cream of celery soup", "Cream of potato soup",
"Wine soup", "Chowder", "Asparagus Soup with Hazelnut Butter",
"Avgolemono", "Beef Barley Soup", "Beer Cheese Soup",
"Broccoli Cheddar Soup", "Brown Veal Stock", "Carrot Vichyssoise",
"Chervil Butter", "Chicken Noodle Soup", "Chicken Stock",
"Chicken and Andouille Gumbo", "Chilled Avocado Soup",
"Chilled Beet Borscht", "Chilled Brie Soup",
"Chilled Cucumber Buttermilk Soup", "Chilled Red Pepper Soup",
"Chilled Yellow Dal Soup", "Chipotle Cream", "Cilantro Cream",
"Cinnamon Chantilly", "Cream of Broccoli Soup",
"Cream of Mushroom Soup", "Cream of Tomato Soup", "Croutes",
"Curry Chicken and Pineapple Soup", "Danish Split Pea Soup",
"Dill Wafers", "Duck Consomme", "Duck Stock", "Fish Chowder",
"Fish Stock #3", "French Onion Soup", "Frozen Coconut Yogurt",
"Gazpacho - Traditional Style", "Gazpacho - Yucatan Style",
"Gorgonzola Soup with Bacon", "Gougere", "Hazelnut Butter",
"Hot Borscht", "Hot and Sour Duck Consomme", "Jamaican Calalou Soup",
"Lamb and Lentil Soup", "Louisiana Oyster Stew", "Manhattan Clam Chowder",
"Minestrone", "Navy Bean Soup", "New England Clam Chowder",
"Parmesan Twists", "Pasta e Fagioli", "Peanut Soup", "Roasted Corn Bisque",
"Rouille", "Scallop and Corn Chowder with Dill",
"Shrimp Bisque with Dill Wafers", "Shrimp Stock", "Shrimp and Oyster Gumbo",
"Smoked Salmon Chowder", "Sopa de Tortilla", "Soupe de Poisson",
"Spanish Almond Soup", "Sparkling Peach Soup", "St. Louis Chili",
"Steak Soup", "Summer Fruit Gazpacho with Coconut Yogurt",
"Swedish Potato Soup", "Tomato Basil Soup", "Tomato Lime Bisque",
"Tortellini in Wild Mushroom Broth", "Vegetarian Black Bean Soup",
"Vichyssoise", "Vietnamese Hot and Sour Shrimp Soup",
"Wild Mushroom Soup with Chervil Butter", "Wild Rice Soup",
"Winter Squash Soup with Toasted Pecans", "Won Ton Soup"
$starting_sentences = array(
"You know, I really love soup:",
"Soups are really an excellent food...",
"I love hot soup on a cold day!",
"Soup is *so* delicious!"
$first_soup = array(
"There's [soup]",
"I like [soup]",
"I've tried [soup]",
"I once ate [soup]",
"I tend to enjoy [soup]"
$middle_sentences = array(
"[soup] is really good",
"[soup] has a great texture",
"[soup] is so tangy",
"[soup] really pleases the palate",
"[soup] is a traditional dish",
"[soup] is packed with flavor",
"constrasting strongly against [soup]"
$conjunctions = array(
", although",
", however",
"even though",
"oddly enough, though",
function substitute($template, $values, $cleanUnmatched=false){
$template = file_get_contents($template);
foreach($values as $key=>$value){
$template = preg_replace('~\['.$key.'\]~', '{'.$key.'}', $template);
foreach($values as $key=>$value){
$template = preg_replace('~{'.$key.'}~', $value, $template);
if($cleanUnmatched) $template = preg_replace('~\[.*?\]~', '', $template);
return $template;
function get_random($array, $soup='Chicken Noodle'){
$value = $array[rand(0, count($array)-1)];
return substitute($value, array('soup'=>strtolower($soup)));
if(!isset($_REQUEST['count'])){ //dump the containing page
function SoupTalker(){
this.count = 0;
SoupTalker.prototype.getXMLHTTPRequest = function(){
var xRequest=null;
if (window.XMLHttpRequest) xRequest = new XMLHttpRequest();
if (typeof ActiveXObject != "undefined"){
xRequest = new ActiveXObject("Microsoft.XMLHTTP");
object = this;
xRequest.onreadystatechange = function(){
if (this.readyState == 4){
var node = document.getElementById('text');
node.innerHTML = node.innerHTML + this.responseText;
return xRequest;
SoupTalker.prototype.talkAboutSoup = function(){
if (
typeof this.request == "undefined"||
typeof ActiveXObject != "undefined"
this.request = this.getXMLHTTPRequest(); //IE bug
"Content-Type", "application/x-www-form-urlencoded"
var soupTalker = new SoupTalker();
<body onload="soupTalker.talkAboutSoup();">
<div id="text"></div>
$soup = $soups[rand(0, count($soups)-1)];
if($_REQUEST['count'] == 0){ //dump the first sentence
if($_REQUEST['count'] > 0){ // dump other sentences
$count = $_REQUEST['count'];
$last_pass_ended = ( ($count-1)% 3 == 0) && ( ($count-1) % 2 == 0);
$this_pass_ends = ($count % 3 == 0) && ($count % 2 == 0);
' '.get_random($conjunctions).' '.
get_random($middle_sentences, $soup).'.'
echo(' '.get_random($first_soup, $soup));
' '.get_random($conjunctions).' '.
get_random($middle_sentences, $soup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment