Skip to content

Instantly share code, notes, and snippets.

View ws909's full-sized avatar
🕳️
Fell into a hole. 3 broken brain cells, and sprained cognitive abilities.

Andreas ws909

🕳️
Fell into a hole. 3 broken brain cells, and sprained cognitive abilities.
  • Norway
View GitHub Profile
@ws909
ws909 / posts.py
Created October 21, 2023 21:19
Community-disputed posts on Stack Overflow
"""
Finds posts where your voting disagreed with the other site members.
Outputs a list of questions that you have downvoted, but have an overall positive score, as well as questions you have upvoted,
which have either been closed, or have an overall negative score.
This information is not available with StacksAPI, unless every single post on the site is iterated through. Is that faster?
If the filtering can be done server-side, or the total amount of data downloaded is smaller, it definitely should be.
One thing is for sure, though: this script is incredibly slow.
@ws909
ws909 / dark-mode-nrk-no.css
Last active April 16, 2023 15:14
Mørkt utseende til www.nrk.no (Dark mode)
body, .kur-house {
background-color: rgb(16, 16, 16);
color: rgb(242, 242, 242) !important;
}
.kur-room--light, .kur-floor--apartment {
background-color: rgb(20, 20, 20);
color: rgb(232, 232, 232);
}
@ws909
ws909 / Swift Arrays using keypaths.md
Last active December 16, 2019 21:14
An example showing how key paths can be useful when programming in Swift

Swift KeyPath example

Ever wondered how key paths can be useful in programming? Let's try to sort arrays, and find items in them, based on properties of the elements, in this case a struct. To do so, we can create a set of generic functions and methods, and use a KeyPath as one of the arguments, specifying the desired property of the elements in the array to process.

First, a filtering function is written. It's a generic function that simply returns a new array containing the elements from a given one, that meet the required condition. It drastically shortens the code needed to write for each case: let s2 = searchFor(property: \String.count, ==, 2, in: ["a", "ab", "abc", "cd"]) // s2 = ["ab", "cd"]

@inline(__always)
func searchFor<Root, Value>(property: KeyPath<Root, Value>, _ condition: (Value, Value) -> Bool, _ value: Value, in array: [Root]) -> [Root] {