Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

A

@A
About
Posts
151
Topics
33
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Algorithm Sum From Offset To Number
    A A

    Yes, Partial sums or Finite series.

    My blog:[^]

    Algorithms com algorithms tools question

  • Algorithm Sum From Offset To Number
    A A

    Wolfram confirmed that the algorithm in my above question is the one to use. To work out the algorithm, start with the algorithm for (sum i from i=0 to number) which is: (n/2.0) * (n+1) Then we need to subtract the offset using the same algorithm: ((n/2.0) * (n+1)) - ((f/2.0) * (f+1)) And finally account for when the offset is greater than zero by subtracting the offset: ((n/2.0) * (n+1)) - (((f/2.0) * (f+1))-f) So the final algorithm is: ((n/2.0) * (n+1)) - (((f/2.0) * (f+1))-f) Incidentally, the same thing applies for i^2, i^3, i^4, and etc, the algorithm just changes.

    My blog:[^]

    Algorithms com algorithms tools question

  • Algorithm Sum From Offset To Number
    A A

    Found the algorithm I was after on www.wolframalpha.com/[^] which answers my question.

    My blog:[^]

    Algorithms com algorithms tools question

  • Algorithm Sum From Offset To Number
    A A

    I was using code similar to the following to calculate the sum from offset(where offset >=0) to length:

    int offset = 2;
    int length = 364;
    
    float sum = 0.0f;
    
    for(int i= offset; i<=length; i++)
    {
        sum += (float) i;
    }
    

    However this seemed a naïve approach so I worked out(from the algorithm for sum (0 to number) that I could use the following: where f=offset n=length sum = ((1+n) * (n/2.0)) - ((1+f) * (f/2.0) - f) which seems to give the correct answer. Out of curiosity what algorithm would normally be used for this kind of thing?

    My blog:[^]

    Algorithms com algorithms tools question

  • Optimizing C++ Code
    A A

    Another good reference for code optimisation(IMHO): http://www.agner.org/optimize/[^]

    My blog:[^]

    The Insider News c++ csharp visual-studio com algorithms

  • Fastest way to select all elements in a *ListBox*
    A A

    Developed a working solution on IE8 though I did run into a select option truncate bug where the first option in innerHTML is removed. :| But in the end I developed a workaround for this bug and have a working hack solution which is much much faster, so all is good. :) cheers.:thumbsup:

    My blog:[^]

    JavaScript javascript com tools question learning

  • Fastest way to select all elements in a *ListBox*
    A A

    BobJanova wrote:

    Manipulating the DOM can be slow. You might do better to get .innerHTML, do a regex replace for '<option( selected)?' with either '<option' or '<option selected', and then reassign .innerHTML.

    Thanks, I'll look into it.

    BobJanova wrote:

    What is with the unroll factor and two loops? That is pointless ... running a for loop 600 times isn't what's slow.

    I'm a c/c++ programmer predominately, force of habit :)

    My blog:[^]

    JavaScript javascript com tools question learning

  • Fastest way to select all elements in a *ListBox*
    A A

    I am trying to select all the elements in a Listbox/SelectBox. At the moment I am using the following function *which is working*, the only thing is it takes around 10 seconds to select all elements(of which there are 652). I'm a beginner at javascript so I was wondering whether anyone knew of a faster way to select all elements.

    //selectBox is the selectbox ID, selectall is a boolean whether to select all elements,
    //ensureOneSelected applies when false is specified for selectall
    //it then ensures that the first element is always selected.

    function selectAll(selectBox, selectAll, ensureOneSelected) {
    // have we been passed an ID
    var selectBoxElement = null;
    var selectBoxOption = null;

    var boolSelect = selectAll;
    
    if (typeof selectBox == &quot;string&quot;) {
        selectBoxElement = document.getElementById(selectBox);
        selectBoxOption = selectBoxElement.options;
    }
    // is the select box a multiple select box?
    if (selectBoxElement.type == &quot;select-multiple&quot;) {
        var max = (selectBoxOption.length);
    
        var modMaxUnrollFactor = (max % 4);
    
        max -= modMaxUnrollFactor ;
    
        for(var i = 0; i &lt; max; i+=4){
            selectBoxOption\[i\].selected = boolSelect;
            selectBoxOption\[i + 1\].selected = boolSelect;
            selectBoxOption\[i + 2\].selected = boolSelect;
            selectBoxOption\[i + 3\].selected = boolSelect;
    
        }
        for (var i = max; i &lt; selectBoxOption.length; i++) {
            selectBoxOption\[i\].selected = boolSelect;
        }
    
        if (typeof ensureOneSelected == &quot;boolean&quot;) {
            if(selectBoxOption\[0\].selected == false)
            {
                selectBoxOption\[0\].selected = ensureOneSelected;
            }
        }
    }
    

    }

    thanks in advance

    My blog:[^]

    JavaScript javascript com tools question learning

  • Linear Regression Most Efficient algorithm calc Line of Best Fit
    A A

    I have a group of points that I need to plot on a graph and calculate the line of best fit(Slope and Intercept) in a programming language. for example x 0 1 2 3 4 y 40 41 45 41 47 At the moment I am using and have implemented the Least Squares algorithm here http://en.wikipedia.org/wiki/Least_squares[^] I was wondering whether anyone knows of a computationally more efficient algorithm with close to the same accuracy and be able to explain how the algorithm works? Thanks in advance :)

    My blog:[^]

    Algorithms com algorithms data-structures tools tutorial

  • Slope method optimisation
    A A

    Thanks Luc. I was so caught up with optimising that I missed the case where offset was one will have to handle that. Good job spotting this.

    My blog:[^]

    C# com data-structures tools help question

  • Slope method optimisation
    A A

    Thanks for the help, and yes the vals array can contain null values.

    My blog:[^]

    C# com data-structures tools help question

  • Slope method optimisation
    A A

    I'm trying to optimise the following Slope method so that it runs in as few clock cycles as possible. Any Suggestions?

        public static double?\[\] slopeImpl(double?\[\] vals, int offset)
        {
            double y = 0;
    
            int iterableLength = vals.Length;
    
            int numValues = vals.Length;
            double invNumValues = 1.0 / (vals.Length - offset);
            double x = (double)(((numValues \* (numValues - 1)) >> 1) - ((offset \* (offset - 1)) >> 1));
    
            for (int i = offset; i < iterableLength; i++) {
    
                y += (vals\[i\].GetType() == typeof(System.DBNull)) ? 0.0 : (double)vals\[i\];
            }
    
            y = y \* invNumValues;
    
            double v1 = 0.0;
            double v2 = 0.0;
            double v2HalfResult = 0.0;
    
            for (int i = offset; i < iterableLength; i++) {
                v2HalfResult = (i - x);
                v1 += (v2HalfResult) \* ((double)vals\[i\] - y);
                v2 += (v2HalfResult) \* (v2HalfResult);
            }
    
            double slope = v1 / v2;
            double intercept = y - slope \* x;
    
            double?\[\] result = new double?\[2\];
            result\[0\] = slope;
            result\[1\] = intercept;
            return result;
        }
    

    What I have considered: 1. There are two loops which are iterating the same number of times; however I am not sure if it is possible to use one loop. The second loop is dependant on the value of y which is calculated in the first loop and the line after. 2. Use a table to calculate x which is of the form n(n-1) /2. Possible, however the values array can contain more than 365 elements. Thanks for any help.

    My blog:[^]

    C# com data-structures tools help question

  • How to write C or C++ program that locks desktop icons placement?
    A A

    For some reason GetStockObject() is not defined. You need to add the following lines to windows.h

    void * GetStockObject(int value);

    If that does not work then replace this line

    wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH)

    with

    wincl.hbrBackground = NULL;

    and the window should turn transparent. Here is some code that partially accomplishes what you want. It does lock the icons on the desktop, although you will not be able to click on them(A nasty trick you could play on someone :-D ). Press the 'Arrange Icons' button to lock the desktop icons. To reenable the desktop icons uncomment this line

    EnableWindow(childOfChildWindow,TRUE);

    in the 'void arrange()' function and recompile. Here is the code:

    #include <windows.h>
    #include <Reason.h>

    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Declare Windows procedure */

    // Forward function(s) declarations
    void arrange();
    void noSaveSettings();
    void restart();

    // Handles

    //The main window handle
    HWND hwnd;

    HWND hLeftArrangeButton; //Handle to the Arrange button
    HWND hDoNotSaveSettings; // Handle to the NoSaveSettings button

    // definitions

    #define WINDOWCLASSNAME "WindowsApp" /* Class Name */
    #define WINDOWTITLE "Auto Arrange"
    #define WINDOWWIDTH 640
    #define WINDOWHEIGHT 480
    #define BUTTONONETEXT "Arrange Icons"
    #define BUTTONTWOTEXT "Add 'NoSaveSettingsKey'"
    #define ERRORTITLE "Error!"

    #define REGKEYNAME "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"

    #ifndef SHTDN_REASON_MAJOR_OPERATINGSYSTEM
    #define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000 //from reason.h
    #endif

    #ifndef SHTDN_REASON_MINOR_RECONFIG
    #define SHTDN_REASON_MINOR_RECONFIG 0x00000004 //from reason.h
    #endif

    #ifndef SHTDN_REASON_FLAG_PLANNED
    #define SHTDN_REASON_FLAG_PLANNED 0x80000000 //from reason.h
    #endif

    int WINAPI WinMain(HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszArgument,
    int nFunsterStil)

    {

    MSG messages;
    WNDCLASSEX wincl;
    
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = WINDOWCLASSNAME;
    wincl.lpfnWndProc = WndProc;
    wincl.style = CS\_DBLCLKS;
    wincl.cbSize = sizeof(WNDCLASSEX);
    wincl.hIcon = LoadIcon(NULL, IDI\_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI\_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC\_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    win
    
    C / C++ / MFC c++ tutorial question

  • How to write C or C++ program that locks desktop icons placement?
    A A

    The instructions from the website http://www.activewin.com/tips/reg/desktop_3.shtml[^][^] are now working(make sure you restart/logoff or it will not work, as I found). Here is the code for a working program that accomplishes the following: 1. Left Align icons on the screen(test this by moving desktop icon(s) to a different part of the screen and then press the 'Arrange Icons' button in the compiled app) 2. Lock icons on the desktop so that they can only be rearranged. The application accomplishes this be creating the NoSaveSettings key as mentioned in the above given website(this sets the Auto Arrange to on after the system has been shutdown/restart/user logged off). 3. Restart the computer. CAUTION before pressing the Add 'NoSaveSettingsKey' button save all of your work as it will restart the computer. You have been warned, use the code at your own risk. Here is the code:

    #include <windows.h>
    #include <Reason.h>

    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Declare Windows procedure */

    // Forward function(s) declarations
    void arrange();
    void noSaveSettings();
    void restart();

    // Handles

    //The main window handle
    HWND hwnd;

    HWND hLeftArrangeButton; //Handle to the Arrange button
    HWND hDoNotSaveSettings; // Handle to the NoSaveSettings button

    // definitions

    #define WINDOWCLASSNAME "WindowsApp" /* Class Name */
    #define WINDOWTITLE "Auto Arrange"
    #define WINDOWWIDTH 640
    #define WINDOWHEIGHT 480
    #define BUTTONONETEXT "Arrange Icons"
    #define BUTTONTWOTEXT "Add 'NoSaveSettingsKey'"
    #define ERRORTITLE "Error!"

    #define REGKEYNAME "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"

    #ifndef SHTDN_REASON_MAJOR_OPERATINGSYSTEM
    #define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000 //from reason.h
    #endif

    #ifndef SHTDN_REASON_MINOR_RECONFIG
    #define SHTDN_REASON_MINOR_RECONFIG 0x00000004 //from reason.h
    #endif

    #ifndef SHTDN_REASON_FLAG_PLANNED
    #define SHTDN_REASON_FLAG_PLANNED 0x80000000 //from reason.h
    #endif

    int WINAPI WinMain(HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszArgument,
    int nFunsterStil)

    {

    MSG messages;            
    WNDCLASSEX wincl;        
    
    wincl.hInstance = hThisInstance;
    wincl.lpszCl
    
    C / C++ / MFC c++ tutorial question

  • How to write C or C++ program that locks desktop icons placement?
    A A

    The following answer makes the assumption that you are using windows XP/vista/7. The following website should help: http://www.activewin.com/tips/reg/desktop_3.shtml[^] If you follow the instructions it locks the desktop icon(s); although it is still possible to rearrange them. To accomplish this in a windows application you will need to use the registry api's(use the 'RegCreate' function(s)) here http://msdn.microsoft.com/en-us/library/aa383729%28VS.85%29.aspx[^] to create a registry key. I tested this on xp and realised that I had auto arrange on, after turning this off it is no longer working. I am now looking for the registry key for auto arrange. I have code in c/c++ that can change the alignment of desktop icons on the (e.g. left align icons), I will post this if you want it.

    My blog:[^]

    modified on Sunday, January 10, 2010 10:05 PM

    C / C++ / MFC c++ tutorial question

  • eMAIL THROUGH VB.NET windows application
    A A

    This article should help, Link: http://www.codeproject.com/KB/vb/VB2005_SMTP_EMail.aspx[^]

    My blog:[^]

    Visual Basic csharp help question

  • Suggestion: Add an Api section
    A A

    One thing that I think would be very useful to have would be an API(Library) section where we can go to look for API's, and anyone can Add any API's that they have found to it. Of course to start this people will have to add API's to it, but it would be a very useful thing to have.

    My blog:[^]

    Site Bugs / Suggestions com tools json question learning

  • gmail doesn't like codeproject
    A A

    Works for me too.

    My blog:[^]

    The Lounge com help question

  • Please help
    A A

    Thanks for the help.

    My blog:[^]

    Algorithms question help com tools

  • Worlds heaviest coin...
    A A

    Steve Mayfield wrote:

    1 inch thick & solid AU (gold)...the Canadian $1 Million coin

    I want that coin...:-D:laugh:

    My blog:[^]

    The Lounge com architecture
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups