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.
extension UIViewController { | |
func performSegue<T:RawRepresentable where T.RawValue==String>(identifier: T, sender: AnyObject?) | |
self.performSegueWithIdentifier(identifier.rawValue, sender: sender) | |
} | |
} |
/* | |
The back of the card is rotated 180 degrees from the card itself, giving | |
the illusion that it really is the back! Unfortunately hiding the back | |
face of both "faces" doesn't work with webkit builds (requires Snow Leopard!) | |
but we set it anyway. | |
*/ | |
.card #back { -webkit-transform: rotateY(180deg); } | |
.card .face { -webkit-backface-visibility: hidden; } | |
/* |
self: super: { | |
spotify = let | |
deps = with super.pkgs; [ | |
alsaLib | |
atk | |
cairo | |
cups | |
curl | |
dbus | |
expat |
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
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) | |
)) |
; Functions can be seen as endomorphisms, hence they are a monoid, which is available | |
; in the reducers library! | |
(use '[clojure.core.reducers :as reducers :only (monoid)]) | |
(def FunctionMonoid | |
(reducers/monoid | |
comp ; append | |
(fn [] (fn [v] v)))) ; zero | |
; Here is a function that, given a boolean, returns another function that | |
; will either return the function f passed to it, or m-zero. The former happens |