воскресенье, 7 ноября 2010 г.

Sorting rubbish in downloads (linux)

#!/bin/bash
echo "Раскидываем помойку по категориям.."
test -d Documents || mkdir Documents
mv *.doc *.docx *.odf *.pdf ./Documents/
test -d Databases || mkdir Databases
mv *.sql ./Databases/
test -d Roms || mkdir Roms
mv *.7z *.gen ./Roms/
test -d Music || mkdir Music
mv *.mp3 ./Music/
test -d Package || mkdir Packages
mv *.deb *.rpm ./Packages/
test -d Text || mkdir Text
mv *.txt *.html ./Text
test -d Sources || mkdir Sources
mv *.tar* ./Sources/
test -d Archives || mkdir Archives
mv *.zip *.rar ./Archives/
test -d Images || mkdir Images
mv *.JPG *.PNG *.png *.jpg *.gif *.GIF ./Images/
test -d Video || mkdir Video
mv *.avi *.flv *.mp4 ./Video/
test -d ISO || mkdir ISO
mv *.ISO *.iso ./ISO/
Run this script in folder, where many files!

понедельник, 1 ноября 2010 г.

MySQL: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Recently I got next exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
Communications link failure 
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

I looking into google, but got no answer, except for "check your server", "check port of your server", "check localhost at /etc/hosts" and some other unavailing stuff.
Problem was in my code, I feel, that I'm Great Indian Coder, then detect it.
Connection conn = DriverManager.getConnection("jdbc:mysql://" + 
app.sql.settings.constants.getHost() +
app.sql.settings.constants.getPort() +
app.sql.settings.constants.getDb() +
app.sql.settings.constants.getUser() +
app.sql.settings.constants.getPassword());

I wrote it too fast and I was distracted on something and don't noticed it. Correct code is:
Connection conn = DriverManager.getConnection("jdbc:mysql://" + 
app.sql.settings.constants.getHost() + ":" +
app.sql.settings.constants.getPort() + "/" +
app.sql.settings.constants.getDb(),
app.sql.settings.constants.getUser(),
app.sql.settings.constants.getPassword());

because correct format of getConnection's parameters is:
jdbc:mysql://host:port/db, user, password

I will be glad if it will help you.

воскресенье, 24 октября 2010 г.

MySQL & Cyrillic Symbols.

To work with Cyrillic symbols in MySQL:
    sudo gedit /etc/mysql/my.cnf
Add next settings in section [mysqld]:
    default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
init-connect="SET NAMES utf8"
skip-character-set-client-handshake
and this to section: [mysqldump]:
    default-character-set=utf8
reboot mysql and enjoy!
Also create table code:
    CREATE TABLE $tablename CHARACTER SET utf8

суббота, 23 октября 2010 г.

Java Samples 4. jFrame close confirmation.

...
main.this.addWindowListener(new WindowListener() {
public void windowClosing(WindowEvent event) {
Object[] options = { "Yes", "No" };
int n = JOptionPane.showOptionDialog(event.getWindow(), "Close Window?",
"Close Window?", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options,
options[0]);
if (n == 0) event.getWindow().setVisible(false);
}
public void windowActivated(WindowEvent event) {}
public void windowClosed(WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
});
initComponents();
...
Also change defaultCloseOperation from EXIT_ON_CLOSE to DO_NOTHING_ON_CLOSE

суббота, 16 октября 2010 г.

суббота, 9 октября 2010 г.

Java Samples 2. SQL connections.

public static void voidName(String query) throws SQLException {
Connection connectionName = DriverManager.getConnection("url" /* хост:порт/база */, "user", "pass");
if (connectionName==null) {
System.exit(0);
}
Statement statementName = connectionName.createStatement();
ResultSet resultsetName = statementName.executeQuery("query");
while(resultsetName.next()) {
resultsetName.getString("columnName");
some_actions_with_columnName
}
}

воскресенье, 3 октября 2010 г.

Java Samples 1 (String & File)

/* Load file content to string */

public static String fileView(String filename) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(filename));
StringBuilder s = new StringBuilder("");
while (br.ready()) s.append(br.readLine()+"\n");
return(s.toString());
}


/* Write text to file*/

public static void writeToFile(String fileName, String text) throws IOException {
try {
File file = new File(fileName);
FileWriter fw = new FileWriter(file, true);
fw.append(text);
fw.close();
}
catch ( IOException ioException ) {
ioException.printStackTrace();
}
}

Java Samples 0 (String & ArrayList)

/* delete spaces around the string */

public static String deleteSpaces(String x) {
if (x.startsWith(" ")) x = x.substring(1);
if (x.endsWith(" ")) x = x.substring(0, x.length()-1);
return(x);
}


/* convert ArrayList to String */
public static String listToString(ArrayList list) {
String s = null;
if (!list.isEmpty) {
for (int i = 0; i < list.size(); i++) {
s.concat(list.get(i).toString()+"\n");
}
}
return(s);
}


/* convert String to ArrayList */
public static ArrayList stringToArrayList(String string) {
String[] pieces = string.split("\n");
for (int i=pieces.length-1;i>=0;i--) {
pieces[i] = pieces[i].trim();
}
ArrayList a = new ArrayList(Arrays.asList(pieces));
return (a);
}

понедельник, 23 августа 2010 г.

How to find file with substring

Ubuntu 10.04
find -type f -name "*.css"|while read filename; do
cat $filename|grep fff & echo $filename;
done
  • find - search
  • -type f - files
  • -name "*.css" - with name contains ".css"
  • |while read filename; do - while read this files
  • cat $filename - write file-content
  • |grep ddb - search substring "ddb" in file-contents
  • & echo $filename; - write name of file
  • done - close while
FreeBSD 7:

find -f *.php|while read filename; do cat $filename|grep theme && echo $filename; done

воскресенье, 22 августа 2010 г.

Sega

Debian i386 way.
1. sudo apt-get install dgen
2. dgen hxw

Debian x86_64 first way.
1. sudo gedit /etc/apt/sources.list
2. replace all "# deb" to "deb"
3. save
4. sudo apt-get update
5. sudo apt-get install ia32-libs
6. sudo apt-get install dgen
7. dgen HxW

Debian x86_64 second stupid but working way.
1. sudo apt-get install wine
2. sudo apt-get remove ttf-mscore-installer //as you get terrible fonts
3. Get emulator.
4. wine

Windows way.
1. Get emulator.
2. Run it and use your fucking GUI.

Roms:

четверг, 19 августа 2010 г.

среда, 21 июля 2010 г.

Correct ia32-libs install (Ubuntu 10.04)

I try to run LAMPP on my AMD64 and got next message:
“XAMPP is currently only availably as 32 bit application. Please use a 32 bit compatibility library”.
But ia32-libs was currently installed. In google I was find many tips like "install getlibs-all", and something like "reboot after install, install it with sudo, etc", sure, it didn't work. But here I was find good advice how to make ia32-libs correctly working:
sudo gedit /etc/apt/sources.list
uncomment all the lines “thats what i did because i am lame”, and
sudo apt-get update
sudo apt-get install ia32-libs
and now all work fine.

суббота, 17 июля 2010 г.

How to convert many images in console (Windows)


1. Get "GraphicsMagick" utility and install it.
2. Create batch-file (.bat) and paste:

echo off
cls
set /p sd="Enter source directory (example: C:\source directory\ ) : "
if %sd:~-1%==\ (echo Ok) else (set sd=%sd%\)
set /p d="Enter destination directory: (example: C:\dest directory\ ) : "
if %d:~-1%==\ (echo Ok) else (set d=%d%\)
set /p s="Enter source extension (example: .tif ) : "
if %s:~0,1%==. (echo Ok) else (set s=.%s%)
set /p n="Enter necessary extension: (example: .png ) : "
if %n:~0,1%==. (echo Ok) else (set n=.%n%)
xcopy ^"%sd%*%s%^" /s /i ^"%d%^"
cd ^"%d%^"
for /r %%1 in (*%s%) do gm convert ^"%%~dpnx1^" ^"%%~dpn1%n%^" & erase /f /q ^"%%1^"

3. Run it.

пятница, 9 июля 2010 г.

After Ubuntu 10.04 Installation

apt-get remove gwibber empathy evolution pitivi
apt-get update
apt-get upgrade
apt-get install avant-window-navigator openssh-server compizconfig-settings-manager gimp flashplugin-installer gstreamer0.10-ffmpeg lynx postgresql pgadmin3 eclipse unrar p7zip thunderbird startupmanager