ITP Glitch: Editing Civilization Save Files

So far in my Glitch class, we’ve experimented with databending and transcoding images, audio, and video, using a variety of different techniques, but mainly trying to de-abstract how software handles file formats so that we can edit the actual bytes of files to alter the expected output — e.g. shifting the bytes by one in order to cause the image’s dimensions to warp or change color.

Here is our homework assignment for this week:

  • Find and write about a file format / specification. For example, ISO/IEC 10918 (JPEG),  ISO/IEC 1172-3 (MP3), ISO/IEC 14496-3 (AAC) GIF89a, ZIP, MIDI, etc. See List of Codecs for more. You should provide an analysis of any features of the format that may be interesting to glitch artists working with it, or provide a history that explains the various biases that are reified by the format, and the advantages and disadvantages of those biases in actual use.
  • Create your own file format / specification. A complete specification will allow someone else to both encode media into an intermediate representation, and then decode it back to an approximation (lossy) or exact replica (lossless) of the original. As far as “types” of media: audio, images and video are popular; dance, haptic sensations, taste, legal requirements, written language, etc. all count as media. You must run at least one piece of media through your encoding / decoding process, but you may do this by hand — it does not need to be executed by a computer.

 

The second assignment seems pretty difficult at this point.  I looked into making “extrafiles” and found this OS X app, extrafile, which introduces a series of unique file formats such as one called “Block Ascii” which is only 1bit color:

So you can save a file into one of those formats using the app.

Coming up with my own file format specification would take a while, and I’m not sure how I would transpose data through media processing without losing everything in a jumble of noise.  However, I did do an assignment last semester dealing with genetic inheritance which involved passing a database record of peoples’ stats (1-10 sliding scales of peoples’ stats, like creativity or strength or determination) into a Wolfram cellular automata algorithm, via a node.js server passing JSON, so that the output looked like this:

But that’s not really a file format per se.  It might be interesting to be able to encode someone’s physical and life characteristics into a photo file of them, so that in, say, 50 years, someone could open up the photo image and see what the person’s biometrics and other statistics were at the time the photo was taken.  Hmm, possible idea!

So in terms of describing another existing file format, it made me think about when I first played Civilization as a kid.  Back then, there was no real internet to speak of, and I was using Prodigy* via a dialup modem so that I could (slowly) browse the Civ forums there.  Some people who knew their shit were hex editing their save files so that they could test the limits of the game (e.g. I think cities couldn’t get any higher than 99 population or something, because of memory issues from going to 3 digits) and cheat to win.  That stuff was over my head so I never played with it, but I remember it to my day as a way that some people were able to change settings for games, registration verification, etc.

Anyway, even though it’s hard to look up info on the first couple Civ games (because most Google results now are for Civ 4 and 5), I did find pages with a pretty good write-up of the Civilization 2 savefile format and of the Civilization 3 BIC file format.

On data types:

"...there are three data types: The null-terminated string is a variable length type for text. It always ends with a byte value of zero, meaning a string of 9 bytes only has place for at most 8 characters. The signedshort integer is a numeric data type taking up 2 bytes. It can take values from -32768 to +32767. The unsigned byteshould be self-explanatory. It takes values from 0 to 255."

For handling states of engineer units:

An engineer in CIV II generates 2 points per turn. A settler generates 1 point. These numbers remain constant when the “Base time for engineers to transform terrain (x2)” is changed in the Rules file. With the “Base time…….” set to 20 (vanilla CIV II), twenty points are needed to transform Grassland to Hills.
Consequently, if the Grassland to Hills transformation command is entered on turn 1, a single Engineer will complete the transformation on turn 10. Its byte 15 is changed to 2 on turn 1, is incremented by 2 on each of the following 9 turns, and reaches 20 on turn 10.
If 2 engineers (E1 and E2) are assigned to the task, their byte 15’s change as follows:
UNIT -- E1 E2
 TURN 1 04 00
 TURN 2 08 00
 TURN 3 12 00
 TURN 4 16 00
 TURN 5 00 00 Task completed

Some culture variables in the savefile:

CULT SECTION (Culture)
  4	char		"CULT"
  4	long		??? (33)
  4	long		??? (5)
  4	long		number of culture opinions
  For each culture opinion:
    4	long		length of culture data (88)
    64	string		culture opinion name
    4	long		chance of successful propaganda
    4	long		culture ratio percentage (3:1 = 300, 3:4 = 75)
    4	long		culture ratio denominator (e.g. the 1 in 3:1)
    4	long		culture ratio numerator (e.g. the 3 in 3:1)
    4	long		initial resistance chance
    4	long		continued resistance chance

It might be interesting, given the exact formats and memory sizes of the variables, to make a random savefile generator, and then open it up within the game to see what you get.  Would the game be playable, or does it require a certain logic within the savefile where, say, you couldn’t have some variables if other variables were of a certain value?

Tool-assisted speedruns have become big as a result of savefiles.  Basically, if you can save the exact state of a game in a file, you can restore from that point without limit.  I played through Zelda: Ocarina of Time via an emulator on my computer back when I was in college, so it was easy to quickly restore at difficult points in the game.  Apparently all this is called save scumming.  This is how you get those weird videos every once in a while that show some Japanese player doing a perfect speedrun through a custom-made annoying-as-holy-fuck Mario Brothers-family game, e.g.:

That video introduces some followup questions.  Why do people subject themselves to such torture?  How did that person not kill everyone in his building?  Is there a good reason he never uploaded past part 3 since 2007?  Did he go on a murderous rampage?

In terms of savefile formats, I know that later Civ games used XML for settings files and maybe savefile formats?  What if you could translate the format of one game’s savefiles to that of another, so you could play your character in a different world?  More importantly, what if there were a standardized player file format that you could re-use between different games through a secure authenticator? (say, you used it on Steam)  This has been done with some games and some networks (such as Mass Effect on Xbox Live), but how about an open player file format?  And how about if it included your real-world Galapag.us characteristics and history?

Understanding Genomes: Extracting DNA from Strawberries

This semester I’m taking Yasser Ansari’s Understanding Genomes class.  Professor Ansari is a co-founder of Project Noah, which lets mobile users become urban citizen scientists, taking photos of flora and fauna to post online for identification, unlocking badges, helping kids learn in class, etc.

We’re already reading the biopunk manifesto and James D. Watson’s book The Double Helix, about his and Crick’s Nobel-winning discovery of DNA’s helical pattern.  We’re also getting to use Lore, which has emerged as a more ajaxy user-friendly, minimalistic-looking alternative to Blackboard and its competitors.

Last week we made online dating profiles using different model organisms to learn about why they’re used, how many base pairs they have, etc.  My model organism was the fruit fly (Drosophila melanogaster); here’s the Okcupid profile.

