1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for chriswelborn

This is another useful script I came across. It prints a color-code chart in your terminal. It can help you find the color-code you are looking for, or view the current color-scheme you are using (people use it on reddit/r/unixporn to show off their system's theme, I use it to …

Software Development shell-scripting
0
385
Member Avatar for chriswelborn

I didn't write this, the credits are in the code. It's a code-golf version, and I'm sorry about that. I am trying to 'decode' it but I don't have the skills, so the 'decoded' version doesn't have the right colors. This is an example of what you can do with …

0
1K
Member Avatar for chriswelborn

I just wanted to show the basic usage of docopt, a module that makes parsing command-line arguments so much easier. I'm not affiliated with the creators of docopt, but I'm certainly thankful for their work and happy to post this little snippet. I will point you to [docopt.org](http://docopt.org) for more …

Software Development github python
1
3K
Member Avatar for ddanbe

Complex numbers are seldom used in daily life, altough you could say that every real number is complex, but with the imaginary part equal to zero. And btw. "complex" is a bit of a misnomer, perhaps we should call them "easies", because often they make it easier to perform certain …

Software Development mathematics
Member Avatar for ddanbe
0
1K
Member Avatar for kingsonprisonic

This module is for validating textboxes.... After using this module in your project you can simply validate all of your text boxes like [CODE] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AssignValidation(Me.TextBox1, ValidationType.Only_Digits) AssignValidation(Me.TextBox2, ValidationType.Only_Characters) AssignValidation(Me.TextBox3, ValidationType.No_Blank) AssignValidation(Me.TextBox4, ValidationType.Only_Email) End Sub [/CODE]

Software Development email vb.net
Member Avatar for Iamateur
4
1K
Member Avatar for riahc3

Hello This is a demo showing Java interacting with Daniweb's new API ( http://www.daniweb.com/api/documentation ) You introduce a member's name and it should show you the total number of posts he has made. Demo is a proof of concept: No bug checking, error checking, etc is in this code. In …

Software Development api daniweb-api daniweb-bug java
Member Avatar for peter_budo
4
878
Member Avatar for vegaseat

Here is a short Python program using the module pygame that lets you play a midi music file. Midi files are instrumental music files that pack a lot of good sound into a small file. They are very popular with web page designers.

Software Development python
Member Avatar for diliupgabadamudalige
0
5K
Member Avatar for vegaseat

A somewhat newer look at Peter Parente's pywin32 based speech engine. It will read text on your computer.

Software Development python
Member Avatar for ZZucker
3
307
Member Avatar for vegaseat

Yes, you can let your computer read text to you. The task is relatively easy, if you have Windows on your machine. All you need is Microsoft's speech-API SAPI, the Python Text to Speech module pyTTS, and an updated version of win32com, all free downloads. Here are some experiments with …

Software Development api python windows-api
Member Avatar for ZZucker
1
2K
Member Avatar for ddanbe

Btw. this is not a sudoku solver. To gain a deeper insight into the workings of the DataGridView beast (but I begin to love and appreciate it) I decided to make myself a sudoku layout with it. Start a forms app. Make the form a bit bigger and fill in …

Software Development vb.net
0
1K
Member Avatar for TrustyTony

You can fix one parameter of function call by calling underlying method of fixed parameter instead of using functools.partial or lambda statement.

Software Development python
Member Avatar for paddy3118
1
290
Member Avatar for vegaseat

This code example shows how to create a dictionary with row,column indexed (r,c) key tuples from a typical list of lists 2D matrix. Also an example is shown of the ease of processing the resulting dictionary.

Member Avatar for TrustyTony
5
6K
Member Avatar for riahc3
Member Avatar for Lardmeister

This code shows how to use a minimum Windows Gui program to display the results of a bubble sort of an integer array.

Software Development gui
Member Avatar for kplcjl
0
1K
Member Avatar for vegaseat

A simple test of PySide's QFileDialog widget and its method getOpenFileNames. Use method getOpenFileName if you want just one file name.

Software Development python
3
3K
Member Avatar for L7Sqr

Hello. This code snippet is a basic calculator. The general concept is that the calculator accepts infix expressions as strings, converts them to reverse polish notation by way of the shunting-yard algorithm and then evaluates the resulting expression. I tried to encapsulate the functionality of each piece so that, in …

Software Development algorithm c++
Member Avatar for happyuk
2
6K
Member Avatar for Diamonddrake

I needed a 5 minute countdown for a project I was working on so I hacked this up, It does nothing more and nothing less. Figured I would post it while I was here to save someone else the trouble. (Not that it's in anyway difficult to do.)

Software Development
Member Avatar for kplcjl
1
3K
Member Avatar for vegaseat

Simple code to show you how to display an image from a Web URL using the Tkinter Python GUI toolkit, the Python Image Library (PIL) and the data_stream created with io.BytesIO().

Software Development image python tkinter
Member Avatar for vegaseat
3
4K
Member Avatar for deceptikon

I was going to post this in a thread, but it turned into something a bit more serious and may be useful as a code snippet. The code shows three files: * menu.h: The header file for the menu library. * menu.c: Implementation of the menu library functions. * main.c: …

Software Development c c++
Member Avatar for deceptikon
3
592
Member Avatar for vegaseat

So you want to find out which day of the week you were born. Well at least some of us do. I actually wrote this program because my whole family was born on Sundays, and my friends didn't believe it! An oldie but goodie, moved from DeSmet C to Turbo …

Software Development c
Member Avatar for jnawrocki
3
1K
Member Avatar for awuja

Hey guys.. need some help with this; I'm pulling my hair out.. i've trawled these boards but can't find anything that answers my question. I, like many others before me (so it seems!) am trying to create a program to check for a palindrome.. this is what I have so …

Software Development assembly
Member Avatar for robertospartan
0
685
Member Avatar for DavidKroukamp

I have seen many questions on autocompeletion for *java text components* like `JTextField` `JTextArea` `JTextEditorPane` etc. There are not many options either: 1) 3rd party library (like SwingX) 2) DIY (i.e using `DocumentListener`, `JWindow` with `JLabel` etc and a few requestFocusInWindow calls) I chose number 2 and put the code …

Software Development java java-swing
Member Avatar for bguild
1
1K
Member Avatar for Arman Majumder

A temperature converter GUI. Converts from Celsius to Fahrenheit and vise versa. Tests JLabels, JButtons and JTextFields. *Two separate programs, Converter and Thermometer (Thermometer Class)*

Software Development gui java
Member Avatar for robinlrandall
0
744
Member Avatar for tinstaafl

Here's a simple wrapper for printing text. Built as a class library, this can be used in any .net application. This has automatic word wrapping. I figured that using the new constructor to accept different parameters would easily allow for printing different documents with different settings. I included Name, Font, …

Software Development asp.net visual-basic
1
582
Member Avatar for delta_frost

The above code computes the value of a mathematical expression supplied at command line by using the concept of converting infix to postfix,then evaluating the postfix expression. Any comments are appreciated.

Software Development java
Member Avatar for delta_frost
0
474
Member Avatar for Dave Sinkula

Finding some text and replacing it with new text within a C string can be a little trickier than expected. Here is what I had come up with one day.

Software Development c
Member Avatar for deceptikon
0
1K
Member Avatar for vegaseat

This short piece of code shows you how to display text in color in a C# windows console program. The corresponding WIN32 API functions are in the kernel32.dll and are imported and declared external. The only other problem is to assign variable types that accommodate the types listed in the …

Software Development api c# windows-api
Member Avatar for KrayZVIII
0
1K
Member Avatar for vegaseat

A permutation is the arrangement of a set of items in different order. One interesting application is the rearrangement of characters in a word to create other words. If all the n characters are unique, you should get n! unique permutations. You can make a list of words unique by …

Software Development python
Member Avatar for vegaseat
1
6K
Member Avatar for vegaseat

Scientists and deficit spenders like to use Python because it can handle very large numbers. I decided to give it a test with factorials. Factorials reach astronomical levels rather quickly. In case you can't quite remember, the factorial of 12 is !12 = 1*2*3*4*5*6*7*8*9*10*11*12 = 479001600, that is 479 million …

Software Development python
Member Avatar for sneekula
2
5K
Member Avatar for vegaseat

This snippet allows you to find the number of ordered permutations of items taken from a population of known size. It uses the well know algorithm with factorials. For very large populations you may want to use an approximation of factorials.

Software Development algorithm python
3
3K
Member Avatar for vegaseat

If you want to know the number of combinations of x things taken n at a time, you can use the Python module gmpy. The module gmpy is a C-coded Python extension module that supports fast multiple-precision arithmetic, very handy if x things reach a large number.

Software Development python
3
476
Member Avatar for Begginnerdev

Upon resizing an anchored combobox - I noticed the text was always selected. This sparked the initiative to fix this problem. (Microsoft decided not to) So by extending the combobox class we can fix this. The following class can be dropped into a form for designer manipulation or as a …

Software Development vb.net
2
276
Member Avatar for Reverend Jim

A lot of questions in the VB.NET forum are database related. Most of the code that gets posted result in one or more comments like "use parameterized queries to avoid SQL injection attacks". I won't describe the nature of a SQL injection because it is easily looked up via google. …

Software Development sql vb.net
Member Avatar for Reverend Jim
6
5K
Member Avatar for vegaseat

This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks.

Software Development gui image python tkinter
4
3K
Member Avatar for vegaseat

Let's imagine you are taking a lot of pictures and modify them with one of those fancy image editors. You burned the image files to a CD, and decided to purge some of the outdated files because your hard drive is getting full. This Python code allows you to set …

Software Development hard-drive python
Member Avatar for Ene Uran
0
540
Member Avatar for deceptikon

As the title says, it's a simple trie class written in C++11. The only operations implemented are insert, remove, and search (both prefix and exact matches). I sort of abandoned the test/debug process, and while I'm somewhat confident that there aren't any serious bugs, I can't guarantee it. Use this …

Software Development c++
Member Avatar for deceptikon
3
406
Member Avatar for Ketsuekiame

So, in answering another thread on this forum, I decided to do some performance testing on String. Mainly because a friend of mine said "You should always use `new String` it's the fastest!". I wasn't convinced and argued in favour of StringBuilder, at which point I was directed to some …

Software Development
Member Avatar for TnTinMN
0
252
Member Avatar for vegaseat

A simple code example to calculate the monthly payment on a mortgage loan. Takes a look at Python's newer print and format functions.

Software Development python
4
9K
Member Avatar for bumsfeld

This shows the code for one simple crypt of text by swapping two adjoining characters each. You can make that more complex if you like. Can also be used for one nice riddle.

Software Development encryption python
Member Avatar for bumsfeld
2
630
Member Avatar for Gribouillis

This snippet defines a Print function which can be used with python 2.4, 2.5, 2.6 and 3.0 (for 3.0 this is just the built-in print function). It's interface is that of the python 3.0's print. It simplifies the task of writing transitional code which runs under python 2.5 and python …

Software Development python
Member Avatar for Lucaci Andrew
1
824
Member Avatar for vegaseat

Just a different way to extract desired data from an xml code string.

Software Development python xml
Member Avatar for HiHe
3
642
Member Avatar for TrustyTony

Here is my celebration post for entering level 3 in Project Euler. Again I left in my debug prints. I am in process of adapting myself to new .format style of formatting. I have commented out the prints though to get visible the running time of the functions own action. …

Software Development python
Member Avatar for TrustyTony
0
706
Member Avatar for HiHe

Explore the Python module bisect to search a sorted list and insert elements in the proper location in a sorted list.

Software Development python seo
Member Avatar for TrustyTony
3
636
Member Avatar for ddanbe

I wanted to make an array of bits which I could click on and off at will. Sort of a register you could manipulate. First thing that came up was a checkbox control. But I wanted to change the usual checkmark with a 1 or a 0. With tips from …

Software Development
Member Avatar for TnTinMN
0
2K
Member Avatar for vegaseat

A short code to show you how you can download and display an image from the internet on Python's Tkinter GUI toolkit.

Software Development image python tkinter
3
330
Member Avatar for ddanbe

These are (I guess) the most basic printing instructions in C#, to let some printed paper coming out of a printer. Start a new Forms application, drop a ComboBox, a Label and a Button on the form. Implement a form Load and a Button Click event and fill in the …

Software Development printer
2
364
Member Avatar for vegaseat

Just a simple Jython code to test drawing on the canvas.

Software Development java python
3
601
Member Avatar for Reverend Jim

One of the things I have been steadfastly avoiding is writing code to print stuff. Most of what I want to print is from withing apps like Outlook or Word that already provide that functionality. But I finally ended up having to bite the bullet. What I ended up with …

Software Development vb.net visual-basic
Member Avatar for tinstaafl
2
3K
Member Avatar for deceptikon

The annoying use case is this: for (vector<int>::size_type i = 0; i < v.size(); i++) { cout << v[i] << ' '; if (i == v.size() - 1) { cout << endl; } } C++11 offers the `auto` keyword for initializer type deduction so that we can avoid verbose and …

Software Development c++
5
323
Member Avatar for vegaseat

A small test program exploring the PySide/PyQT Label widget. With HTML code you can do some nice formatting of the label's text.

Software Development python
5
749

The End.