445 Topics
Ever since I got a fancy iMac and started using the Xcode IDE, I got hooked on Apple's new Swift language. From what I heard, it is supposed to replace the aging Objective C. I left a couple of Swift code snippets in the Computer Science section about my one-month … | |
The strange title comes from a skit by Benny Hill, where he tells his wife all the facts she shouldn't know, but she always answers "I know! I know!" Anyway, this thread is suppose to be a collection of strange facts. Let's have fun! Here are a few facts to … | |
The bubble sort is slow and I thought it would be interesting to visualize the progress as it sorts an array of integers. | |
When East Germany fell apart, one of the first things people there did was to storm the buildings that housed the much hated Stasi (Ministry for State Security), the ministry that was in charge of spying on their own population. How important is privacy to you? | |
Here lambda is used to create a one-line function for factorials. | |
A little experiment with custom sorting the result of a word frequency count using Google's Go language. | |
Just an accumulation of worldly wisdom in question answer format. Q: "How Do You Get Holy Water?" A: "You Boil The Hell Out Of It." | |
This 'sticky' thread is for working examples of Python GUI code. Note that most wxPython examples have their own thread. Please use comments in your code to help the reader. The example code should be usable as a template, so folks get a feel for the toolkit and can use … | |
I have joined the thousands who have done it before, and have compared a number of sorting routines. The sorting is done on the same random-integer arrays. No surprises, quicksort wins this simple comparison hands down. There are clever combinations of sorting routines that are faster, like the snippet by … | |
I am sitting in front of a brandnew 27 inch Apple Macintosh running on OS X Yosemite, trying to compile a timed insertion sort from my Windows days. The Xcode app is a sweatheart, but there are some Windows things in the code that cause a problem. This line ... … | |
Just a couple of number tricks to check Go's mathematical abilities. If you have more, let's show them here. | |
A few hundred years ago the glorious leader of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then doubling it for every … | |
The story has it that a few hundred years ago the ruler of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then … | |
Again, calculate the minimum number of bills or coins required for a given amount of money (change). This time we will use a Go map instead of a csv string converted to a structure. | |
This Go snippet calculates the minimum number of bills or coins needed for a given amount of money (change) requested. The program also gives the denomination and number. US curency is used in this example, but can be changed to another currency. | |
Another translation of one of my Python snippets. This function will return a slice of consecutive prime numbers from 2 to a given value limit. In Go the 'int' type (int32) will go as high as 2147483647, but you can replace 'int' with 'uint64' and go as high as 18446744073709551615. | |
Generators are rather familiar objects in Python. Generators supply data on demand. Using Go you can create a generator with a goroutine and a channel. Here the goroutine is an anonymous function within a function, simple to implement. | |
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 … | |
Some folks go on vacation around the Easter holidays, so it would be nice to know when Easter happens in the years ahead. I had this as a Python snippet in my "oldies, but goodies" file and translated it to Go. It was actually quite easy in this case, and … | |
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. | |
Just some interesting applications of the bitwise and (&), or (|) operators. You might find some other uses. | |
Reading the content of a web page with a given URL is pretty simple with Go. Here we defer the closing of the response body (at an early point, so we won't later forget) until the program exits. | |
This shows the application of a Memoize decorator to speed up recursive functions in Python. | |
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 … | |
Just an example of a persistent list class that could have interesting applications in data mining. | |
Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program. | |
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. | |
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. | |
This shows you how to create a flashcard like quiz game using a Python dictionary. It's up to you to explore the approach and make this a more meaningful game. | |
I thought it would be fun to code all the different ways to show Hello World on the display. Let's start simple ... `print("Hello World")` Can anybody print out "Hello World" vertically? | |
Just wanted to know if anyone on DaniWeb is using or at least experimenting with Go. | |
The Tkinter GUI toolkit's canvas object is very nice for all sorts of drawings and plotting. However, when it comes to saving the image Tkinter limits you to postscript printer files. One solution is to draw the same image in parallel on PIL's image-draw object in memory. This is made … | |
We have had several snippets on the format() function. This one gives a condensed overview of the many options you have. | |
A very basic pygame sprite example. Moving a sprite with the arrow keys, could be the start of a great space game. | |
Well I done it! Got bored after the holidays and bought a Raspberry Pi credit card sized computer ($35), the least expensive LED TV and a Logitech wireless Keyboard/Mouse combo. The way I ordered the kit it cost almost twice as much, but it came with a good 2.5A powersupply, … | |
One way to find the shortest distance between a series of surface (x, y) points is to let Python module itertools find the non-repeating combinations of point pairs. Now you can apply the Pythagoras' theorem to find all the distances and the minimum distance. | |
A simple code example on how to play wave sound files with the Python module PyGame. | |
Here we use the eval() function as the backbone of a simple calculator. One table is used for the display. A second table holds the buttons for the keypad. The whole thing forms an attractive looking calculator. To test it, simply paste the code into an editor like notepad and … ![]() | |
A simple way to find out a Python module's location on your drive. | |
I used csv data readily available from http://www.weatherdatadepot.com/ to create a multiline plot of the average monthly temperatures of a given location. | |
Two third party Python modules imageio and visvis make it easy to load and view images. The modules come with the pyzo scientific package or can be downloaded separately. Module imageio can read many image file formats as shown in http://imageio.readthedocs.org/en/latest/formats.html You could also replace your image file name directly … | |
With just about everybody snooping around your emails today with the excuse of hunting the bad guys, coding to keep some resemblance of privacy is getting important. I will start out with some simple encryption examples to get this started. You are invited to give us your thoughts and codes. … | |
Knowing the longitude and latitude coordinates of two cities you can calculate the distance between them. Use the code in https://www.daniweb.com/software-development/python/code/490561/postal-code-zips-and-location-python to find the coordinates. | |
Using http://download.geonames.org/export/zip/ you can get postal information for most countries in the world. The raw data string can be transformed into a Python list of lists that can be searched for zip codes, locations, longitude and latitude coordinates. | |
Using the Python win32 extensions it is relatively simple to copy to and from the clipboard. Sorry. the Windows OS is a requirement. | |
Just a small mildly optimized function to check if an integer is a prime number. For very large numbers use the Miller-Rabin primality test. There have been questions why I used `not n & 1` to check for even integer n. The more tradional` n % 2 == 0` is … | |
A dictionary in Python is an unordered set of key:value pairs. I show you how to initialize, create, load, display, search, copy and otherwise manipulate this interesting container. Like the name says, it is the closest thing to a dictionary. | |
Python's double ended queue module makes Caesar's cipher easy. | |
Google Drive, Dropbox, iCloud, and OneDrive are all available to try for free (with limited storage). So far I have used Dropbox and OneDrieve and like Dropbox since it handles better on the PC and my iPad. OneDrive is improving and I have used iCloud on my iPad mostly for … | |
Use the PySide (PyQT) GUI toolkit to play animated gif files. |
The End.