1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for TrustyTony

Here slightly edited code from one of my earliest posts to DaniWeb. Limitted by recursion limit of Python as it uses recursion, but interesting for me.

Software Development python
Member Avatar for TrustyTony
0
1K
Member Avatar for TrustyTony

Here is my take on [balanced ternary](http://en.wikipedia.org/wiki/Balanced_ternary) conversion (the base considered by [Donald Knuth](http://en.wikipedia.org/wiki/Donald_Knuth) "Maybe the prettiest")

Software Development python
1
950
Member Avatar for TrustyTony

Here is base conversion function written to deal also with [negative bases](http://en.wikipedia.org/wiki/Negative_base). Not yet balanced ternary, where numbers themselves can be negative, maybe later I add it.. Based on the code in the wikipedia article, which has bug for converting 0.[**Edit: I fixed the bug in wikipedia**]

Software Development python
Member Avatar for TrustyTony
0
249
Member Avatar for CodeNinjaMike

So, basically im using the codea bove to generate coordinates for a grid, but I only want to generate coordinates for the "outer ring" of a square. SO imagine a grid of 7x7, I won't generate coordinates for the inner 5x5 square, only for the outer ring. Basically I drew …

Software Development c++
0
611
Member Avatar for lxXTaCoXxl

I realize I haven't released anything in a while so I figure I'll just type a basic set of things for you all to use or learn from. All of the following requires XNA Framework, but can be easily ported over to .NET Framework for use with forms applications. The …

Software Development
0
123
Member Avatar for venkates.99

I have Excel like #EmpId EmpName ProjName Date JiraId ***Thursday, March 01, 2012***# 1 test3 Project Name 4/11/2012 1810 5 2 test4 Project Name2 4/11/2012 1810 6 when I read data to DataTable the result will be like #EmpId EmpName ProjName Date JiraId ***40969***# 1 test3 Project Name 4/11/2012 12:00:00 …

Software Development
0
154
Member Avatar for pce369

I wrote a linked list program in C++ which compiles and works well. But I have been told that a) I have to have two separate structs instead of one that contains both the info and the node; and, b) that I have to use two pointers instead of the …

Software Development c++ linked-list
Member Avatar for Labdabeta
0
430
Member Avatar for mb01a

Have you ever needed to open a file with your VB program? Here's a way to easily do it. (code copied from an original program written by Mike B) If the program that uses the file is installed on your workstation, the file will be opened in that application. I …

Software Development file-system visual-basic
Member Avatar for deades
1
1K
Member Avatar for vegaseat

This snippet explores the change of a hexadecimal (base 16) string to a denary (base 10) integer and the reverse. Interestingly Python allows the representation of the hexadecimal string in two different forms. For instance 255 can be changed to 'FF' (also 'ff') or '0xff'. Any of these hexadecimal strings …

Software Development python
Member Avatar for warunn
1
8K
Member Avatar for ddanbe

Start a new console application and fill in the about 70 lines of code in the Program.cs file. Run and enjoy!

Software Development
Member Avatar for ddanbe
2
408
Member Avatar for gbertoli3

Get the Driver's Name, Path, Description, Status, and Start Mode

Software Development
Member Avatar for habermanm
1
3K
Member Avatar for TrustyTony

Sometimes, before optimizing your code, you may end up to have very slow running code in list comprehension statement. Because you have not yet tested the code fully, it easy to loose patience and just interrupt the code. If you are making function, you can insert print statements for verification. …

Software Development python
Member Avatar for Gribouillis
1
1K
Member Avatar for CppBuilder2006

this program contains a template function that can calculate determinant of any n by n matrix using permutations. it can be run in Visual C++ 2010 Express.

Software Development c++
Member Avatar for aruldave
2
461
Member Avatar for dwarvenassassin

Again, for anyone working with ID3 version 1 or 1.1 tags. This class is used to store the tags associated with a given file. There is a default constructor in case you need to instantiate an 'empty' instance, but in 99% of cases you pass the filename of the audio …

Software Development audio
0
193
Member Avatar for dwarvenassassin

For anyone working with ID3 version 1 or 1.1 tags in audio files, this static class may come in handy. It uses indexers to convert between the textual to the numerical representation or from numerical to textual and also accounts for unset and invalid values. Being static, it is always …

Software Development audio
0
220
Member Avatar for JJCollins
Member Avatar for Jx_Man

This Code is easy way to load / show data in Datagrid. This Code write in vb.net 2003 and use sqlserver 2000 as database. I use module to connected VB.Net with SqlServer 2000. so the function to connected can be use in every form in this project.

Software Development vb.net
Member Avatar for neronero
1
2K
Member Avatar for verruckt24

I have seen several posters asking for help on programs converting an Infix expression to a Postfix one. I have written a program to convert a simple Infix expression to a Postfix one so that people here can be directed towards some sample code from which they get the idea …

Software Development java
Member Avatar for verruckt24
1
1K
Member Avatar for sandeepparekh9

