java – Mutating input List method argument to add new item

I really don’t like the idea of method (especially public) mutating state of input argument. I been thinking to see what will be the better way of achieving this without violatation.

I wrote a sample code to compare two ways of updating list (There are other ways of doing this and I am interested in understanding Java 8 approach to handle this).

Question: The approach used in method addItemToListUsingConsumerWithPredicate can be considered as not mutating the state of input param?

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

class Scratch {
    public static void main(String() args) {
            new Scratch().testTraditionalForEach();
            new Scratch().addItemToListUsingConsumerWithPredicate();
    }

private void addItemToListUsingConsumerWithPredicate() {

    List<String> inputList = new ArrayList<>();
    inputList.add("one");
    inputList.add("two");
    inputList.add("three");
    List<String> newList = new ArrayList<>();
    newList.add("one");
    newList.add("four");
    newList.add("three");


    newList.stream().forEach(nl -> {
        addIfNotPresentUsingConsumerAndPredicate(nl, p -> !inputList.contains(nl), inputList, x -> inputList.add(nl));
    });
    System.out.println("addItemToListUsingConsumerWithPredicate = " + inputList);

}

private void addIfNotPresentUsingConsumerAndPredicate(String nl, Predicate<String> predicate, List<String> inputList, Consumer<List<String>> listConsumer) {
    if (predicate.test(nl)){
        listConsumer.accept(inputList);
    }
}

 private void testTraditionalForEach() {

    List<String> inputList = new ArrayList<>();
    inputList.add("one");
    inputList.add("two");
    inputList.add("three");
    List<String> newList = new ArrayList<>();
    newList.add("one");
    newList.add("four");
    newList.add("three");

    newList.stream().forEach(nl -> addIfNotPresent(nl, inputList));
    System.out.println("testTraditionalForEach =" + inputList);

}

private void addIfNotPresent(String nl, List<String> inputList) {

    if(!inputList.contains(nl)){
        inputList.add(nl);
    }

}

}

7 – How to get the input value with preprocess from a Fulltext Search Filter exposed form

Maybe not exactly what you’re asking for, but the one way to approach this is to use hook_preprocess_views_view(&$variables) and modify the contents of the header, or add a variable containing the string you want and then it in above/below the header in a views-view.tpl.php template override. If the search string isn’t available through $variables, you can probably grab it from the url since it’s likely included as a query string.

To get the query string from the url and add it to the template variables you’d do something like the following in your module or theme:

/**
 * Implements hook_preprocess_hook()
 */
function my_module_preprocess_views_view(&$variables) {
  // Get the query string from the url.
  // it will be on something like ?the_search_string=big+banana.
  $search_string_raw = $_GET('the_search_string');
  
  // Decode the url to remove special chars
  $search_string_decoded = urldecode($search_string_raw);

  // Add it to $variables so it's available in views-view.tpl.php
  $variables('search_string') = $search_string_decoded;
}

This will make the search_string available in views-view.tpl.php. You can then print it in there with

<?php if($search_string): ?> 
  <?php print $search_string ?>
<?php endif; ?>

// or

<?php

if($search_string) {
  print $search_string;
}

To clarify how hook_preprocess_hook works — the first “hook” is your module name, and the second is the name of the template that you’re targeting. Since we are targeting views-view.tpl.php, we use hook_preprocess_views_view.

In general, the easiest way to get started inspecting php variables is to dump them to the screen. For Drupal 7, I’d recommend installing https://www.drupal.org/project/kint on your site. This will let you print variables to the screen to help you dig into their values and see what’s in there. You’d do like:

function my_module_preprocess_views_view(&$variables) {
  kint($variables);
  // or
  kpr($variables('header'))
}

Then you can see what’s actually inside of $variables and grab/modify the values in there.

7 – Get input from Fulltext Search Filter in views_pre_render for Header

For Drupal 7 I found a workaround to a similar situation here, when combining Core search block forms and search api contextual filters. This “workaround” won’t work when using Search API, if you don’t want the Contextual Filter in your view.

My current setup:
I am using Search API, with a database server, and displaying the results with a Views page. I am using Search: Fulltext search (exposed) and Exposed form in block:Yes for the search block form.

