EzDevInfo.com

writing

Blog about vim, css, and design.

File reading and writing projects to make sure you understand the concept

New to programming, and I'm beginning to tackle file reading and writing. I understand the basic concept, but I was wondering what kind of projects or tasks I should be able to do in order to fully understand the concept and what is needed to perform programming tasks.

tl;dr - What file reading/writing concepts do you need to understand to be successful and what projects would you recommend to help get an understanding?

Thanks!


Source: (StackOverflow)

Python Multiple file writing question

I need python to write multiple file names, each file name is different than the last. I have it writing in a for loop. Therefore the data files written from the Python program should look like this: data1.txt, data2.txt, data3.txt. How can I do this in Python 3.2? Obviously, the number is the only thing changing as the file name.


Source: (StackOverflow)

Advertisements

Regarding how best to expose programming to a foreign audience

I'm writing a novel at the moment and, while programming will not be receiving a great deal of focus, I do want to at least get it into the reader's head that a character's coding background could cause them to be the way there are about various things.

So, my question is this: what d'you reckon is the best way to talk about the art in such a manner that the reader gains a bit of comprehension without being scared away? Should I drop "smart-sounding" keywords here and there? Include a bit of actual code? All suggestions are welcome...


Source: (StackOverflow)

access violation writing location?

I have a simple program and I get access violation at *(str + start). why? i should be able to change it. Right?

void fn()
{
     char *str = "Hello wordl!";
     int end = strlen(str);
     int start = 0;
     end--;
     while(start < end)
     {
         *(str + start) = *(str + end);  <--- Access violation writing location *(str + Start).
         end--; start++;
     }
}

Source: (StackOverflow)

Designing software at complex levels?

I'm writing a software that appears to be quite a lot more complex than I realized earlier. It performs several sub-tasks, has a set of entirely different tasks and integrates itself to other applications, modules and programming languages. There are hundreds of todo's I need to do, and everything seems a bit too complex to think straight forward. What are some good ways to design your software other than "just writing"? I need to organize my project somehow, I need to know what to write without spending one hour first for figuring out what to do next.

Has anyone been in a similar situation?


Source: (StackOverflow)

Tips for collaboratively editing a LaTeX document

My default setup is to put the tex source in a subversion repository and insert notes to each other as comments in the source when making changes to other people's content. It all feels pretty sub-optimal, especially when there are subversion conflicts where all it tells you is "these two versions of this huge paragraph are in conflict."

I've come up with a few tricks but I'm sure there are much better ideas (or better versions of my ideas) out there.

For collaborating on code, see this question:

http://stackoverflow.com/questions/510163/how-do-you-collaborate

(Some of those answers will apply to collaboration on LaTeX documents as well.)


Source: (StackOverflow)

What is the correct way to refer to Java members in text?

In answering questions I find myself referring to method names and online documentation often. I'm confused about how method names should be referenced in text.

For example I often type:

One should use String.equals() for comparing two strings for equality.

However, this is a little misleading:

  1. It makes equals() appear to be a static member.
  2. It makes equals() appear to not take any arguments.

In the interest of compleness, I would like to know:

What is the correct way to refer to both static members and instance members?

I've seen things like:

  • String.equals()
  • String#equals()
  • myString.equals()

Is there a way to refer to methods in an argument-agnostic manner?

For example, in C foo(void) is explicitly a zero-argument function and foo() can be redefined later to have a different set of arguments. (?)


Source: (StackOverflow)

Efficient way of writing to text file in VB.Net

We have some information that we need to write (about 18KB) to a .txt file stored in one of our network drives. The file is re-written about once every 15 minutes but is read practically at least every second. We are currently using StreamWriter to write file.

The file server is in remote location and the round trip ping varies from <1ms to 15ms.

The problem is, sometimes it takes as long as 6 seconds to write the contents to the file, which is definitely way too long even after we take consideration of the network speed.

Therefore, I am just wondering if there is any efficient way to write the file using VB.Net to improve the performance? Java has a very good tool named BufferedOutputStream, which unfortunately is not available in VB.Net (or I just have not found it).

Thanks a lot in advance!


Source: (StackOverflow)

Easily writing Bundles in Cocoa

How can I write bundles in Cocoa without much "fuzz" around it? I just want to have a bundle with an Info.plist, a Contents Folder and that folder should contain a couple of files.


Source: (StackOverflow)

How can I read data faster?

Hmmm... its kinda challenging to find a method for reading/writing data faster enougth to get ACCEPTED in this problem ( https://www.spoj.pl/problems/INTEST/ ) using F#.

My code ( http://paste.ubuntu.com/548748/ ) gets TLE...

any ideas how to speed up data reading?

thx


Source: (StackOverflow)

Synchronize writing to a file at file-system level

I have a text file and multiple threads/processes will write to it (it's a log file).

The file gets corrupted sometimes because of concurrent writings.

I want to use a file writing mode from all of threads which is sequential at file-system level itself.

I know it's possible to use locks (mutex for multiple processes) and synchronize writing to this file but I prefer to open the file in the correct mode and leave the task to System.IO.

Is it possible ? what's the best practice for this scenario ?


Source: (StackOverflow)

Printing a DataTable to textbox/textfile in .NET

Is there a predefined or "easy" method of writing a datatable to a text file or TextBox Control (With monospace font) such as DataTable.Print():

 Column1| Column2|
--------|--------|
      v1|      v2|
      v3|      v4|
      v5|      v6|

Edit

Here's an initial version (vb.net) - in case anyone is interested or wants to build their own:

Public Function BuildTable(ByVal dt As DataTable) As String

    Dim result As New StringBuilder
    Dim widths As New List(Of Integer)
    Const ColumnSeparator As Char = "|"c
    Const HeadingUnderline As Char = "-"c

    ' determine width of each column based on widest of either column heading or values in that column
    For Each col As DataColumn In dt.Columns
        Dim colWidth As Integer = Integer.MinValue
        For Each row As DataRow In dt.Rows
            Dim len As Integer = row(col.ColumnName).ToString.Length
            If len > colWidth Then
                colWidth = len
            End If
        Next
        widths.Add(CInt(IIf(colWidth < col.ColumnName.Length, col.ColumnName.Length + 1, colWidth + 1)))
    Next

    ' write column headers
    For Each col As DataColumn In dt.Columns
        result.Append(col.ColumnName.PadLeft(widths(col.Ordinal)))
        result.Append(ColumnSeparator)
    Next
    result.AppendLine()

    ' write heading underline
    For Each col As DataColumn In dt.Columns
        Dim horizontal As String = New String(HeadingUnderline, widths(col.Ordinal))
        result.Append(horizontal.PadLeft(widths(col.Ordinal)))
        result.Append(ColumnSeparator)
    Next
    result.AppendLine()

    ' write each row
    For Each row As DataRow In dt.Rows
        For Each col As DataColumn In dt.Columns
            result.Append(row(col.ColumnName).ToString.PadLeft(widths(col.Ordinal)))
            result.Append(ColumnSeparator)
        Next
        result.AppendLine()
    Next

    Return result.ToString()

End Function

Source: (StackOverflow)

Strange problem with reading and writing a plist file

I have an application that read info from I plist file. To do it I use this code below:

  NSData *plistData;  
    NSString *error;  
    NSPropertyListFormat format;  
    id plist;  
    localizedPath = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"];  
    plistData = [NSData dataWithContentsOfFile:localizedPath];   

    plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];  
    if (!plist) {  
        NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]);  
        [error release];  
    }  




    NSString *tel=[NSString stringWithFormat:@"tel:%@",[plist objectForKey:@"number"]];
    NSURL *telephoneURL = [NSURL URLWithString:tel];
    [[UIApplication sharedApplication] openURL:telephoneURL];

And to write it I use this code:

- (IBAction) saveSetting:(id)sender{



    NSData *plistData;  
    NSString *error;  
    NSPropertyListFormat format;  
    id plist;  

    NSString *localizedPath = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"];  
    plistData = [NSData dataWithContentsOfFile:localizedPath];   

    plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListMutableContainers format:&format errorDescription:&error];  
    if (!plist) {  
        NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]);  
        [error release];  
    }  

    NSLog([plist objectForKey:@"message"]);
    [plist setValue:textMex.text forKey:@"message"];
    NSLog([plist objectForKey:@"message"]);

    NSLog([plist objectForKey:@"number"]);
    [plist setValue:textNumero.text forKey:@"number"];
    NSLog([plist objectForKey:@"number"]);

    [plist setValue:@"NO" forKey:@"firstTime"];

    [plist writeToFile:localizedPath atomically:YES];

    [self aggiorna];




    [settingScreen removeFromSuperview];

}

Now I have a big problem, tha app work properly in all my developer device and in the simulator and the app read and write properly the file. I submit the app on the Apple store but others user can't read/write this file. Why this? Thanks Paolo


Source: (StackOverflow)

Bit aligned reading and writing from binary files

I would like to read and write n bits from/to binary files. For example, read the next n bits into an integer or the next n bits to a char. I need the data to be bit aligned and not byte aligned.

Are there C++ libraries that allow me to do that?

When I use ostream/istream, I seem to be restricted to using byte aligned data. This is not good enough if I want my data to be packed tightly.


Source: (StackOverflow)

How to read a file starting at a specific cursor point in C#?

I want to read a file but not from the beginning of the file but at a specific point of a file. For example I want to read a file after 977 characters after the beginning of the file, and then read the next 200 characters at once. Thanks.


Source: (StackOverflow)