Wednesday, July 25, 2012

Piping input and Redirection - Linux

A program interacts with two essential principles: input and output. The Linux command line allows us to skew these principles in something called IO redirection and piping, which is a very helpful thing to be able to do. If you already know C++ then your knowledge of the << and >> operators will come in handy. 

About
 Redirection
  Redirection allows you to move output somewhere else. For instance, dmesg > file.txt would move the 
  would move the output of "dmesg" into file.txt instead of to standard output. Input redirection is like output
  redirection, but it gets its input from somewhere else.
  
 Piping
  Piping is using one program's output as another's input.

How to use IO redirection and piping
 We will be using dmesg and espeak for our example. If you cannot get a hold of espeak, it is a program that outputs text given to it as an argument as audio.

Output Redirection
The greater than symbol, ">", is used to shoot output into somewhere else, usually a file. An example would be ls > file.txt which puts the output of "ls" into file.txt.

Input Redirection
Much like >, < is used to redirect input. Input Redirection can be confusing. It uses a file or some other source to get the input for a program. An example would be espeak < file.txt. This will use file.txt as input for espeak.

Combining IO redirection
The following example is going to gather input from a file, get the output, and put it in another file.
 wc < my_files > wc_output. This calls wc on my_files and puts it to wc_output. It would look like this with parenthesis: (wc < my_file)>wc_output. To use this as input, you would need to do program < wc < my_files > wc_output. That is overly complicated, so we will use piping.

Piping
Piping is a very important concept. It uses the pipe bar ( | ) to use the output of one program as input for another. So far we have used ls to put its output in a file and then used espeak to read that file. Now we are going to combine the steps. ls | espeak. What that line means is that the output of ls is going to be piped to espeak as input. Of course, you can still use IO redirection to get espeak's output into some file by using >.
  

What is Portage and how to use it

Gentoo Gnu/Linux is a notoriously hard-to-install minimal Linux distribution. Like many Gnu/Linux distributions it has a package manager and repositories that hold software that can be installed onto a system. Gentoo, unlike other distributions, uses a repository of source code as its primary method of installing software (similar to the FreeBSD source trees). Compiling the source code of your programs provides a few benefits, including a performance gain and source-level customization. Here is how Portage works:


Setting up portage
emerge is the Portage's interface. You may see on online guides emerge X (emerge [anything]) and get the "package not found" message. This is because portage does not have the repositories synced by default. To sync the repository, run emerge --sync. This will take some time (it took about 20 minutes at 138 KiB/second). This gets a file with the names of the packages, their categories, and a bit more information. You will see a list of all of the applications available to you fly down your screen. It was moving at such a steady speed that I was unsure of whether or not it was downloading a file, but when I disabled my wireless connection it was indeed relying on the internet for this step.


General Portage Usage
You can now install software with emerge name, where name is the name of the package that you want to install. If you are searching for a package in the repositories, you can use emerge --search query or emerge --searchdesc query to search through the documentation as well.


What to expect when emerging
When you emerge a file, Portage will hide nothing from you. It outputs all the steps, including logging into an FTP server. If it seems to stop working, use the command tail -f /var/log/emerge-fetch.log  in another terminal window. This will repeatedly output the next line in emerge-fetch.log, which is where fetching progress is stored.


After the program has been fetched, it will run through a list of conditions required to install the program. You will see "Checking blah for blah blah" repeated a lot of times, and then it will install the program. Yes, source compilers, it goes through the makefile.


Keeping Portage up-to-date
Always remember to do an emerge --sync every two days or so to keep your repositories up-to-date. When a new version of Portage comes out, emerge portage will install it. To update your system, the command emerge --update --deep --with-bdeps=y --newuse world will update everything on your system, including USE flags and build dependencies. 


Removing Software with Portage
We all have those bad days where we install a rotten package, or it just conflicts with something else on the system. To uninstall it, use emerge --unmerge X where X is the software to remove.


