Thursday, November 16, 2017

Firefox 57 and lost some shortcuts on mac

There was an old plugin called Customizeable Shortcuts that hadn't been updated for while and was not usable with Firefox 57. I was using it to remap the 'search location bar' shortcut.

Since I already use karabiner to remap some modifier keys for macos, it might be able to use it instead of waiting for a new firefox shortcut addon.

Note: If you're confused by the left_option/left_command it's cause I've first remap left_command to left_option.

1) Have a look at some of the examples for karabiner shortcuts
https://pqrs.org/osx/karabiner/complex_modifications/#key_specific

2) Create a json and take note of the path

{
  "title": "Firefox command-d search location",
  "rules": [
    {
      "description": "command-d search location",
      "manipulators": [
        {
          "type": "basic",
          "from": {
              "key_code": "d",
              "modifiers": {
                  "mandatory": ["left_option"],
                  "optional": ["any"]
              }
          },
          "to": [
              {
                "key_code": "l",
                "modifiers": [
                  "left_command"
                ]
              }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "^org\\.mozilla\\.firefox"
              ]
            }
          ]
        }
      ]
    }
  ]
}


I saved this to my desktop with the name firefox-command-d.json

What is going on? frontmost_application_if only runs the above shortcuts if it's the app focused.
bundle_identifiers is your app id that you can find in the plist.

3) Now run enter this in the url bar in firefox: karabiner://karabiner/assets/complex_modifications/import?url=file:///Users//Desktop/firefox-command-d.json

Enable this and you have your remap.

Friday, January 6, 2017

Blurry Font in Firefox after updating to Linux Fedora 25

I recently did a clean update of fedora and found the font to render quite blurry.

What I found out:

1) gnome-tweak-tool font settings do not work. At the time of the post any of the font settings did not make a difference.

2) You may start trying to use font-tweak-tool or font-manager. Be aware that these may create font config files in your ~/ or in ~/.config

These may need to be deleted so that your gnome settings take precedence.

Note: I've installed microsoft and ubuntu fonts for linux.

So what's the fix?

a) Go to Settings > Fonts and change the settings here to Anti Aliasing: rgba and Hinting: full

At this point your terminal should look good.

b) For me, firefox and sublime text had bad looking fonts.

There's a directory in /etc/fonts/conf.d that controls some additional font rendering. It's odd that there's no GUI to modify this directly.

sudo ln -s  /usr/share/fontconfig/conf.avail/10-hinting-full.conf /etc/fonts/conf.d/
sudo rm  /usr/share/fontconfig/conf.avail/10-hinting-slight.conf

Log out and Log back in and things should be clearer.

Wednesday, September 21, 2016

MacOS 10.12 sierra karibiner and seil are broken

After updating to macos sierra it seems seil and karabiner do not work any more. From the official site it looks like it will take a while before the replacement app karabiner-elements is ready for prime time.

https://github.com/tekezo/Karabiner-Elements

1) Start Karibiner and take a screen shot of your current settings. Check off 'Show enabled only'

2) Uninstall seil and karabiner.

I found that macos would not shut down cleanly after this step. Like it was failing on closing a process and hanged. Seems to have went away after installing karabiner-elements.

3) Install karabiner-elements and create the file ~/.karabiner.d/configuration/karabiner.json

https://pqrs.org/latest/karabiner-elements-latest.dmg (mentioned in the above github README.md)

4) To get back my settings I added the following remaps.

  {
      "profiles": [
          {
              "name": "Default profile",
              "selected": true,
              "simple_modifications": {
                  "caps_lock": "escape",
                  "left_command": "left_option",
                  "left_option": "fn",
                  "fn": "left_command"
              }
          }
      ]
  } 

5) To get the names of keys to add to the above, you can't really use the karabiner event viewer app. I was seeing Command_L and Fn. The following file has a list of all the acceptable names. control-f for left_command and you can see other ones that might suit your needs.

https://github.com/tekezo/Karabiner-Elements/blob/master/src/share/types.hpp

Hope this helps.

Saturday, March 12, 2016

Kernel Crashing after upgrading to Fedora 23

After upgrading to from fedora 22 to fedora 23, I was unable to boot into linux due to a kernel crash. I was able to load up the previous kernel from 22 to get back to desktop.

I thought it might be a bad grub config so I ran this to rebuild grub
grub2-mkconfig -o /boot/grub2/grub.cfg

This produced a lot of errors such as:
ERROR: pdc: reading /dev/sdb[Input/output error]

It looks like the initramfs could be corrupt.

Solution:
sudo dracut --regenerate-all --force
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

No errors were produced at this time.

Monday, October 12, 2015

Getting the fontNames from Swift with XCode 7.01

