Tech Site & Blog Blog about technology & programming

17May/100

Ruby Gem update system on Debian

When you try to update Ruby Gem --system on Debian systems (probably also on Ubuntu) you will get the following error:

ERROR: While executing gem ... (RuntimeError)
gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get.


Gem installed through Debian's aptitude is configured to only be upgraded through aptitude (apt-get) package manager. That would not be a problem if aptitude had newest packages. However, they are updated irregurally and in most cases (almost ever) you will get older version than the current one.

Thankfully there is a simple solution to this problem.

Type following commands (under root user):

gem install rubygems-update
cd /var/lib/gems/1.8/bin
./update_rubygems


After that gem system should be succesfully updated.
Tagged as: debian ruby gem No Comments
11Mar/100

ext2 and ext3 on Windows

If you are using dual boot with Windows and Linux you've probably faced with a problem of accessing ext3 partitions from Windows OS.

Most of the Linux distributions come with NTFS-3G driver, which allow reading & writing to NTFS partiton. Sadly, Windows doesn't offer such filesystem driver for file systems other than FAT16/32 and NTFS.

However, you can use the 3rd party driver such as Ext2 IFS, which allows OS Windows to access such partitions from any program including Windows Explorer.

Ext2 IFS
Ext2 IFS is a freeware program that provides Windows NT4.0/2000/XP/2003/Vista/2008 with full access to ext2/ext3 partitions.

Info: http://www.fs-driver.org/
Download: http://www.fs-driver.org/download.html

I've no problems with accessing partitions with inode size of 128 bytes. However, this program does not support partitions with bigger inode size, which can be a problem in some cases.


Ext2Fsd
If you have a partition with inode size of 256 bytes, you can use this file system driver, which supports Windows NT/2K/XP/VISTA, X86/AMD64.

Info: http://www.ext2fsd.com/
Download: http://sourceforge.net/projects/ext2fsd/files/

Just a word of caution: It is not a good idea to have multiple file system drivers (for the same file system) installed at the same time. Try one and if you have a problem with it, delete it, restart operating system and install another one.

Web sites of both drivers claim that they are not supported by Windows 7. In my case everything worked well on Windows 7 32 bit and 64 bit.
21Feb/100

MS SQL Add User

The simplest way to add user to MySQL and grant privileges for specific database.

1. Connect to MS SQL server using MS SQL Management Studio.

2. Click on the "New query" button in the toolbar on left.

3. Create a database
Type following query and execute it:
create database DATABASE_NAME

Example:
create database MyCMS


3. Create login
create login LOGINNAME with password='PASSWORD'

Example:
create login MyCMSUser with password='abc123'


4. Create user
use DATABASE_NAME
create user USERNAME for login LOGINNAME

Example:
use MyCMS
create user MyCMSUser for login MyCMSUser


5. Grant control of the database to the created user
use DATABASE_NAME
grant control to USERNAME

Example:
use MyCMS
grant control to MyCMSUser


Executing example queries would create user MyCMSUser with password abcd123 with all privileges on database MyCMS.

Queries have to be executed from the first to the last.

If you want to find out how to create a user with MySQL read following post: MySQL Add User
11Dec/090

Hackers Clone E-Passports

Two RFID researchers created a video showing how an RFID reader attached to an improvised explosive device could theoretically identify a U.S. citizen walking past the reader and set off a bomb. They haven't yet tested the theory on a real U.S. passport since the documents have yet to be distributed. They still here show an attack using a prototype passport with RFID chip placed in the pocket of the victim. As the chip passes the reader, the reader detonates an explosive device placed in the trash can.


11Dec/090

RFID on Mythbusters

Adam Savage talks why they didn't do an episode about RFID (In)Security on Mythbusters TV show.


11Dec/090

Human implants

Every day people are replacing keys with RFID implants. You can do a lot things easier with RFID, than with keys. Did you ever misplace car keys? With RFID you just need to be in a range of car's RFID module and car's unlocked.

However, security experts have warned against using tags in that manners because it is really easy to read data from it with almost every RFID reader.

Someone can approach you and scan your tag without your knowledge. Then copy content your card's content to writable tag. And he could drive your car, get in your house or/and even in your workplace.

11Dec/090

What is RFID

