Directory.EnumerateFiles => UnauthorizedAccessException

I Couldn’t get the above to work, but here is my implementation, i’ve tested it on c:\users on a “Win7” box, because if has all these “nasty” dirs: SafeWalk.EnumerateFiles(@”C:\users”, “*.jpg”, SearchOption.AllDirectories).Take(10) Class: public static class SafeWalk { public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOpt) { try { var dirFiles = Enumerable.Empty<string>(); if(searchOpt == … Read more

How to clear cache Android

this will delete cache public static void deleteCache(Context context) { try { File dir = context.getCacheDir(); if (dir != null && dir.isDirectory()) { deleteDir(dir); } } catch (Exception e) {} } public static boolean deleteDir(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < … Read more

What’s so bad about Lazy I/O?

Lazy IO has the problem that releasing whatever resource you have acquired is somewhat unpredictable, as it depends on how your program consumes the data — its “demand pattern”. Once your program drops the last reference to the resource, the GC will eventually run and release that resource. Lazy streams are a very convenient style … Read more

Lazy evaluation in C++

I’m wondering if it is possible to implement lazy evaluation in C++ in a reasonable manner. If yes, how would you do it? Yes, this is possible and quite often done, e.g. for matrix calculations. The main mechanism to facilitate this is operator overloading. Consider the case of matrix addition. The signature of the function … Read more

Spark Transformation – Why is it lazy and what is the advantage?

For transformations, Spark adds them to a DAG of computation and only when driver requests some data, does this DAG actually gets executed. One advantage of this is that Spark can make many optimization decisions after it had a chance to look at the DAG in entirety. This would not be possible if it executed … Read more

When should I use Lazy?

You typically use it when you want to instantiate something the first time its actually used. This delays the cost of creating it till if/when it’s needed instead of always incurring the cost. Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.