Wednesday, June 23, 2010

How to always use a text-based location bar in nautilus...

Open terminal and type the command below
    $ gconftool-2 --type=Boolean --set /apps/nautilus/preferences/always_use_location_entry true
To switch back
    $ gconftool-2 --type=Boolean --set /apps/nautilus/preferences/always_use_location_entry false

Thursday, June 10, 2010

How to fix plymouth bootup resolution...

After installed proprietary driver for NVidia or ATI, plymouth bootup screen has turned large and ugly. Here's how to fix it

1) Install v86d and hwinfo package
    $ sudo apt-get install v86d hwinfo
2) Check maximum resolution supported when running Plymouth
    $ sudo hwinfo --framebuffer
3) Edit the resolutions in the GRUB2 files
    $ sudo gedit /etc/default/grub
Assuming your monitor can support 1280x1024, otherwise change it to whatever resolution supported by your monitor
4) Change the text below
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset video=uvesafb:mode_option=1280x1024-24,mtrr=3,scroll=ywrap"
then look for the text below
    #GRUB_GFXMODE=640x480
and change it to
    GRUB_GFXMODE=1280x1024
5) Edit another file
    $ sudo gedit /etc/initramfs-tools/modules
6) Add the following line at the end of the file
    uvesafb mode_option=1280x1024-24 mtrr=3 scroll=ywrap
7) Run
    $ echo FRAMEBUFFER=y | sudo tee /etc/initramfs-tools/conf.d/splash
8) Update Grub
    $ sudo update-grub2
9) Generate new splash screen
    $ sudo update-initramfs -u

Monday, May 31, 2010

No sound from headphone jack...

Model: Dell Studio XPS 16 - 1647 (reported on 1645)
OS:
Linux Mint 17 - Qiana (64-bit)
Linux Mint 13 - Maya (64-bit)
Linux Mint 10 - Julia
Ubuntu 10.04 - Lucid Lynx

Symptom: no sound when plug-in headphone

Solution:
1) open alsa-base.conf file
$ sudo nano /etc/modprobe.d/alsa-base.conf
2) add the text below to the file (last line)
options snd-hda-intel model=dell-m6
3) restart your machine

Note:
Tested on Ubuntu Lucid Lynx 64-bit.

Update (19/11/2010):
Tested on Linux Mint 10 64-bit.

Update (15/11/2014):
Tested on Linux Mint 17 64-bit.

Tuesday, April 20, 2010

Retrieving data from LDAP...

    //person 
strFilter = String.Format("(&(objectCategory=person)(objectClass=user)({0}={1}))", strFieldNm, strValue);
//distribution group
strFilter = String.Format("(&(objectCategory=group)(objectClass=group)({0}={1}))", strFieldNm, strValue);

private SearchUsersList GetUsersOrDistributionGroups(string strFilter, string strLDAPPath, bool blnIsGroup)
{
SearchUsersList objResult = new SearchUsersList();
DirectorySearcher search = null;

try
{
if (strFilter != String.Empty)
{
search = new DirectorySearcher(new DirectoryEntry(strLDAPPath), strFilter);
}
else
{
search = new DirectorySearcher(strFilter);
}

if (search != null)
{
foreach (SearchResult result in search.FindAll())
{
DirectoryEntry entry = result.GetDirectoryEntry();

if (entry.Properties["mail"].Value != null && !String.IsNullOrEmpty(entry.Properties["mail"].Value.ToString()))
{
SearchUsers objUser = new SearchUsers();
objUser.ID = entry.Properties["samaccountname"].Value.ToString();
objUser.MailAddress = entry.Properties["mail"].Value.ToString();
objUser.UserName = entry.Properties["name"].Value.ToString();
objUser.UserType = blnIsGroup ? "LDAP Distribution Group" : "LDAP User";

objResult.Add(objUser);
}
}
}
}
catch
{
throw;
}
return objResult;
}

Monday, April 19, 2010

My first programming in Linux...

