1. 2

    I’ve used these with the encoding/json package but never knew what they were called or how they worked. Awesome!

    1. 2

      I think the URL needs #fn2 removing to link to the top of the post - confused me starting at the bottom as I didn’t realise I wasn’t at the top of the page initially.

      1. 2

        Thanks for the report but looks like I can’t change that.

        1. 3

          I’ve removed it. Thanks, @caius.

        1. 2

          What existing standard is JMAP competing with? The only protocol I’m aware of that already does what JMAP proposes is Exchange ActiveSync, which is proprietary and Microsoft charges a licensing fee for even clients to implement it.

        1. 2

          Last week I got really stuck into my home automation stuff by writing a DHT11/22 server for Raspberry Pi’s in Golang with quite specific requirements for the behaviour. I wanted it to poll the sensor a couple of times a minute for a reading & cache the latest reading for up to a minute (the sensors aren’t the most reliable!) Exposing that cached reading over HTTP as JSON. Turned out to be quite a nice problem to write in golang, the sensor stuff is all encapsulated in it’s own goroutine emitting readings to a channel, and the webserver handles expiring the latest reading & serving it until that point. Even managed to write some tests as part of it.

          This week is hopefully getting my Digistump Oak‘s hooked up to some more DHT22’s to spread around the house. And a lot of DIY, lots of things sat waiting to be either put up on walls or build from flatpack. Must get that done to reclaim some space.

          1. 1

            I expected this to be a post about BashHub, who I think we’ve linked before from lobsters. I must admit I’d trust this solution a bit more than a company trying to make a profit from centralising shell history. 🙂

            1. 7

              Spent the weekend getting things hacked together for a first foray into a “smart, connected” home via Apple’s Homekit. Hooked up a DHT11 to a Raspberry Pi for temperature/humidity (via this server), and also got control of some 433mhz-controlled sockets (via this server). This is all wired into the Homekit system via homebridge running in a SmartOS Zone.

              It mostly seems to work. A couple of friends have pointed out nodered which looks to remove some of the wiring up work I’ve been doing with http/python so far. Going to check that out this week I think.

              Work on the blood pressure “calculator” iOS app stalled in favour of the homekit stuff, I’ve figured out the behaviour I want from the table rows being tapped (& I also finally understand the highlighted/selected state of UITableViewCells.) Next steps are wiring up the number picker (keyboard) to adjust values in a row, and adding UI to show the averaged result.

              1. 4

                Spent last week clearing my garage out some more and picked up a weight bench & some free weights. Done one session in there so far and could do with some more 5kg plates but mostly I just need to continue lifting. Injured my foot (I think I kicked the bed, but I can’t remember specifically doing it. No cycling till that heals irritatingly.)

                I’ve recently been fed up with recording my blood pressure, as the recommended way to do it is to take three readings a minute apart and record the average of the three results. This means writing down three values and averaging them, to then go enter them into Healthkit on my phone. (Already massively lean on Apple’s ecosystem, one more thing can’t harm.)

                Got bored of doing that, couldn’t find an app that did it for me, so sat down at the weekend and started writing my own. Ended up working out how to present a keyboard when a label is tapped (labelpicker is that test project), and BPCalc is the main app’s repo. This week will be hooking up the data entry, and adding the calculation. Also want it to be able to save straight to the health store for me but that might be next week’s task.

                1. 1

                  I remember taking a look at it when it first came out (I worked at Brightbox at the time, whilst we were laying the foundation for the cloud product) and thinking it looked like something designed by committee rather than something solving discrete problems properly. Not seen anything since to change my opinion of it.

                  1. 3

                    Continuing work on improving my home setup, solved consistent image versions last week (using the last modified date of the folder containing the packer configuration for that particular image). This week I need to polish those base images to make sure they come up successfully & can pull/apply my masterless puppet git repo to themselves. Then begins the slow rebuild of the ~15 zones I have that I want to be managed by puppet. Some of them were hand built, others built from a puppetmaster so will be easier to port as I’ve got puppet configuration for them already.

                    Also been given a Digital Oscilloscope by a friend, so I can investigate what signals my treadmill is sending from the headunit to the motor board, and attempt to replace it with a network-connected controller I can program. Intending on being able to collect stats from it (you walked for x duration at y average speed) for tracking purposes, as well as being able to start/stop/change speed on it from my terminal - I use it as a walking desk so I’ve already got a machine on it with terminal running.

                    1. 2

                      In what other languages would it be possible?

                      I guess everything with properties (functions disguised as fields) so D, C#, etc.

                      Afaik not with C, C++, or Java.

                      1. 26
                        #define a (++i)
                        int i = 0;
                        
                        if (a == 1 && a == 2 && a == 3)
                            ....
                        
                        1. 1

                          Isn’t that undefined behavior? Or is && a sequence point?

                          1. 3

                            && and || are sequence points. The right expression may never happen depending on the result of the left, so it would make things interesting if they weren’t.

                        2. 10

                          This is very easy to do in C++.

                          1. 5

                            You can also do it with Haskell.

                            1. 3

                              Doable with Java (override the equals method), and as an extension, with Clojure too:

                              (deftype Anything []
                                Object
                                (equals [a b] true))
                              
                              (let [a (Anything.)]
                                (when (and (= a 1) (= a 2) (= a 3))
                                  (println "Hello world!")))
                              

                              Try it!

                              Or, inspired by @zge above:

                              (let [== (fn [& _] true)
                                    a 1]
                                (and (== a 1) (== a 2) (== a 3)))
                              
                              1. 3

                                Sort of. In Java, == doesn’t call the equals method, it just does a comparison for identity. So

                                 a.equals(1) && a.equals(2) && a.equals(3); 
                                

                                can be true, but never

                                 a == 1 && a == 2 && a == 3;
                                
                              2. 3

                                perl can do it very simply

                                my $i = 0;
                                sub a {
                                	return ++$i;
                                }
                                
                                if (a == 1 && a == 2 && a == 3) {
                                	print("true\n");
                                }
                                
                                1. 2

                                  Here is a C# version.

                                  using System;
                                  
                                  namespace ContrivedExample
                                  {
                                      public sealed class Miscreant
                                      {
                                          public static implicit operator Miscreant(int i) => new Miscreant();
                                  
                                          public static bool operator ==(Miscreant left, Miscreant right) => true;
                                  
                                          public static bool operator !=(Miscreant left, Miscreant right) => false;
                                      }
                                  
                                      internal static class Program
                                      {
                                          private static void Main(string[] args)
                                          {
                                              var a = new Miscreant();
                                              bool broken = a == 1 && a == 2 && a == 3;
                                              Console.WriteLine(broken);
                                          }
                                      }
                                  }
                                  
                                  1. 2

                                    One of the ‘tricks’ where all a’s are different Unicode characters is possible with Python and Ruby. Probably in Golang too.

                                    1. 7

                                      In python, you can simply create class with __eq__ method and do whatever you want.

                                      1. 4

                                        Likewise in ruby, trivial to implement

                                        a = Class.new do
                                          def ==(*)
                                            true
                                          end
                                        end.new
                                        
                                        a == 1 # => true
                                        a == 2 # => true
                                        a == 3 # => true
                                        
                                    2. 2

                                      In Scheme you could either take the lazy route and do (note the invariance of the order or ammount of the operations):

                                      (let ((= (lambda (a b) #t))
                                             (a 1))
                                        (if (or (= 1 a) (= 2 a) (= 3 a))
                                            "take that Aristotle!"))
                                      

                                      Or be more creative, and say

                                      (let ((= (lambda (x _) (or (map (lambda (n) (= x n)) '(1 2 3)))))
                                              (a 1))
                                          (if (or (= 1 a) (= 2 a) (= 3 a))
                                              "take that Aristotle!"))
                                      

                                      if you would want = to only mean “is equal to one, two or three”, instead of everything is “everything is equal”, of course only within this let block. The same could also be done with eq?, obviously.

                                      1. 1

                                        Here is a Swift version that uses side effects in the definition of the == operator.

                                        import Foundation
                                        
                                        internal final class Miscreant {
                                            private var value = 0
                                            public static func ==(lhs: Miscreant, rhs: Int) -> Bool {
                                                lhs.value += 1
                                                return lhs.value == rhs
                                            }
                                        }
                                        
                                        let a = Miscreant()
                                        print(a == 1 && a == 2 && a == 3)
                                        
                                        1. 5

                                          Had an idea at the weekend, instead of building base images for my standalone SmartOS hypervisors by hand I could lean on packer via the Joyent public cloud. Does the same thing, and costs a few cents per image build. Given I’ll build one of these per quarter most likely, I can live with the cost 😆

                                          Once that’s done, then I just need to move everything on the home server across to a new supported base image and make sure puppet is managing what it needs to on there. Sounds an awful lot like work to me 🤔

                                          1. 10

                                            More like “LinkedIn Considered Harmful”, amirite.

                                            1. 2

                                              Finally decided having a push-based masterless puppet setup was a bit silly, and am now switching it around to be a pull-based one. Yet more shell scripts to maintain, but at least it’s less effort to push changes out across my nodes now. (Also had the bright idea to use bash to install puppet, then use puppet to setup the masterless puppet stuffs properly. Two stage bootstrap ftw.)

                                              Making plans for the next few weeks as well. Lots of DIY in the house to complete, and I’ve made decisions on a couple of things so I can stop stalling and just crack on with it. Also decided that ProjectBMW is going to be sold this year, and I want an MX-5 again. Maybe even an NC, although I still think they’re the worse looking of all generations.

                                              1. 5

                                                Related story about ADSL over a wet string: https://lobste.rs/s/qi8nhd/adsl_works_over_wet_string

                                                1. 3

                                                  Attempting to talk myself out of writing an RSS feed server. I’ve previously tried a couple of paid-for services and found issues with them (at the time, haven’t re-evaluated), and also tried out a mac feed app I love but the sync service has issues and the support team just goes quiet on them (Majorly sad about that.) Tried out ttrss but found it doesn’t do things I consider essential, like importing an OPML of feeds. I don’t want to write a feed server, but I can’t find anything to solve my problem. (Decent fetcher/parser, OPML import, supports fever API. Probably doesn’t expose a web reader interface.)

                                                  Finally got to a place that I’m happy with my hetzner box(es). En-mass migrated from the slower box to the faster box & cancelled the slower one. (Moving VMs between SmartOS hyps is pretty simple. Yay ZFS.) Got the usual LAMP stack setup to run my stuff, split out nicely enough and managed with puppet where appropriate. Also stuck a load-balancer on the public IP, so internally different things can run in isolated zones without using up more IPs. Simples ;-)

                                                  Also spent yesterday hiking up the Wrekin (Big hill in Shropshire UK) in the snow, then building a snow-woman larger than me & an igloo with the kids in the garden. First decent snow we’ve had in 7 years, gotta make the most of that.

                                                  1. 7

                                                    I have been using ttrss for a few years now without a problem, mostly for webcomics and news. There is actually an OPML importer from the preferences menus

                                                    1. 1

                                                      Ah useful to know, thanks

                                                    2. 5

                                                      I like RSS (and ATOM) themselves (sure they could be improved, but there are enough semi-documented versions as it is!) but I think the tooling suffers from a lot of not-invented-here syndrome and/or lack of UNIX-style “do one thing well”.

                                                      For example, my current setup converts RSS posts to maildir messages. There are loads of tools to do this which will periodically check a URL and convert any new posts they find. Not only is this redundant (cron can execute commands periodically and curl can fetch URLs), but the only compelling feature of these tools (their conversion algorithm) can (AFAIK) only be invoked on URLs; yet I also have RSS files I’d like to convert. At one point I was firing up a local web server to make these files available to these tools, but I found this so ridiculous I eventually decided to just fork ‘feed2maildir’ and rip out all of its “features” to get a standalone rss-to-maildir converter.

                                                      1. 1

                                                        I like RSS (and ATOM) themselves (sure they could be improved, but there are enough semi-documented versions as it is!) but I think the tooling suffers from a lot of not-invented-here syndrome and/or lack of UNIX-style “do one thing well”.

                                                        Thanks for posting this, I’ve been thinking about it on and off since you mentioned it and finally came up with a pipeline using smaller tools I prefer to just a single binary that does everything backed by a single db. I guess this means I’m writing a feed server. :->

                                                    1. 9

                                                      AdventOfCode!

                                                      OK, it’s only a small part of the week, but it is fun.

                                                      1. 2

                                                        Thanks for the reminder, I’d completely forgotten about it.

                                                        1. 3

                                                          I’m in smug mode because today’s problem only took me 11 minutes. I would have been on the leaderboard if I’d actually got up at 5am!

                                                          (We’ll gloss over the days that have taken me hours of head scratching :) )

                                                          1. 1

                                                            That leaderboard seems a bit silly. Perhaps they should be timing it from the moment that a particular user first loads the page, although that’s cheatable too.

                                                            1. 1

                                                              Yeah, there’s really no way to make it work that can’t be gamed. Personally, I’m happy to noodle about solving the puzzles without worrying about the leaderboard. Not getting up at 5am is something of an incentive…

                                                        2. 2

                                                          I’m in the lead on my private leaderboard, so the pressure’s on to keep it!

                                                          AoC is definitely one of my favorite things :)

                                                          1. 2

                                                            Having lots of fun with it myself too. Really getting to learn what D can do:

                                                            http://inversethought.com/hg/aoc/file/tip/2017/

                                                            1. 1

                                                              Cool that you’re learning it since it doesn’t get much attention. I’d be interested in your impressions of it by the end on top of what language background you came from before D.

                                                          1. 2

                                                            Picked up a second Hetzner box to replace the first (couple of € more a month for double the ram, seemed rude not to.) So now I’m migrating the handful of SmartOS zones I had running on the old one across to the new one. (Having migrated 400+ zones in the last few months with my team at work, I’m rather used to doing this. Tedious & time consuming more than anything!)

                                                            1. 4

                                                              The security patch for it just dropped - https://support.apple.com/en-gb/HT208315

                                                              1. 3

                                                                I’m over at @Caius@scotland.computer when I remember to update it. Really should hook the bird site up to it, not that I remember to post there much either.