This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
git clone https://github.com/twitter/scalding.git | |
cd scalding | |
./sbt scalding-repl/console | |
*/ | |
import scala.io.Source | |
val alice = Source.fromURL("http://www.gutenberg.org/files/11/11.txt").getLines | |
// Add the line numbers, which we might want later | |
val aliceLineNum = alice.zipWithIndex.toList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time(val hours: Int, val minutes: Int) { | |
def before(other: Time): Boolean = { | |
hours < other.hours || | |
(hours == other.hours && minutes < other.minutes) | |
} | |
def check(other: Time): Unit = { | |
printf("t1: %s, t2: %s, before: %s\n", this, other, this.before(other)) | |
} | |
override def toString = "" + hours + ":" + minutes | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1: Time = 1:23 | |
t2: Time = 1:55 | |
t3: Time = 1:55 | |
t4: Time = 1:56 | |
t5: Time = 2:4 | |
t1: 1:23, t2: 1:55, before: true | |
t1: 1:55, t2: 1:23, before: false | |
t1: 1:23, t2: 1:55, before: true | |
t1: 1:55, t2: 1:23, before: false | |
t1: 1:23, t2: 1:56, before: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val t1 = new Time(1, 23) | |
val t2 = new Time(1, 55) | |
val t3 = new Time(1, 55) | |
val t4 = new Time(1, 56) | |
val t5 = new Time(2, 4) | |
for (pair <- List(t1, t2, t3, t4, t5).combinations(2)) { | |
pair(0).check(pair(1)) | |
pair(1).check(pair(0)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'tbruckhaus' | |
class ThousandDigitFibonacciNumber: | |
""" | |
1000-digit Fibonacci number | |
Problem 25 | |
The Fibonacci sequence is defined by the recurrence relation: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[project_euler] time python p025_thousand_digit_fibonacci_number.py 9:08:32 ☁ master ☀ | |
The first term in the Fibonacci sequence to contain 1000 digits is 4782 | |
python p025_thousand_digit_fibonacci_number.py 0.06s user 0.02s system 68% cpu 0.118 total | |
[project_euler] 9:08:46 ☁ master ☀ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def in_words(i): | |
d = NumberLetterCounts.NUMBER_WORDS | |
words = '' | |
if i >= 1000: | |
thousands = i / 1000 | |
i %= 1000 | |
words = d[thousands] + " thousand" | |
if i > 0: | |
words += " " | |
if i >= 100: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create App | |
rhc app create a myappname -t python-2.6 | |
//Add MongoDB NoSQL Database | |
rhc app cartridge add -a myappname -c add-mongodb-2.0 | |
//Add Upstream Repo | |
cd myappname | |
git remote add upstream -m master git://github.com/openshift/openshift-twt-mongo-demo.git | |
git pull -s recursive -X theirs upstream master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pandigital: | |
def __init__(self, digits): | |
self.p = digits | |
self.N = len(self.p) | |
def find(self, n): | |
for i in range(n - 1): | |
self.step() | |
return self.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val userData = sc.sequenceFile[UserID, UserInfo]("hdfs://...").persist() | |
val events = sc.squenceFile[UserID, LinkInfo](logFileName) | |
val joined = userData.join(events) |
OlderNewer