I just realized that in my entire career life, I've written thousand lines of code just to solve other people's problem (my employee). Never once I did it for myself. Sometime it makes me wonder, can't my problem (computer related) be solve with my programming skills? Today for the first time, I solved my own problem with programming. Though it might sounds odd, but yeah, I did it :)

I have a collection of Bleach anime series. Filename was in format with prefix "Bleach - xxx.avi". I wanted to remove the prefix and try to do it manually, but doing so with 200 over files is kind of annoying. I knew there's a way to rename file extension from uppercase to lowercase or even adding prefix easily with just one single line of command. But I'm not sure whether it's possible to remove the prefix (if there's a linux command guru out there knows how to do it, kindly show it to me).

Since I'm crazy learning Perl scripting lately (thanks to my latest assignment), I've created a script for my problem. My first programming in Linux!!!
    #!/usr/bin/perl

use strict;

my $directory = @ARGV[0];

opendir(DIRECTORYHANDLER, $directory) || die("Cannot open directory");
my @thecontents = readdir(DIRECTORYHANDLER);
closedir(DIRECTORYHANDLER);

my $counter = 1;

foreach my $content (@thecontents)
{
if($content =~ /Bleach\s-\s\d+.avi/i)
{
my $fullpath = "$directory/$content";
print "$fullpath\n";

my $newname = sprintf("%03d.avi", $counter);
my $newpath = "$directory/$newname";

rename($fullpath, $newpath);

$counter++;
}
}

To be honest, once I knew how simple it is to read a file and passing it to a variable in Perl script, I've started to love it. My understanding on regular expression is getting better and thanks to Ady for encouraging me to use Perl instead of .NET console app for the assignment.

Thursday, April 15, 2010

Perl trim function...

    # Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
}

# Right trim function to remove trailing whitespace
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
}

Tuesday, April 13, 2010

How to remove cvc/v value from transaction log...

My first Perl script!!!
    use strict;
use Fcntl qw(:flock :seek);

ProcessDirectory($ARGV[0]);

sub ProcessDirectory
{
my $directory = shift;

opendir(IMD, $directory) || die("Cannot open directory");
my @thecontents = readdir(IMD);
closedir(IMD);

foreach my $content (@thecontents)
{
my $fullpath = $directory . "\\" . $content;

if ((-f $fullpath) && (-r $fullpath) && (-w $fullpath) && (-T $fullpath))
{
ProcessFile($fullpath);
}
elsif(-d $fullpath && $content ne "." && $content ne "..")
{
ProcessDirectory($fullpath);
}
}
}

sub ProcessFile
{
my $filename = shift;

print "Processing $filename ...\n\n";

open(DAT, $filename) || die("Could not open $filename");
my @raw_data = <DAT>;
close(DAT);

my $threedigitcount = 0;
my $fourdigitcount = 0;

foreach my $linedata (@raw_data)
{
if($linedata =~ /<cvc>\d{3}<\/cvc>/i)
{
$linedata =~ s/<cvc>\d{3}<\/cvc>/<cvc>***<\/cvc>/i;
$threedigitcount++;
}
elsif($linedata =~ /<cvc>\d{4}<\/cvc>/i)
{
$linedata =~ s/<cvc>\d{4}<\/cvc>/<cvc>****<\/cvc>/i;
$fourdigitcount++;
}
elsif($linedata =~ /CVV2=\d{4}/i)
{
$linedata =~ s/CVV2=\d{4}/CVV2=****/i;
$fourdigitcount++;
}
elsif($linedata =~ /CVV2=\d{3}/i)
{
$linedata =~ s/CVV2=\d{3}/CVV2=***/i;
$threedigitcount++;
}
}

print "Number of occurences for 3 digits: $threedigitcount\n";
print "Number of occurences for 4 digits: $fourdigitcount\n\n";

open(DAT, ">$filename") || die("Cannot open $filename");
flock(DAT, LOCK_EX);
seek(DAT, 0, SEEK_SET);
print DAT @raw_data;
close(DAT);
}
Here's an update version.
    use strict;
use Cwd;
use Fcntl qw(:flock :seek);

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);

my $LOG_FILE_DIRECTORY = UnixPath2NTPath(getcwd()) . "\\Filter_Log";
my $LOG_FILE_PATH = "$LOG_FILE_DIRECTORY\\" . sprintf("%4d-%02d-%02d_log.txt", $year + 1900, $mon + 1, $mday);
my $EXCLUDE_LOG_DIRECTORY = sprintf("%4d-%02d-%02d", $year + 1900, $mon + 1, $mday);

# Check for log folder, if not there then create it
if (! -d "$LOG_FILE_DIRECTORY")
{
mkdir ("$LOG_FILE_DIRECTORY") || die("Cannot create folder $LOG_FILE_DIRECTORY!");
}

my $timeStamp = localtime time;

Log("\n----------------- Logging started $timeStamp -----------------\n\n");
ProcessDirectory($ARGV[0]);
$timeStamp = localtime time;
Log("\n---------------------- Ended $timeStamp ----------------------\n\n");

sub ProcessDirectory
{
my $directory = shift;

opendir(IMD, $directory) || Log("Can't open $directory directory\n");
my @thecontents = readdir(IMD);
closedir(IMD);

foreach my $content (@thecontents)
{
# if foldername has _ or equal to today's date, skip the process
if($content =~ /_\d{4}-\d{2}-\d{2}/ || $content eq $EXCLUDE_LOG_DIRECTORY)
{
Log("Skip $content\n");
next;
}

my $fullpath = "$directory\\$content";

if ((-f $fullpath) && (-r $fullpath) && (-w $fullpath) && (-T $fullpath))
{
ProcessFile($fullpath);

my @dirname = split(/\\/, $directory);
my $newdirectory = $directory;
$newdirectory =~ s/\\\d{4}-\d{2}-\d{2}/\\_@dirname[-1]/i;

rename($directory, $newdirectory);
}
elsif(-d $fullpath && $content ne "." && $content ne "..")
{
ProcessDirectory($fullpath);
}
}
}

sub ProcessFile
{
my $filename = shift;

Log("Processing $filename ...\n");

open(DAT, $filename) || Log("Can't open $filename\n");
my @raw_data = <DAT>;
close(DAT);

my $threedigitcount = 0;
my $fourdigitcount = 0;

foreach my $linedata (@raw_data)
{
if($linedata =~ /<cvc>\d{3}<\/cvc>/i)
{
$linedata =~ s/<cvc>\d{3}<\/cvc>/<cvc>***<\/cvc>/i;
$threedigitcount++;
}
elsif($linedata =~ /<cvc>\d{4}<\/cvc>/i)
{
$linedata =~ s/<cvc>\d{4}<\/cvc>/<cvc>****<\/cvc>/i;
$fourdigitcount++;
}
elsif($linedata =~ /CVV2=\d{4}/i)
{
$linedata =~ s/CVV2=\d{4}/CVV2=****/i;
$fourdigitcount++;
}
elsif($linedata =~ /CVV2=\d{3}/i)
{
$linedata =~ s/CVV2=\d{3}/CVV2=***/i;
$threedigitcount++;
}
}

Log("Number of occurences for 3 digits: $threedigitcount\n");
Log("Number of occurences for 4 digits: $fourdigitcount\n");

open(DAT, ">$filename") || Log("Can't open $filename\n");
flock(DAT, LOCK_EX);
seek(DAT, 0, SEEK_SET);
print DAT @raw_data;
close(DAT);

Log("$filename completed.\n\n");
}

sub Log($)
{
my $text = shift;
open(LOG_HANDLER, ">>$LOG_FILE_PATH") || die("Can't open $LOG_FILE_PATH");
print LOG_HANDLER "$text";
close(LOG_HANDLER);

print "$text";
}

sub UnixPath2NTPath($)
{
my $string = shift;
$string =~ s/\//\\/g;
return $string;
}