Tuesday, July 30, 2013

list open ports and unix sockets

To do this I use netstat command

to list all open ports:
$ sudo netstat -tuplen

to list open ports and unix sockets:
$ sudo netstat -nlp

note: using sudo you will get more info

Friday, July 19, 2013

Basic yum commands

Original post by imdeemvp
[http://forums.fedoraforum.org/showthread.php?t=25880]
[small modification by me :)]

To update system. Update of the system with all the dependencies that are necessary:
$ sudo yum update

To make a search:
$ yum search any-package

to get package information:
$ yum info any-package

Installation of packages with dependencies:
$ sudo yum install any-package

Uninstalling packages with dependencies:
$ sudo yum remove any-package

The following thing will list all the packages installed in the system:
$ yum list installed | less

To list using *patterns*
For installed packages in database:
$ yum list installed | grep *patterns*

For all packages in database:
$ yum list | grep *patterns*

The following thing will list all the packages installed in the system and that can (they must) be updated:
$ yum list updates | less

Clean yum catch and temp files to free disk space:
$ sudo yum clean all

Group install
Code:
$ sudo yum groupinstall "groupname"
{Don't forget the quotation marks for group install.}

Compile Python2.7 on CentOS 6

[ These steps may work on CentOS 5.*  too]

Prepare your OS for it

$ sudo yum groupinstall "Development tools"

$ sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel

Now Download python 2.7 at any location [say make a directory name py in your home directory]
$ wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
Unzip it:
$ tar xf Python-2.7.5.tar.bz2
Change directory:
$ cd Python-2.7.5
inside Python-2.7.5 directory run these command one by one:
$ ./configure --prefix=/usr/local
$ make

***
when make command finishes at the end you will see something like this:
----------
Python build finished, but the necessary bits to build these modules were not found:
bsddb185           dl           imageop
sunaudiodev                      
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
----------
NOTE: sunaudiodev is for Sun platforms,dl for 32bit platforms, imageop is deprecated and bsddb185 is undocumented.
***

$ sudo make altinstall

** you must use [make altinstall] otherwise you will corrupt the system
(CentOS comes with python 2.6 and yum is dependent on it if you use [make install] it will replace python 2.6 and yum may not work)

to test your installation run this command:
$ python2.7

Sunday, March 4, 2012

java program without main method :)


This is very unconventional but a valid code and it will run!!, the magic is the static initializer block. this block is hidden from every class by default but it executes when the class is first loaded, it prints out “Hello World” without writing a main method and the execution is stopped using System.exit() command, so preventing “main method not found” error.


public class HelloWorldWithoutMain {
    static {
        System.out.println(“Hello World!”);
        System.exit(0); // prevents “main method not found” error
    }
}

Saturday, September 10, 2011

Sharing internet [Macbook and PS3]

I wanted to connect to internet from my PS3 to play online game but I am using a wimax internet modem so its not possible to directly connect it to PS3 because PS3 will not recognize it as a wimax modem.
I have a macbook pro and i wanted to use it's airport to share wimax internet to PS3.
this is how I did it:

step 0: open system preferences->network->airport turn it on then select "create network" from network name section drop-down, if you do not have a network. If so create a network and named it same as your macbook name.
step 1: open system preferences and click to sharing
step 2: enable internet sharing
in share your connection from section select your internet connection
and in to computers using section select Airport
step 3: click on Airport Options... button to set wifi password (optional)
step 4: open terminal
step 5: run this command $ cp /etc/bootpd.plist ~/Documents
step 6: open bootpd.plist file from your Document folder and edit using any text editor
you will find these two lines at the end of the file,
[key]reply_threshold_seconds[/key]
[integer]4[/integer]
change it to this
[key]reply_threshold_seconds[/key]
[integer]0[/integer]
(note: when you read pretend [ as < and ] as > )

step 7: copy modified file to /etc using this command, $ sudo cp ~/Documents/bootpd.plist /etc
step 8: start internet sharing

power up your ps3 and scan for wireless network and connect :)

Tuesday, April 12, 2011

php - keyboard input

I was thinking yesterday that is it possible in PHP to take input from keyboard. I started to digg and find out it is possible but no one use it because PHP was not designed to take input from keyboard :) anyway i am posting code here take a look :

#!/usr/bin/php
[php open tag]
function getinput(){
print("Your input: ");
$stdin = fopen("php://stdin", 'r');
$input = fgets($stdin, 1024);
$input = trim($input);
fclose($stdin);
return $input;
}

function output($message){
print $message."\n";
}

$message = getinput();
output($message);
[php end tag]

Tuesday, March 22, 2011

What are the SUID, SGID and the Sticky Bits?

link: Original Post

* SUID or setuid: change user ID on execution. If setuid bit is set, when the file will be executed by a user, the process will have the same rights as the owner of the file being executed.
* SGID or setgid: change group ID on execution. Same as above, but inherits rights of the group of the owner of the file on execution. For directories it also may mean that when a new file is created in the directory it will inherit the group of the directory (and not of the user who created the file).
* Sticky bit: It was used to trigger process to "stick" in memory after it is finished, now this usage is obsolete. Currently its use is system dependent and it is mostly used to suppress deletion of the files that belong to other users in the folder where you have "write" access to.

Numeric representation

Octal digit Binary value Meaning
0 000 setuid, setgid, sticky bits are cleared
1 001 sticky bit is set
2 010 setgid bit is set
3 011 setgid and sticky bits are set
4 100 setuid bit is set
5 101 setuid and sticky bits are set
6 110 setuid and setgid bits are set
7 111 setuid, setgid, sticky bits are set

Textual representation

SUID, If set, then replaces "x" in the owner permissions to "s", if owner has execute permissions, or to "S" otherwise.

Examples:
-rws------ both owner execute and SUID are set
-r-S------ SUID is set, but owner execute is not set

SGID, If set, then replaces "x" in the group permissions to "s", if group has execute permissions, or to "S" otherwise.

Examples:
-rwxrws--- both group execute and SGID are set
-rwxr-S--- SGID is set, but group execute is not set

Sticky, If set, then replaces "x" in the others permissions to "t", if others have execute permissions, or to "T" otherwise.

Examples:
-rwxrwxrwt both others execute and sticky bit are set
-rwxrwxr-T sticky bit is set, but others execute is not set

Setting the sticky bit on a directory : chmod +t

If you have a look at the /tmp permissions, in most GNU/Linux distributions, you'll see the following:

lokams@tempsrv# ls -l | grep tmp
drwxrwxrwt 10 root root 4096 2006-03-10 12:40 tmp

The "t" in the end of the permissions is called the "sticky bit". It replaces the "x" and indicates that in this directory, files can only be deleted by their owners, the owner of the directory or the root superuser. This way, it is not enough for a user to have write permission on /tmp, he also needs to be the owner of the file to be able to delete it.

In order to set or to remove the sticky bit, use the following commands:

# chmod +t tmp
# chmod -t tmp

Setting the SGID attribute on a directory : chmod g+s

If the SGID (Set Group Identification) attribute is set on a directory, files created in that directory inherit its group ownership. If the SGID is not set the file's group ownership corresponds to the user's default group.

In order to set the SGID on a directory or to remove it, use the following commands:

# chmod g+s directory
# chmod g-s directory

When set, the SGID attribute is represented by the letter "s" which replaces the "x" in the group permissions:

# ls -l directory
drwxrwsr-x 10 george administrators 4096 2006-03-10 12:50 directory

Setting SUID and SGID attributes on executable files : chmod u+s, chmod g+s

By default, when a user executes a file, the process which results in this execution has the same permissions as those of the user. In fact, the process inherits his default group and user identification.

If you set the SUID attribute on an executable file, the process resulting in its execution doesn't use the user's identification but the user identification of the file owner.

For instance, consider the script myscript.sh which tries to write things into mylog.log :

# ls -l
-rwxrwxrwx 10 george administrators 4096 2006-03-10 12:50 myscript.sh
-rwxrwx--- 10 george administrators 4096 2006-03-10 12:50 mylog.log

