Skip to content

Instantly share code, notes, and snippets.

@AllenSH12
Created May 12, 2014 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllenSH12/31a22bf989da07b10a43 to your computer and use it in GitHub Desktop.
Save AllenSH12/31a22bf989da07b10a43 to your computer and use it in GitHub Desktop.
THE CALIFORNIAN, Saturday, November 11, 1865
EXIT "BUMMER." - As we have devoted but little space to an event which has filled our local contemporaries with as much sorrow (judging from the columns of lamentations it has called forth) as would the decease of the best biped in the city, we give "Mark Twain's" view of the occurrence as recorded in the ENTERPRISE of the 8th. Strangely enough, Mark, who can't stand "ballad infliction" seems to think there has not been quite enough of "Bummer":
"The old vagrant 'Bummer' is really dead at last; and although he was always more respected than his obsequious vassal, the dog 'Lazarus,' his exit has not made half as much stir in the newspaper world as signalised the departure of the latter. I think it is because he died a natural death: died with friends around him to smooth his pillow and wipe the death-damps from his brow, and receive his last words of love and resignation; because he died full of years, and honor, and disease, and fleas. He was permited to die a natural death, as I have said, but poor Lazarus 'died with his boots on' - which is to say, he lost his life by violence; he gave up the ghost mysteriously, at dead of night, with none to cheer his last moments or soothe his dying pains. So the murdered dog was canonized in the newspapers, his shortcomings excused and his virtues heralded to the world; but his superior, parting with his life in the fullness of time, and in the due course of nature, sinks as quietly as might the mangiest cur among us. Well, let him go. In earlier days he was courted and caressed; but latterly he has lost his comeliness - his dignity had given place to a want of self-respect, which allowed him to practice mean deceptions to regain for a moment that sympathy and notice which had become necessary to his very existence, and it was evident to all that the dog had had his day; his great popularity was gone forever. In fact, Bummer should have died sooner: there was a time when his death would have left a lasting legacy of fame to his name. Now, however, he will be forgotten in a few days. Bummer's skin is to be stuffed and placed with that of Lazarus."
// 1
val gizmos = Map("Magnificent Steinway \"Barber of Seville\" Grand Piano" -> 320000, "Breville BOV450XL Mini Smart Oven with Element IQ" -> 149, "Conair Waterfall Foot Spa" -> 37)
val discounted_gizmos = for ((k, v) <- gizmos) yield (k, v * 0.9)
// 2
val used_words = new collection.mutable.HashMap[String, Int]
val in = new java.util.Scanner(new java.io.File("bummer.txt"))
while (in.hasNext()) process_word(in.next)
def process_word(word: String) {
if (used_words.contains(word)) {
used_words(word) = used_words(word) + 1
} else {
used_words(word) = 1
}
}
for ((k, v) <- used_words) println(k, v)
// 3
var used_words = collection.immutable.Map[String, Int]()
val in = new java.util.Scanner(new java.io.File("bummer.txt"))
while (in.hasNext()) process_word(in.next)
def process_word(word: String) {
if (used_words.contains(word)) {
val new_count = used_words(word) + 1
used_words = used_words + (word -> new_count)
} else {
used_words = used_words + (word -> 1)
}
}
for ((k, v) <- used_words) println(k, v)
// 4
var used_words = collection.immutable.TreeMap[String, Int]()
val in = new java.util.Scanner(new java.io.File("bummer.txt"))
while (in.hasNext()) process_word(in.next)
// recycled from #3
def process_word(word: String) {
if (used_words.contains(word)) {
val new_count = used_words(word) + 1
used_words = used_words + (word -> new_count)
} else {
used_words = used_words + (word -> 1)
}
}
for ((k, v) <- used_words) println(k, v)
// 5
import collection.JavaConversions.mapAsScalaMap
val used_words: collection.mutable.Map[String, Int] = new java.util.TreeMap[String, Int]
val in = new java.util.Scanner(new java.io.File("bummer.txt"))
while (in.hasNext()) process_word(in.next)
// recycled from #2
def process_word(word: String) {
if (used_words.contains(word)) {
used_words(word) = used_words(word) + 1
} else {
used_words(word) = 1
}
}
for ((k, v) <- used_words) println(k, v)
// 6
var days = new collection.mutable.LinkedHashMap[String, Any]
days += ("Monday" -> java.util.Calendar.MONDAY,
"Tuesday" -> java.util.Calendar.TUESDAY,
"Wednesday" -> java.util.Calendar.WEDNESDAY,
"Thursday" -> java.util.Calendar.THURSDAY)
for ((k, v) <- days) println(k, v)
days = days.empty
days += ("Thursday" -> java.util.Calendar.THURSDAY,
"Monday" -> java.util.Calendar.MONDAY,
"Wednesday" -> java.util.Calendar.WEDNESDAY,
"Tuesday" -> java.util.Calendar.TUESDAY)
for ((k, v) <- days) println(k, v)
// 7
var table = new collection.mutable.HashMap[String, String]
table += ("java.runtime.name" -> "Java(TM) SE Runtime Environment",
"sun.boot.library.path" -> "/home/apps/jdk1.6.0_21/jre/lib/i386",
"java.vm.version" -> "17.0-b16",
"java.vm.vendor" -> "Sun Microsystems Inc.",
"java.vendor.url" -> "http://java.sun.com/",
"path.separator" -> ":",
"java.vm.name" -> "Java HotSpot(TM) Server VM")
val longer_string = (x: String, y: String) => {
if (x.length > y.length) x else y
}
val longest_string = table.keySet.reduce(longer_string)
for ((k,v) <- table) {
var buffer = " " * (longest_string.length - k.length)
println(k + buffer + " | " + v)
}
// 8
def minmax(values: Array[Int]): Array[Int] = Array(values.min, values.max)
// 9
def lteqgt(values: Array[Int], v: Int) = {
val lt = values.count(_ < v)
val eq = values.count(_ == v)
val gt = values.count(_ > v)
(lt, eq, gt)
}
// 10
/*
scala> "Hello".zip("World")
res33: scala.collection.immutable.IndexedSeq[(Char, Char)] = Vector((H,W), (e,o), (l,r), (l,l), (o,d))
Come up with a plausible use case.
http://www.acrdepos.com/wordpress/wp-content/uploads/2013/08/1340433133397.jpeg
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment