Thermaltake Poseidon Z Keyboard on Mac

Best Buy is having a clearance on the Poseidon Z keyboard, and I’ve been wanting to try out Cherry Blue switches. I think they’re actually the Kailh clones, but for $72 I can live with the small difference. Of course, when I got it home and plugged it in, it didn’t work. The arrow keys, as well as a few other keys, wouldn’t register when pressed. After a quick Google search, I found how to install the proper driver:

Poseidon Z Driver for Mac OS X 10.10/

It did require a reboot. The keys worked but I didn’t have a functioning Command key. I thought the Windows key automatically became Command but it didn’t work so I mapped Alt to Command and Command to Option.

keyboard

This worked even though my Command key didn’t originally work.   Finally, I’ve got my Blue clicky switches.  Let’s see how other people like them. 🙂

 

thermaltake

 

Advertisements

Curling a UIView Up/Down with Swift

I had a problem creating the page curling effect between two views. The solution suggested on StackOverFlow is to use a container that uses auto layout for the two transitioning views, which do not use autolayout. Here’s what the problem looked like:
curl_up2

Here’s what the views should look like:

curl_up_working2

I committed the working project to my Swift Github repo: https://github.com/melling/Swift under the Xcode project TransitionWithView. Here’s the main functionality:

    func curlUp() {
        let transitionOptions = UIViewAnimationOptions.TransitionCurlUp
        
        UIView.transitionFromView(cardFront,
            toView: cardBack,
            duration: 5.0,
            options: transitionOptions,
            completion: { _ in
                
                let transitionOptions = UIViewAnimationOptions.TransitionCurlDown

                UIView.transitionFromView(self.cardBack,
                    toView: self.cardFront,
                    duration: 5.0,
                    options: transitionOptions,
                    completion: { _ in
                        //
                })

        })
    
    }

    func buildView() {

        let height = 100
        let width = 100

        container = UIView()
        container.setTranslatesAutoresizingMaskIntoConstraints(false)
        container.backgroundColor = UIColor.blackColor()
        self.view.addSubview(container)
        
        cardBack = UIView(frame: CGRectMake(0, 0, CGFloat(width), CGFloat(height)))
        
        cardBack.backgroundColor = UIColor.redColor()
        container.addSubview(cardBack)
        
        cardFront = UIView(frame: CGRectMake(0, 0, CGFloat(width), CGFloat(height)))
        
        cardFront.backgroundColor = UIColor.greenColor()
        container.addSubview(cardFront)
        

        let viewDictionary:Dictionary = ["container": container]

        let metrics:Dictionary = ["width": width, "height": height]

        let h0Constraint = "H:[container(==width)]"
        let v0Constraint = "V:[container(==height)]"
        
        addStandardConstraints(self.view, constraint: h0Constraint, viewDictionary: viewDictionary, metrics: metrics)
        addStandardConstraints(self.view, constraint: v0Constraint, viewDictionary: viewDictionary, metrics: metrics)
        
        centerViewXY(self.view, child: container)
        
        NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: "curlUp", userInfo: nil, repeats: false)
        
        
    }

Using Swift in a Legacy Objective C Project

I started learning Swift this week. I ran into my first time consuming problem when I tried to import my legacy Objective C classes into my Swift code. There are lots of good instructions on how to accomplish this task.

how-to-call-objective-c-code-from-swift

Unfortunately, I skipped over the one comment that said to include Foundation.h into my Objective C code:

Without it, you will see a lot of Unknown type error messages (e.g.
/Users/melling/Dropbox/dev/ios/Clock/Clock/Number.h:13:30: Unknown type name ‘NSInteger’)


#import <Foundation/Foundation.h>

@interface Numbers : NSObject

@property(assign, nonatomic) NSInteger numericalValue;
@property(assign, nonatomic) NSInteger dictId;

@property(strong, nonatomic) NSString *arabic;
@end

First Swift Program

I wrote my first Swift program tonight. It simply puts a button on the screen and handles the click event. Everything is done in code. Code on Github: https://github.com/melling/swift/tree/master/CenteredAutoLayoutButton

The relevant functions are here:

 func addButton() {
        centeredButton = UIButton()
        centeredButton.setTitle("Am I centered?", forState: .Normal)
        centeredButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
        centeredButton.setTranslatesAutoresizingMaskIntoConstraints(false)
        centeredButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)
        
        self.view.addSubview(centeredButton)
        
        var viewDictionary:Dictionary = ["centeredButton": centeredButton]
        
        let horizontal:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat("H:|-50-[centeredButton]-50-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewDictionary)
        
        let vertical:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat("V:|-100-[centeredButton]-100-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewDictionary)
        self.view.addConstraints(horizontal)
        self.view.addConstraints(vertical)
        
    }
    
    func pressed(sender: UIButton!) {
        var alertView = UIAlertView();
        alertView.addButtonWithTitle("Ok");
        alertView.title = "My Title";
        alertView.message = "Congratulations";
        alertView.show();
    }

Autoincrement insert-select on a non-autoincrement column

There are often times when you need to insert into an existing table that contains data with a unique numeric field. If you created the field as AUTOINCREMENT, everything is fine. However, in my case, I did not because I generate sqlite tables from my MySql database. So, I have many tables that look like this:

drop table concentration_card if exists;

create table concentration_card (
	card_id int not null default 0,
	/*
      ...
	*/
);

create unique index idx0 on concentration_card (card_id);

I came across this answer on StackOverFlow, which I used to solve my problem: http://stackoverflow.com/a/3127004/2122052

First we need the maximum value from the desired field:

select max(concentration_card); -- We don't need a +1 here because we increment in SELECT

Then set the initial @curRow value and create the insert-select query:

 --insert into concentration_card
  SELECT @curRow := @curRow + 1 as card_id, 0, p.dict_id, 
      p.dict_id, 'Verbs' as name, 0 as inactive,
      '' as comments, 6 as major_group_id
  FROM picture_dictionary p
  JOIN    (SELECT @curRow := 1526) r
  where p.word_group = 'Verbs'
   and p.`dict_id` not in (  
 select word1_id
 from concentration_card
 where name in ('Basic Verbs', 'Common Verbs')
 );