As you can see in this example, George gave full permissions to everybody on myscript.sh but he forgot to do so on mylog.log. When Robert executes myscript.sh, the process runs using Robert's user identification and Robert's default group (robert:senioradmin). As a consequence, myscript fails and reports that it can't write in mylog.log.

In order to fix this problem George could simply give full permissions to everybody on mylog.log. But this would make it possible for anybody to write in mylog.log, and George only wants this file to be updated by his myscript.sh program. For this he sets the SUID bit on myscript.sh:

# chmod u+s myscript.sh

As a consequence, when a user executes the script the resulting process uses George's user identification rather than the user's. If set on an executable file, the SUID makes the process inherit the owner's user identification rather than the one of the user who executed it. This fixes the problem, and even though nobody but George can write directly in mylog.log, anybody can execute myscript.sh which updates the file content.

Similarly, it is possible to set the SGID attribute on an executable file. This makes the process use the owner's default group instead of the user's one. This is done by:

# chmod g+s myscript.sh

By setting SUID and SGID attributes the owner makes it possible for other users to execute the file as if they were him or members of his default group.

The SUID and GUID are represented by a "s" which replaces the "x" character respectively in the user and group permissions:

# chmod u+s myscript.sh
# ls -l
-rwsrwxrwx 10 george administrators 4096 2006-03-10 12:50 myscript.sh
# chmod u-s myscript.sh
# chmod g+s myscript.sh
# ls -l
-rwxrwsrwx 10 george administrators 4096 2006-03-10 12:50 myscript.sh

Saturday, December 4, 2010

Limit apt-get download speed

I wanted to limit apt-get download.
The solution is this:

$ sudo apt-get -o Acquire::http::Dl-Limit=25 upgrade

Thursday, September 2, 2010

how to fix osCommerce and php 5.3.* problem

The problem is php 5.3.* deprecated some functions.
so when you run osCommerce on php 5.3.* it gives warnings.

you can find deprecated functions here:
http://php.net/manual/en/migration53.deprecated.php

there is two ways to fix this.
1. replace all the deprecated functions with
equivalent alternative one (the hard way)
exmp:
replace eregi("[regex]", $str) with preg_match("/[regex]/i", $str)

2. disable deprecated warning from php.ini file.
set error reporting value to this: error_reporting = E_ALL & ~E_DEPRECATED

3. use php 5.2.*

Wednesday, August 11, 2010

QTableWidget bug

to remove rows from QTableWidget you have to
run the loop in reverse order. like this:

in python do this:

for x in reversed(range(self.tableWidget.rowCount())):
self.tableWidget.removeRow(x)

for c++ do this:

for (int i=view->rowCount()-1; i >= 0; --i)
removeRow(i);
for (int i=view->columnCount()-1; i>=0; --i)
removeColumn(i);

Wednesday, July 7, 2010

Dolphin Complete Setup Guide

source: http://forums.dolphin-emu.com/thread-3533.html

Ripping your games is not discussed in this topic, this is ONLY the setup of dolphin itself. Warez is not supported on this forum, so don't ask where to get them, you'll be banned.

First... Things you need:

- A fast computer. (preferably Core 2 Duo or better, or high Athlon 64 X2(5200+ or better)
- The internet
- Roms to use with Dolphin (gamecube or wii)
- Time
- Two hands (it's possible to do with just one, but much easier with two)
- A Brain (This is very important.)

Now then, assuming you have all of the above, you'll be playing in no time, just follow these easy steps.

1.) Download Dolphin from your favorite builder. If you don't know where to get them, they are in the General Discussion sub-forum of the Dolphin-emu SVN Builds forum. Located here: http://forums.dolphin-emu.com/forum-6.html If you're unsure, just click the link in my signature, I update my builds quite often.

2.) Most people use 7zip to compress their releases, some use .zip or .rar, for those you can use Winzip or WinRAR, 7-Zip will work with them all, I suggest you download and install 7-zip from http://www.7-zip.org/

3.) Now, extract the downloaded compressed file to a new folder, make sure you know where this folder is.

4.) When you extract it, you will get several files and folders. Most releases have both the regular Dolphin as well as DolphinIL. the IL build is slightly faster than the original, however, it's also more unstable. You can use either one you want. So double click and open Dolphin or DolphinIL.