So this week, we had to use a recipe for extracting DNA (nucleic acid extraction, includes RNA as well as DNA) from strawberries.  Here are the instructions:

DNA Extraction at Home

In this exercise, you will extract DNA from strawberries. Below is a list of materials along with a protocol courtesy of Genspace. Document the process and pay attention to the procedure so we can discuss your experience in class. Feel free to work in groups and share materials. Read through the materials and protocol before you start the experiment. Contact me if you have any questions or concerns.

Materials:

  • Strawberries (at least 2 juicy ones)
  • Quarter teaspoon of Table salt/NaCl (don’t use too much of this)
  • A teaspoon of dishwashing detergent (any brand will do)
  • Meat Tenderizer (any brand should work)
  • Half a glass of water
  • Ziplock baggie (1 quart volume)
  • A disposable coffee filter
  • A plastic funnel (to hold the coffee filter in place. Feel free to ditch it if you have a better method)
  • Rubbing alcohol (91% isopropanol works better than the 70% strength)
  • Ice or a fridge to cool the rubbing alcohol prior to using
  • A tall glass (Note: don’t drink this stuff.)
  • A thin wooden stick or skewer (to pull out the DNA)

Protocol:

  • Step 1: Place the strawberries into a ziplock baggie.
  • Step 2: Add the detergent, meat tenderizer and salt (again, don’t use too much salt).
  • Step 3: Seal the baggie and “mechanically disrupt the cells”. This “science speak” for you to start squishing the strawberries in the baggie with your hands. Squish and mix them really well with all of the ingredients. Knead the bag for about 5 minutes until you have the consistency of a smoothie. (Note: again, don’t drink this crap)
  • Step 4: Open the baggie and add a little bit of water. Shake it up a little.
  • Step 5: Place your filter in the funnel and place this in the glass. Now pour the contents of the baggie (the strawberry mixture) into the filter.
  • Step 6: Let the contents drip through the filter into the glass. It should look milky pink. Be patient! If the filter is working too slowly, you can gently squeeze it, but not too hard or it may break.
  • Step 7: Holding the glass at an angle, very slowly pour the chilled rubbing alcohol down the side into the strawberry mixture. You want to pour it slow enough so that a layer of the clear alcohol forms on top of the pink layer underneath, since the alcohol is less dense than the water layer containing the strawberries. If you pour too quickly you won’t see this layer form, so remember to do it slowly. Pour enough alcohol so that you have at least a 2 inch layer on top.
  • Step 8. Now set your glass down. You should start to see a wispy white layer start to form between the bottom pink layer and the clear alcohol on top (like the photo shown in class). It should take about a minute or more to develop. It will start to look like a small ball of cotton. Sometimes it looks like many small pieces of cotton. Give it some more time and it will gently rise to the surface. This is the strawberry’s DNA starting to precipitate!
  • Step 9: Using your thin wooden stick, you can now fish out the DNA. It will be rather “stringy” since DNA molecules form long chains. These types of molecules are known as “polymers”.

Some questions to think about:

Why use strawberries?

Strawberries have far more DNA than other readily-available materials, and their cell membranes are delicate, which means they’re easy to remove for access to the DNA. [possible citation]

What’s the table salt for?

Salt helps the DNA precipitate when the rubbing alcohol is added. It ensures that proteins in the cell are not released from the rest of the solution with the DNA. [citation #1, #2]

What about the detergent?

The detergent breaks apart the cell membranes in the strawberries. [citation #1#2]

Meat tenderizer, what’s that for?

Meat tenderizer contains bromelain and papein, which break apart proteins, allowing us to get at the DNA. [citation #1#2]

And the rubbing alcohol?

DNA is insoluble in alcohol, so it will precipitate for us to see with the naked eye, and for us to extract it in clumps. [citation #1#2]

Documentation

Phil, who dropped the class, wanted to do this homework with me anyway (we’re such a good pair) so we worked on it Monday night.

Me, as Phil tests the camera

Prepping the strawberries with salt, meat tenderizer, and detergent.

Mashing up the materials.

The materials turn dark purplish

Phil crushing the materials like a pro

Pouring the contents into the filter

Filtering the materials through a coffee filter plus funnel

Phil macgyvers together a pretty awesome pipette technique using a straw to drop in rubbing alcohol slowly

Rubbing alcohol separating the DNA

Separated DNA

DNA tendrils

Fall 2012 Classes

Summer’s just starting but my schedule for next semester is confirmed.  You can see how these classes very specifically support my plans for researching and building out Galapag.us.

Basic Analog Circuits – Eric Rosenthal (Syllabus)

Today’s mostly digital world also requires a basic knowledge of analog circuits. In this course students learn about the basic principles of analog circuits design and operation. Students learn about discrete components such as resistors, capacitors, diodes and transistors as well as integrated components such as operational amplifiers. In addition, students become familiar with the operation of basic electronic test equipment such as digital multimeters, oscilloscopes, function generators. The instructor lectures on, and demonstrates, basic analog concepts so that students can form a basic rule of thumb understanding of analog circuits, concepts and components. In the lab, students can integrate analog solutions into their project work.

Data Without Borders: Data Science in the Service of Humanity – Jake Porway

We are living in the dawn of the big data era, a time in which the vast digitization of our world has created incalculable amounts of information that is now being used to drive our every decision, from what movie we decide to watch this weekend to how we navigate the globe next year. Though data can be immensely transformative, much of the efforts in data science are still focused on first-world gains, such as optimizing ad networks or recommending restaurants. As designers, developers, and scientists, it is not only incumbent upon us to understand how to analyze, understand, and tell stories with data, but also to think about its use in meaningful and socially conscious ways. This class will train students in the basic tools and trade of data science through exploration of a socially conscious data project. Students will learn to scrape, merge, and clean data with Python, perform statistical analysis and use machine learning algorithms in R, and visualize and explore data with R and D3. In addition to training students as junior data scientists, we will discuss the important social issues around data provenance, privacy, and the responsibility that comes with making claims from data.

Glitch – Kyle McDonald / Jeremiah Johnson

“…our control of technology is an illusion, and … digital tools [are] only as perfect, precise, and efficient as the humans who build them.” – Kim Cascone

“If it works, it’s obsolete.” – Marshall McLuhan

How do the tools and media we use affect the work we create? What biases are embedded in the software and data formats we take for granted? In this class we will reverse, invert, and deconstruct prescribed workflows. We’ll empower ourselves by digging into the intricacies of different formats. We’ll explore the limitations of our tools, and exploit the strange behavior at those limits. We’ll also spend a significant amount of time understand the history and theory behind glitch and noise, through enlightening readings, discussion, and exercises.

While this class will cover a variety of low level, technical topics, there are no prerequisites, and there is no single tool, environment, or language that we will focus on. We will instead aim for a more process-oriented approach, and students will be challenged at every level of technical expertise.

This two-credit will meet the first seven weeks of the semester.

PAC I – Evan Korth (Syllabus)

An accelerated introduction to the fundamental concepts of computer science for students who lack a formal background in the field. Topics include algorithm design and program development; data types; control structures; subroutines and parameter passing; recursion; data structures; searching and sorting; dynamic storage allocation; abstract data types, such as stacks, queues, lists, and tree structures; and an introduction to the principles of object-oriented programming. The primary programming language used in the course will be Java.

Understanding Genomes: An Introduction to Biohacking – Yasser Ansari (Syllabus)

This class will expose the tools and fundamental principles underlying the emerging biohacking and DIY Bio movements, providing students with practical knowledge and awareness of specific techniques. Beginning with the discovery of the three-dimensional structure of DNA and building up to genes, genomes, and genome sequencing, we will uncover the biological mechanisms at play and the specialized equipment and protocols being used in today’s laboratories, studios, and garages. Along the way, we will study scientific breakthroughs like the generation of the first recombinant DNA molecules, deconstruct infamous bioart pieces like “Alba” the bioluminescent bunny, and examine interesting amateur projects like homebrewed insulin. The first phase of the class will be focused on introducing core concepts through investigation and discussion. Continuing on, the second phase of the class will allow students to apply what they’ve learned through the design and development of their own projects. Class assignments will range from individual exercises and readings to group presentations and projects. Guest lecturers and visits to local laboratories will help provide additional context and insight during the semester. The ultimate goal of this class is to equip students with enough knowledge and skill to explore biologically driven concepts and projects with confidence. Although topics from molecular biology will be covered, no previous knowledge is required.

Redial Final Project: Hermes Ordering System

In my Redial class, we learned about the dark arts of telephony in an age of digital, packets, and VOIP.  Once we learned the basics of operating in an Asterisk telephony server environment, we moved on to how to write scripts in Ruby, bash, whatever to interact with Asterisk during a phonecall.  We set up our own Rackspace servers loaded up with Asterisk and used our professor’s script to install needed software on its Ubuntu instance.  I’ve saved that script to add extra stuff when I’m setting up a new Ubuntu server from scratch.  Ubuntu basic literacy is now attained.

That part was fun enough, but it started to get interesting when our badass professor, Chris Kairalla, published some code to Github for interacting with a web front-end in JavaScript by using socket.io, node.js, and a Ruby-Asterisk Gateway Interface script interfacing with calls placed to Asterisk. That’s when the realm of ideas greatly opened up.  Real-time interaction with the phone dialpad to control a screen, an Arduino, robots, electric switches, whatever.  And with the explosion of JavaScript and Node.js, it couldn’t have come at a better time.

Here are the class notes:  http://www.itp-redial.com/class/

And the Github repo: https://github.com/itp-redial/

I set out with confidence, knowing I could use Professor Kairalla’s brilliant tinyphone code, which provided the framework to facilitate an incoming call into a caller object that one could manipulate in the web page DOM.

My idea was to build a bar or restaurant menu displayed on screens around a bar which would let customers place orders by just pressing digits on their phone, instead of waiting on waitstaff or having a gimmicky touchscreen or table screen.  The orders would be tied to someone’s phone number so paying for bills wouldn’t require the awkward splitting up of the bill, and customers would be able to use a very personal device to them, their own cellphone, to control interaction in the bar/restaurant.  Orders could be processed quickly, verified afterwards, and immediately incorporated into a database which could provide business intelligence in the form of statistics on food orders, frequencies, favorites for each customer, etc. All in a scalable, modular framework such as Node.js + Express.

Previous blog documentation: post #1.

Demo video:

Screenshots of some functionality:

Initially I figured I’d follow advice and build out the API first.  For that, I’d need an admin dashboard to perform CRUD operations to build up the menu.  I’m pretty tired of having to build out AJAX and menus to add, remove, edit, etc. so I’ve started building a Node.js app with all that stuff built-in, including JSON operations and other common usage events so I don’t have to keep testing it.  Anyway, I got my menu add functions working so I quickly started adding all my favorite Stellas, Dark & Stormies, Mojitos, etc.

Then I spent most of my development time building an interface that could only use the dialpad numbers 1-9, 0, *, and #.  Because I was fairly ill-versed with JavaScript still, I actually ended up refactoring my interface about three or four times, each time becoming more and more modular, using JavaScript objects which contained each “menu” (i.e. a beer menu that would point to each individual beer’s screen, which would pass to another object that would fill out a screen to let you order the beer) pushed into an interface that had no more than 8-9 choices.  Then the screen would have to have text displayed large enough to read, yet still accomodate perhaps 3-4 simultaneous callers at once.

var menuFoodObj = {
	name : "Food/Drinks Menu",
	upMenu : "Main",
	currentMenu : "Food",
	id : "",
	p : ["", "Beer", "Wine", "Liquor", "Non-Alcoholic Drinks", "Water", "Burger", "Specials", "Chips & Salsa"],
	pClick : ["", "Beer", "Wine", "Liquor", "Other", "Water", "Burger", "Specials", "Chips"]
}

By the end of the refactoring though, I had a really nice (but still a little soupy) interface of JavaScript objects being pushed into the DOM by jQuery.  I learned OO JavaScript pretty well although I didn’t understand fully how to create new objects and then properly make methods for objects (I was declaring new functions within objects).  Since I did most of the development and testing just using the web browser and mouseclicks, I was happy when all my refactoring allowed me to easily map a phone’s keypresses to the interface interactions using jQuery’s .triggerHandler event.  My code is still quite soupy though, and I think I’m about ready to learn backbone.js for injecting data from models into a static template — it would have been perfect for this type of project where the layout remains mostly the same but the data changes frequently.  I’m happy, though, that it was easy for me to instantiate new user objects (e.g. user[1] = new User();) for the 4 users that Hermes currently supports.

I actually ran into a weird problem after I’d hooked in caller keypresses, which I thought at first was within the DOM.  Keypresses from my softphone (I used Zoiper to connect via SIP) were happening twice and I thought the click event handler was being called twice in the DOM.  This did not occur on normal phone calls over, say, a cellphone.  Further inspection saw two keypresses coming across in Asterisk:

 <SIP/general_sip-000000ae>AGI Rx << WAIT FOR DIGIT -1
 <SIP/general_sip-000000ae>AGI Tx >> 200 result=50
 <SIP/general_sip-000000ae>AGI Tx >> 200 result=50

Prof. Kairalla found that we were actually picking up feedback on my laptop from the call being made over the software.  Once we muted my laptop, the audio wasn’t being sent to the Asterisk server, which had been detecting the extra audio as what it assumed was an extra keypress.

I added an option to check news headlines from Google News’ API, which has been deprecated so will probably disappear soon?  The other bad thing about this was that you can’t really link to the body of an article since 1) Google News just provides the link and the source’s weak abstract and 2) news sources are so proprietary about people stealing their content.  APIs always leave a bad taste in my mouth because they’re hamstrung from the outset.  Anyway, there’s a definite art to creating headlines, as I learned in my previous job covering the news cycle, and most headlines are expertly packed with relevant info, enough for you to get an idea of things just at a glance.

I also added features for sending drinks/orders to another table, to facilitate social interaction within the bar.  Trivia can be played as well, though it wasn’t built into a central system where scores are kept.  Right now it just tests a user’s response against the correct answer and then generates a random question.  Another feature added was to flirt with other tables and send them messages.

I used Flowroute, which was super easy to set up in my sip.conf and extensions.conf for Asterisk, using Flowroute’s web-based cheatsheets for config settings unique to my account.  Very nice set-up screens there.

emailjs and Twilio

To process orders (when someone wishes to buy a beer, but he hasn’t received it yet) and tabs (for delivered food/drinks), I took advantage of node.js’s awesome modules and found emailjs, which lets you package up a JS object and send it as an email via SMTP to, say, gmail.  So when a customer places an order in Hermes, the order is sent via email to the company for later verification.  Easy, piece of cake.  Can be used with any SMTP server you have an account on and that has permissions.

Then Prof. Kairalla mentioned that it would be great if a customer received a text message thanking them after they close their tab.  So I bought a phone number on Twilio ($1/mo) and used the Twilio SMS API to package up another JS object with the tab details, and then have it again email the company but also text msg the caller with his closed tab details.  I actually had some problems with this and didn’t like the available Node.js modules (because they didn’t include examples for SMS), but luckily I found Dustin McQuay’s godsend blog post in which he posts some easy node.js code as a sendSMS() function, which I used to get my Twilio SMSs working.  I then had further problems but I found out I had pasted in the wrong Twilio auth token, so once I re-checked that, it then worked!  I feel as though the auth token changed because I funded my Twilio account, changing it from a free account to a paid one, and changing the token.  I assume?  Anyway, too much time wasted on that…

I also got a fraud alert from my credit card after trying to fund my Twilio.  Apparently they get a lot of fraudulent credit card funds, which makes sense since I’m pretty sure telephony and stuff related to it are havens for people trying to commit fraud, fake identities, and game systems.  But my credit card company cleared my purchase and I was fine within minutes.  Just thought it was worth mentioning.

Conclusion

I demo’d this in class and had 4 people call in.  They quickly broke it, but it was mostly the display of each person’s menu on the page.  That’s an easy UI fix.  I also found that I would need to make each person’s number more clearly visible so he’d know which interface he’d be working on.  But I felt like people were very quickly navigating through the menus and would learn it fairly quickly once they figured out it was just using a phone dialpad.  One thing that broke the demo was that the bottom bar (telling you how to use ‘*’, ‘0’, and ‘#’) got pushed down so people couldn’t see it.  Big problem there!

This app works hand in hand, I think, with my other app, Karaoke Flow.  I would love to create products to make the bar/restaurant/club/concert/dance party/rave/big gathering experience more enjoyable for people looking to have a kickass time and more profitable for the businesses providing it to them.

And I’m blown away with what is possible now with socket.io and Node.js.  All these projects I’ve wanted to do, like a web-based MUD to hook into Galapag.us, real-time chat, real-time flowing data, it’s now possible.  Love it.  And Redial…what a great class.  It’s recaptured the mystique of phones before they went smartphone, the weirdness and coolness of the phonebooth which has become a portal in pop culture (Doctor Who, The Matrix, Danger Mouse), and the fun of messing with somewhat quirky and buggy technology after it’s fallen out of vogue.  And to see how easy it is to set up a Vonage-like system!

Nature of Code Final: Genetic Crossings

Professor Daniel Shiffman’s Nature of Code is outstanding.  Just check out the syllabus. And play with the Nature of Code repo Processing sketches hosted on Github. And be sure to get his book when it comes out! We covered some basic algorithms for simulating inside the Processing environment vectors and forces/repellers, genetical algorithms, Wolfram cellular automata, neural networks, autonomous agents, flocking behavior, particle systems.

Background

For me, the pull towards genetic algorithms, heredity, fitness, evolution, Punnett squares, etc. was great, so my project for my first intro to computational media class turned into my Nature of Code final.

My "EUDAIMONIA" Tattoo

My Genetic Crossings project attempts to create a simulated environment where people exist within a world connected to God, the peoples’ religions, their nationalities, and each other.  They produce offspring based on characteristic attraction rules (for my demo I only used “appearance”, “money”, and “religion”, but only to demonstrate what was possible –I would like to create a more fully-formed algorithm for my personal reputation/identity ecosystem Galapag.us to approximate and adjust to the infinite ways that people become attracted to each other and become married or have children or devote themselves to the other), and they can die.  Their well-being or happiness (what in Galapag.us will be eudaimonia) is dependent on their quality of living within their religions and nations.

Map View

A video from an older version:

See previous documentation on this project:

 

Here are the initial characteristics I created for each person.  There are so many more yet to add! Strength, intelligence, wisdom, charisma, stamina, wit, humor, education, creativity, responsibility, discipline, honesty, religiosity, entrepreneurialism, appearance, money, gracefulness, stress, health, luck, talent_math, talent_art, talent_sports.

Initial nationalities/regions: USA, China, EU, Africa, South America.  Characteristics of security, innovation, job opportunity, immigration policy, life expectancy, education, sanitation, standard of living, pollution, biodiversity, crime, political freedom, and nutrition.  By no means comprehensive.

Initial religions/spiritualities: Christianity, Judaism, Islam, Taoism, Confucianism, Hinduism, Buddhism.  With characteristics of commercialism, morality, hierarchy, portability.  Obviously these need some tightening up/additions/discarding.

Final Project

So in my midterm I managed to add Verlet 2D physics to the sketch so that people, nations, and religions have connections to each other which make them bounce around like they’re on springs, relative to their attractions and strength of ties to each other.

In my final proposal, I sought to add the following:

  1. Wolfram cellular automata
  2. Connect to external database
  3. A selection algorithm to choose certain parts from parents based on mutation rate and fitness to pass along to new offspring
  4. Interaction sliders to change variables
  5. Macro events that affect well-being of all objects in the world, such as earthquakes or war
  6. Micro events that affect individual well-being, like rites of passage
  7. Discrete clusters of people, mostly based on familial strength of ties, instead of one big clump of people in the middle like in my midterm

 

I managed to get most of this done.

I enjoyed adding Wolfram CA.  I wrote a node.js app for express which would act as a JSON middleman between my main genetic crossings sketch and a wolfram sketch.  Basically, when viewing the chromosomal stainings (genotypes), you can click on the CA button to the left of a person’s staining, and this will pass a JSON object (using Prof. John Schimmel’s Processing-Nodejs code) to the node server, which is detected within 5 seconds by a polling timer within the wolfram sketch.  The wolfram sketch then uses the JSON object as its data to apply rules to to construct a pattern unique to the selected person’s genetic characteristic code.

1) I added a third parameter to the rules which would display as either black or aqua, depending on the CA rules.  Prof. Shiffman’s code used base-2 groups of 3, which had 2^3, or 8 total possible combinations (using only the digits 0 and 1), but I used base-3 (0 = white, 1 = black, 2 = aqua), so it became 3^3, or 27 possible combinations.  For this ruleset, I duplicated Wolfram rule 90 three times, then added a few extra codes.  The triangular look seemed the most visually interesting for what I was doing.  Anyway, what was cool about Prof. Shiffman’s code was that it keeps streaming the pattern from bottom to top.  So when a new person is clicked on, that person’s signature is integrated into the flow seamlessly once the sketch loads the JSON off the node server.  I don’t know that any of this actually is useful except that it looks cool and uses principles from class and maybe, just maybe, shows someone’s digital characteristic “signature”.

Streaming Wolfram CA on top of Processing sketch code. Console of Processing shows a passed JSON object.

2) I’m happy I was able to set up a MongoDB to be accessed via node as well as by my Processing sketches.  When I build out Galapag.us, I’ll be able to pump out JSON objects of actual users into these sketches for data visualization.  I’d been wanting to do this since my first semester and now it’s done.  Most credit goes to John Schimmel though for writing the hook into node though!

node.js instance output including passed JSON object

3) I realized that I already had some mutation within my matingDance.sex() function, once the two parents’ characteristics were passed to a matingDance.punnettSquare() function.  Before, the function would just average the two parents’ characteristic values together and then add or subtract a random amount from them for mutation.  What I changed was making the function choose randomly from either parent’s base characteristic.  So if one parent had 10, and the other had 1, the result would not be 5 (rough average) but either 1 or 10.  Then I would offset a random amount (hardcoded as 4) if mutation kicked in (if a random number between 0 and 50 was less than 2, for approximately a 1 in 25 chance of mutation per characteristic).  What this ended up doing was increase the diversity within the genepool and more accurately reflect reproduction.  I still need to tweak these numbers to get more consistent levels of variety but the algorithm is mostly there.

Here’s a view of the chromosomal stainings before I changed the algorithm — here it averaged the parents’ traits, which, in the case of this sketch’s iteration’s octomom, created many extremely similar offspring:

Before

And here’s the view after picking from either parent and allowing for a slim chance of mutation:

After

I feel as though the end result has a more diversified population with more variability between generations and individuals.  I need to tweak this so that if the value from a parent is at 1 or 10, it may mutate in only one direction, but here’s the matingDance.punnettSquare() function:

int punnettSquare(int comp1, int comp2) {
    int mutation = (int)random(0, 50);
    int dominance = floor(random(0, 1.99));
    int crossover = 0;
    if (dominance == 0) {
      crossover = comp1;
    }
    else {
      crossover = comp2;
    }
    if (mutation < 2) {
      crossover += (int)random(-4, 4);
    }
    // don't want it to be out of bounds
    // TODO: fix so it can mutate only one way if parent is 1 or 10
    if (crossover < 1) { crossover = 1; } else if (crossover > 10) { crossover = 10; }
    return crossover;
  }

4) I didn’t add sliders to change variables mid-sketch — at this point I can use variables pre-set in the main class but I’d like to make the interface more user-friendly and interactive later.

5 and 6) I didn’t do macro and micro events because I figured they’d just require making a button that, when pressed, would cause particles’ values to change.  What would be interesting would be to have random events happen based on their likelihood to occur and then some events would have permanent effects (damage to peoples’ personalities) or temporary effects (nationalities’ well-being that would later recover).  This kind of introduces the possibility for individual peoples’ health and whether they have injuries/disabilities/diseases/gifts/talents.

I did add a Ritual class though, which only includes right now a funeral function.  When funerals are recognized by a culture (by pressing ‘f’), the dead are removed from view on the map and their attraction springs are removed as well.  What this is supposed to represent is that funerals are a way for the living to remember the dead and then put them to rest so that the living can move on and create new ties with the living.  I do like the idea that we retain our ties to the past, which can sometimes become weaker in death and sometimes become even stronger.  I didn’t model that yet.

public class Rituals {

  Rituals() {
  }

  void funeral(boolean funeralsRecognized) {
    println(funeralsRecognized);
    for (int i=0; i<numPeople; i++) {
      if (person[i].parent1 != -1 && person[i].parent2 != -1 && person[i].alive == false) {
        if (funeralsRecognized == true) {
          physics.removeSpring(parentSpringArray.get(person[i].parent1Spring));
          physics.removeSpring(parentSpringArray.get(person[i].parent2Spring));
          physics.removeSpring(parentMinDistanceSpringArray.get(person[i].parent1MinDistanceSpring));
          physics.removeSpring(parentMinDistanceSpringArray.get(person[i].parent2MinDistanceSpring));
          person[i].lock();
          person[i].display(0);
        }
        else { // TODO: re-reference spring after it's recreated?
          parentSpringArray.add(new VerletConstrainedSpring2D(person[i], person[person[i].parent1], person[i].parent1RL, random(parentGravity1, parentGravity2)));
          person[i].parent1Spring = parentSpringArray.size()-1;
          physics.addSpring(parentSpringArray.get(parentSpringArray.size()-1));
          parentSpringArray.add(new VerletConstrainedSpring2D(person[i], person[person[i].parent2], person[i].parent2RL, random(parentGravity1, parentGravity2)));
          person[i].parent2Spring = parentSpringArray.size()-1;
          physics.addSpring(parentSpringArray.get(parentSpringArray.size()-1));
          parentMinDistanceSpringArray.add(new VerletMinDistanceSpring2D(person[i], person[person[i].parent1], random(parentMinDistanceRL1, parentMinDistanceRL2), random(parentGravity1, parentGravity2)));
          physics.addSpring(parentMinDistanceSpringArray.get(parentMinDistanceSpringArray.size()-1));
          parentMinDistanceSpringArray.add(new VerletMinDistanceSpring2D(person[i], person[person[i].parent2], random(parentMinDistanceRL1, parentMinDistanceRL2), random(parentGravity1, parentGravity2)));
          physics.addSpring(parentMinDistanceSpringArray.get(parentMinDistanceSpringArray.size()-1));
          person[i].unlock();
          person[i].display(1);
        }
      }
    }
  }
}

7) Discrete clusters.  I ended up adding relationships between people and their parents from just constrained springs to a combination of constrained springs and minimum distance springs.  What this would change is that a person’s distance from his parents is both constrained to no more than a certain length but also more than a minimum length, so that they can both be more visible instead of overlapping visually, and also be more clustered together.  I found that this makes certain groups on the map appear more clustered instead of forming a big ball in the middle.  I still need to do more work on this though because as there are more people in the sketch, the big clusterfuck returns (because there are too many connections between everything and I can’t zoom in closer to see the gaps and relative spacing between different networks).

I converted a lot of my arrays of spring connections over to one large ArrayList, which I think was easier to deal with in the end in terms of manipulating them after they were initiated into the environment.  I did find, however, that I had to pass a reference to the spring’s number (since it was just an ArrayList entry) to the person’s class instance so it could refer to it later.  A problem with this though, as I realize just now, is that if I remove springs (as I do in the funeral ritual), I’ll lose the correct references.  So I have to make sure that when the springs are added again, when funerals are disabled, that a pass a new reference to the ArrayList.

I also found that there tends to be super-breeders every time I run the sketch, with certain people tending to produce tons of offspring while others produce none.  I’m talking like 1 or 2 people will produce 10 kids, which tends to make the sketch appear too tightly clustered because everyone is closely linked.  Perhaps this is a feature, rather than a bug, of reproduction?

Code

You can download the code from Github.  You’ll probably want to start up a node instance and then start the genetic crossings sketch, then finally the wolfram sketch.  Instructions are in the README.md.

Github: https://github.com/Xeus/Genetic-Crossing

Conclusion

And this leads me to some closing notes. I shied away from adding fitness yet again to my reproduction algorithms because I felt like “fitness” in the short-term was too much like large-scale evolution theory and autonomous agent simulation.  In my sketch there wasn’t really an ideal fitness state, with no limitations or rules imposed on the larger scale.  What I wanted was to break into modeling some culture into the simulation, so that choices were made between sexual partners based on cultural norms and not as much on randomized reproduction. Obviously modeling culture would work best if it were overlaid on top of basic biological reproductive theory such as choosing the fittest partner and whatnot, but I felt that was too much for the scope of this simulation, which I wanted mainly to focus on social networks.

JavaScript has come a long way.  It’s now the same on the backend and the frontend.  Processing can be exported to JavaScript in some capacity, and dataviz libraries such as D3 are taking off.  Soon we will be able to introduce more fluid, data, physics, and particle system simulations within a browser.  It’s too early for my sketch yet (ToxicLibs takes some finagling) but this is a glimpse of the web to come.

As I begin to do more serious work on the internal mechanics of Galapag.us, it’s stuff like this Processing project that makes me appreciate how careful I’ll have to be with positioning different factors against each other so that people can create their own formulae/evolutions to weight different priorities how they deem fit.

Looks like this book out of the Harvard Berkman Center, “Interop: The Promise and Perils of Highly Interconnected Systems”, by John Palfrey and Urs Gasser, is a must-read.

What I do feel is that current online social networks have not really tried to map out the complex interweaving, competing, variable connections and attractions we have between ourselves and others, between the different identities we all have, between the things we care about more or less at different times in our lives, etc.  To facilitate something like this, I can’t help but feel there needs to be a massive API that allows people to access all this data (if privacy settings allow it) so that we can take advantage of the multi-dimensional nature of our species.

You can think of someone’s identity as a meshed web that is being pulled apart by the external world and people and ideas and being pulled together by muscle and ligament and cartilage and sense of self and personality and such.  You can think of a community as a bunch of these springy people pulling on and apart from each other constantly, but at a stronger tension than from other communities.  Communities form religions and nations and cultures, again with that same network of relationships and competing identities. I hope that’s the dynamic I was able to capture in doing this project.

Credit

Special thanks to:

  • Prof. Dan Shiffman for all his documentation and code from Nature of Code, particularly his chapters on forces, genetic algorithms, ToxicLibs, and cellular automata
  • Prof. John Schimmel for his Processing-Nodejs code

Dynamic Web Dev Final: Karaoke Flow

My NYU-ITP Dynamic Web Dev class ended up being fantastic.  We moved to Node.js Express, incorporated AJAX, MongoDB, Heroku, and Amazon S3, built a JSONic API, and toyed with socket.io and even some Processing + HTTP POST.  You can read the class notes and fork/view the github class code from Professor John Schimmel’s repositories online.

Karaoke Flow

My final project ended up being a party game.  People hit the site, probably best with a keyboard, and start creating “rhymes” based on a prompt of two topics, such as “yo momma” and “swag”, or “basketball” and “Maybach music”.

You start off with three choices: 1) start a new “flow” (an individual song) which 2) you can join into with the second choice (using autocomplete JavaScript to parse a list of open flows from the database), and 3) skip all the rhyme creation part and go right to performing a randomized flow.

If you work on an open flow, all the participants have five minutes (using a JavaScript countdown script) to come up with as many rhymes as you can.  When five minutes is up, everyone can submit one more rhyme before they’re sent to the performance page.

On the performance page, the next person up will (eventually) be able to grab a mic, start the random beat (so far I have random beats from Wiz Khalifa’s “Star of the Show”, Three Six Mafia’s “Hard Out Here for a Pimp”, and Drake’s “I’m on One”), and move up and down through the lyrics using the ‘j’ and ‘k’ keys.

 

 

 

I’m hoping eventually it can be recorded and people can vote on the best rendition of the performance.  People are judged (though this isn’t captured through the site yet) on how well they deliver their spontaneous flow.

I wanted to do a project related to music and parties, hence the project; hopefully at some point in my life, I’ll get to work on projects that make parties more kickass through technological integration with human party impulses.

Karaoke Flow was also my entrée into Node.js and Express, which I now love and will rewrite Galapag.us into it over the summer in preparation for my thesis next spring.

Online Presence

A demo of the site is up at Heroku: http://karaokeflow.herokuapp.com/

I have instructions on how to clone the code and install it so you can run a node.js instance at github: https://github.com/Xeus/Karaoke-Flow

Previous documentation from my blog: post #1, post #2.

Things Learned for the Future

I think what I got most out of this was an appreciation for JavaScript objects.  To be able to package up variables and containers and clone objects or pass them along into JSON, it was like what I was missing in web sites.  I’m still on the road down to something more like Backbone.js, which will allow for even more use of objects and static templating filled in with data.  Definitely enjoying being able to JSONify data into something that I can use throughout the site or offer to others.  I’m sold.

Our professor showed us passport, which is a brilliant module for handling users and security.  I was missing something similar when I was using Ruby + Sinatra.

Conclusion

If anyone’s interested in taking this further with me, let me know.  I definitely think some combination of karaoke, rhyme-writing, parties, and randomness would be a huge hit.

Final Proposal for Redial: Hermes

My Redial class is awesome.  We’ve set up Rackspace servers with Asterisk telephony software and now we’re executing shell/ruby/php scripts through phonecalls which are now interacting with node.js servers to execute web site interfaces, Arduino RC car controls, etc.

I really want to focus on using node.js and socket.io with Asterisk/phonecalls for my final project.  So here’s what I propose:

Hermes

Hermes is an ordering interface for bars and restaurants.  When you sit down and order food, or when you’re standing at the bar trying to get a drink, you dial in with your phone to the establishment’s screen/s to place an order.

Say you sit down at a table and the table either has a built-in screen (like those old Pizza Hut arcade games where you could play Pac-Man using a joystick and buttons underneath the table surface), or it has a monitor or projection on the wall.  It will have a phone number for you to dial.  When you call in, it begins to interact in real-time with you both by voice and with on-screen instructions.  By pressing phone keys, you can place simple orders from simplified menus displayed on-screen.

Multiple people can dial in to the same line at the same table.  The screen will split depending on the number of people, allowing people to tie their orders to their phone number and to order independently of each other.

At the bar, when it’s packed, a projection above the bartender area will have a number to place calls.  The bartender can then cue drinks in the order they’re received in a fair way.  People can auto-order favorites or have drinks set to order every x minutes.  Complex group orders are handled digitally.

Multiple screens can be installed around the establishment so people don’t have to wander too far to place an order.

The screens can also be used for entertainment, as people could play phone trivia or mini-games via their phones, browse the news, change TV/music stations (handled via weak FM signal?), etc.

Why Hermes?

Hermes was recognized as the God of commerce and social interaction, and patron god to diplomats, messengers, and heralds:

Due to his constant mobility, he was considered the god of commerce and social intercourse, the wealth brought in business, especially sudden or unexpected enrichment, travel, roads and crossroads, borders and boundary conditions or transient, the changes from the threshold, agreements and contracts, friendship, hospitality, sexual intercourse, games, data, the draw, good luck, the sacrifices and the sacrificial animals, flocks and shepherds and the fertility of land and cattle. [Wikipedia]

Problems of a Hermes-Less World

  • Ordering food and drink is still a primitive process.  McDonalds has figured out how to move a lot of customers through quickly and efficiently with minimal job training.  But most restaurants and bars suffer from bad image and service because overworked waiters, waitresses, and bartenders can’t keep up with everyone’s needs 100% of the time, particularly when customers are fickle, intentionally hard to please at times, etc.  Streamlining the ordering process so that people can order as much food and drink as they would like, without inconveniencing themselves or waiting for some attention from an employee would increase business and increase consumer satisfaction.  There’s a problem when people discuss strategies to elbow their way into a bar just to maybe get a drink in 15 minutes, 15 minutes spent away from the party they came to attend.

Problems of a Hermes World

Hermes is not without its limitations.

  • Screen readability is limited by the size of the monitor, the customer’s ability to see clearly, the design of the interface, and how much text can be displayed at once.
  • There is also a problem linking orders to phones.  While something like Google Wallet, where one could pay via phone, would be preferable, at this point the phone number would only be an identity link to the customer and his order, and for reaching the customer afterwards for non-payment.  There are most likely large security/spoofing vulnerabilities in this approach unless a credit card number is somehow associated with the phone number.
  • Why would one find that dialing on a phone is a superior interface to asking a person, or using a touchscreen, or even using a custom web-app or mobile site to order?

