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.

Monday, September 1, 2014

Using Chef to auto create an instance on Amazon ec2

Chef is one of the major server automation tools out there along with Puppet and Ansible. I decided to give chef a try by auto creating an ec2 instance. They're all trying to get you to buy saas packages for nodes greater than around 5. I will be using the free account offered by opscode to store my recipes.

1) Create a new chef-repo or use your current chef-repo


For testing I cloned a new chef-repo
git clone git://github.com/opscode/chef-repo.git ec2chefrepo

2) From the previous tutorial ./chef-repo copy over ./chef-repo/.chef into our new chef-repo


3) In Amazon Ec2 click on your name in the top right


I get a password old/new page. Instead go to the left side and click on Users.

Then click on your email and then the security credential tab

4) Get the Access Keys and Secret Keys


Click on Manage Access Keys
Create a new key and you will get two strings.
Note: The secret key is show and available this one time. You will need to create new access keys if the secret key is lost.

Access Key Id
AKAJG6Z4AFQ5YPQ

Secret Access Key
Mw5sHvDgJRtAVP2vkA8gL8XJkvoZijhNMf

5) With the above access keys and your ec2 .pem add these lines to ec2chefrepo/.chef/knife.rb


knife[:aws_access_key_id] = 'AKAJG6Z4AFQ5YPQ'
knife[:aws_ssh_key_id] = 'bunwichchef'
knife[:aws_secret_access_key] = 'Mw5sHvDgJRtAVP2vkA8gL8XJkvoZijhNMf' 


Note: the ssh_key_id is your key name without the pem

6) Create a gemfile to install some gems


gem install bundle
rbenv rehash
cd ~/ec2chefrepo/
vim Gemfile

source 'https://rubygems.org'
gem 'chef'
gem 'knife-ec2'


Note: I had to run this before running bundle installs
sudo yum install gcc-c++

bundle install

7) Create and Deploy An Instance


Had to run:
gem install rb-readline unf
http://aws.amazon.com/amazon-linux-ami/
To get a list of AMI Image Ids

knife ec2 server create \
  --availability-zone us-east-1b \
  --node-name bunwichchefinstance.demo \
  --flavor t1.micro \
  --image ami-ba18d2 \
  --run-list "role[memcached]" \
  --identity-file ~/.ssh/bunwichchef.pem \
  --ssh-user ec2-user