5.) You will get the main interface pop up. You could simply load the game from here, but chances are you will want to configure everything, like controls, graphics, sound, hacks and such.

6.) Click the options menu and click Configure. There are a lot of options. For the best settings for specific games, see the individual game posts in the Game Discussion forum.
For most games The best config is as follows:
- ON: Dual Core, Idle Skipping, HLE the BIOS all the time, Enable the JIT dynarec, Lock Threads to cores, Optimize Quantizers, LLE DSP on Thread, Confirm on Stop.
- OFF: Use Panic Handlers.
- You will also want to set your framelimiter to the desired framerate of the game you're playing, most of the time this will be 60, but for PAL games most is 50, some games are 30.

7.) In the second tab, This is all your own preference, you can set your language, controller types, and paths to memory cards. For most, the defaults will suffice.

8.) The next tab over is the Wii tab, Most Wii games prefer Progressive Scan on, but some do not, if you're having difficulties playing some wii games, you might want to disable this. You can also set sensor bar location, screen saver, aspect ratio and language. These are all you own preference options, the other option is called Enable EuRGB60 Mode (PAL6) Use this if playing PAL games, best to leave off if you don't play PAL games.

9.) The next tab is the Paths Tab. Here you'll want to add the paths to your roms, you might also want to set it to use subfolders depending on how you have your folders setup with your roms. Simply click Add, and browse to the location of your roms and click OK.

10.) The next and final tab is the Plugins tab, here you can select different plugins for Dolphin to use, Currently there are two video plugins for Dolphin, OpenGL or Direct3D. Direct3D currently runs faster than OpenGL, however has more graphical problems, if you're looking more for quality/compatibility use OpenGL, if the game seems to work with Direct3D without problems, you might be better off with it. Next is the DSP plugin, and you have 2 choices here, HLE and LLE. Unless you're just testing things on LLE, you're better off using HLE for the DSP plugin. (this is mostly for audio) The Pad plugin is for your controller or Keyboard setup, best to use nJoy 0.3, but you can play with the others and see which ones work best for your controller/keyboard. Last is the WiiMote plugin, there is only one as of this time.

11.) Click OK on this and click Options and select Graphics. Here you have options to setup resolution, aspect ratio, filtering, vsync, rendering to main window, post processing shaders, etc. Most of these are going to be your own preferences, If you are setting your own resolution and not using the native one, you should turn on Auto Scale. The rest of the settings are pretty much up to you to set. I'm not sure what games need Real XFB, but if a game isn't working you might try enabling that.

12.) In the other tab of the Graphics configuration, here's where the game discussion forum will come in handy, most people have documented the best settings for certain games.
- The top portion is informational, most of these you'll just leave off, I like to have FPS displayed so I turn that on.
- The Rendering portion is where you can disable certain features depending on the game, they require different settings. EFB Copy for the most part should be set to Copy EFB to system RAM. But again some games require this to be different.
- Below these is the Utilities, most of the time you'll just leave these disabled. Free look is kind of fun, but not useful to playing the game.
- Below that we have the hacks. Here's some of the hacks that help games to work better or work at all. Unless the game you're playing needs the hack, it's best to set this to none. Safe Texture cache is mainly for the Metroid Prime series, this should be off unless you're playing those games.

13.) Now click Close on that window, From here click OPtions and go to DSP Settings. Here you can set the volume and Audio and DSP settings, most games will use HLE Audio, DTK Music and Other Audio, enabled. RE0 fix is just a fix for Resident Evil game. should be disabled unless you are playing that game. Audio backend should be set to DSound, OpenAL works, but it's buggy.

14.) Click OK on that screen. Now all you have to do is set up your controller settings. (Options -> Pad Settings or Wiimote Settings for Wiimote) Those screens are pretty self explanatory just click the button you want to setup and press the button on your controller or keyboard you want to set it to.

And that's it, you're all setup to play, your games should be listed in the window and you can open them by just double clicking them.

list open ports and unix sockets

To do this I use netstat command to list all open ports: $ sudo netstat -tuplen to list open ports and unix sockets: $ sudo netstat -...