Author Archives: Jack

Setting Static IP in Linux

To setup a static IP in ubuntu, edit your networking settings file.

Here is an example of how to do it:

Open /etc/network/interfaces:

Use these configurations:


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.10
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

DHCP Address Configuration:


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

Then restart the service: /etc/init.d/networking restart (Make sure you are running with admin privileges when restarting 🙂 )

How to pass parameters back from intent

Tonight I ran across the issue of, "How do I send a result back to the parent that spawned an intent?"

After finding out that it is nearly impossible to pass instances of objects to the intent, I decided why not send the result back from the spawned intent.

To do something like this, use the following code to spawn the child intent:

//Starting a new Intent
Intent intent = new Intent(getApplicationContext(), whateverClass.class);

// Maybe add a param or two?
intent.putExtra("someParam", paramValue);

// starting new activity
startActivityForResult(intent,SOMEINTEGERSHOULDGOHERE);

When you are done with the intent, use this code to close it.

Intent intent=new Intent();
intent.putExtra("myParam", thiscouldbeastringvariable);
intent.putExtra("mySecondParam", thiscouldbeanintvaraible);
setResult(RESULT_OK, intent);
finish();

Lastly, here is how we process our result given from the child:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (SOMEINTEGERSHOULDGOHERE): // this was the integer you used to spawn the activity previously
if (resultCode == Activity.RESULT_OK) {
// Do whatever you want here.
// data.getStringExtra("ThisGetsOurParamBack");
}
break;
}
}

This is basically how to send data, process it in a new activity/intent, and then spit the results back to the parent.

Pulling Active Directory account info via alias email address

I have been working on a PHP project that interfaces with active directory through LDAP.  I noticed that some accounts weren't being resolved via email address.  I thought, hmm this is strange...  After a few hours, I finally figured out that the issue was due to an alias email address.  By default, the "mail" attribute only has the main email address listed, so any alias addresses will not be searched upon lookup.

Solution?

Use this query to select an item from AD via its alias email address:

(proxyAddresses=smtp:[email protected])

Generating a SSL Cert with Apache & openSSL

Registering a SSL cert is always kind of a mystery for me. You always have to use a crazy long command line command and the wizard always asks funky questions. Hopefully this tutorial will help clarify the process.

First run the following command:

openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr

And what the command does is it is generating a 256bit SSL certificate. RSA:1024 would generate a 128bit certificate. When the process has finished, you will have yourdomain.key and yourdomain.csr. yourdomain.key should NOT be distributed. This is your key to decrypt your traffic. The CSR should be presented to your CA (certificate authority).

As far as the generation process goes, you will be presented with a few questions:
Country: The two-letter International Organization for Standardization (ISO) format country code for where your organization is legally registered. This would be US for the United States.
State or Province: Name of the state or province where your organization is located. Write out the name in full.
City or Locality: Name of the city where your organization is registered/located. Write out the name in full.
Organization Unit: This may be left blank. However, if you are a company, you may want to put your company nickname here. I.e. Vooba instead of Vooba LLC
Organization: Vooba LLC
Passphrase: Depending on your registrar, you can/can't use this. If you can't use it, I recommend finding a different company. Use a strong password here.
Common Name: The fully-qualified domain name (FQDN), or URL, you want to secure. If you are not using a wild-card domain (*.yourdomain.com), use www.yourdomain.com. This will allow www.yourdomain.com and yourdomain.com to be secured. If you only secure yourdomain.com, www.yourdomain.com will be invalid.

Hope this helps and clarifies the process!

Errors From Package Manager in Ubuntu 11.10

Getting the following message from Package Manager in Ubuntu 11.10?

Requires installation of untrusted packages
The action would require the installation of packages from not authenticated sources.

And when you click on the Details dropdown it shows all of the packages that need to downloaded?

Run the following commands:

cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get update

These commands will save a backup of the old lists and then create a new lists folder.

More information can be found here.

How to make textview stay visible with softkeyboard

If you have a textview that spans a few lines, but have buttons or something else below the textview that you would like to be shown, you can have the textview object be resized automatically to make room for Android's softkeyboard. To do this, simply add one line to your AndroidManifest.xml file.

android:windowSoftInputMode="adjustResize"

This line of code should go inside of the

<activity
android:name="SomeActivityName"
android:windowSoftInputMode="adjustResize" >
</activity>

How to link text in Android

One of the weirdest things I stumbled across was the ability to hyperlink text in the Android environment.  Here is how to hyperlink text and then make it clickable.

TextView txtTheLink = (TextView)findViewById(R.id.txtTheLink); // Grab our textview/whatever with the HTML
txtTheLink.setText(Html.fromHtml("<a href=\"https://www.vooba.net\">Go to Vooba!</a>")); // Convert from HTML to remove the HTML tag>
txtLinks.setMovementMethod(LinkMovementMethod.getInstance()); // Activate the link

Hope this helps!

Permission to enable read/write access to SD card

If you are looking for the permission to add to your AndroidManifest file, you are looking for the WRITE_EXTERNAL_STORAGE setting. To do this programmatically, use this code:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

How to get default preferences

You can get the default preferences from your preferences.xml file by using the following code:

// Get the xml/preferences.xml preferences
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String settingValue = preferences.getString("setting", "");

PHP Arrays in JAVA

Going from PHP to Java is a step backwards when dealing with arrays (imo).  One of the more beneficial things that you can do with a PHP array is define keys.  For example I can do something like:

$myList = array("oranges"=>15, "apples"=>25);

Then I can access how many oranges I have by going echo $myList["oranges"];

To do something like this in JAVA is a bit different than just defining a normal array. In JAVA you need to use a HashMap:

HashMap<String,Integer> myList = new HashMap<String,Integer>();
myList.put("oranges", 15);
myList.put("apples", 25);
If you need to store two strings, then change the object type (I.e. HashMap<String,String>).
To get the value, simply use the get method.

myList.get("oranges");