Ever Thought if it was possible to not WebBrower control and use the Firefox Browser in your c# window Application...?? Yes ,, It is possible using GeckoFx wrapper class for C#.net and vb also. You will need the Followings: 1. [URL="http://code.google.com/p/geckofx/downloads/list"]GeckoFx Wrapper[/URL] 2. [URL="http://mirrors.directorymix.com/mozilla/xulrunner/releases/1.9.1.2/runtimes/"]Xul Runner[/URL] (Download the zip file from …

Software Development c#
Member Avatar for newlonator
0
936
Member Avatar for vegaseat

The code shows a fast prime number generator using a sieve algorithm. It looks at only odd numbers. Technically 1 and 2 are prime numbers too, since they are only divisible by unity and themselves, exceptions are made for 1 and 2. Zero and negative numbers return an empty list. …

Software Development algorithm python
Member Avatar for Mavericks
1
3K
Member Avatar for ddanbe

While surfing the web I got to this site: [url]http://en.wikipedia.org/wiki/Fourier_series[/url] “Hey, I why not write something like this in C#!” The rather scary looking formulas did not withhold me to start coding (see below Fig. 1 and Fig. 2) The formula from Fig. 2 is hidden under one of the …

Software Development c# mathematics
Member Avatar for skatamatic
0
3K
Member Avatar for Gribouillis

I discovered and installed a firefox addon called Remote Control. This addon starts a telnet server which lets you send javascript commands to the firefox web browser. Combined with python telnetlib module, it becomes very easy to reload or change the content of a tab in a running firefox from …

Software Development python web-browser
Member Avatar for Gribouillis
0
928
Member Avatar for serkan sendur

Query your datatable like sql's "select distinct" statement

Software Development
Member Avatar for alokgolu
0
287
Member Avatar for Gribouillis

These two functions compute the orders of the lowest bit and the highest bit set in the binary representation of an integer. I expect them to handle securely very large integer values.

Software Development python
Member Avatar for Gribouillis
1
2K
Member Avatar for Fungus1487

below is a very simple encryption class which shows how to encrypt sensitive data (very simply) this example converts a string to hexadecimal form and back again with some simple error handling. please leave some feedback if you find this useful

Software Development encryption vb.net
Member Avatar for enelramon
0
370
Member Avatar for Aniqa Shaikh

Hay guys, i wanted to get the code for a very large factorial but i was unable to do so. Now, i had to work and develop the code myself, which i did. This code calculates factorial of numbers uptil 14000. . i havent tried more. But i guarantee this …

Software Development c++
Member Avatar for sameershah21
1
673
Member Avatar for tux4life

I've written a program to add two hexadecimal numbers ... Njoy ! tux4life

Software Development c++
Member Avatar for alebuddy
0
1K
Member Avatar for lxXTaCoXxl

I haven't tested this yet but it should work. The implementation is fairly simple. I don't have my laptop so I can debug the code at the present time. This basically increments the frame count everytime the game draws itself (allowing us to calculate frames per second considering the draw …

Software Development
Member Avatar for lxXTaCoXxl
0
257
Member Avatar for lxXTaCoXxl

I've developed a simple class and enum that will make ammunition creation and usage simpler in game development for those who are interested. I will be making a tutorial video on how I made this so that you will fully understand how the code works if you do not. Simply …

Software Development
Member Avatar for lxXTaCoXxl
-1
248
Member Avatar for lxXTaCoXxl

I used a label inside my snippet just to test it; but this will simply increment and decrement a float value by 0.2f between the values specified in the conditionals. I have it updating between 8f and 15f. Must be run on a timer (make sure the interval is low …

Software Development
Member Avatar for lxXTaCoXxl
2
176
Member Avatar for abelLazm

Just came across a code of compressing file thought to share :). Code for text file only can be changed for other filetypes....It reduces nearly 97% of the file size ... [CODE]OpenFileDialog opd = new OpenFileDialog(); FolderBrowserDialog fbd = new FolderBrowserDialog(); textBox1.Text="Path + File To compress";//open file by open file …

Software Development file-system
Member Avatar for skatamatic
0
875
Member Avatar for vegaseat

Take a look at a typical Windows GUI frame (form) with a menubar, statusbar, panel, label and buttons. Set the font and size of text, click the buttons to create some events. All of this and much more is in the free wxPython package.

Software Development gui python
Member Avatar for pyphil
2
284
Member Avatar for lxXTaCoXxl

There only two glitches within this code that I can't seem to get 100% spot on. However, this will create a functioning menu (text based) on your form at runtime. I plan to develop an actual control exactly like it. It uses a custom class I developed called LocationBounceEffect that …

Software Development
0
170
Member Avatar for ddanbe

Short snippet on how you could remove all occurrences of a char from a string using LINQ.

Software Development asp.net
Member Avatar for ddanbe
0
1K
Member Avatar for lxXTaCoXxl

XNA Game Studio is not required to use this functionality. This example is very basic, and I typed it up because I was bored. It does not contain functionality for navigation through the menu, but it will display the menu as it should at the specified location. Please enjoy it, …

Software Development
Member Avatar for lxXTaCoXxl
0
153
Member Avatar for raj26061990

eg. 14 and 15 Find all the factors of 14 and 15. 1,2,7,14 are factors of 14 1,3,5,15 are factors of 15 Sum all the factors of two numbers and if sum of factors of two numbers taken are respectively equal they are Amicable numbers.

Software Development java
Member Avatar for cms271828
0
487
Member Avatar for TrustyTony

Inspired by discussion in [url]http://www.daniweb.com/tutorials/tutorial238544.html[/url] (test cases are from there) I used my magic pattern matching function transformed from numbers and adding the parts length checking loop. I like my own solution better, I do not know about you.

Software Development email python
Member Avatar for TrustyTony
0
2K
Member Avatar for Gribouillis

This snippet defines a decorator @mixedmethod similar to @classmethod, which allows the method to access the calling instance when it exists. The decorated functions have two implicit arguments [i]self, cls[/i], the former having a None value when there is no instance in the call. Using python's descriptor protocol, the implementation …

Software Development python
Member Avatar for TrustyTony
1
440
Member Avatar for Jaks_maths

Returns the largest sum of contiguous integers in the array Example: if the input is (-1, 2, -3, 2, 0, 5, -11), the largest sum is 7 Time complexity is O(n).

Software Development c
Member Avatar for mariola
-1
1K
Member Avatar for roverphoenix

A simple program to calculate permutations of a string using recursion, I have used a malloc string of size 100 , you can change it to whatever value you want. The author is currently working at Microsoft,any questions can be directed to [email snipped]

Software Development c
Member Avatar for roverphoenix
0
422
Member Avatar for invisal

this function will calculate a string formula which support cos, sin, log, abs, mod, and example : [10*2+(2+3)]/(5 mod 4) and you will get the answer, and this function it really easy to plugin with you code.

Software Development visual-basic
Member Avatar for JoeyJoeC
1
307
Member Avatar for sandeepparekh9

hi.. guys.. just joined daniweb.. and this is my first post this one's very easy... i suffered a lot to find this simple program.. i hope you guys like it.. here is a quick preview of it...[URL="http://lh4.ggpht.com/_blnOia1d0Pw/TQs3BhaCClI/AAAAAAAACco/3vPqJIlyG-M/gmail%20client.JPG"]http://lh4.ggpht.com/_blnOia1d0Pw/TQs3BhaCClI/AAAAAAAACco/3vPqJIlyG-M/gmail%20client.JPG[/URL] 1. First Of All Add the Following Line to your code: [CODE]Imports System.Net.Mail[/CODE] …

Software Development vb.net
Member Avatar for kothaisaravan
0
455
Member Avatar for agent154

I created this simple inherited class to add a function for moving a row up or down within a DataTable. Sometimes it is desired to do so, and I've seen a few people online looking for a way to do it. Would be nicer if I knew how to properly …

Software Development
0
1K
Member Avatar for vegaseat

Version 2.6 of wxPython has support for playing animated gif image files. The example sets up a panel on a frame and then uses wx.animate.GIFAnimationCtrl() to do the hard work. Actually pretty simple code.

Software Development python
Member Avatar for woooee
1
2K
Member Avatar for PdotWang

I want to create 100 buttons in a Form. This is what I just tested. When you finish the following steps, you will see it is very nice. Enjoy. Step 1, Create a Form called Form1. Step 2, Add a TableLayoutPanel called TableLayoutPanel1. Step 3, Make it 10 X 10 …

Software Development vb.net
Member Avatar for jaimin4829
2
975
Member Avatar for ddanbe

When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the …

Software Development c# mathematics
Member Avatar for skatamatic
0
4K
Member Avatar for lxXTaCoXxl

This release is an updated version of my previously released code snippet entitled "Get Internet Connection State". I've made this snippet into an actual control that you can add to your toolbox. It can be used with all versions of Visual Studio C#. I'm also posting the main source code, …

Software Development visual-studio
Member Avatar for lxXTaCoXxl
1
153
Member Avatar for lxXTaCoXxl

I've developed a code that is intended to be used in an application extension (as with all my codes) that will tell you if the current computer has an internet connection. To use just include the namespace given at the top of the snippet, then the connection state is a …

Software Development
Member Avatar for lxXTaCoXxl
0
237
Member Avatar for Unhnd_Exception

Went to sort a dictionary today and found that MyDictionary.Sort wasn't there. Heres a method to sort a dictionary by value. [code] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Non sorted Dictionary Dim Dictionary As New Dictionary(Of Integer, String) Dictionary.Add(1, "Greg") Dictionary.Add(2, "Marsha") Dictionary.Add(3, "Peter") …

Software Development vb.net
Member Avatar for Unhnd_Exception
0
2K
Member Avatar for vegaseat

Folks have asked numerous times for a code snippet of a binary search of an array. Here is heavily commented code with a few test printf() included to give you a picture of what is going on.

Software Development c
Member Avatar for codinghavok
1
769

The End.