I ran across a very strange line of code in a legacy Perl application. The code here is part of a homegrown RSS reader that does some caching to prevent being blacklisted.
open(CAT, "/usr/bin/cat -v /tmp/cat-cache 2>&1|");
Does it seem likely that the original author ran the results through cat -v to strip out non-printing characters...
I wrote these lines but i have NullReferenceException. please help me how to fix it!
string FullPath = TempPath + FileName;
System.Drawing.Image Adimg = null;
Adimg = System.Drawing.Image.FromFile(MapPath(FullPath));
I put these lines in a Public bool method and TempPath is class property and FileName is input for the method.
excepti...
I have a windows service running which moves files from a watched folder (IO.FileSystemWacher) to a UNC share on a network.
The network share is secured, but the share has full control for the Service user; despite this I get problems with the file path not being found.
I intend to impersonate the service (current) user, but am not su...
I'm running Visual Studio 2008 on a Vista Ultimate box. When I create a brand new console application and run the following code via the debugger, I get an expected result -- an UnauthorizedAccessException is thrown and the directory is not created.
Sub Main()
Dim path = "C:\Windows\zzzz"
Try
IO.Directory.CreateDirect...
What is the most efficient solution when you need to record some data on every page view in your application - should you write to a file or write to the database?
Or maybe neither - perhaps you should cache the data in memory or a file and only write it to the database (or file system if you use a memory cache) occasionally?
...
We have a working WPF app that we are looking into running in the browser via Silverlight. The big question mark right now is; what kind of file access will we have (without jumping thought to many hoops)?
Can we open server-side files?
Can we open client-side files?
Can we get change notification on files (client or server side)?
Can ...
This is just a personal project I've been digging into. Basically, I parse a text file (say from 20mb up to about 1gb) using StreamReader. The performance is pretty solid, but still... I've been itching to see what would happen if I parse it in binary. Don't misunderstand, I'm not prematurely optimizing. I am defintely micro-optimizing o...
I have written a PHP application which requires storage of millions of integers between 0 and 10,000,000 inclusive. Each number is incremented by one very frequently (on average 100 values are updated every second) and read very frequently (20,000 reads per second). The numbers are reset to 0 either nightly, weekly, monthly or annually.
...
I have a file that's about 7 MB that saves to my local share in a matter of seconds. However, saving that file to a network location takes minutes. I'm wondering what I can do to speed this up. Here are my current options:
Save the data to a temporary file on the local machine, then copy the temporary file over to the network path. ...
Hello everyone! I've been contemplating writing a simple "event log" that takes a paramater list and stores event messages in a log file, trouble is, I forsee this file growing to be rather large (assume 1M entries or more) the question is, how can I implement this system without pulling teeth, I know that SQL would be a possible way t...
Just getting into python, and so I decided to make a hangman game. Works good, but I was wondering if there was any kind of optimizations I could make or ways to clean up the code. Also, if anyone could recommend a project that I could do next that'd be cool.
import sys
import codecs
import random
def printInterface(lst, attempts):
...
I have a code that looks like this:
int main () {
fstream file;
file.open("test.bin", ios::out | ios::binary);
if(!file.is_open())
{
return -1;
}
int n = 3;
file.write(reinterpret_cast<char*>(&n), sizeof(n));
file.close();
return 0;
}
when I run it alone, it exits with -1, so obviously it failed to open "test.b...
I created this program:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
fstream file;
file.open("test.bin", ios::in | ios::out | ios::binary);
if(!file.is_open())
{
return -1;
}
int n = 5;
int x;
file.write(reinterpret_cast<char*>(&n), sizeof(n));
file.read(reinterpret_cast<char*>(&x), ...
I need to determine in 80% if a file is binary or text, is there any way to do it even quick and dirty/ugly in c#?
...
Hi, I was playing around with memory-mapped files in C and was wondering if there
is a way to replace the FILE * from fopen with a memory mapped file transparently.
Example:
FILE * fp = g_fopen(...);
//Program does things to this fp.
fclose();
But instead, is it possible to have FILE *fp = my_fopen(...)
Where my own function would...
EDIT: Apparently, the problem is in the read function: I checked the data in a hex editer
02 00 00 00 01 00 00 00 00 00 00 00
So the zero is being stored as zero, just not read as zero.
Because when I use my normal store-in-bin file function:
int a = 0;
file.write(reinterpret_cast<char*>(&a), sizeof(a));
It stores 0 as the char ve...
Given an arbitrary file descriptor, can I make it blocking if it is non-blocking? If so, how?
...
In my application I am gathering small data bits into a bigger file over time. As a result, the target file becomes excessively fragmented. What can be done to limit fragmentation of the output file with .NET?
...
When I try to call System.IO.File.Encrypt() on an existing file, it throws a generic IOException, and the message is "Parameter is incorrect".
System.IO.File.Encrypt("C:\Project\StorageDirectory\file.txt")
The current user the process is running under has full control to the "StorageDirectory" folder. Is there something I'm missing...
I'm trying to make my C# code add an image to my (WPF) application's canvas. However, my code does not work.
Image I = new Image();
I.Source = System.IO.File.Open(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", System.IO.FileMode.Open);
I get the error:
Cannot implicitly convert type 'System.IO.FileStream' to 'System.Window...