RFID is the use of an object (RFID tag) applied to or incorporated into a product, animal, or a person for the purpose of identification and tracking using radio waves.
11Dec/090

About RFID

Passive RFID tags (most common): no battery, require an external power source

Active RFID tags: contain a battery, can transmit signals autonomously and can transmit over longer distances

RFID tags are used for: - passports - race timing - transportation payments - product tracking - transportation and logistics - animal identification - inventory systems - human implants - libraries

Potential risks
RFID for authenticating people is very risky due to the way you can read RFID tag. It is possible to read content of RFID tag just by passing by the person who has it implanted.
6Dec/094

ffmpeg and x264

How to install ffmpeg with x264 codec support on Debian Lenny (5.0)?

Why is this useful? By using x264 codec rather than a FLV video format you will gain on video and audio quality.

1. We need to remove any previous ffmpeg installations.

2. Add additional repository to /etc/apt/sources.list

Open file with nano editor:
nano /etc/apt/sources.list

and add following line on the end of the file:
deb http://www.debian-multimedia.org stable main

3. Install needed libraries:

apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libx11-dev libxfixes-dev libxvidcore4-dev zlib1g-dev libogg-dev

4. Install x264
git clone git://git.videolan.org/x264.git
cd x264
./configure
make
sudo checkinstall --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`" --backup=no --default

5. Install libtheora
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure
make
sudo checkinstall --pkgname=libtheora --pkgversion "1.1.1" --backup=no --default

6. Install ffmpeg
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion "4:0.5+svn`date +%Y%m%d`" --backup=no --default

7. Install qt-faststart

Normal mp4 file needs to be fully downloaded before it can be played by Flash Player. qt-faststart fixes this.

Type following command from ffmpeg source directory:
make tools/qt-faststart

Example:
ffmpeg -i input.mov -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre hq -crf 22 -threads 0 output.mp4
./tools/qt-faststart output.mp4 output2.mp4

Now you can play output2.mp4 by any Flash player. LongTail's freeware JW Player is quite good, has many options and can play both mp4 and flv.

Now you can use ffmpeg to compress videos with x264 codec. Read more about converting video with PHP

Warning: Latest ffmpeg version has some problems with FLV format and it's impossible to convert video to .flv with it! If you need flv support try installing older version of ffmpeg (if you install it by apt-get install ffmpeg you will be able to convert to FLV but there is no x264 support).

Source: http://ubuntuforums.org/showthread.php?t=786095
28Nov/091

Use MySQL database in your C++ projects

How to use MySQL DB in your C++ projects. This tutorial is written for Debian Lenny/Ubuntu 9.10. With a few minor changes, it should work on other distributions also.

What will you need?

- gcc <-- c++ compiler

- MySQL server 5.0 installed

- MySQL C API

To install above programs run this command as root:
apt-get install build-essential mysql-server mysql-client libsoci-mysql-gcc

When you have everything installed you need to create database and add user (MySQL Add User).

Now you will need to add a new table. The easiest approach is to use phpMyAdmin.

Simple program to test MySQL C API (copy it and save as filename.cpp):
#include <iostream>
#include <mysql.h>

using namespace std;

//MySQL variables
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;

int main() {
//Connects to MySQL DB
mysql_init(&mysql);

connection = mysql_real_connect(&mysql, "localhost", "username", "password", "database", 0, 0, 0);

//Checks if there was a problem with connection
if(connection == NULL) {
cout <<mysql_error(&mysql);
return 1;
}

//Execute query
query_state = mysql_query(connection, "SELECT * FROM table");

if(query_state != 0) {
cout << mysql_error(connection);
}

//Loads query data
result = mysql_use_result(connection);

//Writes data to stdio from first column on all rows in table
while((row = mysql_fetch_row(result)) != NULL) {
cout << row[0] << endl;
}

mysql_free_result(result);
mysql_close(connection);
}

You can compile it with following command:
g++ filename.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql

If there was no error displayed then your program compiled successfully. You can run by typing:
./a.out

And now you made your first C++ program that gets data from MySQL DB. You can do a lot more than just that.

You will probably need to read MySQL C API Manual to learn others commands.

Next time I will write about preparing Apple Xcode and Microsoft Visual Studio for using MySQL C API.
Tagged as: Linux MySQL C++ 1 comments