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
//read a file and build a concordance list of the tokens in the file | |
//there's gotta be a nicer way to do this | |
def two(fileName:String): Unit = { | |
val scanner = new Scanner(new File(fileName)) | |
val concordanceList = new mutable.HashMap[String, Int]() | |
while(scanner hasNext) { | |
scanner.nextLine() | |
.split(" ") | |
.foreach { | |
word => if(concordanceList contains word) { |
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
//submatrix determination for calculating determinants of matrices | |
def submatrix(i : Int, j : Int, matrix : Array[Array]) = { | |
//returns a new array of size n-1 with the ith index removed | |
def removeIndex(index : Int, arr: Array): Array = { | |
arr | |
.zipWithIndex //what you call if you need an indexed loop | |
.filter{ case (_,index) => index != r } | |
.map { case (value, _) => value } | |
} | |
removeIndex(i , matrix.map{ case row => removeIndex(j, row) } ) |
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 s_mach.string | |
import scala.collection.mutable.ArrayBuffer | |
import scala.util.matching.Regex | |
trait WordSplitter { | |
def split(s: String) : Iterator[String] | |
/** |
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
/** @return string with all occurrences of regex replaced with the paired string returned by supplying the match generated by the regex. Ensures recursive replacements cannot occur. */ | |
def findRegexReplaceMatch( | |
s: String, | |
zomRegex: Seq[(Regex, Match => String)] | |
) : String = { | |
var t = s | |
for((regex, matchingFunc) <- zomRegex) { | |
t = regex.replaceAllIn(t, matchingFunc) | |
} | |
t |
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
val table : Table[Product] = Products.products //this is the DTO | |
private def database(f : => Unit) = { | |
Database.forURL("jdbc:mysql://127.0.0.1:3306/products", driver = "com.mysql.jdbc.Driver") withSession { | |
implicit session => f | |
} | |
} | |
def add(product : Product) = { | |
database {//the compiler complains that there is no implicit session to run this with |
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 findRegexReplaceMatch(s: String, zomRegex: collection.immutable.Seq[(Regex, Match => String)]) : String = { | |
import scala.language.implicitConversions | |
//I really needed the start and end points of a regex match, this makes it less awkward in expressions | |
implicit def match2tuple(m : Match) : (Int, Int) = (m.start, m.end) | |
//detects overlaps in a set of regions. | |
def overlaps(set :scala.collection.mutable.Set[(Int,Int)], region : (Int, Int)) : Boolean = { | |
set.exists { case (begin, end) => | |
region._1 > begin && region._1 < end || | |
region._2 > begin && region._2 < end | |
} |
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
# ! pip install xarray adlfs zarr planetary_computer matplotlib | |
from adlfs import AzureBlobFileSystem | |
import xarray as xr | |
import planetary_computer | |
signed_url = planetary_computer.sign("https://azureopendatastorage.blob.core.windows.net/noaa/conus404.zarr/") | |
_, sas_token = signed_url.split("?", 1) | |
fs = AzureBlobFileSystem(account_name="azureopendatastorage", sas_token=sas_token) | |
ds = xr.open_zarr(fs.get_mapper("az://noaa/conus404.zarr")) | |
ds # In a notebook, print this out to see all 200+ variables |