What I am trying to achive:
I would like to put what was searched for in the Header of the view, and also at the top of No Results Behavior like this:

You searched for bananas

The problem:
When using Search: Fulltext search (exposed), the replacement patterns for the input value are not available in the Global Text Area. They are only available by adding a Fulltext Search Contextual Filter. There is an issue for this with a patch for Drupal 8 here.

My question:
Is there a views_pre_render or some other hook that can be used for the Header or No Results region to output the value that was input into the Search: Fulltext search (exposed) form?

There is a dev module to create a token, but it only works for the Results Summary.

fa.functional analysis – Lower-bounding the eigenvalues of a certain positive-semidefinite kernel matrix, as a function of the norm of the input matrix

Let $phi:(-1,1) to mathbb R$ be a function such that

  • $phi$ is $mathcal C^infty$ on $(-1,1)$.
  • $phi$ is continuous at $pm 1$.

For concreteness, and if it helps, In my specific problem I have $phi(t) := t cdot (pi – arccos(t)) + sqrt{1-t^2}$.

Now, given a $k times d$ matrix $U$ with linearly independent rows, consider the $k times k$ positive-semidefinite matrix $C_U=(c_{i,j})$ defined by $c_{i,j} := K_{phi}(u_i,u_j)$, where

$$
K_phi(x,y) := |x||y|phi(frac{x^top y}{|x||x|})
$$

Question. How express the eigenvalues of $C$ in terms of $U$ and $phi$ ?

I’m ultimated interested in lower-bounding $lambda_{min}(C_U)$ in terms of some norm of $U$ (e.g spectral norm or Frobenius norm).


Let $X$ be the $(d-1)$-dimensional unit-sphere in $mathbb R^d$, equipped with its uniform measure $sigma_{d-1}$, and consider the integral operator $T_phi: L^{2}(X) to L^2(X)$ defined by
$$
T_{phi}(f):x mapsto int K_{phi}(x,y)f(y)dsigma_{d-1}(y).
$$

It is easy to see that $T_phi$ is a compact positive-definite operator.

Question. Are the eigenvalues of $C_U$ be expressed as a function of (eigenvalues of) $K_{phi}$ ?

taproot – What makes cross input signature aggregation complicated to implement?

Pieter Wuille answered this on Twitter.

The most important complication of cross input aggregation is explained in this Bitcoin dev mailing list post by AJ Towns.

TL;DR: if softforks change which signatures are checked, they mustn’t
change what is aggregated together. This is especially complicated when they interact with BIP341’s OP_SUCCESSx upgrade mechanism, which could easily let future softforks change script semantics entirely. There is nothing fundamentally hard here – it’s just engineering complexity to make sure everything works well together.

Pieter added at a London BitDevs Socratic Seminar on BIP-Taproot:

Graftroot and cross input aggregation are such deeply conceptual changes. You can’t permit building them later. It is such a structural change to how scripts work. These things are not something that can be just added later on top of Taproot. You need a successor. Cross input aggregation, the concept of script verification is no longer a per input thing but it is a per transaction thing. You can’t do it with optimal efficiency, I guess you can invent things. The type of extensibility that is built in is new opcodes, new types of public keys, new sighash types, all these things are made fairly easy and come with almost no downsides compared to not doing them immediately. Real structural changes to script execution, they need something else.

kde – How do I mix together a real microphone input and a virtual microphone using pulseaudio as a single default recording device?

I’m running Kubuntu 20.04 and what I’m trying to accomplish is to use pulseaudio to mix together a real microphone (Blue Snowball) and a virtual microphone created using pactl like so:

pactl load-module module-pipe-source source_name=virtmic 
    file=/home/pyle/dev/virtmic format=s16le rate=16000 channels=1
pactl load-module module-null-sink sink_name=mysink
pactl load-module module-loopback sink=mysink
pactl load-module module-loopback sink=mysink

The desired result is to have some kind of virtual recording device which takes input both from the real microphone and from the virtual microphone device. Preferably also while playing back any audio coming from the virtual microphone to the default output device.

I’ve tried reading the docs and tinkered with sinks but I can’t seem to get it working right. I can set the virtual microphone as the default recording device and pipe audio to it but that won’t let me use the real microphone at the same time, and I would also like to hear the audio piped to the virtual microphone (but not the audio from the real microphone) played back to the default audio output.

I do seem to get a “monitor” stream, or whatever the pulseaudio terminology is, which is clearly reflecting both the real microphone input and the piped audio to the virtual microphone but I can’t choose it as my default input device.

In all this seems like the sort of thing that should be relatively simple to do but I can’t really find any documentation that directly touches on it, just a lot of sort-of similar things with guides that boil down to “do exactly this thing to accomplish exactly this result” without any deeper explanation of just what’s going on. And the pulseaudio docs feel like they were written for someone who already knows what they’re doing (at least to me who last did a deep dive into audio on Linux when /dev/dsp was just going out of fashion).

SharePoint list How to restrict input value format

I have a column with name Secure in my SharePoint list. And I want to set validation in that column as below mentioned conditions. and if any user not entered in that format than , he will not able to save the form.

Condition :-

  1. it should contain total 12 characters
  2. first four character should be Alphabet (i.e. A to Z)
  3. next 4 characters should be any number between 0 to 9
  4. next 4 character should follow DDMM format (i.e. DD should allow maximum value 31/30/29/28 as per month and MM should between 01 to 12)

keyboard – Reason for difference in behaviour of autcomplete interactions in input fields

There seems to be two different schools of thought when it comes to the autocompletion of input fields and I am wondering if there is a particular reason or rationale for each.

Basically, when the user is completing an input field (usually text based) it is typical for autocomplete functionalities to be implemented when there has been previous inputs provided. The user can then choose to continue completing the input or to use the autocomplete feature by:

  • Pressing the ENTER key
  • Pressing the TAB key

Alternatively they can use the mouse and click on the autocomplete suggestion but it breaks the flow of typing from the keyboard.

Is there any particular reason (both from a technical AND user perspective) why some sites use the ENTER key while others use the TAB key for this? I think it creates a confusion because it is likely for a user to go to websites that implement this feature both ways.

javascript – ENVIAR ID DE UN INPUT A LA BASE DE DATOS

buen dia

tengo un codigo de java que me genera un codigo y con el id me lo muestra en el campo del id pero al momento de enviarlo no se guarda en la base de datos alguien sabe como hacer para que me lo deje enviar ??
”’maquina

  <label >producto</label>
  <input id="lote" type="text" name="$Producto"  value="$(lote)">
  <button type="submit">enviar</button>

”’
esto me muestra en el input pero al momento de enviarlo solo me envia el campo maquina cabe aclarar que escribo un dato manual en le campo producto y si me lo envia

en resumen como puedo hacer que el texto del campo producto se a valido para poderlo guardar en la base de datos

gracias

signature – signing multiple input raw transaction – algorithm and sighash types

I have an unsigned raw transaction:

01000000020dcc23ccdb3665779a7657577cd33c5c0660e969ea2ffaf5438c58306ebc9dd20100000000ffffffff49508924c21b25ee2ff6aed61ccc202793aa992d3e033f12f2bf4a94d6346d010000000000ffffffff0240420f00000000001976a9140d7ca1e17524d6c96209cf503fb053613cecf8f688aca0f703000000000017a91452636ce984783dac880e139fa3b69b4d9be39ab68700000000

I have read these threads:
How to redeem a basic Tx?
Redeeming a raw transaction step by step example required

These threads explain signing a raw transaction with 1 input.

Questions

Do I understand correctly that both inputs are to signed separately?
So first, we sign the first one, then the second one. To sign an input we replace scriptSig for this input with the scriptPubKey, that locks this input. ScriptSig for the other one remains blank.

It this correct?

But in both threads in step 13 something is appended at the end of transaction. It is called hash code type

What is this? Is this has anything to do with sighash type byte the one that is appended to the signature? If not how to determine this value?

What is the correct sighash type for the scenario I described above (signing inputs separately)?
Is this: 0x81 (SIGHASH_ALL | SIGHASH_ANYONECANPAY)?
Or should this be 0x01 (SIGHASH_ALL)?

I don’t know which one is correct as transaction to be signed contains the other input (without scriptSig set but still, it contains it).