USE flags
Use flags are an important part of the Portage environment. USE flags tell Portage what your tastes are in certain kinds of packages. For instance, if you were to download a flight simulator WITHOUT a "3d" use-flag, it wouldn't download 3d support. If you had "3d" as a use-flag, it would download it if the package recommended it. /etc/portage/make.conf is where your USE flags are stored. You define it like this:
USE="-X -aqua -dvd gnome"
A list of USE flags is stored here: http://www.gentoo.org/dyn/use-index.xml
Extra documentation on USE flags can be found here: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=2

General Portage usage
Two other useful tricks are emerge --fetchonly X and emerge --pretend X. The first one will only download the software and cache it; it will not install. The second command will not download anything, but it will calculate the dependencies and tell you how much space you need to install it with. Along the same lines of --pretend, --ask will make sure that the user wants to download the software after they see the size.


Test it out
Here are the commands necessary to emerge firefox (yes, it is really this easy):

A Warning to the Impatient
Compilation takes a very long time for large programs like Firefox or qtcreator. It can take hours on a new machine, and the older a processor is the worse it will do. Gentoo is not for you if you cannot wait a few hours for a large piece of software to install. I figure that it is unlikely you sat around for Gentoo to compile if this was the case, but be warned.

Sunday, July 22, 2012

Crunchbang Linux Review

As a long Linux user I have experimented with a lot of different operating systems. I have used Debian for a short while (before a dependency managed to bring the system down), Linux Mint, Ubuntu, and a lot of other Debian based Linux distros but it wasn't until about two days ago that I decided I would try out crunchbang: a lightweight Debian derivative using Openbox as its primary window manager. Here is a breakdown of its strong points and weaknesses:


Good: Speed
Crunchbang's boot process beat my Ubuntu partition by about 30 seconds. I do have a lot of bloaty services running on Ubuntu, but this is quite a big bonus; especially so if reboots are commonplace.


Good: Stability
Depending on the version of Crunchbang that you chose (testing, stable, backports, etc) there will be varying degrees of stability. It's based on Debian, which is a widely used operating systems on servers, so it inherits a lot of Debian's stability. I have not had a graphical hiccup or a kernel panic once.


Bad: Backport Repositories
On crunchbang it is easy to change around the repositories using synaptic or just editing /etc/apt/sources.list. That makes this issues less of a big deal. However, the backports did not seem to have enough packages that I am used to having. Codeblocks was not in here, and dependencies were an issue. Adding Debian Wheezy's repositories fixed some of the issues.


Very Bad: Installer
I installed Crunchbang twice. The first time, the installer failed to recognize my Ubuntu partition and when it wrote Grub to the master boot record. This gave me a barely functioning crunchbang install and no Ubuntu. For a novice computer user this would be an instant dealbreaker, because of they do not know their way around mount then all of their data would have been lost.

When I entered the (then only) operating system on the grub screen I was immediately displeased. Thunar (the file manager) would not start because it could not find the display and glibc6 was not found. These are two enormous errors. Rebooting solved those issues, but not the issue of the MBR. I reinstalled Crunchbang and it worked perfectly, detecing all three of my Operating Systems.

Great: Aesthetics
In addition to Openbox, a dark icon theme, and a light gray background (simple yet elegant) Crunchbang comes with my personal favorite display manager: SliM. SliM is one of the simpler display managers available. It is configurable if you have the root password, and allows quick different user logins. It doesn't show a list of users. It just shows :username and :password. If your username goes along the lines of xXxXleethaXorZxX then SliM is not for you.


You decide: Ice*
On Debian and Crunchbang Mozilla Firefox is replaced with a browser called Iceweasel. This is because some of Mozilla Firefox (the crash handler and images) is proprietary. Iceweasel is completely free, but lags behind a bit in terms of features and up-to-datedness (aurora is 11.0). Firefox addons and themes are fully compatible. Iceweasel has a brilliant feature added to the search bar. It can search for Debian packages, which is a lifesaver on the broken backports repoistory.

Icedove, the Thunderbird replacement, is also a bit outdated but is not as noticeable. It works the same as Thunderbird and even has (in my opinion) a prettier icon.

Bad: Out of the box software
Crunchbang comes with a bit of preinstalled software, but not all the choices are good. The file manager (thunar) and the terminal emulator (terminator) are two of the few good examples of preinstalled software. Abiword and Geany are the only two text editors that come with the system (if you discount VI). There is no middle ground and no libreoffice. If someone wanted to edit their rc.lua file for the Awesome window manager, lets say, they would have to decide between opening it in a word processor with no syntax highlighting or a full fledged IDE.

Gedit does not have many dependencies, so installing it was easy enough.

Other essential tools like CUPS and git are not included, but a welcome script called cb-welcome allows them to be downloaded.

Conclusion
I have had a love-hate relationship with Crunchbang over the past few days. Dependencies have killed me, but the stability and speed are good things. Crunchbang is NOT for beginners, unlike what Crunchbang enthusiasts may try and tell you. I had to mount my /dev/sda7 partition from the command line to even get my old files transfered over (and no, thunar did not detect it). However, if you are an experienced Linux user that wants to escape the bloaty grasp of Canonical or the outdated and fully free beast that Debian Squeeze is, then Crunchbang could be for you.

Wednesday, July 18, 2012

Comparison of C++ IDEs

C++ is the second language that I ever learned overall, with Java being my first. Java is a very IDE-centric language, so I was accustomed to that coming into C++. My journey took me through almost all of the IDEs available on Linux that can write, highlight, and compile C++ code all in one place. Here is my comparison.

Eclipse
 Although Eclipse is one of my favorite integrated development environments for Java and the industry standard for Android application development, I was definitely not a fan of it for use in C++. By default, it does not work with cout or endl (and presumably other objects that are located in separate header files). Even with the scope operator "::" (that a beginner may not even think to use) it will not accept the usage of these objects as statements. Until these issues are figured out, Eclipse is not a good C++ solution.

Netbeans
Although I no longer have Netbeans installed  to provide a picture or recall exactly how it handles C++, I can vouch for it. Netbeans, once it is set up with gcc, is one of the better C++ IDEs. It has code completion, documentation lookups for certain functions, and a built-in run display like Geany. The performance of Netbeans, however, is not worth downloading and installing Java and Netbeans itself if you don't already use it for something else.

Geany
IDE window
This is Geany, a cute lightweight IDE coming in at only 4MB in size. It has a lot of nice features, like a symbols browser (outline of a program), document browser (for active files), good settings dialog complete with re-mappable keybindings and some unexpected stuff (like a jump-to-line feature). For being such a small IDE it has a lot packed into here. I have never used Geany much, but it's just about as good as it gets with C++ IDE's, despite its small size and simplistic feel. I've even seen its argument-completion be more accurate than code::blocks. 

Qt Creator
 Qt Creator is an enormous beast using the Qt graphical framework. It is cross-compatible, which is a plus, and is centered on Qt development. I cannot express what a great IDE this is to use. Code completion, documentation lookups, formatting, a GUI to create user interfaces, a settings manager that covers every detail, and a symbol browser are just a few of the good things about this IDE. This is the smartest of the IDE's I have ever used. It often corrects my mistakes (changing "." to "->" when talking about pointers) for me without me even realizing it. Another added bonus is that the IDE uses a .pro file to map out all of the files in a particular project, so it can categorize and remember what files belong to which project.

Qt creator is good for editing console-only code, too. It uses qmake, which may cause some minor complications, but that minor inconvenience aside it is a full-featured IDE.

Code::Blocks
 Code::Blocks is the IDE that I personally prefer, even though it has less features than Qt creator. It is light for an IDE (only about 7 MB) and has a lot of pre-installed templates for C programs on embedded systems. Code::Blocks is very useful for console application development, and possibly GTK, but not much else. Its settings manager is similar to Geany's, but with a few more features. Two bonuses to using codeblocks are a formatting plugin called "Astyle" with a bunch of pre-installed themes and optional speed optimization (at the cost of compile time). Codeblocks has a symbol browser in one of the toolbars which are fully customizable. You can have as many or as few toolbars as you wish. You can even detach them. Another feature, although it does not matter to a C++ developer much, is the scripting console that Codeblocks comes with.

Conclusion
Those are all of the major IDE's for C++ development. Some prefer to use a text-editor and a compiler, and if you do, see Comparison of Text Editors. Otherwise, follow these trees:

Trees (Best to worst)

Features
Qt Creator
Codeblocks
Netbeans
Geany
Eclipse

 Size (smallest to biggest)
Geany
Codeblocks
Netbeans
Eclipse
Qt creator

Ease-of-use
Netbeans
Geany
Qt creator
Codeblocks
Eclipse   

Customization
Qt creator
Codeblocks
Geany
Netbeans
Eclipse

Compiler Integration
Codeblocks
Geany
Netbeans
Qt Creator
Eclipse

FINAL
Codeblocks: 14
Geany: 13
QtCreator: 13
Eclipse: 1 

This, of course, is based on Console applications and does not include code extra features like code completion. The bottom line is, beginners should use Codeblocks and "Intermediates" should probably use Qt creator.

Firefox, Beta, Aurora, and Nightly

I recently started using Aurora and I have been impressed with how stable it was. I was more impressed with how well the Firefox update stream is laid out. Below I have a description of each web browser that Mozilla releases along with the Firefox Beta PPA, Aurora PPA, and the nightly PPA for Ubuntu. To install any of these browsers, add the PPA and do an an update and upgrade.

Firefox, Firefox Beta (referred to here as "Beta"), Aurora, and Nightly are four web browsers developed by Mozilla and the community. In the end they will all become Firefox, but they are laid out like a chain in a brilliant update stream. Each of the browsers serves a different purpose and has a varying level of usability. Here is the breakdown of what each web browser does.

Firefox
Firefox is the standard web browser sponsored by Mozilla. Additions are added to Firefox only after they have been added to all of the other web browsers in the chain. Firefox is stable and has the most support for add-ons and themes.


Firefox Beta
Beta is for features that have gone through alpha and pre-alpha testing and are almost ready to be added to the Firefox web browser. This is one last testing phase before additions are finalized and implemented in Firefox. Stability isn't usually an issue at this stage, but some addons with poor support may be incompatible.
sudo add-apt-repository ppa:mozillateam/firefox-next
 
Aurora
Aurora is equal to an Alpha stage of development. At this point  features are still relatively new, but have been confirmed to be useful and usable by nightly. This is the most stable of the "Cutting-Edge" browsers, but can still be hit by stability issues like crashes with any new features, although it is uncommon. Addon support and Theme support take a much larger hit than in Firefox Beta. Only web developers and computer hobbyists should use Aurora. Normal computer users probably wouldn't find many problems with aurora, but there would be no benefits worth risking crashes and a lack of addons.

sudo add-apt-repository ppa:ubuntu-mozilla-daily/firefox-aurora

Nightly
Nightly is a web developer where features are added literally every day and then trickle downstream. Nightly users get the raw code churned out from code contributors, which can lead to crashes and problems. Using Nightly is seen as a show of status, almost like a volunteer. Nightly users receive the worst addon and theme support out of the bunch of the builds. A knowledge of programming and patch submission is not required, but is helpful to further the progression of updates inlcluded in this browser.
sudo add-apt repository ppa:ubuntu-mozilla-daily/ppa

Although I mentioned that addon and theming support gets worse as the versions get larger, this is not a dealbreaker. Many good addons are supported on all versions. Nightly is the only browser that may go dark for certain addons.

Sunday, July 15, 2012

New and Exciting web browser: Qupzilla

The world of web browsers is a split between the core used to render web pages. Webkit is used by Midori and all Google Chrome / Chromium variants. The other option, Gecko, is used by Firefox. Webkit offers some functionality over Gecko, including plugins and faster rendering of pages. A new web browser has recently come into existence that is fully cross-platform compatible and uses webkit called Qupzilla. Despite the weird sounding name, this web browser could give some of the larger browser a run for their money if it gets some of its kinks worked out. Here is the breakdown:
 Every operating system that has a Qt port and webkit can run Qupzilla. Windows, OS X, and any major Unix are all eligible. That is better support than Google Chrome and it's only a year old. Other than the great support it has other advantages:

