This file contains hidden or 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
import pytz | |
from pytz import timezone | |
from datetime import datetime,timedelta | |
import time | |
utc = pytz.utc | |
utc.zone | |
eastern = timezone("America/New_York") | |
loc_dt = eastern.localize(datetime.now()) | |
offset = loc_dt.utcoffset() |
This file contains hidden or 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
object App{ | |
def isPalindrome(s: String) = { | |
(for (x <- 0 to s.length/2) yield (s(x) == s(s.length - x - 1))) | |
.reduceLeft((acc,n)=> acc && n) | |
} | |
} |
This file contains hidden or 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 isPalindrome(s): | |
return s[0:len(s)/2] == s[len(s) - len(s)/2:len(s)][::-1] | |
isPalindrome('foof') #true | |
isPalindrome('fooof') #true | |
isPalindrome('fooob') #false | |
isPalindrome('foob') #false |
This file contains hidden or 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 reverse[T](xs: List[T]): List[T] = xs match { | |
case List() => List() | |
case x :: xs1 => reverse(xs1) ::: List(x) | |
} |
This file contains hidden or 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 Queue[T]( | |
private val leading: List[T], | |
private val trailing: List[T] | |
) { | |
/* | |
if leading.isEmpty return a new Queue | |
where trailing is reversed and leading | |
is Nil | |
This file contains hidden or 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
object Monad2{ | |
/* | |
Imagine you have a string name and you want to do a bunch of operations on it | |
but you want to program defensively. In Java this would be implemented as | |
a number of tiered null checks. Scala's Option Monad allows us to do this | |
much more elegantly | |
1. Option can be one of two states Some or None. None covers any states that | |
are not Some in this case ("" , null, Null, Nothing, None"). In pure math terms | |
this is called a Monadic Zero. Operations on Monadic Zero have pretty much |
This file contains hidden or 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
import scala.annotation.tailrec | |
object BinarySearchApp{ | |
def main(args: Array[String]){ | |
val l = List(1,2,4,5,6, 8,9,25,31); | |
println("Hello World!") | |
println(search2(5, l)) | |
println(search2(6, l)) | |
println(search2(7, l)) | |
} |
This file contains hidden or 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
package com.art.samples.inplace_string_reverse; | |
/** | |
* Hello world! | |
* | |
*/ | |
public class App | |
{ | |
/** | |
* @param args | |
*/ |
This file contains hidden or 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
/* | |
Article: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/ | |
The cake pattern is a way to do dependency injection in Scala. | |
Rather than using explicit xml configuration we compose our | |
configurations using a combination of self-typ annotations, traits, | |
and companion objects. | |
self-type Annotation | |
==================== |
This file contains hidden or 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
/* | |
Assignment compatibilty has several dimensions. The object type and the | |
type of its parameters. Type parameters can be covariant the object type | |
cannot. What's the difference? Covariant parameters allow subclassing. | |
Defintions: | |
========== | |
covariant: converting from wider(Animals) to narrower(Cats) | |
contravariant: converting from narrower to wider Triangles->shapes | |
invariant: not able to convert |
OlderNewer