Store data in txt/xml file, read/write to database? - data-structures

My wordpress theme accepts skin files. These skin files all install into my main theme folder via a zip uploader that's part of my theme.
Each skin has a set of custom color codes (4 in all) that are stored in the wordpress options table like so...
Assume the skin name is "halloween"...These are the values in my options.php for one of my skin values...
halloween_color1 = 000000
halloween_color2 = ff0000
halloween_color3 = 777777
halloween_color4 = 333333
So I just need a means to store these values inside of each new skin's folder (the one that I send to people who use my theme) so that when they install the skin (via a simple zip extractor upload) I can place code into my zip extractor to write the skin's custom color values to the database.
I'm assuming a simple, colors.txt or colors.xml file will suffice.
How should I store the data in the text file in order to easily parse it and write it to the database? Name/value pairs or XML?
<skin>
<color name="halloween_color1" value="000000" />
<color name="halloween_color2" value="000000" />
<color name="halloween_color3" value="000000" />
<color name="halloween_color1" value="000000" />
</skin>

There are several options. Two that PHP can read natively are ini and CSV.
INI example:
[skin]
halloween_color1 = 000000
halloween_color2 = ff0000
halloween_color3 = 777777
halloween_color4 = 333333
CSV example:
halloween_color1;000000
halloween_color2;ff0000
halloween_color3;777777
halloween_color4;333333
For me personally, YAML has become the favourite format for human-readable configuration files.
YAML example:
skin:
halloween_colors:
- 000000
- ff0000
- 777777
- 333333
its advantages in my view are:
Parsing is very strict; it will exit immediately and throw an error if it doesn't like the file's structure
It supports nested data structures, the building of associative arrays, typing, and lists (Useful e.g. if you want to add a fifth halloween colour)
But, it needs a third party library. Whether that is justified, you have to decide.
See a list of PHP parser libraries here.

Related

Markdown like UI representation editor for app-config files (INI)

I like the way markdown works. It is just a simple text to represent in graphic format. I'm curious if any similar one available for config file INI representations in UI format. Is there anything of that sort?
Example Config
[Game Config]
Player Name = "John"
//String
Type=Football
//Enumeration List
//Football
//Basketball
//Volleyball
Time in minutes = 45
//Integer number
//Game time in minutes
An UI representer would automatically represent in UI like below

Reading and writing Windows "tags" with Python 3

In Windows image files can be tagged. These tags can be viewed and edited by right clicking on a file, clicking over to the Details tab, then clicking on the Tags property value cell.
I want to be able to read and write these tags using Python 3.
This is not EXIF data so EXIF solutions won't work. I believe it's part of the Windows Property System, but I can't find a reference in Dev Center. I looked into win32com.propsys and couldn't see anything in there either.
I wrote a program that does this once before, but I've since lost it, so I know it's possible. Previously I did it without pywin32, but any solution would be great. I think I used windll, but I can't remember.
Here is some sample code that's using the IPropertyStore interface through propsys:
import pythoncom
from win32com.propsys import propsys
from win32com.shell import shellcon
# get PROPERTYKEY for "System.Keywords"
pk = propsys.PSGetPropertyKeyFromName("System.Keywords")
# get property store for a given shell item (here a file)
ps = propsys.SHGetPropertyStoreFromParsingName("c:\\path\\myfile.jpg", None, shellcon.GPS_READWRITE, propsys.IID_IPropertyStore)
# read & print existing (or not) property value, System.Keywords type is an array of string
keywords = ps.GetValue(pk).GetValue()
print(keywords)
# build an array of string type PROPVARIANT
newValue = propsys.PROPVARIANTType(["hello", "world"], pythoncom.VT_VECTOR | pythoncom.VT_BSTR)
# write property
ps.SetValue(pk, newValue)
ps.Commit()
This code is pretty generic for any Windows property.
I'm using System.Keywords because that's what corresponds to jpeg's "tags" property that you see in the property sheet.
And the code works for jpeg and other formats for reading (GetValue) properties, but not all Windows codecs support property writing (SetValue), to it doesn't work for writing extended properties back to a .png for example.

Keras - using predefined training / validation split

I'm working with Tensorflow/Keras. I have two text files (train_{modality_name}.txt and val_{modality_name}.txt). They contain the split I want to use for the images I'm processing.
The format of these files is the following:
example_0_path category_id
example_1_path category_id
...
example_N_path category_id
and my folder structure is like this:
/labels
train_X.txt
val_X.txt
/data
/modality_1
...
/modality_M
(e.g. data/sketch/abbey/id)
How can I make use of the files?
'flow_from_dataframe' did the job, additionally it was necessary to preprocess the txt with pandas. This tutorial was very helpful: https://medium.com/#vijayabhaskar96/tutorial-on-keras-imagedatagenerator-with-flow-from-dataframe-8bd5776e45c1
Still having problems with matching target size of the arrays (labels seem to have the wrong format)

How to load a file with a JSON array per line in Pig Latin

An existing script creates text files with an array of JSON objects per line, e.g.,
[{"foo":1,"bar":2},{"foo":3,"bar":4}]
[{"foo":5,"bar":6},{"foo":7,"bar":8},{"foo":9,"bar":0}]
…
I would like to load this data in Pig, exploding the arrays and processing each individual object.
I have looked at using the JsonLoader in Twitter’s Elephant Bird to no avail. It doesn’t complain about the JSON, but I get “Successfully read 0 records” when running the following:
register '/tmp/elephant-bird/core/target/elephant-bird-core-4.3-SNAPSHOT.jar';
register '/tmp/elephant-bird/hadoop-compat/target/elephant-bird-hadoop-compat-4.3-SNAPSHOT.jar';
register '/tmp/elephant-bird/pig/target/elephant-bird-pig-4.3-SNAPSHOT.jar';
register '/usr/local/lib/json-simple-1.1.1.jar';
a = load '/path/to/file.json' using com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad=true');
dump a;
I have also tried loading the file as normal, treating each line as a containing a single column chararray, and then trying to parse that as JSON, but I can’t find a pre-existing UDF which seems to do the trick.
Any ideas?
Like Donald said, you should use a UDF here. Here in Xplenty we wrote JsonStringToBag to complement ElephantBird's JsonStringToMap.

how to select few words from text area in selenium rc

steps:
1. i uploaded file using browse option.
2. uploaded file content displayed in non-editable format
3. now i have to select few words.
for this i used mouseMoveAt (100,200) mouseDown() mouseMoveAt (150,250) mouseMoveUp().
This is not working..
Can anyone can give sample code?
I'm not sure I understand your question completely, but here's my take -
You can use selenium.getText(); for retrieving the text on a page and storing it in a variable. You can use this variable, which you can verify for correctness.
Here's an example syntax:
String var = selenium.getText(your_identifier_for_text);
Further, if you need to extract and verify just a portion of the text contained in var, you can use Java string functions.

Resources