c# – How to print text string as QR code?

Need to integrate with a legacy program but cannot change its source code, currently the program can print text label, we would like to change its print result as QR code, i.e., when the program sends text string to the printer, the text string needs to be printed out as equivalent QR code.

Any suggestions on how to achieve this?

Thought maybe need a middle layer virtual printer, the legacy program sends printing text string to the virtual printer, the virtual printer converts the text sting to the equivalent QR code and forward the QR code to the physical printer. Not sure if this is doable? Is there any open source virtual printer project available for modification for the above purpose?

jquery – Replace Source query string value without redirecting

If you are working with browsers that support the HTML5 History API, you could use replaceState:

$(document).ready(() => {
    var redirectUrl = _spPageContextInfo.webAbsoluteUrl + "/" + _spPageContextInfo.layoutsUrl + "/Redirect.aspx";

    var queryParameters = {}, queryString = location.search.substring(1), re = /((^&=)+)=((^&)*)/g, m;

    while (m = re.exec(queryString)) {
        queryParameters(decodeURIComponent(m(1))) = decodeURIComponent(m(2));
    }

    queryParameters('Source') = redirectUrl;

    var updatedParams = location.search.replace(location.search, $.param(queryParameters));

    if (history.replaceState) {
        var newurl = window.location.origin + window.location.pathname + "?" + updatedParams;
        window.history.replaceState({ path: newurl }, '', newurl);
    }
});

However, if you are trying to modify the source on a form in SharePoint, that won’t be sufficient. Some onclick events are populated when the page loads with the initial Source value and these events will have to be override as well since they will redirect to the previous value:

$("#part1").on("click", "input(value='Cancel')", function (e) {
    e.preventDefault();
    window.location.href = redirectUrl;
});

$("#Ribbon.ListForm.Edit.Commit.Cancel-Large").click(function (e) {
    e.preventDefault();
    window.location.href = redirectUrl;
});

java – URLify a given String – replace spaces with %20

Your code does what you describe, but the code does not what it is really supposed to do.

You are not the first person ever who needs to convert an arbitrary string into a form that can be embedded in a URL. Several people before you have already solved this problem. The crucial point is to know how these people named the method or function or class or module where they implemented this function.

In Java, most network-related things are in the package java.net, and since URLs and URIs are network-related, they are there as well. Directly next to the classes URL and URI you will find the class URLEncoder that does all the work for you, including several edge cases you probably never heard of. Using this heavily tested and well-known piece of code is much better than rolling your own.

Hmmm, a pretty heavy down-side of Java’s URLEncoder is that it is old and dusty and probably will not be updated anymore. It does not even encode spaces as %20, but as +, and the + is something that only works in the query string part of a URL.

This Stack Overflow answer describes the bad API that standard Java is providing for this use case. The encoding part of this answer to that question is good, the general Java approach is bad, as I wrote in the comment below that answer. So be careful and don’t copy that code blindly.

google sheets – Function/formula to return only the first string proceeding the first carriage return

Is there a function/formula to return only the first string proceeding the first carriage return using Google Sheets?

Example Text:

Bob & Mary Smith   
bob@email.com   
555-111-1234   

Assuming the above text is in cell A1, I would like the formula to return the following to Cell B1 “Bob & Mary Smith”

C string parser criticism – Code Review Stack Exchange

I have written a program to parse a string depending on the string the user provides.
Any advise/criticism is appreciated.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>

#define DEFAULT_SIZE 10
#define RESIZE_MULTI 2

/*compares value to see if it exists in parse. return 0 if exists*/
static uint8_t compare(const char value, const char *parse)
{
   size_t i;

   i = 0;
   while(*(parse + i) != '')
   {
      if(*(parse + i) == value)
         return 0;
      i++;
   }
   return 1;
}

