Posts

Showing posts from April, 2012

MySQL couldn't find log file on Snow leopard

If you have removed the Binary logs from the file system that exits in the mysql data folder and during the start up an error will occur

These is after tailing the error log of mysql.

/usr/sbin/mysqld: File './mysql_bin.000025' not found (Errcode: 2) [ERROR] Failed to open log (file './9531_mysql_bin.000025', errno 2) [ERROR] Could not open log file [ERROR] Can't init tc log [ERROR] Aborting InnoDB: Starting shutdown... InnoDB: Shutdown completed; log sequence number 0 2423986213 [Note] /usr/sbin/mysqld: Shutdown complete
Basically, MySQL is looking in the mysql-bin.index file and it cannot find the log files that are listed within the index. This will keep MySQL from starting, but the fix is quick and easy. You have two options:

Edit the index file
You can edit the mysql-bin.index file in a text editor of your choice and remove the references to any logs which don't exist on the filesystem any longer. Once you're done, save the index file and start MySQL.

Difference between "and" : "&&" in Ruby

and v/s &&

Many people seem to prefer using and instead of && in Ruby, as it sounds more like speech.

However, do note that it’s slightly different from using &&. The difference is important enough that I think you should avoid using and.

&& (double ampersand) vs and
The difference is that && has higher precedence. This means that it will get evaluated before and.

So, we end up with weird stuff in some situations. This is perhaps most likely to cause weirdness when using the ternary operator, as it is evaluated before and. Here’s a real life example:

>> a = true >> b = false # 1 >> a and b ? 'hello' : '**silence**' => "**silence**" # 2 >> a && b ? 'hello' : '**silence**' => "**silence**" # 3 >> b and a ? 'hello' : '**silence**' => false # oops # 4 >> b && a ? 'hello' : '**silence**' => "**si…

How to change the TimeStamp using RUBY

For Changing the TimeStamp we are going to use touch
FileUtils.touch 'sample.txt', :mtime => Time.now - 2.hours If you omit the :mtime the modification timestamp will be set to the current time:
FileUtils.touch 'sample.txt' You may also pass an array of filenames:
FileUtils.touch %w[ foo bar baz ], :mtime => Time.now - 2.hours
Non-existent files will be created.

Generate abbreviations from string

Generate abbreviations from string

>> str = "nishant nigam" => "nishant nigam" >> str.split(" ").map {|name| name[0].chr }.join.upcase => "NN"

Compression Related Commands

tar cf file.tar files – create a tar named file.tar containing files tar xf file.tar – extract the files from file.tar tar czf file.tar.gz files – create a tar with Gzip compression tar xzf file.tar.gz – extract a tar using Gzip tar cjf file.tar.bz2 – create a tar with Bzip2 compression tar xjf file.tar.bz2 – extract a tar using Bzip2 gzip file – compresses file and renames it to file.gz gzip -d file.gz – decompresses file.gz back to file

Process Management by Commands on Unix/Linux

Process Management
ps – display your currently active processes top – display all running processes kill pid – kill process id pid killall proc – kill all processes named proc * bg – lists stopped or background jobs; resume a stopped job in the background fg – brings the most recent job to foreground ping host – ping host and output results fg n – brings job n to the foreground

Basic File Related Linux/Unix Commands

ls – directory listing ls -al – formatted listing with hidden files cd dir - change directory to dir cd – change to home pwd – show current directory mkdir dir – create a directory dir rm file – delete file rm -r dir – delete directory dir rm -f file – force remove file rm -rf dir – force remove directory dir * cp file1 file2 – copy file1 to file2 df – show disk usage free – show memory and swap usage mv file1 file2 – rename or move file1 to file2 whereis app – show possible locations of app touch file – create or update file cat > file – places standard input into file more file – output the contents of file head file – output the first 10 lines of file tail file – output the last 10 lines of file tail -f file – output the contents of file as it