func fontForDisplay(atIndexPath indexPath: NSIndexPath) -> UIFont? {
    if indexPath.section == 0 {
        let familyName = familyNames[indexPath.row]
        let fontName = UIFont.fontNamesForFamilyName(familyName).first as String
        return UIFont(name: fontName, size: cellPointSize)
    } else {
        return nil
    }
}


The above snippet of code is from
Beginning iPhone Development with Swift Exploring the iOS SDK
I'm trying this on el capitan and xcode 7.01, which now uses swift 2.0

The first issue is that xcode will warn you that 'String?' is not convertible to 'String'
Adding a ! to force cast and will allow the code to run. (append it to either first! or String!)

The next issue is that this is thrown: EXC_BAD_EXCEPTION
Looking at the trace, we can see

familyName = (String) "Bangla Sangam MN"
fontName = (String!) nil

So it appears that we're trying to get the first element of an empty array. I ended up with this solution:

    let fontArray: String? = UIFont.fontNamesForFamilyName(familyName).first
    let fontName = (fontArray != nil) ? fontArray! : ""


Let me know if there is a more idiomatic way of doing this with Swift 2.0

Thursday, January 8, 2015

golang: Do you need a singleton? Where are my private/public class modifiers?

Intro: Singletons can be useful, but as mentioned in other people's posts they are an anti pattern and can make testing and debugging difficult. A post on stack overflow had this short nonspecific message "Just put your variables and functions at the package level." http://stackoverflow.com/questions/1823286/singleton-in-go I took this as a hint that with a little more knowledge of how go packages work, I could get a single instance of an object and have it abstracted so that modification would be difficult, if not impossible.

Let's start with three files.

src/logger/logger.go
src/chat_server/main.go
src/chat_server/sub/sub.go

logger.go

package logger

import (
     "fmt"
)

type logger struct {
    Timestamp int
}

type Togger struct {
    Timestamp int
}

var log = logger{Timestamp: 12345}
var Tog = Togger{Timestamp: 12345}

func (l *logger)writeInfoFile(s string) {
    fmt.Println(s)
}

func (l *logger)writeErrorFile(s string) {
    fmt.Println(s)
}

func Debug(s string) {
    log.writeInfoFile(s)
    fmt.Println(&log.Timestamp)
}

There is a logger object named log with a single timestamp field. The other thing to note is that the functions, variables and structs (golang's version of a class) can have an upper or lower case first letter.

"if something starts with a capital letter that means other packages (and programs) are able to see it" - http://www.golang-book.com/11/index.htm

For those us who are used to having public and private keywords in our OO language, this capital letter convention is how go restricts access. This means that Togger, Tog, and Debug() can be referred to once logger is imported in another file. While log, loger and write*() can not. This takes a little closer to our goal because we should be able to instantiate an instance of logger, and only allow specific functions to act on it.

main.go

package main

import (
    "logger"
    "chat_server/sub"
    "fmt"
)

func main() {
    logger.Debug("one")
    logger.Debug("two")
   
    sub.CheckingAddress()
   
    isPublic := logger.Togger{Timestamp: 555}
   
    fmt.Println(isPublic.Timestamp)
    fmt.Println(logger.Tog.Timestamp)
   
    // These will cause an error
//    fmt.Println(logger.log.Timestamp)
//    isPublic := logger.logger{Timestamp: 333}
}   

Here are some examples of how this works. Debug is a function that can be accessed after the import. It can refer to var log as it's within the same package. Trying to access logger.log directly is not allowed, while the analagous struct value logger.Tog can be called. Any attempt to init a new 'logger' object also fails.

There is one more quick check that I wanted to verify and that is to confirm the log object continues to be the only instance no matter where it is imported.

sub.go

package sub

import (
    "logger"
)

func CheckingAddress() {
   
    logger.Debug("In SUB")
   
}

Way back in logger.go I print out the memory address of the Timestamp field.

fmt.Println(&log.Timestamp)

After running main, the output is:

one
0x547068
two
0x547068
In SUB
0x547068
555
12345

We get the same address so it's good.

Conclusion: I was able to create a single instance of my logger struct without resorting to a singleton and learned how go packages limit access to vars and and functions.

Wednesday, December 17, 2014

VMware Player Free and changing boot devices.

VMWare player free doesn't include all the settings that the commercial editions offer. In order to boot an iso, you must hand edit the *.vmx file and add the following settings.

bios.bootOrder = "cdrom,hdd,floppy"
bios.hddOrder = "scsi0:0,ide1:0"

Adding the above information allowed me to install fedora 21 over my existing fedora 20.

Tip: After installation, I powered the vm off. Removed the above lines and removed the fedora iso from the vmware cd drive.