Screen Captures on Android Phones

I know you can take a screen shot on an iPhone by holding down the only two buttons, which got me thinking "I should be able to do that on Android phones too." So doing some googling for a few minutes, the only thing that I was able to find was connecting phone to a computer and firing up Eclipse and doing it through the SDK/IDE, downloading a special App and again connecting it to your computer, or installing a 3rd party app.
I know it's possible to do this without rooting the phone, or having to do any of the above ways. I was able to do this on two Samsung phones running Android 2.2 and 2.3, but with different key combinations. So far these are the only two phones I was able do a screen capture on:

  • Samsung Droid Charge: Hold the Back button and hit Home
  • Samsung Galaxy S: Hold the Back button and hit the Power button.

When I get some more free time, I'm going to go to a Verizon store and try to figure out how to do this on other phones, providing that it's possible. It doesn't make sense why this feature was would be left out because it's such a small and nice feature to have.

Having Views Initially Display Empty Text and Setting a Default Value

I have found a way to initially show no results when a view loads, but if I want to display a specific value if nothing is found, that's a different story. One instance that you would want to do something like this is when you're making a distributor or representative locator. In this case, if no results are found, then you want to display the corporate office's contact information. 

I am assuming you have selected the fields you want to display, filtered how you wanted, and exposed what filters you want the user to use.

The first set is to add an argument of null. After clicking on the '+' in the arguments section of the display, select Global from the group dropdown.

When configuring the argument select the following options:

  • Under where it says ACTION TO TAKE IF ARGUMENT IS NOT PRESENT
  • Select provide default argument.
  • Provide a default argument by supplying PHP Code
  • In the PHP Argument Code Box paste the following code:
    $is_filtered = FALSE;
    foreach ($view->filter as $filter) {
      if ($filter->options['exposed']) {
        if (!empty($view->display[$view->current_display]->handler->handlers['filter'][$filter->options['id']]->value)) {
          $is_filtered = TRUE;
          break;
        }
      }
    }
    return $is_filtered;
  • The Validator needs to be set as PHP Code
  • Select ACTION TO TAKE IF ARGUMENT DOES NOT VALIDATE
  • Make sure that there actually isn't anything in the settings for 'Empty Text'

Now the view will not display anything until you filter it. However, the next step is to only display something if there aren't any results. Throw the following code into a glue module:

function MODULENAME_views_pre_render(&$view) {
  if ($view->name == 'VIEWNAME' && count($view->result) == 0) {
    if ($view->current_display == 'DISPLAY' && $view->exposed_data['EXPOSEFIELD'] != 'All')
      $view->attachment_after = HTML;
  }
}

Change the following to fit your needs:

  • MODULENAME - The name of your module.
  • VIEWNAME - The name of the view you are working with.
  • DISPALY - This may or may not be needed. If you have more than one display on this view, then you will need to be specific.
  • EXPOSEDFIELD - This will vary depending on what field you have exposed or not.
  • HTML - The message, plain text or HTML to display when no results are found.

 

Setting up a Static IP and route in Linux

The first step is to setup the interface with an IP and a netmask:

 

# ifconfig eht0 192.168.1.25 netmask 255.255.255.0 up

 

Next we need to tell where we want to route the information to:

 

# route add default gw 192.168.1.1 eth0 

 

The above command is saying that we want a default gateway on interface eth0 to be 192.168.1.1 which is a router.

Creating a Database, User, and Granting Privleges

I always for get how to creat a database, user, and granting privileges to the new user for that database:

 > CREATE DATABASE new_db;
 Query OK, 1 row affected (0.02 sec)
 
 > CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
 Query OK, 0 rows affected (0.03 sec)
 
 > CREATE USER 'new_user'@'%' IDENTIFIED BY 'password';
 Query OK, 0 rows affected (0.03 sec)
 
 > GRANT ALL PRIVILEGES ON 'new_db'.* TO 'new_user'@'localhost' IDENTIFIED BY 'password';
 Query OK, 0 rows affected (0.03 sec)
 
 > GRANT ALL PRIVILEGES ON 'new_db'.* TO 'new_user'@'%' IDENTIFIED BY 'password';
 Query OK, 0 rows affected (0.03 sec)
  

