Permanent link to this article: https://blog.openshell.in/2013/01/ssh-login-without-password/

Cassandra basic commands:

Create keyspace:

create keyspace Keyspace1;

Create column family:

// This command is used to create column family and mention comparator, default_validation_class and key_validation_class to insert rows for undefined column.

create column family column_family1 with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;

Update column family:

update column family column_family1 with
column_metadata =
[
{column_name: first, validation_class: UTF8Type},
{column_name: last, validation_class: UTF8Type},
{column_name: age, validation_class: UTF8Type, index_type: KEYS}
];

Insert/Update data:

set User[‘jsmith’][‘first’] = ‘John’;
set User[‘jsmith’][‘last’] = ‘Smith’;
set User[‘jsmith’][‘age’] = ’38’;

Retrieve Data:

get User[‘jsmith’][‘first’];
get User[‘jsmith’];
get User where age = 38;

list User;

Create indexing column:

UPDATE COLUMN_FAMILY users WITH comparator = UTF8Type AND column_metadata = [{column_name: birth_year, validation_class: LongType, index_type: KEYS}];

Set data expiring time:

set User[‘jsmith’] [utf8(‘coupon_code’)] = utf8(‘SAVE20’) WITH ttl=864000;

Delete Row and Column:

del User[‘jsmith’][‘first’];
del User[‘jsmith’];

Drop column family and keyspace:

drop column family column_family1;
drop keyspace Keyspace1;

Super column family:

create column_family FbUsers with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type and subcomparator=UTF8Type and column_type=’Super’;

Encode column value of specific column family:

ASSUME COLUMN_FAMILY KEYS AS ascii;
ASSUME COLUMN_FAMILY COMPARATOR AS ascii;
ASSUME COLUMN_FAMILY VALIDATOR AS ascii;
ASSUME COLUMN_FAMILY SUBCOMPARATOR AS ascii;

Permanent link to this article: https://blog.openshell.in/2013/01/cassandra-basic-commands/

Export Hive data into CSV file

Use the following command used to export hive data into CSV file.

set hive.io.output.fileformat = CSVTextFile;

INSERT OVERWRITE LOCAL DIRECTORY ‘dir_path’ SELECT FIELD1, FIELD2, FIELD3 FROM TABLE1;

Permanent link to this article: https://blog.openshell.in/2013/01/export-hive-data-into-csv-file/

How to reload your bashrc file

How to reload your bashrc file

Here’s a quick way to reload your bachrc file without having to invoke a new shell.

[code]
[root@user]# source ~/.bashrc

or

[root@user]# . ~/.bashrc
[/code]

Permanent link to this article: https://blog.openshell.in/2013/01/how-to-reload-your-bashrc-file/

How to find php exec() function run without error

Use the following method to trace exec() function in PHP.

Syntax:

[php]
exec($command, $output, $return_value);
[/php]

example1:
[php]
$command = "ls";
exec($command, $output, $return_value);
// $output will contains list of files as array.
// $return_value will be zero.
[/php]

Output:
Array
(
[0] => File1.txt
[1] => File2.txt
)
0

example2:
[php]
$command = "l2";
exec($command, $output, $return_value);
// "l2: not found" this error will araise if use the above command
// So, exec() command will not capture error into $output.
// $return_value will be not zero.
[/php]

So, we can use this before calling exec() function.
$command .= ” 2>&1″;

It will redirect the STDERR stream to STDOUT, so that you can capture both OUTPUT as well as ERROR from your PHP script into $output.

example3:
[php]
$command = "l2";
$command .= " 2>&1";
exec($command, $output, $return_value);
[/php]

Output:
Array
(
[0] => sh: 1: l2: not found
)
127

Permanent link to this article: https://blog.openshell.in/2012/11/how-to-find-php-exec-function-run-without-error/

dpkg status database is locked by another process

This problem will arise when you accidentally kill the apt-get process or package manager not shutting down properly. So, dpkg become orphan process.

To solve this problem you can either restart your computer or open up the terminal and type in the following:

Code:

sudo rm /var/lib/dpkg/lock

Then:

Code:

sudo dpkg --configure -a

Permanent link to this article: https://blog.openshell.in/2012/11/dpkg-status-database-is-locked-by-another-process/

Access External Property File in Spring Application Context using PropertyPlaceHolderConfigurer

Target Audience: Web Component Developers, Configuration Managers and Deployment Managers

What should you know already: J2EE, Spring MVC

In an enterprise application we often use property files to share data in Java classes and XML configuration files. The problem is accessing these property files in your code. Whenever you want to read a value out of the key, you have to open stream and read the value by passing property key. This repeats every time when you want to read. Spring has excellent solution for this. The PropertyPlaceholderConfigurer brings down such complexities. Spring makes simple things simple, and complicated things possible.

Read Properties from classpath

[xml]
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:conf/settings.properties</value>
</property>
</bean>
[/xml]

This will search the mentioned properties file in WEB-INF/classes folder.

Read Properties from external file

[xml]
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:#{ systemProperties[‘user.home’]}/ur_folder/settings.properties</value>
</property>
</bean>
[/xml]

This will search the mentioned properties file in the user home directory. Here I have used SpEL ( Spring Expression Language) to get the user home directory, so that the platform independent application context loading guaranteed.

Access the property values

Say, I have the following properties saved in my home folder named xyz.properties and configured PropertyPlaceholderConfigurer in my Spring applicationContext.xml file as shown below.

The content of xyz.properties
[code]
xyz.project.name=some value
xyz.project.location=yet another value
[/code]

The bean declaration for PropertyPlaceholderConfigurer
[xml]
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:#{ systemProperties[‘user.home’]}/xyz.properties</value>
</property>
</bean>
[/xml]

Now, to read the value of some key from the xyz.properties file, I could simply use as follows. Here I’m injecting my object.
[xml]
<bean id="config" class="com.myproject.ProjectConfig">
<property name="name" value="${xyz.project.name}" />
<property name="location" value="${xyz.project.location}" />
</bean>
[/xml]

Permanent link to this article: https://blog.openshell.in/2012/11/access-external-property-file-in-spring-application-context-using-propertyplaceholderconfigurer/

Base 64, Part 2: Padding

Well, Part 1 of this blog explained about the basics of base 64, here I would like to discuss more about base 64.

Base 64 Padding

I’m starting from example rather explaining in words. In Part 1 I took 3 letter word ‘man’ to explain, now I am taking a 4 letter word ‘many’. Lets do it again,

  • The binary representation of each letter is
    m 01101101
    a 01100001
    n 01101110
    y 01111001
  • Now, group 6-bits, you will get five groups of 6-bits and two bits remaining. See the following table.
    011011 010110 000101 101110 011110 01
  • Now, how do you get base 64 alphabet for the last 2-bit group? This is where the padding helps. To get exactly 6-bits in each group, keep increasing the binary string (filled with zeroes) to its right hand side. See the following table after increasing 1 byte The newly added bits are in green color.
    011011 010110 000101 101110 011110 010000 0000
  • Here also, the last group is not 6-bits, so add one more byte, resulting in the following table.
    011011 010110 000101 101110 011110 010000 000000 000000

    Now, we are exactly getting 6-bits in each group.

This is why padding is needed in base 64 whenever the base 64 string is not divisible exactly groups of 6-bits each. Well, the next step is find the base 64 alphabet for each group. Take the equivalent decimal value of each group.

bit groups 011011 010110 000101 101110 011110 010000 000000 000000
equivalent decimal (ie. index) 27 22 5 46 30 16 [pad] [pad]
encoded value b W F u e Q = =

Permanent link to this article: https://blog.openshell.in/2012/10/base-64-padding/

Base 64, Part 1: How and basics

Base 64 is an encoding method. It is used in many internet protocols and SMTP emails. One of the widest usage of base 64 in SMTP protocol is all binary file attachments are base 64 representation of its original data. It neither compress nor encrypt data, just encodes using the 64 alphabets shown in Table 1.

I would like to explain the basics of base 64 encoding in this blog, Part 2 of this blog will explain about Padding in Base 64.

Table 1: Base 64 Alphabets
Index Symbol
0 A
1 B
2 C
3 D
4 E
5 F
6 G
7 H
8 I
9 J
10 K
11 L
12 M
13 N
14 O
15 P
16 Q
17 R
18 S
19 T
20 U
21 V
22 W
23 X
24 Y
25 Z
26 a
27 b
28 c
29 d
30 e
31 f
32 g
33 h
34 i
35 j
36 k
37 l
38 m
39 n
40 o
41 p
42 q
43 r
44 s
45 t
46 u
47 v
48 w
49 x
50 y
51 z
52 0
53 1
54 2
55 3
56 4
57 5
58 6
59 7
60 8
61 9
62 +
63 /
padding =

Lets look at the basics of base 64. For simplicity, take 3 letter the word ‘man’ to encode using base 64.

  1. Take the binary representation of each letter. m – 01101101, a – 01100001, n – 01101110
  2. Group 6-bits, you will get four 6-bits. The grouped bits are as follows 011011, 010110, 000101 and 101110
  3. Take the equivalent decimal value of each group, in our case we get 27, 22, 5 and 46
  4. Now check Table 1, take the symbols of the index what you got in the previous step. Thats it, encoding over. In our example we are getting bWFu, (27th symbol is b,22nd symbol is W,5th symbol is F and 46th symbol is u)

Permanent link to this article: https://blog.openshell.in/2012/10/how-base-64/

Disable foreign key checks in MySQL

Disabling foreign key checks in MySQL is usefull when you are dealing with tables that use foreign keys (InnoDB engine).

You can not delete (drop) multiple tables, a parent table or a child table until you disable foreign key checks four your current database.

The sql command to disable foreign key checks is:

[sql]SET FOREIGN_KEY_CHECKS = 0;[/sql]

To enable the foreign key checks use the opposite command:

[sql]SET FOREIGN_KEY_CHECKS = 1;[/sql]

Permanent link to this article: https://blog.openshell.in/2012/09/disable-foreign-key-checks-in-mysql/