Skip to content

Instantly share code, notes, and snippets.

/**
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
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
}
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
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))
}
__author__ = 'tbruckhaus'
class ThousandDigitFibonacciNumber:
"""
1000-digit Fibonacci number
Problem 25
The Fibonacci sequence is defined by the recurrence relation:
[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 ☀
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:
//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
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()
val userData = sc.sequenceFile[UserID, UserInfo]("hdfs://...").persist()
val events = sc.squenceFile[UserID, LinkInfo](logFileName)
val joined = userData.join(events)