System Programming

40K

Solutions

19K

Contributors

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
How to correct

        public static void InsertText(string docName, string text)
        {
            // Open the document for editing.
            Using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(docName, true))
            {
                // Get the SharedStringTablePart. If it does not exist, create a new one.
                SharedStringTablePart shareStringPart;
                if (spreadSheet.WorkbookPart.GetPartsOfType<SharedStringTablePart>().Count() > 0)
                {
                    shareStringPart = spreadSheet.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First();
                }
                else
                {
                    shareStringPart = spreadSheet.WorkbookPart.AddNewPart<SharedStringTablePart>();
                }

                // Insert the text into the SharedStringTablePart.
                int index = InsertSharedStringItem(text, shareStringPart);

                // Insert a new worksheet.
                WorksheetPart worksheetPart = InsertWorksheet(spreadSheet.WorkbookPart);

                // Insert cell A1 into the new worksheet.
                Cell cell = InsertCellInWorksheet("A", 1, worksheetPart);

                // Set the value of cell A1.
                cell.CellValue = new CellValue(index.ToString());
                cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);

                // Save the new worksheet.
                

Open in new window

0
Hi,
To this event
        public static void CreateSpreadsheetWorkbook(string filepath,string SheetName0)
        {
                SpreadsheetDocument spreadsheetDocument;
                if (System.IO.File.Exists(filepath) == false)
                {
                    // Create a spreadsheet document by supplying the filepath.
                    // By default, AutoSave = true, Editable = true, and Type = xlsx.
                    spreadsheetDocument = SpreadsheetDocument.
                        Create(filepath, SpreadsheetDocumentType.Workbook);
                }
                else
                {
                    spreadsheetDocument = SpreadsheetDocument.Open(filepath, false);
                }

                // Add a WorkbookPart to the document.
                WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                workbookpart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();

                // Add a WorksheetPart to the WorkbookPart.
                WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
                worksheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(new SheetData());

                // Add Sheets to the Workbook.
                DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
                    AppendChild<DocumentFormat.OpenXml.Spreadsheet.Sheets>(new DocumentFormat.OpenXml.Spreadsheet.Sheets());

  

Open in new window

0
Hi,
I want to check if relevant SpreadsheetDocument is existing or not, per given filepath (having both full path and document name). Only if the file does not exist, then I create it. Otherwise, I just open it. What to adjust below?
        public static void CreateSpreadsheetWorkbook(string filepath,string SheetName0)
        {
                SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
                    Create(filepath, SpreadsheetDocumentType.Workbook);

Open in new window

0
I was looking a a sed command online (which seems to work fine) and didn't understand why the recommended solution included a [^>].  I don't think it's needed, so I was hoping someone could explain why the poster may have thought it was.   Here's the jist of the questions an recommended solution.

User had a xml file which was all on one line (for clarity it's broken up into multiple lines below) and looked something like this:
<Point><Time>2014-02-12T18:18:49+11:00</Time>
<Position><Lat>35.209656</Lat><Lon>28.99924</Lon></Position>
<AltMeters>586.99994</AltMeters>
<DisMeters>148.30713</DisMeters>
<Cad>4</Cad>
</Point>

Open in new window

The user wanted to remove all occurrences of <DisMeters>.....</DisMeters> from the line in the file.  The recommended solution which seems to work fine was:
sed 's/<DisMeters>[^>]*>//g' file

Open in new window

Why include the [^>], which negates the >?  Doesn't seem needed or am I missing something?
0
Hi,

I am working on below challenge




wordMultiple
Given an array of strings, return a Map<String, Boolean> where each different string is a key and its value is true if that string appears 2 or more times in the array.

wordMultiple(["a", "b", "a", "c", "b"]) → {"b": true, "c": false, "a": true}
wordMultiple(["c", "b", "a"]) → {"b": false, "c": false, "a": false}
wordMultiple(["c", "c", "c", "c"]) → {"c": true}

do i need to care about the output sorting of values like alphabetical ascending or descending etc.

please advise
0
Hi,

I am working on below chalenge

http://codingbat.com/prob/p103593

Loop over the given array of strings to build a result string like this: when a string appears the 2nd, 4th, 6th, etc. time in the array, append the string to the result. Return the empty string if no string appears a 2nd time.

wordAppend(["a", "b", "a"]) → "a"
wordAppend(["a", "b", "a", "c", "a", "d", "a"]) → "aa"
wordAppend(["a", "", "a"]) → "a"


wordAppend(["a", "b", "a"]) → "a"

i expected aa for above as a is at index 2.

please advise
0
Hi,

I am working on below challenge.

http://codingbat.com/prob/p168493

Given an array of non-empty strings, return a Map<String, String> with a key for every different first character seen, with the value of all the strings starting with that character appended together in the order they appear in the array.

firstChar(["salt", "tea", "soda", "toast"]) → {"t": "teatoast", "s": "saltsoda"}
firstChar(["aa", "bb", "cc", "aAA", "cCC", "d"]) → {"d": "d", "b": "bb", "c": "cccCC", "a": "aaaAA"}
firstChar([]) → {}

i was not clear on above description. please advise
0
Hi,

I am working on below challenge.
http://codingbat.com/prob/p117630

The classic word-count algorithm: given an array of strings, return a Map<String, Integer> with a key for each different string, with the value the number of times that string appears in the array.

wordCount(["a", "b", "a", "c", "b"]) → {"b": 2, "c": 1, "a": 2}
wordCount(["c", "b", "a"]) → {"b": 1, "c": 1, "a": 1}
wordCount(["c", "c", "c", "c"]) → {"c": 4}

do i need to worry about sorting like alphabetica in output?
0
Hi,

I am working on below challenge.
http://codingbat.com/prob/p107259
Psedo code:
1. check if mp has a and b as key
2. if yes append keys and values and return map

I wrote my code as below and passing all tests
public Map<String, String> mapAB(Map<String, String> map) {
  if(map.containsKey("a")&&map.containsKey("b") ){
    map.put("ab",map.get("a")+map.get("b"));
  }
  return map;
}

Open in new window


Any improvements or alternate approaches?      

please advise
0
I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine.

Few details of variables passed as a parameter:
server_id = hostname
first_line_log_file =sample.gz
first_line_date_time=2016-09-14 01:09:56,796
last_log_first_line=2016-09-15 04:10:29,719
$do_action_on_cell_2=Do action on cell BL330

ssh -q -o "StrictHostKeyChecking no" $server_id "cd /intucell/data/logs/app; zcat $first_line_log_file | sed -rne '/$first_line_date_time/,/$first_log_first_line/p'| zgrep -A10 -i '$do_action_on_cell_2';" >> ./output.log

However, on executing the above i get the below error

sed: -e expression #1, char 62: unterminated address regex

I think the problem is with sed expression, Please suggest a way forward.
0
Windows 10 just went through yet another update.
Now my view is blocked whenever I want to write anything. Windows assumes I can't hit the keys and offers me handwriting instead.
Where can I say NO once and for all?
And what is he "thing" called in Windows lingo?
Thankyou!
------------------------------------------------------------------------------------------------------------------
screen shot
0
Hi,

 I am working on below challenge
http://codingbat.com/prob/p197888


[/Map-1 > mapBully
prev  |  next  |  chance


Modify and return the given map as follows: if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the value "". Basically "b" is a bully, taking the value and replacing it with the empty string.

mapBully({"b": "dirt", "a": "candy"}) → {"b": "candy", "a": ""}
mapBully({"a": "candy"}) → {"b": "candy", "a": ""}
mapBully({"b": "carrot", "c": "meh", "a": "candy"}) → {"b": "candy", "c": "meh", "a": ""}

how below got below result

mapBully({"a": "candy"}) → {"b": "candy", "a": ""}

there is no b in the input map right then how it came in the output map?
0
Hello Everyone,
I wonder if MFC::CString is ansi or utf-8 by default.  My thought would be to consider it as ansi so the question is how to convert the following sequence:

1. CString str = _T("Hello World");
2. char* pszAnsi = str.GetBuffer();
3. wchar_t* pwUnicode = CString(pszAnsi).AllocSysString();
4. wchar_t* pwUTF-8 = ConvertUnicodeToUTF-8(pwUnicode);

Is it the right sequency ? I know I can directly skip from 1 to 3 but my big wish is to have a method from char* ansi to wchar_t* utf-8 directly.

What can you tell me about that conversion query ?
Thank you very much in advance.
Best regards.
MiQi
0
Ok I am very lost on this part. I have Products and each product has 4 Product Conditions. These Product Condition Codes are NSOP NSSP USOP USSP . Each Product has a parent. Basically Just the Product. Each Product has a Unique SKU Identification Code called ProductParentSKU . They are 11 length Alphanumeric String. Every Product Variant  has a Unique SKU also. It is the ProductParentSKU and then NSOP NSSP USOP USSP suffixed on the end. Example Parent ProductParentSKU would be 59KNC5BWM3K and the Variants would be 59KNC5BWM3KNSOP / 59KNC5BWM3KNSSP / 59KNC5BWM3KUSOP / 59KNC5BWM3KUSSP.
I have just read for days and have tried to set my tables up the best I can with the knowledge I have collected. I have a main table for all the product called ParentProductTable . I then in that ParentProductTable table have 4 fields for each ProductVariantSKU . Like I said this is just what I have read. Wrong or right Who knows.  i read that I needed to set it up like a Customer Order table with a Order Product Table. So I assumed I needed a ProductVariantTypesTable wich I made and I now have to link it back to the fields in my main table.

This is where i am lost.

1: Is this a self joining or what?

2: How do I set it up so that when a customer orders a variant that i can input the correct variant and MS Access get the correct Variant of NSOP NSSP USOP USSP?

3: Is my tables EVEN set up correctly???

I know I could just make every variant a record but that would Quadruple (4X) …
0
Someone helped us here with this cod to ctach an exception and pop up a message to the user with this code:

        private void button1_Click(object sender, EventArgs e)
        {
            lineChanger("QWERTY", "MyTextFile.txt", 2);
        }

        static void lineChanger(string newText, string fileName, int line_to_edit)
        {
            int attemptCounter = 0;
            for (attemptCounter = 1; attemptCounter <= 10; attemptCounter++)
            {
                try
                {
                    System.Diagnostics.Debug.WriteLine("Attempt " + (attemptCounter));
                    string[] arrLine = File.ReadAllLines(fileName);
                    arrLine[line_to_edit - 1] = newText;
                    File.WriteAllLines(fileName, arrLine);

                    // No error - break
                    break;
                }
                catch (IOException ioex)
                {
                    System.Diagnostics.Debug.WriteLine("IOException happened: " + ioex.ToString());
                    if (attemptCounter >= 10)
                    {
                        MessageBox.Show("File is in use");
                    }
                }
            }
        }

Open in new window


However when the message MessageBox.Show("File is in use"); is launched the applciation gives this error:

"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application"

How can be fixed the problem or what could be the problem?

Thank you
0
Hi Team,

I need an help on the unix command, I need to write an single command which will display the number of files in the current directory.
I tried the below command , but not getting the desired output.

ls-al | grep "^d|^ " | wc -l

Any help is really appreciated.
0
Hello all,
    I am newish to bash and I have been researching and looking at hundreds of examples for a large personal project (especially thanks to my help from folks on here), and I have most of the code pretty trimmed down and clean, using a file for config, another for functions, etc, but not quite sure what to do with what I have below. I know bash has ways of doing multiple things in a single line, but I just do not know enough about it to do it. The code works just fine, I get all my output to what I need, just if someone could show me some quick examples of how I can take this code and clean it up, I would greatly appreciate it!
# Get user input for needed variables
function getuserinput(){
read -p "Please specify the new username: " NEWUSER
	if test "$NEWUSER" = ""; then
        echo "$0: sorry, username cannot be blank" >&2
        exit 1;
fi
	if test $? -eq 0; then
        echo 'Username set' >&2
	else
        echo 'Change attempt failed' >&2
        exit 1
fi
read -s -p "Please specify the new password: " NEWPASS
echo ""
	if test "$NEWPASS" = ""; then
        echo "$0: sorry, password cannot be blank" >&2
        exit 1;
fi
	if test $? -eq 0; then
        echo 'password set' >&2
	else
        echo 'change attempt failed' >&2
        exit 1
fi
read -p "Please specify your domain: " NEWDOMAIN
	if test "$NEWDOMAIN" = ""; then
        echo "$0: sorry, domain cannot be blank" >&2
        exit 1;
fi
	if test $? -eq 0; then
        echo 'domain set' >&2
	else
  

Open in new window

0
i need to redirect the input and output.conf files for my workstations so it see my current splunk server. which is the correct location of the file?

C:\Program Files\SplunkUniversalForwarder\etc\system\local

or

C:\Program Files\SplunkUniversalForwarder\etc\system\default
0
Hi,

I am working on below challenge
http://codingbat.com/prob/p118230

Psedo code:
1. if array length is zero return ""
2. if array length is 1 and it is x return ""
3. if array length is 1 and it is not x return same str
4. else find location of x and replace with "" if greater than length
5. return replaced string

public String noX(String str) {
  if(str.length()==0){
    return "";
  }
  if(str.length()==1&&"x".equals(str)){
    return "";
  }
   if(str.length()==1&&!"x".equals(str)){
    return str;
  }
   if(str.length()>1){
    return str.replace("x","");
  }
  
  
  return null;
}

Open in new window




I am passing all tests

How to improve/modify my design, code and any other alternate approaches. please advise
0
Hi,

I am working on below challenge
http://codingbat.com/prob/p101372

Psedo code:
1. if array length is zero return 0
2. if array length is 1 and it is x return x
3. if array length is 1 and it is not x return same str
4. else find location of x and replace with y if greater than length
5. return replaced string
I wrote my code as below

public String changeXY(String str) {
  if(str.length()==0){
    return "";
  }
  if(str.length()==1&&"x".equals(str)){
    return "y";
  }
   if(str.length()==1&&!"x".equals(str)){
    return str;
  }
   if(str.length()>1){
    return str.replace('x','y');
  }
  
  
  return null;
}

Open in new window




I am  passing all tests



How to improve/modify my design, code and any other alternate approaches. please advise
0
Hi,
would request your advise on this pls

I have a couple of directories with bunch of sub directories in date format

eg.
directory name :
/u01/app/date_list/2016-09-10
/u01/app/date_list/2016-09-11
/u01/app/date_list/2016-09-12
/u01/app/date_list/2016-09-13
/u01/app/date_list/2016-09-14
/u01/app/date_list/2016-09-15

would like to delete some directories by accepting date range in comma separated and delete only those directories.
e.g 2016-09-11,2016-09-13,2016-09-15

so outcome after delete would be
/u01/app/date_list/2016-09-10
/u01/app/date_list/2016-09-12
/u01/app/date_list/2016-09-14

I can hard code the base directory to be safe e.g

date_range=$1
base_dir=/u01/app/date_list
 for currentDt in $(echo ${date_range} | sed "s/,/ /g")
do
	if ([ "${currentDt}" != "" ] || [ "${currentDt}" != "*" ]); then
		# is this enough? or can we add some more validation ?
		# rm -Rf  ${base_dir}/${currentDt}
	fi
done

Open in new window



pls help is there any strong validation that I can perform. or a better way to handle this.

thanks in advance
0
Hi,

I am working on below challenge
http://codingbat.com/prob/p120015

Psedo code:
1. if first two numbers return same
2. else call same fibonacci method by passing n-1 and n-2 and sum it up

public int fibonacci(int n) {
  
   if ((n == 0) || (n == 1)) // base cases
      return n;
    else
      // recursion step
      return fibonacci(n - 1) + fibonacci(n - 2);
  

}

Open in new window




I am passing all tests
Expected      Run            
fibonacci(0) → 0      0      OK      
fibonacci(1) → 1      1      OK      
fibonacci(2) → 1      1      OK      
fibonacci(3) → 2      2      OK      
fibonacci(4) → 3      3      OK      
fibonacci(5) → 5      5      OK      
fibonacci(6) → 8      8      OK      
fibonacci(7) → 13      13      OK      
other tests
OK      

How to improve/modify my design, code and any other alternate approaches. please advise
0
I have PC's that have only 240 watt power and small form factor, and they need upgraded graphics cards for Virtual Reality.  I thought that Alienware Graphics Amplifier would be an ideal solution, but Dell told me they don't release drivers for this for any other pc's than their own Alienware branded units.  Does anyone know a workaround for this if I got an Alienware Graphics Amplifier unit to use with other pc's than the Alienware pc's?  Are there any alternative drivers or 3rd party drivers that would somehow work?  Is there another device like this that you might recommend if not that could do the same job?  My computers are USB 3.0 and Thunderbolt compatible.  Thanks!
0
To simplify the problem I found analogical one. Let say you clone the project ( for example this one https://github.com/ignl/BinarySearchTrees )
It use libs from open jdk

https://gyazo.com/47773b9d8f39e7d8be195da83f77441f

Okey I intstall openJDK from here https://github.com/ojdkbuild/ojdkbuild
( I use intellij idea last edition community edition ) I press ctrl + alt+ shift + s and connect the jdk with my project
https://gyazo.com/810cf4bafec0cefc92481cad6c30d4d8
and still it don't work... what could be the problem please help !
0
I'm looking to use a condition for use with serial option in ansible.

The current line is :
serial: '{{ serial_var | default("0") }}'

I would like something like the following but I'm unsure if of syntax:
serial: '{{ serial_var | "0" if action == "deploy" else "1" if action == "upgrade" }}'

The following works but I would prefer not to have both in my file.

- hosts: [mysqlcluster-ndb, mysqlcluster-api]
  serial: '{{ serial_var | default("0") }}'
  roles:
    - { role: mysqlcluster, tags: mysqlcluster, when: enable_mysqlcluster | bool }

- hosts: [mysqlcluster-ndb, mysqlcluster-api]
  serial: 1
  roles:
    - { role: mysqlcluster, tags: mysqlcluster, when: enable_mysqlcluster | bool and action | default('upgrade') }
0

System Programming

40K

Solutions

19K

Contributors

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.

Top Experts In
System Programming
<
Monthly
>