I found a post about suspending and then going into hibernate that included a really clever script. Turns out that with NixOS this is even esaier to coordinate as you have systemd so can have a before
and after
service. I just include this in my /etc/nixos/configuration.nix
file and nixos-rebuild
; then a systemctl suspend
or a close of the lid will cause the hibernate timer to be set.
self: super: { | |
spotify = let | |
deps = with super.pkgs; [ | |
alsaLib | |
atk | |
cairo | |
cups | |
curl | |
dbus | |
expat |
In my last post I took a piece of imperative code for parsing a comma separated string and generating an instance of a structure, and turned it into a functional piece. At the end we had a bunch of functions that related to code working with Optional
, some related to Array
, and a bunch that dealt with the actual application code. The "top level" functions we've written looked like this:
func build(fields: Array<String>) -> Optional<MyRecord> {
let field1Value = fields[0]
let field2Value = lift(stringToInt)(fields[1])
return .Some(createMyRecord) <*> field1Value <*> field2Value
}
func build(data: String) -> Optional<MyRecord> {
I’ve been writing a load of Swift code recently for work and this has lead me into the world of typed functional programming. The app needs to build certain objects from a comma separated string, and this lead me to applicative functors, which lead me to brain ache but enlightenment. So here’s my thoughts on how I got to understand these a little better.
All of the code is in Swift, so less clean than Haskell. I’m also only a about 6 weeks into Swift development so I probably haven’t got all of the idioms right. I’ve avoided the optional shorthand wherever possible here, preferring Optional<Type>
over Type?
because I believe the latter is hiding something that helps understand this code in the context of other generic classes.
It’s also long! I think it’s probably the longest blog post I’ve ever written but I found it interesting and useful, for myself, to write. If you’re one of those people who skip to the end of a book to find out whodunit then I’ve included
extension UIViewController { | |
func performSegue<T:RawRepresentable where T.RawValue==String>(identifier: T, sender: AnyObject?) | |
self.performSegueWithIdentifier(identifier.rawValue, sender: sender) | |
} | |
} |
I hereby claim:
- I am mattdenner on github.
- I am mattdenner (https://keybase.io/mattdenner) on keybase.
- I have a public key whose fingerprint is 7177 7706 1497 3A2C B930 3921 E120 A382 2201 460F
To claim this, I am signing this object:
never even more words you jim up before but hanner's the eye. this unfortunate to | |
going to grand to the foot of the better. gimme a sheep story.valuable information. a will | |
give her innocence and fever. don't ever find out he said he allowed they'd think | |
you consent from my dear to see nothing if you studied avoidance spoke well does | |
up with kitty. as a rock. from it. you've got ityou hear a resemblance of | |
never in the weighted by the light now in about what this line a and | |
going to bust out of advantage for avoiding mrs. bennet i shall not quitted me would | |
let it individually to see another voice of about dead if they were at them | |
you had the accomplishment of one great deduction which end in ignorance and cast off | |
down off mr. collins. from my present moment i flatter myself to a brother i |
; The Sieve of Eratosthenes | |
; | |
; This is a simple example of how to calculate prime numbers. | |
; | |
; Typically the algorithm is described as making a list of numbers from 2 until the maximum number you | |
; want to test for primality(?). You then take the first number that hasn't been crossed off (2 at this | |
; point), and cross off all of the numbers in the list that are multiples of it. Then you repeat for the | |
; next number that hasn't been crossed off. At the end all of the numbers that have not been crossed off | |
; are prime. | |
; |
; Two infinite sequences of repeating pattern. | |
(def threes (lazy-cat [nil nil "fizz"] threes)) | |
(def fives (lazy-cat [nil nil nil nil "buzz"] fives)) | |
; A lazy sequence of "fizz", "buzz", "fizzbuzz" or nil | |
(def fizz-buzz-ing (map (fn [t f] (let [s (str t f)] (if-not (empty? s) s))) threes fives)) | |
; A lazy sequence of "fizz", "buzz", "fizzbuzz" or a number (starts at 1) | |
(def fizz-buzz (map (fn [f v] (or f v)) fizz-buzz-ing (rest (range)))) |
; My first attempt would have been my typical approach: wrap the function being used in the map. What I dislike, even though | |
; this is my current natural (read "first thing I try normally") is that 'reporter' looks more complicated than I'd like, plus | |
; 'report-progress' knows about the idea of "progress". | |
(defn reporter | |
[report-every f] | |
(fn [val cnt] | |
(let [rv (f val)] | |
(and (zero? (mod cnt report-every)) (println "Done" cnt)) | |
val) | |
)) |