Built-in addons
The web browser has multiple addons installed by default. Greasemonkey, a personal information handler, a speed dial (pictured, and adblock are all installed from the get-go.

Theming and Configuration
Themes are installable like in other browsers. The browser comes  with a few themes installed by default. They try to mimic the appearance of a theme for a certain operating system. The Linux theme integrates with you Qt theme specified in qt4-qt4config (run with qtconfig).

 Configuring Qupzilla is similar to configuring Firefox. Going to edit>preferences brings up a terse set of menus for configuring your web browser. A bunch of goodies are packed into here, including network proxy configurations, notifications, the password manager, and the download manager. A dialog for notifications is also including, and I was impressed at how well it integrated with free-desktop compliant notifications as well as OSD just like a more mature project like clementine does.


Compatibility
Qupzilla can import bookmarks from most major browsers. For playing video and game content, HTML 5 and Flash both work perfectly.

Browsing experience
Webkit loads pages very fast. I am on a slow connection and I was able to take note of the speeds that were achieved with webkit. Because of Qupzilla's use of Webkit and how it works with the operating system the memory usage should be FAR lower per-tab than any other major web browser. There are also other features in the browsing experience that make it unique. The IP address of a loaded page and the progress of loading is shown in the status bar. The search bar AND omnibar can both use different search engines depending on a set preference dialog or a key-letter like "g" for google or "d" for duckduckgo. Flash playing support is installed by default.
Like Firefox, Qupzilla has a download manager. A feature that I found to be very interesting was the ability to pass off an external program and parameters as the download manager.

Development Process
Major web browsers always feel the same anymore. Qupzilla is not to that point of maturity yet. Every update (which are somewhat frequent) brings some new and exciting feature along with it. The project is open-source and listed on github. The developers and anybody interesting in helping the project (as well as just normal users) should join #qupzilla on the freenode IRC network. I've talked a bit to the developers, and they are all very nice people that tend to listen to suggestions.

Of course, like any project it has its disadvantages too. Here is a rundown of those:


Addon support
The web browser has an extension system, but almost nobody is developing extensions that work with Qupzilla. The addons including by default are ported by the developers and may not be fully functioning. In fact, my beloved spell check doesn't work. This was the only real dealbreaker for me. Userscripts do work but they may not work exactly right.

Stability
The project is relatively new and bugs are being worked out. I haven't had a crash from it yet, but at one point it wiped all of my speed dial entries.

Conclusion
Qupzilla certainly is not the best web browser in the world in its current state. The major gripe with its users is addon support, and I couldn't agree more with how much this helps a browser out. I've contacted the developers, urging them to improve the plugin framework by looking at Firefox and Eclipse's approach. If addon support improved and better UI customization came to be, I would definitely use this as my default browser.

Wednesday, July 11, 2012

What is the Ouya, and why is it a good idea?

The ouya is a new prototype for a $99 Android box that can be connected directly to a television. It surged in popularity today, gaining millions of dollars on Kickstarter where the project gets its funds. It also has deals with major gaming companies as well as Mojang to port games to it if it is successful in next year's launch. Everyone is so excited about this, so what is it?

Ouya is, as stated, a console that runs Android 4.0, the Open Handset Alliance's mobile operating system. Some have criticized it for brining a mobile system into the stationary setting of a home, but those are the people that do not understand the true power of having an android powered gaming console; I will describe the benefits in the next section. The founders wanted to go against exactly the sentiment. The founder fears that games are moving away from the TV and that the experience is just not the same anymore for a possible gamer.

 A prototype is already complete with software, controllers, and all. Now the creators of the console are going to fund the production of the final version version. Take a look at the prototype software (from their kickstarter):




Neat. A game console running on Android. What are the benefits of such a device?
Well, good question. Android is open-source, meaning that programmers (for games and other apps) can find out how to best utilize the Android system in their software. Also, hobbyists from around the world can make improvements to the system, unlike the proprietary nature of almost all of the world's gaming consoles. Even the hardware specifications will be made open once the final version is released.

Another great advantage is the popularity of the Android SDK. Android has a lot going for it right now, especially with the popularity of tablets and smart phones nowadays.  This means that more developers will be willing to make games and other apps for the Ouya. Not only is it a popular platform, but it is also very easy to distribute applications. Unlike, for instance, the Xbox style of game distribution, an independent developer could publish an App onto Ouya free of charge (not counting the $25 Android market license). There is a 70 / 30 cuts between the developer and Ouya, just like on the Android market.

Yet another benefit for developers is the power of the SDK and Java, which apps are built in. The android SDK covers a lot of ground, so developers don't have to spend their time re-inventing the wheel. Developers can get right to the creative part of coding.

Another huge benefit is the hackability of the console. All Android devices can be "rooted", that is gaining superuser control over your device. By default the Ouya is not rooted, but if you do decide to go root it will not void your warranty. This is highly uncommon for a company to encourage tinkering with their system. In fact, for hardware hackers there is a USB port so custom peripherals can be developed for it. The software is just as hackable, since Android is completely Open-source.

With all these perks for developers, what do the users get?
The users get the result of a happy developer. More games will be developed for this platform than any other because of the openness of the android market and Android as a whole. Also, the user benefits from buying a $99 dollar Android box with a 4-core processor and wifi (plus that USB port mentioned above). Those are good specs for the money (although I feel that the 1GB of RAM is a bit low).

Here is a picture of the Ouya controller from their kickstarter page:


For applications that do not support the Ouya controller, they have included a touchpad. This makes all applications available for Android (at least the ones that don't use phone-specific services) immediately portable to the Ouya console. Even for games that do not require a touchpad, it could be added as a new feature of the controller. It is my estimate that applications developed specifically for Ouya will still utilize the touchpad. It's not just a safety measure.

I have donated to the project, and I am trying to aid by spreading word here. Personally I do not support it for a gaming platform, but for the spread of open-source software onto the console market that has been dominated by proprietary software just about since it came about.

Friday, July 6, 2012

Function Pointers in C (and C++) - What are they and How to use them

If you are using the C programming language, you have probably already worked with pointers extensively. Chances are that you have also worked with functions. So, when you put two and two together, you get a function pointer; that is a pointer to a function. Function pointers are a wonderful way to organize and use functions and can also save some space. Here are some examples of how they are used:

int func(int x){return 0;}//This will be used throughout the post.

Function pointers work just like any pointer, meaning they will hold the address of a function (for quite some time I ignorantly assumed that functions didn't have their own memory address). However, the type is a bit weird. The syntax is

primitive-type (*pointer_name) (parameters)


for our above example we would make a function pointer like this:


int (*funcPoint)(int x)=&func;

Function pointers can be returned as well as executed. Lets pretend that a function called getPoint returns a function to a pointer like this:

int (*getPoint(int x))(){return &func;}//1

To call the pointer this returns, the code would look like this:

funcPoint = getPoint();//2
funcPoint(4);//3

Let's explain what just happened in the few lines above:

1: We declared a function returning a pointer with one argument (x) that returns an int. The function itself has no parameters (thus the ()).

2: We assigned funcPoint (declared earlier) the address of the function returned by getPoint();

3: We called the function stored in funcPoint with an argument of 4.

Of course, function pointers are more powerful than just returning and calling from functions they have more uses.

1: When a function needs to get passed into another file without using an #include

2: When organization is key. For plugin systems (I made a small one called Crunch once) it is helpful to keep an array of function pointers to call. They are declared like this:

At the top of the file: typedef int (*func)(int);
Somewhere else:        func functions[10];
(Yes, you can also just do int (*func[10])(int); but I think it is a lot more organized to use typedef.)

Of course, members are added to the array as such: &function (NOTE THAT THERE ARE NO ()'s FOR PARAMETERS)

3: For something that resembled exception handling
You can fix issues by having a file named "helper.h" that returns a function based on some variables in "helpme.h". All you would need is a function that gets some information from helpme.h (possibly with a function pointer to a function returning an array pointer like this:
char** (*func(int))(){};
)
and a function in helper.h that returns a function to aid helpme.h in whatever it needs.

----
Pointers have an endless amount of possibilities. Anything with a type and a memory address can and will be assigned to a pointer. I consider function pointers the "final frontier" of pointery, since variables and functions make up the whole of a C program. And yes, this also applies to C++, but I didn't want to talk about C++ because it gets even more confusing with class members and what-not. It is still possible, though. To check out the full potential of function pointers go here: http://www.newty.de/fpt/fpt.html. That is the resource that I used to learn function pointers so I owe it a shout-out.

Also, I would like to take this time to plug my complete rewrite of nAI. It contains something called crunchLand.h that uses a lot of function pointers https://github.com/dymatic/C---Dumb-AI-with-extras/blob/master/HEADER/Crunch/crunchLand.h
That is crunchLand.h

Thursday, July 5, 2012

Set Keyboard Shortcuts in Gnome 3.*

After a lot of use of Awesome WM, I tried Gnome 3.4 for the first time since a much earlier version of Gnome. I noticed many improvements, especially extensions. However, coming from Awesome I wanted to make it fully usable from the keyboard. Going into the gnome control center did not work, and neither did modifying them from ccsm and using compiz as the window manager. After a bit of searching, I found the answer.

Why it doesn't work:
It turns out that Unity no longer uses the same method of keyboard shortcut definitions that Gnome does. That means that Gnome Control Center sets the shortcuts for Unity, but no longer for Gnome

How to make them work:

Use a program called "Dconf-Editor". Then, go to org > gnome > desktop> wm > keybindings. This is where you can edit the keybindings. The keybindings go inside of the [' s and end with a ']. For instance, closing a window with alt+f4 would look like this: ['<Alt>F4']. Notice that the F is capitalized here. If you use an F1-F12 command, the F is capitalized. More about the semantics in the next section.

Semantics
F1-F12: Capital 'F' followed by number.
Special keys: <Key>, like <Alt> and <Control>. <Control> is spelled out. <Ctrl> will not work.
shift keys: If you use shift in the key combination, the letter with it should be capital.
The Super (Windows logo) button on keyboards is called <Mod4>

Extra
I was worried that binding <Mod4> to anything would invoke the sea of windows. It does not as long as you do not use it by itself. However, whenever all of the windows on a workspace are closed the sea will activate itself.

Sunday, July 1, 2012

Access UI in Android Application Development

This summer I took a class in Android application development with Java. Coming into the experience I had an extensive knowledge with C++ and the Qt framework as well as Swing and Awt which are Java-specific. Qtcreator, a popular Qt IDE, used to make it very simple to access and change the ui using (ui->objname). With Android no such object was generated with the Eclipse IDE, which is the most popular tool for Android application development. I will assume that you are using Eclipse and ADT since that is the most popular choice for developing apps.

The Example
We have a grid layout with a Button called "Button1" in the middle of it. We are going to change the text from the Activity from which it is made.

The Implementation
Down to the business. We need to first access the button object using something called "findViewById()".

In Eclipse there is a variable named "R" that relates to the generated Dalvik Java. To alter the UI, we need to go through this "R" variable to get the ID of a object. The ID is the name given to the object in the layout xml file.

First off, make a Button that will be assigned to the button in the application. (Button b = new Button()). You need to import android.widget.Button to do this. Then, assign it to the button in the layout like this (inside onCreate is a good place to do this. After setContentView) (b= (Button)findViewById(R.id.Button1). This assigns b to the button with that ID from the XML. It is neandroid.wiget.buttoncessary to cast it to a Button since it is just finding the view by ID. Now you have access to all of the methods for that button. To change the text just use the "setText()" method. (b.setText("Button Text")).

Here is the condensed version of all of this as a note: