in Batch:keep functions in the file they are used in, or keep functions in function-specific files - function

About a week ago I started making a small batch text/turn-based rpg.
Currently what I'm doing is putting all the functions that are used in a file in that file, i.e I have a file named 'Init.bat' I put all the display/logic/arithmetic/validation/variable-functions in it. What I'm wondering is.. would it be better to put the functions in their own file, i.e file for display/logic/etc, or continue what I'm doing now?
The only files that are 'working' are: Classes.bat,Init.bat,PlayerInfo.bat
https://github.com/Ravkrat/batchrpg/tree/fixingInit <-latest build
(hopefully its ok for me to link to GitHub.. the batch file is large now and don't want to make this post to long)
TL;DR
separate functions from the file they are used in and put them in function specific files,or keep functions in the file that uses them.

Related

Access using VBA to change a File Extension wtihout losing formatting

I am not sure that this can be done but I am working on a searchable database for the code for the machines I work on. Basically its a C to VBA interpreter that allows me to quickly find all instances of a variable and move around the code easier to figure out what is going on when I get new versions of the code. To do this I am renaming my C files to text files then using code to scan line by line and add variables, calls, ect.. to my database linking appropriate data.
My question is this when I change the extensions on the files manually from .c or .h to .txt the formatting doesn't change but when I use the VBA name function to copy the file and change the extension over to .txt I loose all white space formatting and instead of having 100 lines of code I end up with everything on a few lines. Theoretically I should be able to still convert it all being on a couple of lines, but I am curious if anyone knows a different way to change the file extension through VBA without altering the format, basically just renames the file without any other alterations. I have tried both the Name function and the FileCopy functions but they both end up removing all white space and putting all the code on a couple of lines.
Thanks for any help on this one.
-Zak

PhpStorm virtual file splitting

I can't find a more appropriate. I'm using PhpStorm to create web content (php, html, css, js..) and I'm facing the problem of long files (not even so long few hundred lines enough to be lost) where it gets hard to find things and remove unnecessary content.
I was wondering if there is a functionality, plugin or external file manager where it creates different files from one file on disk.
For example: when we have a .css file, for sure it's content is dealing with different features/parts of the html but they are all on the same html page. So it's a bad idea to create different .css file for each part, but it would be nice to have different virtual files for each part/feature where we can code and debug separately our code; but they are saved to same file.
Lets say:
common_header.css: deals with headers
common_menu.css: deals with menu (some menu we have on our page)
common_footer.css: deals with what ever to the end of page
... and so on
So now while coding we see different files (best as a subtree of the original file) some thing like that on file manager:
....other file // the dot here should be + since subtree hidden
common.css // the dot here should be - since subtree is shown
common_header.css
common_menu.css
common_footer.css
...
....other file
But when on disk they are all on the same file common.css that is loaded to our browser as one too.
If your target is to reduce the number of files being loaded from your server, after the application has been deployed, you might merge and compress your files as shown here.
In case you don't want to waste computing time to compress the files on each call, you could adjust your build process to generate them once during build (something like minify).

How do you constantly monitor the contents of a file in clojure?

I have an incanter dataset that I would like to re-load every time another processes changes the source csv file. In other words, the mydata_ incanter dataset should be current every time I look. How can I implement this in idiomatic clojure?
(use 'incanter.io)
(def mydata_ (read-csv "./changingfile.csv"))
At some point, another process changes changingfile.csv, how do make sure that mydata_ is updated automatically? This is a bit different from just adding a watch function to an existing data structure within clojure.
Thanks.
nice library for watching the file system here: https://github.com/derekchiang/Clojure-Watch
can be used to watch the csv and can set mydata_ as an atom, or whatever uses mydata can be kicked off from clojure-watches callback.

tiffcp.exe merging a results file with a results file in a loop

I am building a web app that takes several tiff image files and merges them together into one single tiff image file using GNUWin32 tiffcp.exe from command line.
The way I was doing it was to loop through the file list and build a string of file names to merge into one single variable.
strfileList = "c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dvv.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-axs.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dxzs.tif"
Then I would just write to the command line:
tiffcp.exe strFileList results.tif
The file names are guids and so the paths are fairly long and I do not have any control to shorten them. So if I have a bunch of these documents (over 20 files or so), the length of the string variable exceeds the limits for windows command line and the merge fails.
Since this process is just merging files, my next thought was instead of writing the file names to a string, just do the merge one file at a time. So the first time the loop runs the following type of code:
tiffcp.exe file1.tif results.tif
The result is a perfect 476k tif file. But the next iteration of the loop needs to merge the second file plus the contents of the first "results" tif file. So I do this:
tiffcp.exe results.tif file2.tiff results.tif
The results each time are a blank 1K tiff file?
All the examples I can find of tiffcp.exe say file1.tif file2.tif results.tif, none use the results file to write back to itself?
Any suggestions on how to do this?
Try the -a switch to tiffcp.exe
I'm doing something similar in Python and inside my file processing loop I'm issuing the command:
tiffcpp.exe -a temp.tif output.tif
works fine.
For an ASP.NET project you may want to try LibTiff.Net (free, open source, BSD license). That port of libtiff library contains tiffcp utility with source code. You may try to use it in your code.
Disclaimer: I am one of the maintainers of the library.
I believe your problem is caused by the use of results.tif as both input as output. If you increment the file name (i.e. results1.tif to results2.tif etc.) I believe it should work.
This is a rather inefficient approach (tiff1 is copied 9 times if you have 10 files). Since you refer to libtiff, you may take a look at the source of libtiff cp and check if it is worthwhile to embed it.

How can I add file locations to a database after they are uploaded using a Perl CGI script?

I have a CGI program I have written using Perl. One of its functions is to upload pics to the server.
All of it is working well, including adding all kinds of info to a MySQL db. My question is: How can I get the uploaded pic files location and names added to the db?
I would rather that instead of changing the script to actually upload the pics to the db. I have heard horror stories of uploading binary files to databases.
Since I am new to all of this, I am at a loss. Have tried doing some research and web searches for 3 weeks now with no luck. Any suggestions or answers would be greatly appreciated. I would really hate to have to manually add all the locations/names to the db.
I am using: a Perl CGI script, MySQL db, Linux server and the files are being uploaded to the server. I AM NOT looking to add the actual files to the db. Just their location(s).
It sounds like you have your method complete where you take the upload, make it a string and toss it unto mysql similar to reading file in as a string. However since your given a filehandle versus a filename to read by CGI. You are wondering where that file actually is.
If your using CGI.pm, the upload, uploadInfo, the param for the upload, and upload private files will help you deal with the upload file sources. Where they are stashed after the remote client and the CGI are done isn't permanent usually and a minimum is volatile.
You've got a bunch of uploaded files that need to be added to the db? Should be trivial to dash off a one-off script to loop through all the files and insert the details into the DB. If they're all in one spot, then a simple opendir()/readdir() type loop would catch them all, otherwise you can make a list of file paths to loop over and loop over that.
If you've talking about recording new uploads in the server, then it would be something along these lines:
user uploads file to server
script extracts any wanted/needed info from the file (name, size, mime-type, checksums, etc...)
start database transaction
insert file info into database
retrieve ID of new record
move uploaded file to final resting place, using the ID as its filename
if everything goes file, commit the transaction
Using the ID as the filename solves the worries of filename collisions and new uploads overwriting previous ones. And if you store the uploads somewhere outside of the site's webroot, then the only access to the files will be via your scripts, providing you with complete control over downloads.