mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2024-12-25 06:18:58 +01:00
changed prism colors
This commit is contained in:
parent
31c106c58e
commit
859c1d81b7
@ -12,13 +12,15 @@ This is the repository for my personal blog/website [rickvanlieshout.com](https:
|
||||
|
||||
- hide mode toggler
|
||||
- hide "all articles" link in posts
|
||||
- hide menu
|
||||
- hide social buttons
|
||||
- change "header title"
|
||||
|
||||
- Change theme of prism.js
|
||||
- "time to read" (https://www.gatsbyjs.com/plugins/gatsby-remark-reading-time/)
|
||||
<!-- migrations -->
|
||||
- migrate resume
|
||||
- migrate projects
|
||||
- migrate some example blogs
|
||||
- migrate blogs
|
||||
|
||||
<!-- optional stuff -->
|
||||
|
||||
|
145
content/posts/2022/scala-day-4-a-challenge.md
Normal file
145
content/posts/2022/scala-day-4-a-challenge.md
Normal file
@ -0,0 +1,145 @@
|
||||
---
|
||||
title: Scala Day 4 - A challenge!
|
||||
date: "2017-04-05"
|
||||
template: "post"
|
||||
draft: false
|
||||
slug: "slsw-day4"
|
||||
category: "Development"
|
||||
tags:
|
||||
- "Development"
|
||||
- "slsw"
|
||||
description: "The last day of my journey with Scala is said to be a challenge"
|
||||
# socialImage: "/media/42-line-bible.jpg"
|
||||
---
|
||||
|
||||
The book doesn't offer a day 4, my school, however, does. Or rather, it wants us to "create" a day 4. The main objective of day 4 is to "create a [smart](https://en.wikipedia.org/wiki/SMART_criteria) goal which fits the language and challenges you". For this purpose I came up with the following goal:
|
||||
|
||||
> For the "4th" day in the "Seven Languages in Seven Weeks" book, I want to create a sitemap builder which prioritises URLs based on their number of occurrences.
|
||||
|
||||
I picked this specific goal because Scala has awesome functionality for collections, as such it should make creating a site map a piece of cake! All the code I created for this fourth day can be found on [Github](https://github.com/Mastermindzh/Seven-Languages-in-Seven-Weeks/blob/master/Scala/Day%204/src/main/scala-2.12/MyApp.scala) or at the end of this blog post.
|
||||
|
||||
## My journey with Scala (and the book...)
|
||||
|
||||
Scala, for the most part, is pretty ok. The development tools aren't up to par with those of say Java, Python or even .net but with a bit of hassle, we can make do. The Scala collections are wicked though! I've done some really crazy things using the collections already and I'm sure there is more to come. (if anyone ever wants me to write a bit of Scala that is)
|
||||
|
||||
The concurrency chapter was a big failure, the book is old (2010) and covers the older API. This meant that I had to cast aside the book and create the examples with the new API myself. A drag, to say the least.
|
||||
|
||||
As far as functional goes, my opinion hasn't changed much. I still prefer OO, maybe because I grew up doing everything the OO way or maybe because functional programming is just not for me. Whatever the case I still prefer OO. But.... I've gained a new appreciation for the functional languages so I guess you could call this experiment a success.
|
||||
|
||||
Anyways, that was it for me guys, hope you enjoyed and see you later!
|
||||
|
||||
```scala
|
||||
import java.io.{File, PrintWriter}
|
||||
|
||||
import scala.collection.immutable.ListMap
|
||||
import scala.io.Source
|
||||
|
||||
object PageLinkLoader {
|
||||
//I stole this regex from somewhere for a previous project, don't remember where
|
||||
|
||||
// regex commented out because pretify can't handle it
|
||||
//val hrefRegex = """<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1""".r
|
||||
|
||||
// merge two maps
|
||||
def mergeMap[A, B](ms: List[Map[A, B]])(f: (B, B) => B): Map[A, B] =
|
||||
(Map[A, B]() /: (for (m <- ms; kv <- m) yield kv)) { (a, kv) =>
|
||||
a + (if (a.contains(kv._1)) kv._1 -> f(a(kv._1), kv._2) else kv)
|
||||
}
|
||||
|
||||
// run through all links on a page and add them to a list
|
||||
def getLinks(url: String, urls : Map[String, Int], visited : List[String] = List[String]()) : Map[String, Int] = {
|
||||
|
||||
val content = Source.fromURL(url)(io.Codec("ISO-8859-1")).mkString
|
||||
val links = hrefRegex.findAllIn(content).matchData.toList.map(_.group(2).toString)
|
||||
|
||||
// filter out / , # , http://url and anything else not starting with http:// or www.
|
||||
val filteredList = links.filter(
|
||||
l => l.startsWith("/") ||
|
||||
l.startsWith("#") ||
|
||||
l.startsWith(url) ||
|
||||
l.contains(url.replace(url.split("/").last, ""))
|
||||
)
|
||||
|
||||
// create new mutable list and fill with visited
|
||||
var newVisited = scala.collection.mutable.ListBuffer.empty[String]
|
||||
newVisited ++= visited.filter(p => !p.equals(url))
|
||||
|
||||
//add to newVisited
|
||||
filteredList.foreach(s => {
|
||||
if(!newVisited.contains(s)){
|
||||
newVisited += s
|
||||
}
|
||||
})
|
||||
|
||||
// convert list to map, count occurrences
|
||||
val foldedLinks = filteredList.foldLeft(Map[String, Int]())((map, link : String) =>
|
||||
map + (link -> links.count(_.equals(link)))
|
||||
)
|
||||
|
||||
newVisited = newVisited.filter(s => !s.equals(url))
|
||||
|
||||
if(newVisited.isEmpty){
|
||||
// return merged map
|
||||
mergeMap(List(urls, foldedLinks))((v1, v2) => v1 + v2)
|
||||
}else{
|
||||
getLinks(newVisited(0),mergeMap(List(urls, foldedLinks))((v1, v2) => v1 + v2), newVisited.toList)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object MyApp extends App{
|
||||
|
||||
val urls = List(
|
||||
"http://servers.rickvanlieshout.com/scalatest"
|
||||
)
|
||||
|
||||
def getSiteMap() = {
|
||||
|
||||
var siteMap : Map[String, Int] = Map[String, Int]()
|
||||
|
||||
for (url <- urls) {
|
||||
siteMap = PageLinkLoader.getLinks(url, siteMap)
|
||||
siteMap.foreach (x => println (x._1 + "-->" + x._2))
|
||||
createSiteMap(url, siteMap)
|
||||
}
|
||||
}
|
||||
|
||||
// creates a sitemap, uses Java which is wicked.
|
||||
def createSiteMap(url: String, urls : Map[String, Int]) = {
|
||||
// start off with a priority of 1.0 (ranges from 1.0 to 0)
|
||||
var currentPriority = 1.0
|
||||
|
||||
//sort descending
|
||||
val descUrls = ListMap(urls.toSeq.sortWith(_._2 > _._2):_*)
|
||||
|
||||
// write to a file called "sitemap_for_domain.txt"
|
||||
val domainRegex = """^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)""".r
|
||||
val pw = new PrintWriter(new File("sitemap_for_"+domainRegex.findAllIn(url).matchData.toList.map(_.group(1)).mkString+".txt" ))
|
||||
//write xml header
|
||||
pw.write("\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">")
|
||||
|
||||
// for each url write an url block with priority, then decrease priority
|
||||
descUrls.foreach(s => {
|
||||
pw.write(
|
||||
"\n<url>\n " +
|
||||
"<loc>" + s._1 + "</loc>\n" +
|
||||
"<priority>" + currentPriority + "</priority>" +
|
||||
"</url>"
|
||||
)
|
||||
// decrease priority if possible
|
||||
if(currentPriority >= 0.1){
|
||||
currentPriority -= 0.1
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// write the closing statement for a sitemap
|
||||
pw.write("\n</urlset>")
|
||||
pw.close()
|
||||
}
|
||||
|
||||
getSiteMap()
|
||||
|
||||
}
|
||||
```
|
@ -1 +1,3 @@
|
||||
import "./src/assets/scss/main.scss";
|
||||
import "./src/assets/scss/prism/github.scss";
|
||||
import "./src/assets/scss/prism/prism-tomorrow.scss";
|
||||
|
@ -1,4 +1,3 @@
|
||||
@charset "UTF-8";
|
||||
|
||||
@import "base/generic";
|
||||
@import "base/prism";
|
||||
|
@ -1,117 +0,0 @@
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: #657b83;
|
||||
font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
|
||||
font-size: 1em;
|
||||
-ms-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-webkit-hyphens: none;
|
||||
hyphens: none;
|
||||
line-height: 1.5;
|
||||
-o-tab-size: 4;
|
||||
-moz-tab-size: 4;
|
||||
tab-size: 4;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-break: normal;
|
||||
word-spacing: normal;
|
||||
word-wrap: normal;
|
||||
}
|
||||
|
||||
pre[class*="language-"] {
|
||||
border-radius: 0.3em;
|
||||
margin: 0.5em 0;
|
||||
overflow: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
background-color: #fdf6e3;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"] {
|
||||
border-radius: 0.3em;
|
||||
padding: 0.1em;
|
||||
}
|
||||
|
||||
code[class*="language-"] ::-moz-selection,
|
||||
code[class*="language-"]::-moz-selection,
|
||||
pre[class*="language-"] ::-moz-selection,
|
||||
pre[class*="language-"]::-moz-selection {
|
||||
background: #073642;
|
||||
}
|
||||
|
||||
code[class*="language-"] ::selection,
|
||||
code[class*="language-"]::selection,
|
||||
pre[class*="language-"] ::selection,
|
||||
pre[class*="language-"]::selection {
|
||||
background: #073642;
|
||||
}
|
||||
|
||||
.token.cdata,
|
||||
.token.comment,
|
||||
.token.doctype,
|
||||
.token.prolog {
|
||||
color: #93a1a1;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #586e75;
|
||||
}
|
||||
|
||||
.namespace {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.boolean,
|
||||
.token.constant,
|
||||
.token.deleted,
|
||||
.token.number,
|
||||
.token.property,
|
||||
.token.symbol,
|
||||
.token.tag {
|
||||
color: #268bd2;
|
||||
}
|
||||
|
||||
.token.attr-name,
|
||||
.token.builtin,
|
||||
.token.char,
|
||||
.token.inserted,
|
||||
.token.selector,
|
||||
.token.string,
|
||||
.token.url {
|
||||
color: #2aa198;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
background: #eee8d5;
|
||||
color: #657b83;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.token.atrule,
|
||||
.token.attr-value,
|
||||
.token.keyword {
|
||||
color: #859900;
|
||||
}
|
||||
|
||||
.token.class-name,
|
||||
.token.function {
|
||||
color: #b58900;
|
||||
}
|
||||
|
||||
.token.regex,
|
||||
.token.important,
|
||||
.token.variable {
|
||||
color: #cb4b16;
|
||||
}
|
||||
|
||||
.token.bold,
|
||||
.token.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
131
src/assets/scss/prism/github.scss
Normal file
131
src/assets/scss/prism/github.scss
Normal file
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* GHColors theme by Avi Aryan (http://aviaryan.in)
|
||||
* Inspired by Github syntax coloring
|
||||
*/
|
||||
[data-theme="light"] {
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: #393A34;
|
||||
direction: ltr;
|
||||
font-family: Consolas, Bitstream Vera Sans Mono, Courier New, Courier, monospace;
|
||||
font-size: .9em;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
line-height: 1.2em;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-break: normal;
|
||||
word-spacing: normal;
|
||||
}
|
||||
|
||||
pre>code[class*="language-"] {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
pre[class*="language-"]::-moz-selection,
|
||||
pre[class*="language-"] ::-moz-selection,
|
||||
code[class*="language-"]::-moz-selection,
|
||||
code[class*="language-"] ::-moz-selection {
|
||||
background: #b3d4fc;
|
||||
}
|
||||
|
||||
pre[class*="language-"]::selection,
|
||||
pre[class*="language-"] ::selection,
|
||||
code[class*="language-"]::selection,
|
||||
code[class*="language-"] ::selection {
|
||||
background: #b3d4fc;
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
background-color: #fff;
|
||||
border: 1px solid #dddddd;
|
||||
margin: .5em 0;
|
||||
overflow: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre)>code[class*="language-"] {
|
||||
background: #f8f8f8;
|
||||
border: 1px solid #dddddd;
|
||||
padding: .2em;
|
||||
padding-bottom: 1px;
|
||||
padding-top: 1px;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: #999988;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.namespace {
|
||||
opacity: .7;
|
||||
}
|
||||
|
||||
.token.string,
|
||||
.token.attr-value {
|
||||
color: #e3116c;
|
||||
}
|
||||
|
||||
.token.punctuation,
|
||||
.token.operator {
|
||||
color: #393A34;
|
||||
/* no highlight */
|
||||
}
|
||||
|
||||
.token.entity,
|
||||
.token.url,
|
||||
.token.symbol,
|
||||
.token.number,
|
||||
.token.boolean,
|
||||
.token.variable,
|
||||
.token.constant,
|
||||
.token.property,
|
||||
.token.regex,
|
||||
.token.inserted {
|
||||
color: #36acaa;
|
||||
}
|
||||
.token.tag,
|
||||
.token.selector {
|
||||
color: #00009f;
|
||||
}
|
||||
|
||||
.token.atrule,
|
||||
.token.keyword,
|
||||
.token.attr-name,
|
||||
.language-autohotkey .token.selector {
|
||||
color: #00a4db;
|
||||
}
|
||||
|
||||
.token.function,
|
||||
.token.deleted,
|
||||
.language-autohotkey .token.tag {
|
||||
color: #9a050f;
|
||||
}
|
||||
|
||||
.language-autohotkey .token.keyword {
|
||||
color: #00009f;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.function,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
}
|
124
src/assets/scss/prism/prism-tomorrow.scss
Normal file
124
src/assets/scss/prism/prism-tomorrow.scss
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
|
||||
* Based on https://github.com/chriskempson/tomorrow-theme
|
||||
* @author Rose Pritchard
|
||||
*/
|
||||
[data-theme="dark"] {
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
background: none;
|
||||
color: #ccc;
|
||||
font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
|
||||
font-size: 1em;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
line-height: 1.5;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-break: normal;
|
||||
word-spacing: normal;
|
||||
word-wrap: normal;
|
||||
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
margin: .5em 0;
|
||||
overflow: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
background: #2d2d2d !important;
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre) > code[class*="language-"] {
|
||||
border-radius: .3em;
|
||||
padding: .1em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.block-comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.token.tag,
|
||||
.token.attr-name,
|
||||
.token.namespace,
|
||||
.token.deleted {
|
||||
color: #e2777a;
|
||||
}
|
||||
|
||||
.token.function-name {
|
||||
color: #6196cc;
|
||||
}
|
||||
|
||||
.token.boolean,
|
||||
.token.number,
|
||||
.token.function {
|
||||
color: #f08d49;
|
||||
}
|
||||
|
||||
.token.property,
|
||||
.token.class-name,
|
||||
.token.constant,
|
||||
.token.symbol {
|
||||
color: #f8c555;
|
||||
}
|
||||
|
||||
.token.selector,
|
||||
.token.important,
|
||||
.token.atrule,
|
||||
.token.keyword,
|
||||
.token.builtin {
|
||||
color: #cc99cd;
|
||||
}
|
||||
|
||||
.token.string,
|
||||
.token.char,
|
||||
.token.attr-value,
|
||||
.token.regex,
|
||||
.token.variable {
|
||||
color: #7ec699;
|
||||
}
|
||||
|
||||
.token.operator,
|
||||
.token.entity,
|
||||
.token.url {
|
||||
color: #67cdcc;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
color: #008000;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user