Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

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

Monday, November 5, 2012

Python - Coding with fun

How to reverse a string?

s = 'abcdef'
s = s[::-1]
print s 
Explanation: "::" is known as stride notation
s[::2]
s[::-2]
Returns "ace" and "fdb" respectively.

How to read from console in Python?
name = raw_input()

Want to read an integer?
num = raw_input()
num = int(num) # raw_input returns string, so convert it to integer

Swap values in python:
a, b = b, a

My motivation to learn python is: life is short - you need Python

Tuesday, October 9, 2012

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info.

#go to terminal and give the msg as below
#sudo python sms.py 'CellNumber Msg you want to send'
import gammu
import sys

def main():
    words = sys.argv[1].split(None, 1)
    dest = words[0]
    msg = words[1]
    print msg + "-----" + dest
    #return

    sms = gammu.StateMachine()
    sms.ReadConfig()
    sms.Init()

    message = {
        'Text': msg,
        'SMSC': {'Location': 1},
        'Number': destinationNumber,
    }
    print sms.SendSMS(message)

if  __name__ =='__main__':
    main()

Thursday, September 20, 2012

How to create non-editable JTable:

Override the method "isCellEditable" and implement as needed, such as:

//instance table model
DefaultTableModel tableModel = new DefaultTableModel(){
    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
};
//...other codes
table.setModel(tableModel);