vankuik.nl

Latest weblog entries

2016-05-26 Printing on a Kyocera FS2020D from OS X

Here's how you can install a Kyocera FS2020D printer on OS X.

First, download and install the driver: https://www.kyoceradocumentsolutions.co.uk/index/products/download_centre.false.driver.FS2020D._.EN.html#MAC

While it's downloading, find out the IP address of the printer. On the printer, press the menu button, then arrow right and arrow down. The display should say "status page". Press OK and a single status page is printed. It'll mention a couple of things, but most importantly its IP address.

On OS X, in System Preferences, go to Printers & Scanners, add a printer with the plus button, go to the second tab and fill in the IP address.

kyocera.png

That should be all you have to do. If you wish, adjust the name, then click the Add button.

Happy printing.

2016-05-25 Quote from Philip Morgan

Here's a nice quote from Philip Morgan:

"If you look at your marketing message and say, “wow, there are probably only 10 companies out there that fit that profile”, then you are in the right ballpark in terms of specificity. The reality is that there will be far more than 10 candidates, and those 50 or 100 truly ideal clients will find your marketing extremely compelling. Trust me, they won’t find it compelling if you don’t have the courage to be extremely specific.”

2016-05-24 home shortcut key for Firefox on OS X

If for some reason you are moving from Safari to Firefox on OS X, you might miss the Cmd-Shift-H shortcut key to go to the homepage. On Firefox, this is by default Option-Home but since there's no Home key on Apple keyboards, this becomes the Fn-Option-LeftArrow shortcut which I can never remember.

An alternative is to press Option-K which will bring up the search screen if you have removed the search field from the toolbar. Very useful when you don't want to close the last remaining tab, but want to clear the current page.

2016-05-24 Swift example of CoreData max query

Here's a copy/paste example of doing the equivalent of a SQL MAX() function. I know, I know "CoreData is an object graph". It's in a project where I had to keep track of the sequence in which entities were added. As far as I know, there's no equivalent of AutoIncrement in CoreData.

    func nextSequence(moc: NSManagedObjectContext) -> Int {
        let quantityExpression = NSExpressionDescription()
        quantityExpression.name = "max.sequence"
        quantityExpression.expression = NSExpression(format: "@max.sequence")
        quantityExpression.expressionResultType = .Integer32AttributeType
        
        let predicate = NSPredicate(format: "form == %@", self.form)
        
        let request = NSFetchRequest()
        request.entity = NSEntityDescription.entityForName("UMAQuestion", inManagedObjectContext: moc)
    //  request.propertiesToGroupBy = ["sequence"]
        request.resultType = NSFetchRequestResultType.DictionaryResultType
        request.propertiesToFetch = [quantityExpression]
        request.predicate = predicate
        
        var maxSequence = 0
        
        do {
            let results = try moc.executeFetchRequest(request) as? [[String:AnyObject]]
            if let maxSequenceDict = results!.first {
                if let maxSequenceResult: AnyObject = maxSequenceDict["max.sequence"] {
                    maxSequence = maxSequenceResult as! Int
                } else {
                    fatalError("Couldn't find max.sequence in dict")
                }
            } else {
                fatalError("Didn't get first result")
            }
        } catch let error as NSError {
            fatalError("Error fetching max sequence: \(error)")
        }
        return maxSequence + 1
    }

Paste this in your model file. Adjust the predicate or uncomment and adjust the propertiesToGroupBy.

2016-05-16 Renewing letsencrypt certificates via crontab

Last time, I showed how I installed the LetsEncrypt certificates but not how to automatically renew them. To do so, create a file and call it, say, "letsencrypt.sh" or something, then move it to a directory of your choice. /opt was empty so I put it there. Adapt the webroot and domain parameters of course. This works on Debian 8.0 so your mileage may vary.

  #!/bin/sh
  letsencrypt certonly --force-renewal --webroot -w /var/www/example.com -d example.com
  service apache2 reload

The --force-renewal is there because we renew monthly, while the certs are valid for three months and the client warns about this.

Now create a file in /etc/cron.d so the script gets called. Be sure to not just call it on midnight the 1st of every month -- we want to call it at some particular randomly chosen moment so the letsencrypt people don't get hit with a deluge of calls every 1st of the month. So create a file named "letsencrypt" in /etc/cron.d with the following line:

  33 5 21 * *     root   /opt/letsencrypt.sh

This particular example will call the script on the 33rd minute, on the 5th hour, and on the 21st day of the month. In other words, it'll get called once on 5:33 AM every month. Make up some values for your particular case.

It's prudent to now put a marker after this date in your calendar, to actually check whether the renewal succeeded.

As an aside, the letsencrypt package is called certbot nowadays. It's at version 7. It might be better to follow their instructions :)

More...

Weblog Archive

Weblog entries 2015

Weblog entries 2014

Weblog entries 2013

Weblog entries 2012

Weblog entries 2011

Weblog entries 2010

Weblog entries 2009

Weblog entries 2008

Weblog entries 2007

Weblog entries 2006

Weblog entries 2005

Weblog entries 2004

All weblog entries

Articles

Articles, chronologically (latest first). This is pretty old stuff.

Scribblings

Not yet finished. Maybe will never be finished. Maybe they'll get deleted. Who knows?

Programming:

System administration:

Others:

Files: