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
// repeat char n times | |
function repeat(char, n) { | |
return Array(n + 1).join(char); | |
} |
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 charFrequency(str: String): Map[Char, Int] = { | |
var chars = Map[Char, Int]() | |
for { | |
c <- str | |
if c != ' ' | |
} { | |
chars += (c.toLower -> (chars.getOrElse(c, 0) + 1)) | |
} | |
chars | |
} |
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 mod(m: Int, n: Int) = ((m % n) + n) % n |
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
import com.github.nscala_time.time.Imports._ | |
import org.joda.time.Years | |
def getAge(start: String, end: String): Int = { | |
Years.yearsBetween( | |
new DateTime(start), | |
new DateTime(end) | |
).getYears | |
} |
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 circular[A](as: Seq[A]): Iterator[A] = Iterator.continually(as).flatten |
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 loadResource(filename: String) = { | |
val source = scala.io.Source.fromURL(getClass.getResource(filename)) | |
try source.mkString finally source.close() | |
} |
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
function getNestedProperty(obj, path) { | |
return path.split('.').reduce(function(prev, next) { | |
return prev ? prev[next] : undefined; | |
}, obj); | |
} |
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './App'; | |
import './index.css'; | |
const rootEl = document.getElementById('root'); | |
ReactDOM.render( | |
<App />, | |
rootEl | |
); |
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
const S3 = require('aws-sdk').S3; | |
const fs = require('fs'); | |
const body = fs.createReadStream('./my-file.txt'); | |
const s3 = new S3(); | |
s3.upload({ | |
Bucket: 'my-bucket', | |
Key: 'my-directory/my-file.txt', | |
Body: body |