Privileges

ALL
ALTER
ALTER_ROUTINE
CREATE
CREATE  ROUTINE
CREATE TEMPORARY TABLES
CREATE USER
CREATE VIEW
DELETE 
DROP
EVENT
EXECUTE
FILE
GRANT OPTION
 INDEX
 INSERT
 LOCK TABLES
 PROCESS
 REFERENCES
 RELOAD
 REPLICATION CLIENT
 REPLICATION SLAVE
 SHOW DATABASES
 SHOW VIEWS
 SHUTDOWN
 SUPER 
 TRIGGER
 UPDATE
 USAGE

 

Using Git

Below are some notes on how to use git from day to day.

Basics

 

Command Description

$ git config --global user.name "<your name>"
$ git config --global user.email "<your email>"

Configures git with your name and your email. If you don't do this at a global level or at a repository level, git will complain about this.
$ git init Run this command inside a directory that alread has source code to set up a repository.
$ git clone <url> <dest_dir> Creates a new repository in the specified directory.
$ git status Checks that status of the files in the repository. There are two states for files, one being Tracked, and the other being Untracked. Tracked includes all file that are unmodified, modified, or stages while Untracked is everything else. For example, if you add a file to the repositiory after cloning, then the added file is considered Untracked.
$ git add <file> Adds a file to be tracked and commited next time the commit comand is issued. If you run this command, and then make changes and then commit. The changes that were made after it was staged will not be commited.
$ git commit
$ git commit -m "message"
$ git commit -a -m "message"
First command will open up the default editor so you can create a commit message.
The second command will take the commit message as a parameter.
The third command will stage all files and then take the commit message as a parameter. This means you do not need to do git add <file>
$ git diff
$ git giff --cached
 First command shows what changes that were made and that are unstaged.
The second command shows what will be commited.
$ git rm <file>
$ git rm --cached <file>
$ git rm mv <file> <file>
First command deletes the file from the repository and the hard drive.
The second command will remove the file from being tracked.
The last command will rename the file.

 

Ignoring Files

 

Pattern Description
 dir/  Ending slash means to exclude directory.
 /README  Ignore the README file in root directory.
 *.log  Ignore all files with the extension of log.
!out.log Do not ignore the out.log file, this would be used in conjunction with the above pattern.

 

Git Logs

 

Comand Description
$ git log lists the commits made in the repository in reverse chronological order.
$ git log stat Shows stats on commits.
$ git log -p -2 Shows the differences in each commit. The -2 shows last two commits.
$ git log --pretty=format:"%h - %n, %ar : %s" For mats the log according to user input.
$ git log --pretty=format:"%H - %ar" --graph Displays the commits in a ASCII graph.

 

Filtering and Output Options

 

Option Description
-p Shwo the patch introduced with each commit.
--stat Show statics for files modified in each commit.
--shortstat Display only the changed/insertions/deletions line from the --stat command.
--name-only Show the list of files modified after the commit information.
--name-status Show the list of files affected with added/modified/deleted information as well.
--abbrev-commit Display the date in relative format instead of using the full date format.
--graph Show an ASCII graph of the brand and merge history beside the log output.
--pretty  show commits in an alternat format. Options include oneline, short, full, fuller, and format -- where you specify your format.
-(n) Show the last n commits.
--since, --after Limit the commits to those made after a specified date.
--until, --before Limit the commits to those made before a specified date.
--author Only show commits in which the author entry matches the specified string.
--commiter Show only mitts in which the commiter entry matches the specified string.

 

Log Formatting Options

 

Option Description
%H Commit Hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author email
%ad Author date
%ar Author date, relative
%cn Commiter name
%ce Commiter e-mail
%cd commiter date
%cr commiter date, relative
%s subject

Changing Last Commit

$ git commit -m "message"
$ git add stdio.h
$ git commit --ammend

Misc commands

To unstage a file:

$ git reset HEAD stdio.h

To discard changes to a file

$ git checkout -- stdio.h

Working with Remote Repositories

Command Description
$ git remote -v Shows short name and url for repositories
$ git remote add <name> <url> Adds a remote repository.
$ git fetch <remote-name> Doing this will give you access to all branches of the remote repository. No local files will exist for you to work on.To get files to work on, you must check out the branch.
$ git pull gets a branch and merges it.
$ git push <remote-name> <branch> Pushes a branch to a remote repository. If the remote branch has changed since you started working on it, you must run git fetch <remote-name> to synchornize the work.
$ git remote rename <from> <to> Rename
 $ get remote rm <remote-name> Deletes a remote name.

Defaulting PHP safe_mode to off in Plesk

When creating a domain in Plesk, PHP safe_mode is enabled by default. To change the default behavor do the following as the admin:

  • On the home screen in Plesk go to Event Manager
  • Click on Add New Event Handler
  • Fill in the form with the following values:
    Event: Physical Hosting Created
    Priority: default is fine
    User: root
    Command: /usr/local/psa/bin/domain -u <new_domain_name> -php_safe_mode false

 

Adding Custom Fields to Ubercart Checkout

I had to add the SKU to the checkout of Ubercart, to do that, I had to do the following:

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  switch($form_id) {
    ....
    case 'uc_cart_view_form':
      // Reordering existing columns
      $form['items']['#columns']['desc']['weight'] = 3;
      $form['items']['#columns']['qty']['weight'] = 4;     
      
      // Adding SKU column
      $form['items']['#columns']['sku'] = array('cell' => 'SKU', 'weight' => 2);

      // Iterating through the items array element. Since there are more than just 
      // products in this array, we have to make sure we are modifying the correct 
      // arrays. I do this by checking to see if the element has an array element 
      // called 'nid'
      for($i=0; $i < count($form['items']); $i++) {
	if(isset($form['items'][$i]['nid'])) {
          // Loading the node so we can retrieve the information we need.
	  $product = node_load($form['items'][$i]['nid']['#value']);
          
          // Adding the sku/model to the prodct that is in the user's cart.
	  $form['items'][$i]['sku']['#value'] = $product->model;
	  $form['items'][$i]['sku']['#cell_attributes'] = array('class' => 'cart-sku');
	}
      }
      break;
      ......
  }
}

Reading an InputStream to a String

InputStreamReader isr = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
{
     sb.append(line);
}
br.close();
result = sb.toString();
System.out.println(result);

 

  1. Get an Input Stream from an existing object such as a connection object and pass it as the parameter in the constructor of the InputStreamReader
  2. Create a new BufferedReader object and pass the newly created InputStreamReader throught the constructor.
  3. Create a StringBuffer object for later use.
  4. Iterate through the BufferedReader, reading each line of data. Append the data into the StringBuffer object.
  5. When done close the BufferedReader object.
  6. Convert the StringBuffer to a string and print it.

 

Pushing / Forwarding Email from one server to another.

When transfering domains from one server to another, sometimes the emails get delievered to the old server after the DNS has been updated. When that happens, you can run the following script to forward the emails to the other server, or to a different email address.

 

#!/bin/sh

for i in /var/qmail/mailnames/<domain>/*
do
user=$(echo $i | cut -d'/' -f6)
for msg in $i/Maildir/{cur,new}/*
do
formail -n3 -s /usr/sbin/sendmail < $msg \ $user@<domain>
done
done

This will iterate through all the usernames in the domain directory of QMail, then look in the cur and new directory for message files and forward the emalis to $user@<domain>

Plesk Backup Error: Specified file is not accessible

 I just did a kernel upgrade on the server and after making sure that the IPs and services were working properly I tried to backup a domain through the web interface and got this error:

 

Plesk Backup Error: Specified file is not accessible

 

I know that the location for Plesk back up files are located here:

 

/var/lib/psa/dumps

 

The owner was correct, psaadmin:psaadmin. Then I noticed that the tmp directories permissions were set to 700, so after running:

 

chmod 711 /var/lib/psa/dumps/tmp

 

I was able to backup through the web interface.

Syndicate content