Tuesday, November 30, 2010

Pig Latin Encoder

To encode a word in pig latin, we need to handle two cases as described on p. 277.

The following function is a partial (but not complete) solution.

For example, how does it encode swing? rhythm? Aardvaark? CIS?

/* return word w encoded as pig latin */
function encode(w){
if(w.search(/[aeiou]/) == -1 || w.search(/[aeiou]/) == 0)
return w + 'way'
else
return w.substring(1, w.length) + w.charAt(0) + 'ay'
}

MISC PIG LATIN NOTES

var w = 'oops!!'
var punct, bareWord, pLatin, ans

//peel off punctuation
punct = w.substring(w.search(/[!,.]/), w.length)
bareWord = w.substring(0, w.search(/[!,.]/))

pLatin = encode(bareword)

ans = pLatin + punct

Test Cases:

Eighthstreet, gym, myrrh, aeon, llama, kvetch.

gnome, bloom, brew, clue, snow, smart, wrench.

rhythm, crypt, rhyme, gypsy, strength, scrimp, shrimp, schlep, shrapnel, splice, sphygmomanometer, strap, scrap, spring,

Pig Latin koans: Xylophone, tsktsk, eau de Cologne.
Enhanced by Zemanta

Sunday, November 28, 2010

Final Exam Review Problems