/*string must be null terminated. the string that needs to be split*/
/*parse must be null terminated. contains value that the string will be split at*/
/*matrix contains all the string that was split based on parse. the function return how how many string there are*/
size_t parse_string(const char *string, const char *parse, char *** const user_matrix)
{
   /*how many spots there are*/
   size_t temp_matrix_size;
   /*how many acctually string there are*/
   size_t temp_matrix_length;
   char **temp_matrix;
   size_t i;
   size_t counter;

   /*allocate initial memory. array of pointers*/
   temp_matrix = malloc(sizeof(*temp_matrix) * DEFAULT_SIZE);
   if(temp_matrix == NULL)
      goto FAIL0;
   temp_matrix_size = DEFAULT_SIZE;
   /*since right now there 0 string aka pointers to strings*/
   temp_matrix_length = 0;


   i = counter = 0;
   while(*(string + i) != '')
   {
      /*resize array of pointers*/
      if(temp_matrix_length >= temp_matrix_size)
      {
         char **temp = realloc(temp_matrix, sizeof(*temp_matrix) * temp_matrix_size * RESIZE_MULTI);
         if(temp == NULL)
            goto FAIL0;
         temp_matrix = temp;
         temp_matrix_size = temp_matrix_size * RESIZE_MULTI;
      }

      if(compare(*(string + i), parse) == 0)
      {
         char *temp;
         if(counter > 0)
         {
            /*need the plus 1 for terminating char*/
            temp = malloc(sizeof(*temp) * (counter + 1));
            if(temp == NULL)
               goto FAIL0;

            /*setting terminating char*/
            *(temp + counter) = '';
            /*copy over the string before the parsing char*/
            memcpy(temp, string + (i - counter), counter);

            /*store the string*/
            *(temp_matrix + temp_matrix_length) = temp;
            temp_matrix_length++;
         }

         /*store only the parsing char with null terminated char*/
         temp = malloc(sizeof(*temp) * 2);
         if(temp == NULL)
            goto FAIL0;
         *(temp + 0) = *(string + i);
         *(temp + 1) = '';

         *(temp_matrix + temp_matrix_length) = temp;
         temp_matrix_length++;

         i++;
         counter = 0;
      }
      else
      {
         i++;
         counter++;
      }
   }

   /*special case*/
   if(counter != 0)
   {
      char *temp = malloc(sizeof(*temp) * (counter + 1));
      if(temp == NULL)
         goto FAIL0;

      /*setting terminating char*/
      *(temp + counter) = '';
      /*copy over the string before the parsing char*/
      memcpy(temp, string + (i - counter), counter);

      /*store the string*/
      *(temp_matrix + temp_matrix_length) = temp;
      temp_matrix_length++;
   }

   *user_matrix = temp_matrix;

   return temp_matrix_length;

   FAIL0:
   if(temp_matrix != NULL)
   {
      /*free all the strings*/
      for(i = 0; i < temp_matrix_length; i++)
      {
         free(*(temp_matrix + i));
      }
      /*free the array of pointers*/
      free(temp_matrix);
   }
   *user_matrix = NULL;
   return 0;
}

int main(void)
{
   char **matrix;
   size_t size;

   /*can have anything you want*/
   char *str = "Hello Word!!!";
   /*can have any char you want*/
   char *parse = "! ";

   size = parse_string(str, parse, &matrix);

   for(size_t i = 0; i < size; i++)
   {
      printf("%sn", *(matrix + i));
   }

   for(size_t i = 0; i < size; i++)
   {
      free(*(matrix + i));
   }
   free(matrix);

   return 0;
}

sharepoint online – Problem with compare two String in powershell

I want to identify the type of web part by its name, in this case “news”. If the title of the web part was the same as “string2” I would like to delete this web part. I don’t understand why I keep getting false. I also tried compareTo.

If I write the value of the variable -> $webParts.Title

I get the string “Wiadmości” I do a comparison with the string “Wiadmości” I get false

**strong text**
$global:importFileName="sitesURL.csv"
functionmain()
{​​​​​​​​
$sites=import-csv$global:importFileName
$global:credentials=Get-Credential
ForEach($sitein$sites)
    {​​​​​​​​           
RemoveWebParts-sourceUrl$site.spUrl-location$pwd
    }​​​​​​​​
}​​​​​​​​
 
functionRemoveWebParts(){​​​​​​​​
Param( $sourceUrl
) Process{​​​​​​​​
Write-Host"###################### '$sourceUrl' ######################"-ForegroundColor Green
Connect-PnPOnline-Url$sourceUrl-Credentials$global:credentials
$page=Get-PnPClientSidePage-Identity"Home.aspx"

Write-Host"Search web parts:"-ForegroundColor Cyan
$webParts=$page.Controls

$loopCounter=0
foreach($webpartin$webparts) {​​​​​​​​
 
        (String) $string1=$webParts.Title
        (String) $string2="Wiadomości"

if( $string1-eq$string2) {​​​​​​​​
Remove-PnPClientSideComponent-Page$page-InstanceId$webpart.InstanceId
Write-Host"Deleted '$webpart.Title'"-ForegroundColor Green 
$loopCounter++
        }​​​​​​​​
    }​​​​​​​​
if($loopCounter-gt0){​​​​​​​​
Write-Host"Removed web parts '$loopCounter'"-ForegroundColor Green
    }​​​​​​​​
Write-Host"No items were found for removal "-ForegroundColor Yellow
}​​​​​​​​
}​​​​​​​​
Measure-Command {​​​​​​​​main}​​​​​​​​

code review – display an input string many times

I’d like to create a function that add 2 to an integer as much as we want. It would look like that:

>>> n = 3 
>>> add_two(n)
Would you like to add a two to n ? Yes
The new n is 5
Would you like to add a two to n ? Yes
the new n is 7
Would you like to add a two to n ? No

Can anyone help me please ? I don’t how I can print the sentence without recalling the function.