25
Jun 14

Automating Terminal Experience with Aliases

Even though, I think terminals are kind of ancient tool, it is unquestionably useful when you are accessing to a remote server and etc. Despite the fact that I know how to add aliases for my ssh connections(thanks to Murat Kırtay), I really hated to go through to my .zshrc configuration to edit it to add an alias.

First I wrote a very basic alias adder script and placed it to the /Users/tdgunes/Utils folder. (I am sorry that I didn’t find the time to make it completely modular and clean for other people.)

After putting this into Utils folder named as new_alias.py, go to your .zshrc file. And add this at the end of the file:

Now it will become so easy to add other python files. Go to my terminal utils gist, you can download the other scripts. For instance, you can automate your ssh logins by just adding the script (named as add_ssh.py) to your aliases and then when your alias is called, by filling user name and the host name, your password twice and it will put to your keychain, so you don’t need to write your password every time when you login to a remote server.

Happy hacking!


23
Jun 14

At 2:00 AM to 4:00 AM = A Pong on Arduino

In 2013 Fall, I bought a TFT LCD Screen for my Arduino Uno (r3), in order to increase the level of fun I get from electronics. Especially after EE203 course, it is fun to play with something that works without making you crazy at the end of the day (check this hotel-safe circuit, that I built for course project. Painful hours.).

photo

I got rid of all of the cables of my hotel safe project that were attached to the breadboard. By looking this schema, I connected my TFT LCD Screen to my Arduino Uno. I tested it with TFTDisplayText example. At 2:00 AM, with an unknown inspiration, I put a small challenge to myself to make the game Pong playable throughout the serial port.

ardupong

For the code you can get it from this gist. Have fun with electronics at last. 🙂


03
Jun 14

New Lang from Apple, Swift – Making a HTTP Request

Bye bye Objective-C, welcome Swift!

Today, Apple released its new language which claims to lose C from ‘Objective-C’ and much more. I downloaded Xcode 6 Beta and tried to implement a simple HTTP Request, after reading some of their very good-written documentation about Swift. For brief features here, for iBook version here.

My first impression is, it seems like a good language, however popularity of this language will be increase not only by that, but also the great market. The reason why Objective-C is on Top 3 in TIOBE Index, my personal opinion is because of that.

Update: Well, After implementing Socivy and migrating Dilixiri to Swift, “good” seems to be not enough, for a very young language, it’s perfect. (even though, there are some small problems with UISearchBar with Scope Bar, that’s ok 🙂 )

(Apple may be inspired by Go-Lang for the type annotations.)
(Check Swift REPL mode, you will like Playground feature.)

Swift syntax seems much clear while comparing with the Objective-C version of the code above, despite its cleanness, I believe some of the core Objective-C libraries must be rewritten.

As you can see above, for making an HTTP request I have used old NSURLConnection class, and called a very sendAsynchronousRequest method. For making libraries both accessible from Objective-C and Swift, seems like Apple intention currently, so I am not expecting a huge API changes on core libraries such as UIKit etc. Apart from that, there will be dozens of new third-party libraries which will be more swiftic(like pythonic) than Objective-C ones. (For instance, HTTP library for python, requests is more pythonic than standard python library for making http requests)

For projects that are awaiting me on iOS platform this summer, it is exciting yet, a bit sad to put Objective-C behind. And yes, I think I am going to go with Swift for these projects. 🙂

Small note: My async handler unables to access to the UI, for some reason I don’t know(weirdly sometimes does). I tried to implement it by looking some of my old Objective-C implementations. Since there is nothing on the web about Swift now. (It is released just today, come on!) If you know why, it would be great if you write a comment.

Update: This is because of GCD. Please check this detailed explanation.