vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Telling the computer what to do! Might be wishfull thinking, but it is a good exercise for your brain. An exercise that could just keep old age Alzheimer's away.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Have not used wxPython ever since Python3 came out.
I still have Portable Python276 on my flashdrive and found this.

Have you tried wxPython's wx.lib.plot.PlotCanvas()?
Here is an example ...

# using wxPython's wx.lib.plot.PlotCanvas()
# to show a line graph of some trig functions
# also save graph to an image file
# vega

import wx
import wx.lib.plot
import math

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        # calculate data lists of (x, y) tuples
        # x is in radians
        sin_data = []
        cos_data = []
        x = 0
        while True:
            y = math.sin(x*x)
            sin_data.append((x, y))
            y = math.sin(x*x) + math.cos(x**0.5)
            cos_data.append((x, y))
            x += 0.01
            if x > 4*math.pi:
                break

        # set up the plotting canvas
        plot_canvas = wx.lib.plot.PlotCanvas(self)
        # get client usable size of frame
        frame_size = self.GetClientSize()
        # needed for SaveFile() later
        plot_canvas.SetInitialSize(size=frame_size)
        # optional allow scrolling
        plot_canvas.SetShowScrollbars(True)
        # optional drag/draw rubberband area to zoom
        # doubleclick to return to original
        # right click to shrink
        plot_canvas.SetEnableZoom(True)
        # optional
        # set the tick and axis label font size (default is 10 point)
        plot_canvas.SetFontSizeAxis(point=8)
        # set title font size (default is 15 point)
        plot_canvas.SetFontSizeTitle(point=10)

        # connect (x, y) points in data list with a line
        sin_lines = wx.lib.plot.PolyLine(sin_data, colour='red', width=1)
        cos_lines = wx.lib.plot.PolyLine(cos_data, colour='blue', width=1)

        # assign lines, title and axis labels
        gc = wx.lib.plot.PlotGraphics([sin_lines, cos_lines],
            'red=sin(x*x)   blue=sin(x*x) + cos(x**0.5)',
            'X Axis (radians)', 'Y Axis')
        # draw the plot and set x and y axis sizes
        plot_canvas.Draw(gc, xAxis=(0, 7), yAxis=(-2, …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I used Abiword in my diaper days. Now it's all Open Office.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Application and some personal whim will make the choice.

Tcll commented: agreed +4
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This time just a simple example of grading scores (0 - 100) with letters (A - F). Two approaches are presented, one using switch/case in an "on the fly" function, and the other uses the score as an index to a string of letters F through A.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

“Wealth consists not in having great possessions, but in having few wants.”
... Epictetus

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The 10 happiest countries are
Switzerland
Iceland
Denmark
Norway
Canada
Finland
Netherlands
Sweden
New Zealand
Australia

Source ...
http://www.bloomberg.com/news/articles/2015-04-23/these-are-the-happiest-countries-in-the-world

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

When the future switches from being a promise to being a threat, it's time to leave!

Slavi commented: one does not simply leave! +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

One of those high fiber cereals that tastes like saw dust.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A condom stands up to inflation, halts production,
destroys the next generation, protects a bunch of
pricks, and gives you a sense of security while you're
actually being screwed.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another little adventure into Go coding. This time a slice (a Go open ended array) of structures is used as a record for some data processing. For those who miss the ; at the end of a line of code, you can use them, but the lexer of the compiler will put them in for you. Go slices are simpler to work with and faster than traditional arrays, even though they use arrays as a backbone. Go was written for efficiency and speed of compilation in mind, it is intolerant of unused imports and unused variables. The reason you will see the blank identifier _ on occasion.

Note that in Go a multiline string is enclosed in ` (ascii 96, whatever those are called).

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You still do recursion, it's just more efficient in some cases.

BustACode commented: The idea is to use recursion, but when it won't work properly, to use memoization, as in the demo provided. +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Use Google's modern Go language (aka. golang) to convert a denary number (base 10) to a roman numeral. Just a good exercise to explore Go's map, slice, sort and for loop features.

Note that in Go the := is shorthand for assigning a type (by inference) and a value to a variable. A slice is like an array that can grow, and a map is a key indexed list. Go has only the for loop, but the syntax is very flexible and can accomplish all the usual loop duties.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just an example of a persistent list class that could have interesting applications in data mining.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The problem with Small Basic is that it has a goto but no comefrom.

ddanbe commented: Nice! +15
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The dentist slipped and hit the tooth above, so I had to pay for five teeth.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Shows how to convert a comma separated value (csv) string to a list of records, and then do some data processing. The csv strings usually come from csv files created by spreadsheets.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Some folks will do anything to get fresh milk.

Slavi commented: lol +0
Mya:) commented: Haha +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Notice in a farmer's field:
THE FARMER ALLOWS WALKERS TO CROSS THE FIELD FOR FREE, BUT THE BULL CHARGES.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Let's assume you would have to design a 500 ml (about 1.1 pint) food/beverage container like a can and use the least amount of material. Here is a Python program that explains the steps to achieve this.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is an example where I knew the codec (latin_1) ...

# a simple byte string
bs = b'\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef'

# decode Python3 byte string to a string
s = bs.decode("latin_1")

print(bs)
print(s)

''' result (Python34) ...
b'\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef'
àáâãäåæçèéêëìíîï
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another way using the slice operator ...

s = "f0cbf260e0ca8ec2431089fb393a1c29513aaaa5847d13e8be84760968e64dc6"
sx = r"\x" + r"\x".join(s[n : n+2] for n in range(0, len(s), 2))

print(sx)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another concept of Python is slicing ...

mylist = [0, 3, 6, 8, 8, 5, 2, 0, 7, 1, 9, 5, 0, 7, 7, 4, 2]

s = "".join(str(n) for n in mylist)

s2 = "0"
for n in range(0, 17, 4):
    s2 += " " + s[n+1:n+5]

print(s2)    # 0 3688 5207 1950 7742
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

After the media scared us with the high arsenic content of California wine, I am drinking beer again.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A young man goes into a drug store to buy condoms. The pharmacist says the condoms come in packs of 3, 9 or 12 and asks which the young man wants.

"Well," he said, "I've been seeing this girl for a while and she's really hot. I want the condoms because I think tonight's "the" night. We're having dinner with her parents, and then we're going out. And I've got a feeling I'm gonna get lucky after that. Once she's had me, she'll want me all the time, so you'd better give me the 12 pack." The young man makes his purchase and leaves.

Later that evening, he sits down to dinner with his girlfriend and her parents. He asks, if he might give the blessing and they agree. He begins the prayer, but continues praying for several minutes. The girl leans over to him and says, "You never told me that you were such a religious person."

The young man leans over to her and whispers, "You never told me that your father is a pharmacist!"

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

When you write large programs, compile time can be an issue. A language like Go has been developed to minimize compile time by orders of magnitude.

The joke has it that Go was developed by three computer scientists at Google while they were waiting for a very large C++ program to compile.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"April Fool" stems from people who refused to adopt the Gregorian calendar in favor of the older Julian calendar when it was established in the 16th century Europe. While most adjusted to the new calendar, which moved the New Year from April 1 to Jan. 1, those who refused to recognize the change were reportedly subjected to pranks and ridicule.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Using module base64 ...

import base64
encoded = "SGVsbG8gV29ybGQ="
try:
    # Python2
    decoded = base64.decodestring(encoded)
except TypeError:
    # Python3
    decoded = base64.decodestring(encoded.encode("utf8")).decode("utf8")
print(decoded)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

What have you coded so far?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Without thinking ...

mylist = [0, 3, 6, 8, 8, 5, 2, 0, 7, 1, 9, 5, 0, 7, 7, 4, 2]

s = ""
n = 1
for ix, k in enumerate(mylist):
    if ix == n:
        s += ' '
        n += 4
    s += str(k)

print(s)  # 0 3688 5207 1950 7742
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A simple test for a widget ...

''' ps_test_QLabel_image_scroll.py
test PySide widgets
label with an image on it

QScrollArea class provides a scrolling view onto another widget
for more info see ...
http://srinikom.github.io/pyside-docs/PySide/QtGui/QScrollArea.html
'''

from PySide.QtCore import *
from PySide.QtGui import *

app = QApplication([])

# ----- start your widget test code ----

# the image file can be a .jpg, .png, ,gif, .bmp image file
# if not in the working directory, give the full path
image_file = "../image/PorscheBoxster.jpg"

imageLabel = QLabel()
image = QImage(image_file)
imageLabel.setPixmap(QPixmap.fromImage(image))

scrollArea = QScrollArea()
scrollArea.setBackgroundRole(QPalette.Dark)
scrollArea.setWidget(imageLabel)

#scrollArea.ensureVisible(300, 500)
#scrollArea.ensureWidgetVisible(imageLabel, xmargin=150, ymargin=150)

scrollArea.show()

# ---- end of widget test code -----

app.exec_()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A pregnant goldfish is called a twit.

RikTelner commented: A pregnant teen is called a twat. +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is the popularity of computer languages worldwide, Mar 2015 compared to a year ago ( http://pypl.github.io/PYPL.html ) ...

+------+--------------+----------+-------+
| Rank | Language     | Share(%) | Trend |
+------+--------------+----------+-------+
|    1 | Java         |   24.7   |  -0.4 |
|    2 | PHP          |   11.7   |  -1.2 |
|    3 | Python       |   10.6   |  +0.9 |
|    4 | C#           |   8.9    |  -0.3 |
|    5 | C++          |   8.2    |  -0.5 |
|    6 | C            |   7.8    |  +0.1 |
|    7 | Javascript   |   7.2    |  -0.3 |
|    8 | Objective-C  |   6.1    |  -0.2 |
|    9 | Matlab       |   3.0    |  -0.2 |
|   10 | R            |   2.7    |  +0.6 |
|   11 | Ruby         |   2.5    |  +0.0 |
|   12 | Swift        |   2.5    |  +2.9 |
|   13 | Visual Basic |   2.3    |  -0.7 |
|   14 | Perl         |   1.3    |  -0.3 |
|   15 | lua          |   0.5    |  -0.1 |
+------+--------------+----------+-------+
(Trend is in % vs a year ago)
Mian_3 commented: Java 24.7% +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can of course use a generator expression to create a generator ...

gen = (c for c in "Hello World")

while True:
    try:
        print(next(gen), end='')
    except StopIteration:
        print('')
        break
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Module kivy ( http://kivy.org/#home ) anyone?

from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout

class TestApp(App):
    def build(self):
        s1 = "drag me with the left mouse button "
        s2 = "or your finger on a touch screen"
        App.title = s1 + s2
        # this will be the root widget to return
        flo = FloatLayout()
        # allows dragging
        scatter = Scatter()
        s = "Hello World"
        label = Label(text=s, font_size=150)

        flo.add_widget(scatter)
        scatter.add_widget(label)
        return flo

TestApp().run()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a wild guess, look into Jython.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

x * y = 12345678987654321

... that is 1 to 9 and down again. Write a C program that finds the integer values for x and y, where x and y are equal.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Assume you are involved in making closed cylindrical metal cans. Calculate the ratio of radius to height, to give you the largest volume for the least amount of sheet metal.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Apply the financial formulas presented at:
http://www.financeformulas.net/
to create C financial functions.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You see an ad for a software job that goes for 14 days. The conditions are:
on the first day you make 1 cent,
on the second day you double to 2 cents,
on the third day you double this to 4 cents and so on?

Would you take the job?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Write a C program that finds the smallest number that can be divided by each of the numbers from 2 to 10 without leaving a remainder.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Find all the duplicate words in a text using C code.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Write a C program to prove that the sentence
"the quick brown fox jumps over a lazy dog"
uses every letter of the English alphabet.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Today is Pi day (March 14th), so write a C program to show that factorial(0.5) == sqrt(pi)/2

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Q: "What to you call gin and water?"
A: "Hydrogin."

Slavi commented: lols +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Talking about "friggatriskaidekaphobia" the irrational fear of Friday the 13th ...

''' friday13th.py
find all the Friday the 13th of a given year
'''

import datetime as dt
import calendar as cd

# pick a year
year = 2015

begin_year = dt.date(year, 1, 1)
end_year = dt.date(year, 12, 31)

oneday = dt.timedelta(days=1)

friday_list = []
next_day = begin_year
for k in range(0, 366):
    if next_day > end_year:
        break
    if next_day.weekday() == cd.FRIDAY and next_day.day == 13:
        friday_list.append(next_day.strftime("%d%b%Y"))
    next_day += oneday

print("All Friday the 13th for {}:".format(year))
for item in friday_list:
    print(item)

''' result ...
All Friday the 13th for 2015:
13Feb2015
13Mar2015
13Nov2015
'''
more info
help("calendar")
help("datetime")
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

All Friday the 13th for 2015:
13Feb2015
13Mar2015
13Nov2015

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I enjoy hiking in the nearby Sierra Nevada mountains, even on Friday the 13th.

Stuugie commented: Nice! +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The UK is facing a significant skills shortage, with 1.4 million "digital professionals" estimated to be needed over the next five years.

To introduce digital knowledge to younger children, the BBC is giving 1 million "Micro Bit" computers to schools in the UK. When it launches in September it will be compatible with three coding languages - Touch Develop, Python and C++.