Saturday, December 22, 2012

Enable Hibernate in Ubuntu 12.04


In Ubuntu 12.04 and newer, hibernation has been disabled by default in policykit. To enable hibernation, you can follow official documentation here.

 Before enabling hibernation, please try to test whether it works correctly by running pm-hibernate in a terminal. The system will try to hibernate. If you are able to start the system again then you are more or less safe to add an override.

To do so, start editing:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla


Paste the following lines:

[Re-enable hibernate by default]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

Save and exit gedit.

Restart and hibernation is back!

Or run the following code to just reset the menu:
killall unity-panel-service

Source: How to enable hibernation?

AUTHOR: OBSCURE

Wednesday, December 5, 2012

Serial Port Communication From Java - RxTx Installation.

Want to communicate with serial port using Java? You may want to try RxTx library. It's easy to use.
To install follow the instruction below:

The official RxTx binary pack is available here. The provided link will download the distro with some standard binaries (for linux 32bit, 64 bit, etc). If binaries for your specific operating system are not included, you may consider recompiling RxTx yourselves.
For a custom Win64 RxTx distro, have a look at the CloudHopper's web site.
To install it, unzip the distribution file in a temporary place and do the following copies:
  • File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
  • The necessary library( .so for linux, .dll for windows) should go under JDKDIR/jre/bin/
AUTHOR: OBSCURE

Sunday, December 2, 2012

Ambiguity problem in C++

Functions with predefined value can cause ambiguity in C++. See the example below:


If I call this like this, the first call is ok, but the second call give the ambiguous function error.




AUTHOR:
OBSCURE

Thursday, November 29, 2012

PYTHON REFERENCES

    1. Online Python Tutor : It is a free educational tool that helps students overcome a fundamental barrier to learning programming: understanding what happens as the computer executes each line of a program's source code. Using this tool, a teacher or student can write a Python program directly in the web browser and visualize what the computer is doing step-by-step as it executes the program.
    2. life is short - you need Python!: A blog on Python with tutorials, code, programs, tips and tricks, how-to, book-list, crawler / spider help, data structure and algorithm implementation and many more ... maintained by Tamim Shahriar Subeen, one of the best IT professional in Bangladesh.
    3. Python for fun - advanced python codes: This collection is a presentation of several small Python programs. They are aimed at intermediate programmers; people who have studied Python and are fairly comfortable with basic recursion and object oriented techniques. Each program is very short, never more than a couple of pages and accompanied with a write-up.
    4. site aims to be both a library of educational materials using Python to teach computer programming, and a virtual meeting place for teachers and students engaged in learning and teaching using Python.  Happy computing!

Monday, November 26, 2012

Turtle

Turtle is a Python module to draw pictures.
import turtle # allows us to use the turtles library
wn = turtle.Screen() # creates a graphics window
alex = turtle.Turtle() # create a turtle named alex
alex.forward(150) # tell alex to move forward by 150 units
alex.left(90) # turn by 90 degrees
alex.forward(75) # complete the second side of a rectangle
wn.exitonclick()

Friday, November 23, 2012

Sending SMS via USB Connected Cell Phone with Python

import serial
import time
class SMSsender:
    def __init__(self):
        self.destination = ""
        self.msg = ""

    def setRecipient(self, dest):
        self.destination = dest

    def setContent(self, message):
        self.msg = message

    def connectPhone(self):
        #replace '/dev/ttyACM0' with your device name
        #replace 460800 with a suitable baud-rate of your phone 
        self.ser = serial.Serial('/dev/ttyACM0', 460800, timeout=2)
        time.sleep(1)

    def sendMessage(self):
        self.ser.write('ATZ\r')
        time.sleep(1)
        self.ser.write('AT+CMGF=1\r')
        time.sleep(1)
        self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
        time.sleep(1)
        self.ser.write(self.content + "\r")
        time.sleep(1)
        self.ser.write(chr(26))
        time.sleep(1)

    def disconnectPhone(self):
        self.ser.close()
To send sms use this follow the code below:
sms = SMSsender()
sms.setRecipient('+8801*********')
sms.setContent('Write your message here')
sms.connectPhone()
sms.sendMessage()
sms.disconnectPhone()
You may also try this link(I've not tested yet): sms-over-3g-and-bluetooth-from-python
Source: linux-101.org

Tuesday, November 6, 2012

Make them all glow, can you?


Instructions:
 Click on orbs arranged in a grid to make them all glow. Clicking on an orb 
changes its state from unlit to lit or lit to unlit along with the 
neighboring orbs. Turn on all the orbs to pass a level with as few moves 
as you can. There are 9 levels, each with more orbs than the previous one.
Two difficulty modes. In the easy mode, all orbs are unlit in the beginning 
and in the hard mode, some orbs are already lit to make things difficult 
for the player.
Author:
MUKTO SOFTWARE LTD.