I have file text structured as follows
key1,value1
I want to add these key values as facters in my host. I have splitted those key (configs[0]) , values (configs[1]). How to add those to facters using ruby. I have tried following code but not succeeded
configs = File.read("........configuration.txt").split(",").map(&:strip)
Facter.add(configs[0]){
setcode { configs[1])
}
Regards,
Malintha
Related
I googled so far and tried to find out the solution but not yet.
I know require() works only with static path, so I want alternative ways to solve my problem. I found this answer here but it doesnt make sense for thousands of resources.
Please advise me the best approach to handle such case.
Background
I have thousand of json files that containing app data, and declared all the file path dynamically like below:
export var SRC_PATH = {
bible_version_inv: {
"kjv-ot": "data/bibles/Bible_KJV_OT_%s.txt",
"kjv-nt": "data/bibles/Bible_KJV_NT_%s.txt",
"lct-ot": "data/bibles/Bible_LCT_OT_%s.txt",
"lct-nt": "data/bibles/Bible_LCT_NT_%s.txt",
"leb": "data/bibles/leb_%s.txt",
"net": "data/bibles/net_%s.txt",
"bhs": "data/bibles/bhs_%s.txt",
"n1904": "data/bibles/na_%s.txt",
.....
"esv": "data/bibles/esv_%s.txt",
.....
},
....
As you can see, file path contains '%s' and that should be replace with right string depends on what the user selected.
For example if user select the bible (abbreviation: "kjv-ot") and the chapter 1 then the file named "data/bibles/Bible_KJV_OT_01.txt" should be imported.
I'm not good enough in react-native, just wondering if there is other alternative way to handle those thousands of resource files and require only one at a time by dynamically following the user's selection.
Any suggestions please.
Instead of exporting a flat file, you could export a function that took a parameter which would help build out the paths like this:
// fileInclude.js
export const generateSourcePath = (sub) => {
return {
bible_version_inv: {
"kjv-ot": `data/bibles/Bible_KJV_OT_${sub}.txt`
}
}
}
//usingFile.js
const generation = require('./fileInclude.js');
const myFile = generation.generateSourcePath('mySub');
const requiredFile = require(myFile);
then you would import (or require) this item into your project, execute generateSourcePath('mysub') to get all your paths.
I just studied Lua language. I am very confused about it.
I have two file
string.lua
STRINGS=
{
CHARACTER_NAMES =
{
web = "webby",
sac = "sacso",
}
}
STRINGS.BUNNYNAMES =
{
"Brassica",
"Bunium",
"Burdock",
"Carrot",
}
And I have generate.lua file for get value form table in string.lua.
Then print value.
But I don't know how to acess table form another file.
I want to use STRINGS and STRINGS.BUNNYNAMES too,
Please advise me.
string.lua defines one global variable named STRINGS which contains a table.
You need to execute string.lua before you can access STRINGS. Just do dofile("string.lua") for instance.
I want create an iOS app for my school.
This App will show Week schledule and when I tap on Cell with Subject, it will show me detail info about subject...
My problem:
Our teachers use shotcuts for their names, but I want show their full name... I created the file "ucitele.h" with definitions of their names, but I don't know, how to use it 😕.
This is how that file looks:
//
// ucitele.h
//
#define Li #"RNDr. Dan---vá"
#define He #"Mgr. Ja---hl"
#define Sm #"Ing. Mich---rek"
#define Ks #"Mgr. Svat---á"
I get the shortcut of Teacher from previous view from "self.ucitel" and I maybe want compare the contents of the "self.ucitel" with definitions and set the "ucitelFull" string from the definitions? I don't know how to say it 😕.
when the content of the self.ucitel will be #"Sm", than I want parse "ucitelFull" as #"Ing. Mich---rek"
Answers in Objective-C only please
Okay, sounds like your trying to map a short identifier to a full name:
-(NSString*)fullNameFromShortName:(NSString*)short {
NSDictionary * names = #{#"Li" : #"RNDr. Dan---vá",
#"He" : #"Mgr. Ja---hl", ... };
return [names objectForKey:short];
}
Use like:
self.ucitelFull = [self fullNameFromShortName:self.ucitel];
This is a dictionary that has the short name as a key and the full name as the value.
Some further suggestions:
try using lowercase keys and comparing lowercaseString's, incase the user doesn't enter the value with the correct case.
You can move the dictionary definition into a json file and read it from your bundle, to eliminate the hardcoding
I'm reading a CSV file and one of the columns has text that contains symbols that is not recognized. After I read the file, symbols such as ' becomes � . I'm also saving this into a DB.
Obviously when I display this on a webpage, it shows garbage. How can I substitute HTML code (ex. ´ ;) for this with Grails?
I am reading the CSV using the csv plugin. Code below:
def f = "clientDocs/testfile.csv"
def fReader = new File(f).toCsvMapReader([batchSize:50, charset:'UTF-8'])
fReader.each { batchList ->
batchList.each {
def description = substituteSymbols(it.Description)
def substituteSymbols(inText) {
// HOW TO SUBSTITUTE HERE
}
Thanks for any help or suggestions. I've already tried string.replaceAll(regExp).
Grails comes with a basic set of encoders/decoders for common tasks.
What you want here is it.Description.encodeAsHTML().
And then if you want the original when displaying in the view, just reverse it with .decodeHTML()
You can read more about these here: http://grails.org/doc/latest/guide/single.html#codecs
(Edited decode method name typo as per the comment)
I have a directory named 'import' and would like to get all files and their corresponding date (based on filename). Sample content of the directory is this:
input_02202010.xls
input_02212010.xls
input_02222010.xls
I would like to have a Map that contains the path of the file and a Date variable.
Can anyone show me how Groovy will solve this?
Use new File("/foo/bar/import").list() to get the file names, just like you would in Java. Then create file objects from the strings and check lastModified() for the last modification date.
EDIT:
Groovy adds eachFile() methods to java.io.File, we can use that to make it a bit more groovy...
To extract the date from the filename, use
Date d = new java.text.SimpleDateFormat("MMddyyyy").parse(filename.substring(6,14))
To make it all into a map (using the filename as key and the date as value, though redundant):
def df = new java.text.SimpleDateFormat("MMddyyyy")
def results = [:]
new File("/foo/bar/import").eachFile() { file ->
results.put(file.getName(), df.parse(file.getName().substring(6,14)))
}
results