6/30/13
6/18/13
Essential Eclipse Shortcuts
Essential Shortcuts
The list of shortcuts in Eclipse is fairly long yet readily available. In fact starting with Eclipse 3.1 the full list of shortcuts can be displayed from anywhere via Ctrl+Shift+L. Nevertheless, call it information fatigue or simply a matter of style, deserving shortcuts frequently remain overlooked.
Below is a list of those shortcuts I find essential. What I mean by that is if you don't use them then you probably need additional time to execute essential everyday tasks and are not very comfortable navigating around.
So without further ado here is the list:
| Ctrl+Shift+T | Find Java Type | Start typing the name and the list gets smaller. Try typing the capital letters of the class only (e.g. type "CME" to find "ConcurrentModificationException") |
| Ctrl+Shift+R | Find Resource | Use this to look for XML files, text files, or files of any other type. which are in your workspace. |
| Ctrl+E | Open Editor Drop-Down | Presents a popup window listing currently opened files. Start typing to limit the list or simply use the down arrow key. |
| Ctrl+O | Quick Outline | Use this to find a method or a member variable in a class. Start typing to limit the choices. Press Ctrl+O a second time to include inherited methods. |
| Ctrl+Space | Content Assist | Context sensitive content completion suggestions while editing Java code. |
| Ctrl+Shift+Space | Context Information | If typing a method call with several parameters use this to show the applicable parameter types. The current parameter where the cursor is will be shown in bold. |
| Ctrl+Shift+O | Organize Imports | After typing a class name use this shortcut to insert an import statement. This works if multiple class names haven't been imported too. |
| F3 | Open Declaration | Drills down to the declaration of the type, method, or variable the cursor is on. This works much like a browser hyperlink. |
| Alt+Left | Backward History | This works like a browser's Back button. |
| Alt+Right | Forward History | This works like a browser's Forward button |
| Ctrl+L | Go to Line | Go to a specific line number. |
| F4 | Open Type Hierarchy | Show the type hierarchy (downward tree) or the supertype hierarchy (upward tree). |
| Ctrl+Alt+H | Open Call Hierarchy | Show where a method is called from. In the Call Hierarchy view keep expanding the tree to continue tracing the call chain. |
| Ctrl+H | Open Search Dialog | Opens a search dialog with extensive search options for Java packages, types, methods, and fields. |
| Alt+Shift+R | Rename - Refactoring | Use this to rename type, method, or field. All existing references will be refactored as well. |
| Alt+Shift+L | Extract Local Variable | Use this to create a local variable from the selected expression. This is useful for breaking up larger expressions to avoid long lines. |
| Alt+Shift+M | Extract Method | Use this to extract a new method from existing code. The parameter list and return type will be automatically created. |
Trying Out Shortcuts
A few things to keep in mind as you try the above shortcuts. If a shortcut doesn't have the described effect check if one of these is the cause of your problem:
- Do you have an older version of Eclipse? Check the Help section to confirm the shortcut is available.
- Is the shortcut applicable to the context (perspective) you're in? For example Ctrl+Shift+T (Open Type) is applicable in the Java perspective but not in the Resource perspective. You can find out where each shortcut is applicable by pressing Ctrl+Shift+L or by checking the Help section.
- Is the shortcut already taken by another application? If so the other application will probably come to the foreground when you use the shortcut.
- Is the shortcut defined twice in Eclipse? This can happen on occasion if you install additional plugins with overlapping shortcuts or more likely if you've tried to map shortcuts of your own. If there is conflict the shortcut won't work. To check this go to the Preferences or press Ctrl+Shift+L twice.
Additional Favorites
Here are some additional shortcuts, perhaps not essential but still very useful:
| Alt+Shift+Up Alt+Shift+Down Alt+Shift+Left Alt+Shift+Right | Select Enclosing Element Restore Last Selection Select Previous Element Select Next Element | Useful for selecting context-sensitive blocks (e.g. surrounding loop, method, class, etc.) |
| Ctrl+Up Ctrl+Down | Scroll Line Up Scroll Line Down | Very handy if you want to scroll by 1 line without changing your cursor position or using the mouse. |
| Ctrl+Shift+Up Ctrl+Shift+Down | Go to Previous Member Go to Next Member | Great for stepping down through the methods of a Java source file. |
| Ctrl+Shift+U Alt+Shift+U | Show Occurrences in File Remove Occurrences Annotations | Use this to search within the same file - useful for occurrences of private fields and methods. |
| Ctrl+Shift+P | Go to Matching Bracket | Helps to find the closing bracket of lengthly if-else statements. |
| Ctrl+J Ctrl+Shift+J | Incremental Find Reverse Incremental Find | The first matching occurrence is shown with each typed letter. Press again and the next matching occurrence is shown. |
| Shift+Enter Ctrl+Shift+Enter | Insert Line Below Insert Line Above | Insert a line above or below the current line. |
| Ctrl+/ Ctrl+\ | Add Block Comment Remove Block Comment | Comment in/out blocks of code with a key stroke. |
| Ctrl+M | Maximize Active View or Editor | Maximize the current view or editor at the expense of all other currently shown views. Press again to restore to normal view. |
| Ctrl+F6 Ctrl+F7 Ctrl+F8 | Next Editor Next View Next Perspective | Learn these to switch among edited files, open views and perspectives. |
| Ctrl+Alt+Up Ctrl+Alt+Down | Duplicate Lines Copy Lines | Doesn't seem like it at first but a great shortcut once you learn to use it. Instead of select, copy and paste simply select and duplicate without affecting the clipboard. |
| Alt+/ | Word Completion | This is excellent for code editing or writing plain help files with variables and other words having no English language equivalents. The word completion is based on the set of words already present in the current file. |
| Ctrl+I | Correct Indentation | Select a block of Java code or an entire class file and use this shortcut to correct its indentation. |
| Shift Tab Tab | Remove Tab Add Tab | Select one or more lines of code and use this shortcut to intent them further/less. |
6/17/13
Tutorial: How to use your Raspberry Pi like an Arduino
Tutorial: How to use your Raspberry Pi like an Arduino
Finally got to experiment with the Raspberry Pi’s GPIO (General Purpose Input/Output) pins. I tried three methods: Python, Bash and C, and will describe each. But first, here’s some setup information.
- Connecting to the RPi’s GPIO header: I used an old floppy disk drive IDE ribbon cable. It has 34 pins, but the RPi’s header is only 26 pins, so part of the connector is unused. I soldered some breadboard-friendly header pins onto the other end, which is working pretty well so far. Bear in mind that some IDE cables may be more complicated than they look. Before powering anything up, make sure you check that each conductor is indeed separate and you’re not accidentally grounding or shorting anything. You can always make your own by getting some 26-conductor IDC connectors and using a vice to crimp it onto a piece of ribbon cable.
- Pin Connections: …are confusing! There’s a master table here, and a diagram here. Looking at the diagram, my breakout header starts with 3.3V and moves left to right, top to bottom. Here are the pin connections from my header as pictured:
- Pin 2: 5V
- Pin 3: “GPIO0″. Connected to one end of the switch (the other end is connected to ground, since this GPIO pin has an internal pull-up resistor. This means that when the switch is not closed, the pin reads as “High,” and when closed, “Low.”
- Pin 6: GND (note that it’s jumpered to my ground rail on my breakout board)
- Pin 7: “GPIO4″. The anode of the LED through a 220-ohm resistor.
- I’ll use this breakout board setup for all the following examples. Different libraries/tools use different pin numbers, adding to the confusion, so I’ll try to clear it up. Also note that I’m doing this through an SSH session, so there’s no monitor attached to the RPi. See my beginning instructions here if you don’t already have an SSH connection to your Pi.
- Important Note: The RPi Wiki takes pains to remind you that these GPIO pins are unbuffered and unprotected, so if you short something out, you could fry your whole Pi, so be careful! There are a number of other breakout boards being developed that should make this safer.
- Important Note: Any program that accesses the GPIO pins must be run as root, so if you get an error, remember to “sudo” your command.
- Python: One of my preferred languages, so I figured I’d try it out. First, install pip (Python package installer):
sudo curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
- Next, install the RPi.GPIO Python module:
sudo pip install rpi.gpio
- Now, you can enter the python interpreter (sudo python) and do stuff like:
import RPi.GPIO as GPIO GPIO.setup(7, GPIO.OUT) GPIO.output(7, True) GPIO.output(7,False)
- Bash: Something I’ve always loved about Unix is the idea that everything is a file. On the Raspberry Pi,the GPIO pins are files too! With the pictured breadboard setup, we can do the following to turn the LED on and off (note that this uses the “BCM” pin numbering but the breadboard stays the same!):
- (You can’t just put sudo before each command because the second command that the output is directed to would not be run as root. So, for simplicity, we drop into root first.)
sudo su - echo "4" > /sys/class/gpio/export echo "4" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio4/direction echo "1" > /sys/class/gpio/gpio4/value echo "0" > /sys/class/gpio/gpio4/value
- To read from an input, ‘cat’ it like any other file!
echo "0" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio0/direction cat /sys/class/gpio/gpio0/value
- (You can’t just put sudo before each command because the second command that the output is directed to would not be run as root. So, for simplicity, we drop into root first.)
- C: Good old C. The native example for C is really hairy, but luckily a plucky fellow named Gordon wrote an Arduino-like library just for the Raspberry Pi! Here’s what you need to do:
- Download and install the library:
cd /tmp wget http://project-downloads.drogon.net/files/wiringPi.tgz tar xfz wiringPi.tgz cd wiringPi/wiringPi make sudo make install cd ../gpio make sudo make install
- Your Pi’s system now has the wiringPi library installed, so we can write a little program that uses it.
cd ~ nano blink.c
- Type or paste in this program:
1234567891011121314151617181920212223242526272829 /** blink.c:* Simple test program to blink an LED on pin 7*/#include#includeint main (void){int pin = 7;printf("Raspberry Pi wiringPi blink test\n");if (wiringPiSetup() == -1)exit (1);pinMode(pin, OUTPUT);for (;;){printf("LED On\n");digitalWrite(pin, 1);delay(250);printf("LED Off\n");digitalWrite(pin, 0);delay(250);}return 0;} - And compile it:
cc -o blink blink.c -L/usr/local/lib -lwiringPi
- And run it:
sudo ./blink
- You should have a happily blinking LED. Yay! Now for something more interesting:
12345678910111213141516171819202122232425262728293031323334353637 /** buttonLED.c:* Simple test program to change the blinking rate of an LED when a button is pressed*/#include#includeint main (void){int pin_LED = 7; // GPIO7 / header pin 7int pin_switch = 8; // SDA0 / header pin 3int del = 250;printf ("Raspberry Pi wiringPi button LED test\n") ;if (wiringPiSetup() == -1)exit (1);pinMode(pin_LED, OUTPUT);pinMode(pin_switch, INPUT);for (;;){if (digitalRead (8) == 0){ // button presseddel = 100;} else {del = 250;}digitalWrite(pin_LED, 1);delay(del);digitalWrite(pin_LED, 0);delay(del);}return 0 ;}
- Download and install the library:
- Where’s my analogRead? Sadly, unlike an Arduino, the RPi doesn’t have an onboard ADC (Analog to Digital Converter). However, some of the breakout boards being designed will include an external ADC, such as the Gertboard. You can add your own external ADC, such as this one, by using the SPI bus on the RPi (the MOSI, MISO and SCK pins).
- That’s all for now! Hope this helps, and as always, let me know if it works or you run into any problems.
6/14/13
How can I get Ubuntu to show the serial number of a drive?
Both hdparm and Disk Utility work for me:
Code:sander@netbook:~$ sudo hdparm -i /dev/sda /dev/sda: Model=WDC WD1600BEVT-22ZCT0, FwRev=11.01A11, SerialNo=WD-WXE509V16360 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq } RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=50 BuffType=unknown, BuffSize=8192kB, MaxMultSect=16, MultSect=off CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=312581808 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120} PIO modes: pio0 pio3 pio4 DMA modes: mdma0 mdma1 mdma2 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6 AdvancedPM=yes: unknown setting WriteCache=enabled Drive conforms to: Unspecified: ATA/ATAPI-1,2,3,4,5,6,7 * signifies the current active mode
6/5/13
Using parameters with Talend Open Studio
Using parameters with Talend Open Studio
Passing parameters to Talend Open Studio is a usefull and common solution to parametrize a job's execution. When you realize how to use Context parameters in Talend Open Studio it becomes an easy task.
Talend Open Studio Context
1) First launch Talend Open Studio and open an existing project or create a new one.
2) Next press the right mouse button over Contexts in the Repository tab and select Create context group from the menu. In Talend you can create as many Contexts as you want and choose wich one to use during execution. Most of the times, as in this tutorial, you'll use only one Context.
3) Give a name to the new context, as example "Default", and press Next
4) The next window is used to define the parameters in the Context. To add a new parameter press the plus button and give a name to the new item. You can also define a parameter type and write a mnemonic Comment.
5) Now you can assign a default value for each parameter, so they can be used in Talend's jobs. Press on "Values as table" tab and assign the values you want. In this example ParamA has "Test!" as default value while ParamB has "Value!". You can change parameters values every time you want, using the Talend Open Studio's wizard (Right click on Context item -> Edit Context group ->Next) or setting parameter directly at runtime (we'll see how to in the next paragraph).
Press Finish to close the wizard and apply the changes you made.
Using Context parameters in a Talend's Job
Talend Open Studio is now ready to assign Context parameters to a Job. For this example we create a new Job (Job Designs -> right click -> Create job), but you can always choose an existing one. Once a Job is open select the Contexts tab and click on the button pointed by the cursor in this picture.
In the form that appears you can select which parameters to make avilable in the job. For example select all the values.
The context variables you checked are now passed to the Talend's job. Context parameters can be used in many components, for example in query component or datasource components to parametrize db connections and query executions. To apply a parameter to a component's field simply press Ctrl+Space. Talend will suggest you which parameters are available for the current job.
For example put a tWarn component from the Palette into the Job editor. Then put a tLogCatcher and link it to a new tLogRow component (right click on tLogCatcher -> Row -> Main and point the cursor to tLogRow).
Now select tWarn component and choose the Component tab. As you can see in the picture you can fill component value with parameters and Ctrl+Space key help you much in this task.
Now when you run the Job the parameters will be replaced by Talend with the values you have assigned. This is really usefull when you need to parametrize database connections or other procedures.
Assign parameteres values in command line
Parameters are really usefull when you compile your Talend Job and make it executable. To compile a job in Talend Open Studio simply right click on job name and select Export Job Scripts.
In the next form make sure the Context scripts field is checked and choose a path where saving the archive ("To archive file" form field).
Talend compiles the job into a Java (or Perl) application. To run the application first extract the archive created by Export job scripts procedure and then run the command JobTest/JobTest_run.bat (or JobTest_run.sh in Linux).
The most important thing to know is that you can pass a runtime parameter at the application using --context_param command line switch. For example
JobTest_run.bat --context_param ParamA=ValueA --context_param ParamB=ValueB
You can also edit JobTest_run.bat and set the param value directly into the script:
java -Xms256M -Xmx1024M -cp classpath.jar; test2.jobtest_0_1.JobTest --context=Default --context_param ParamA=ValueA --context_param ParamB=ValueB
Passing parameters to sub-jobs
Sometimes in your applications a Job calls another Job and so on. When you use parameters you need a method to transmit parameters to sub-jobs. In Talend Open Studio this task is quite easy. When you create a sub job (that is a job who calls another job) simply click its Component tab and make sure Transmit whole context is checked.
Next time you run or compile the main Job all parameter values will be transmitted to the depending sub Jobs.
Subscribe to:
Posts (Atom)