Benefits

  • Tests with digital ordering systems seem to indicate people will order more food and drink if they can do it quickly, digitally, and without pause.  The systems seem to increase efficiency and overcome social shyness.
  • People strongly and affectionately associate with any actions involving their own phones, so using their phones as an ordering device empowers them.  It also is a potential bridge to have “preferences” that people can set and save with their “account”, linked through their phone number as identity.
  • Digital ordering produces a digital record, which is better for book-keeping and for validation of records in the event of disagreement between employees, customers, and management later.
  • Projections could be expanded upon — when people aren’t ordering food, they could be consuming news, shows, art installations, using Kinect-ish hands-free interfaces, messaging other tables, etc.  There is an exciting potential for linking different tables and screens with each other, via competition, flirting, or just networking or social lubrication.
  • Client interface consists of normal 1-0/*/# phone pad, can work with installed phones or smartphones or even simple cellphones, while all the customized, complex work can be handled server-side

Technology

  • Flowroute number linked to an Asterisk server installed on Rackspace
  • Asterisk dialplan forwarding to a ruby-agi script that sends data to a node.js instance
  • Node.js instance that takes incoming phone commands and passes instructions via socket.io (real-time, no polling) to the client that is installed on the projection/screen
  • jQuery/UI/AJAX/node.js client interface that handles order entry and routing, and can run multiple instances via the node.js cluster module, and can also forward to other instances for video, news, chat, etc. while keeping order entry instance CPU/memory load available just for order entry/processing

Long-Term

  • Tie-in to payment system/gateway?
  • Data saved into MongoDB
  • Employee and management interfaces to see stats on sales, database analysis, modify orders on the fly

Research Links

Nature of Code: Final Proposal

For my Nature of Code final, I plan to continue the Genetic Crossings Processing sketch project and incorporate some of the concepts from the second half of the course.

Previous documentation for this project: Nature of Code & Intro to Computational Media

Specifically, I want to do the following:

  • Use each person’s characteristics (rated from 1-10, and numbering a total of about 20 characteristics per person) as a ruleset for the Wolfram Cellular Automata structures.  I will have to adapt the code by remapping the 1-10 scale either to a binary state or by making more complex rules (perhaps using color instead of white/black or on/off).  I don’t know that there’s any benefit to the overall project from implementing Wolfram CA here, but perhaps it might give each person within the sketch a unique signature or fractal pattern.

  • Of the three characteristics of genetic algorithms — heredity, variation, and selection — I have implemented my own versions for heredity and variation, but have not really introduced much selection.  The only selection that seems to take place is that, because I have more heavily weighted religion, appearance, and money in the sex() algorithm, those with high stats in those areas will probably reproduce easier.  But this is not equivalent to having an actual fitness algorithm that determines “ideal” environmental success.  As Professor Shiffman writes in his notes, “There must be a mechanism by which some members of a population have the opportunity to be parents and pass down their genetic information and some do not. This is typically referred to as “survival of the fittest.””  I might also try to implement a mutate() function as used in example code, since all I do at the moment is take the average of the parents’ characteristics and then randomize an offset to come up with “mutation”.  Very hacky.
  • System variables and sliders: I liked the Processing sketch “flocking_sliders.pde” from the Shiffman’s chapter 6, “Autonomous Agents” because it let you play with variables on the fly to see how it would affect the simulation: how would you get boids to fly together, but not too close together, and could you enforce more solo or flocking behavior easily?  So I think I would like to use the God person or perhaps a fake country or religion to simulate how wild changes in traits or characteristics of a larger group-level entity could markedly affect individual persons linked to them.  Could I even have individuals leave group-level entities in search of more favorable ones?  What I picture is the person objects bouncing around the environment as the strengths of their relationships change between others, their parents, religions, and countries.  This also introduces the idea of migration patterns.
  • Similarly, I would like to be able to introduce world-level events such as earthquakes, global warming, war, Renaissance, etc. which add or subtract from multiple entities all at once, or even over iterations/time.
  • On an individual level, I wonder if I could implement rites of passage, liminal events in persons’ lives such as turning 21, getting married, having children, etc. that affect their relationships to their communities and increase/decrease their stats.  Would this necessitate perception of stats as opposed to actual stats?  In my Galapag.us project, I’m trying to study the multi-dimensional nature of our presence in the world — what we think of ourselves, what we actually are (objective truth/science?), and what others think about us. Reputation within a community is not often of one mind — one can hold various degrees of influence and respect among different components of the same community.  How does one code this?
  • Visually, I am hoping to make the networks a little more discrete.  For my midterm, the sketch ended up looking mostly like a hub (God) and spokes as more persons were introduced.  What it should be, though, are clusters of parents and offspring, dispersed between different group-level clusters.

 

Other influences:

  •  Joshua Epstein’s “Growing Artificial Societies: Social Science from the Bottom Up”, loaned to me by my classmate James Borda.
  • Prof. Shiffman posted this video of a talk by Bret Victor, which argues for real-time feedback for coding, so we can visualize the results of our code and experiment with unintended changes or extremes testing or rapid prototyping for artistic-based projects such as building animations.  Blew my mind.  Seriously, I don’t watch many long lecture vids anymore, but this was awesome:

Mobile Web Final: StreetEyes

Phil Groman and I presented our mobile web app, StreetEyes, for our NYU-ITP mobile web class.  StreetEyes is intended to be a way for a web viewer to look at a map of broadcasters and ask them to collect information on a desired event, protest, or location.  The app allows a web user to view a map of broadcasters, select one, and make a view request to him to start collecting data from the ground and reporting it to the news “stream” that the viewer made from the web.  The viewer and broadcaster (or multiple viewers) could chat in real-time to assign tasks for info collection or to take more photos or to get more descriptive updates.

We feel a good application of this would be for documenting a quick-moving protest, or for getting eyes on a line at a supermarket or at the DMV.  Traditionally, news is collected by sifting through peoples’ random Twitter updates, or more crafted news stories that come later.  If some investigative curator or someone who knows which details are pertinent in an emergency (say, a first-responder), then there is not much way to contact people on the ground to gather data.  We rely on people on the ground to be knowledgable enough to get the right data, but this is the wrong way to go about things.

Why not have curators direct people to breaking news or emergencies?

 

TODO:

  • Make the camera work, submit photo to a stream.
  • Fix display bugs in Google Map dynamic view.
  • Much better styling for the stream page.
  • Video-streaming?
  • User authentication and multi-user potential.

 

Final note.  We feel as though video-streaming apps are stuck on just getting the video up.  Ustream has a nice Android app that very quickly allows you to view a full-screen stream, or start your own.  But it does not function well in disseminating information, particularly on a directed topic.  We would like to be able to embed the video into a stream so that the end result is like a curated Reuters news feed, which differentiates between admins, editors, and random commenters.  Those last commenters are very important though, as they may actually be on-site and have a lot of info to share.  It is a curator’s role to promote that info and demote the chaff.

Another thing.  We found prezi very useful for our presentation, as well as the app Droid@Screen, which is a Java file that goes in your Android SDK folder containing adb.  That app allows you to display what’s going on on your phone’s display onto the monitor, which can then be projected onto a wall or large screen.

Redial Midterm: Gotta Take This

For my Redial midterm, I did something functionally pretty straight-forward.  Ever been in a situation where you’re talking to someone and you want to get out of it, like when that person is one of those folks who just keeps going and going and you haven’t said a word in ten minutes because they wouldn’t you talk?  Or if the conversation is so forced and awkward that you can’t stand it?

I’ve got an app for you.

It’s called Gotta Take This, although I think I pitched it originally as Panic Button.  I think I chose the former because it sounded a little less alarmist but still conveying the purpose.

What the app does is, upon opening it on your phone, it shows you a life preserver.  Tap on the preserver and casually exit to something else on your phone, like checking email.

Five minutes later (I set this to 1 minute for the demo), you’ll get an “Urgent Call” from a pre-set number.  When you answer it, an Asterisk dialplan takes over and plays, for my demo anyway, a long recorded message that gives you plenty of cover to have a quick conversation.

This gives you multiple opportunities to tell your present company, “Hey, uhh, I gotta take this…  It’s urgent/important/just a quick call/getting information.”

Now, once you’ve moved away with the call, you’re free to slink out of the place, or distractedly fall into a conversation with other people.

The app is made for Android with PhoneGap.  I got the icon from iconmaker.com.  The PhoneGap app’s button triggers jQuery Mobile to go to a ruby script I set up on ITP’s server, which generates a callfile with pre-set call information to be executed at a certain time in the future.

My ruby script, running via Sinatra:

require "rubygems"
require "sinatra"

# Main route  - this is the form where we take the input
get '/gottatakethis' do
  minutes = 1
  t = Time.now + (60 * minutes)
  # %H-%M-%S-%m-%d-%Y == 09-09-03-07-24-2006
  timeCallBack = t.strftime("%H-%M-%S-%m-%d-%Y")
  numbertocall = 15555555
  senderNum = 15555555

  # set the temp dir & filename & destination path to write from/save to
  temp_dir = "/tmp/"
  callfile = "call_" + timeCallBack + ".call"
  startcallfile = temp_dir + callfile
  end_dir = "/var/spool/asterisk/outgoing/"
  endcallfile = end_dir + callfile

  #write file to disk
  file = File.open(startcallfile,"w")
  file.puts("Channel: SIP/itp_jnctn/#{numbertocall}\n")
  file.puts("MaxRetries: 2\n")
  file.puts("RetryTime: 60\n")
  file.puts("WaitTime: 30\n")
  file.puts("Context: vt520_gtt\n")
  file.puts("Extension: 1\n")
  file.puts("CallerID: Urgent Call ")
  file.close

  #change file permission
  File.chmod(0777, startcallfile)
  FileUtils.chown(ENV['USER'],'asterisk',startcallfile)

  #move file to /var/spool/outgoing
  if (timeCallBack != "")
	timesplit = timeCallBack.split('-')
	ctime = Time.local(timesplit[5],timesplit[3],timesplit[4],timesplit[0],timesplit[1],timesplit[2])
	File.utime(ctime,ctime,startcallfile) #change file time to future date
  end
  FileUtils.mv(startcallfile,endcallfile)

  body = "Sent."
  body

And the relevant dialplan:

[vt520_gtt]
exten => s,1,Answer()
   same => n,Wait(3)
   same => n,Playback(/home/vt520/asterisk_sounds/soundfile)
   same => n,Hangup()