final examsImage by sashamd via Flickr

  • (1) Write an alarmClock() function that accepts an integer representing the day of the week (Mon=1, Tue=2, ... Sun=7) and returns a string: On weekdays the clock tells us to get up, and weekends it tells us to snooze more. On Monday, the clock adds some extra harassment to get us out of bed.

    Examples

    alarmClock(2) => Hi ho, hi ho, it's off to school we go...

    alarmClock(6) => Hit the snooze button!

    alarmClock(1) => Daylight in the swamps! Up and at'em!

    Strategy: Use an else-if (See fig. 11.7, p. 203; dice.html)

  • _______________________________________________

    (2) Write a bowlingScoreFeedback() function that accepts a bowling score 0 .. 300 and returns one of these messages:

    300: "most triumphant!"
    200..299: "pretty good!"
    50..199: "making progress!"
    0..49: "better take up Scrabble!"

    Examples

    bowlingScoreFeedback(250) => pretty good!


    bowlingScoreFeedback(25) => better take up Scrabble!

    _________________________________

    (3) Suppose you want to get a table at a hip restaurant: The variable "style" represents the stylishness of your clothes and "bribe" represents the bribe presented to the Maitre'd.

    The Maitre'd is satisfied if style is 8 or more and bribe is 5 or more.

    One way to code this up is to write the "satisfied" expression as a straight translation of the problem statement, and then put a ! in front of it:
    //Say something mean if not satisfied
    function maitreD(style, bribe){
    if (! ((style >= 8) && (bribe >= 5)) ) {
    return "tant pis pour vous"
    else
    return "Ainsi, s'il vous plaƮt"
    }

Wednesday, November 24, 2010

If your 111 website generates a "403: Forbidden" error

Any .html file you upload to your 111 folder on the server must be "world readable," otherwise a 403 error results ("Forbidden: You don't have permission to access") when you try to open the file in a browser.

Permissions are usually set correctly by default but, sometimes, a permission gets changed during the upload. Then you will have to set the file's access mode explicitly.

Here's how to DIY (Do It Yourself):

Using either SSH (Windows) or Cyberduck (OS X), you can select the file on the server and list its Properties. "Read" permission needs to be enabled for "Other".

Example (SSH):
http://www.ssh.com/support/documentation/online/ssh/winhelp/32/file_properties.html

Example (Cyberduck):
http://trac.cyberduck.ch/wiki/help/en/howto/info
Enhanced by Zemanta

Monday, November 15, 2010

Use a CSS Reset

A perfect desktop image for CSS developersImage via WikipediaItem #27: Use a CSS Reset, from nettuts+.



If your tables, list items, etc., are receiving that extra bit of padding when you didn’t specify it anywhere in your CSS file, then start with a CSS reset.

30 HTML Best Practices for Beginners



30 HTML Best Practices for Beginners , from net.tutsplus.com.



Thirty best practices to observe when creating xhtml, css and JavaScript.

30 HTML Best Practices for Beginners

30 HTML Best Practices for Beginners , from net.tutsplus.com.

Thirty best practices to observe when creating xhtml, css and JavaScript.
Enhanced by Zemanta

Breaking down Internet privacy legislation

privacyImage by alancleaver_2000 via Flickr

Breaking down Internet privacy legislation

An 11/14/10 article from the Washington Post,

By Cecilia Kang, discussing current internet privacy measures in congress.

Wednesday, November 10, 2010

PetaFlops in the News

Q: How long does each instruction take to execute?

http://www.bbc.co.uk/news/technology-11644252

China claims supercomputer crown

Tianhe supercomputer, Nvidia  
China has claimed the top spot on the list of the world's supercomputers.
The title has gone to China's Tianhe-1A supercomputer that is capable of carrying out more than 2.5 thousand trillion calculations a second.
To reach such high speeds the machine draws on more than 7,000 graphics processors and 14,000 Intel chips.

Key Terms to Understand this Story

CPU speeds are dependent upon the type of instructions being executed: some are hard and some are easy.
FLOPS are hard and, in general, more meaningful than MIPS and MOPS.
SI Prefixes and Large Number Names.
Enhanced by Zemanta

PetaFlops in the News

Q: How long does each instruction take to execute?



http://www.bbc.co.uk/news/technology-11644252

China claims supercomputer crown

Tianhe supercomputer, Nvidia

China has claimed the top spot on the list of the world's supercomputers.

The title has gone to China's Tianhe-1A supercomputer that is capable of carrying out more than 2.5 thousand trillion calculations a second.

To reach such high speeds the machine draws on more than 7,000 graphics processors and 14,000 Intel chips.

Key Terms to Understand this Story

CPU speeds are dependent upon the type of instructions being executed: some are hard and some are easy.

FLOPS are hard and, in general, more meaningful than MIPS and MOPS.

Google's Book Search: A Disaster for Scholars

Google's book search is clearly on track to becoming the world's largest digital library. Will it support scholarly research as well as bricks-and-mortar libraries? Metadata will be the deciding factor.



Google's Book Search: A Disaster for Scholars, by G. Nunberg.

PetaBytes in the News

With smartphones growing in popularity, mobile data traffic is set to grow 40X (8 petaBytes/month to 325 petaBytes/month) in the next five years, according to research from Coda Research Consultancy, via TechCrunch.



Wednesday, July 14, 2010

Creative Theory Machine Buttons



In the category of creative Theory Machine buttons:
  • ifSixWasNine, by Jared Hendricks (a.k.a. "Jimi" ;-)

    alert(ifSixWasNine(6)) ==> 9
    alert(ifSixWasNine(12)) ==> 18

Tuesday, July 13, 2010

The replace() method for Strings

String theory?Image by trailfan via Flickr
The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring. It searches the string on which it is called for matches.

If the g flag is set, the method replaces all matches in the string with the replacement string; otherwise it replaces only the first match it finds.

EXAMPLES

//replaces first match
//wasit a rat i saw
var s = 'was it a rat i saw'; alert(s.replace(/[ ]/, ''))

//replaces all matches
//wasitaratisaw
var s = 'was it a rat i saw'; alert(s.replace(/[ ]/g, ''))
Enhanced by Zemanta

Monday, July 12, 2010

On Palindromes

la porte du palindrome / the palindrome doorImage by TisseurDeToile -[*] via Flickr



Example from class:

var s = "Too Hot, to Hoot!!"
var arr = s.split(' ')
var result = ''


//process all words in sentence
for(var i = 0; i < arr.length; ++i)
//result = result + encode(arr[i]) + ' '
arr[i] = encode(arr[i])



Example from Class

var s = "Radar, mom!"
var arr = s.split(' ')
var i = 0


//check words
//not quite there yet..
while(isPalindrome(arr[i]) && i < arr.length){
++i
}

//determine result
if(i == arr.length)
//every word is a pal
else
//not all words are pals
Enhanced by Zemanta

xhtml: logical vs physical tags

Just a random blob with "XHTML" writ...Image via Wikipedia

HTML includes two types of Style Tags:

  • logical (a.k.a. phrase elements)
    tag the information according to its meaning (e.g., abbr, acronym, code, etc.)
  • physical
    tag the exact appearance of the information (i.e. b, i, etc.)
Both <em> and <i> display italics. CSS is the preferred way to style content rather than logical tags. Logical style tags are preferred over physical tags (which is why the latter are deprecated in xhtml).

Rationale: the goal in xhtml is to separate structure elements from style elements, and remove the latter from xhtml. Content should be styled with CSS rather than xhtml. Logical tags describe the structure or semantics of content and are, therefore, preferred over style elements like <b> and <i>.
Enhanced by Zemanta