## go – https POST not working as expected in golang , but works fine in Python

I am trying to implement a python code from the JIRA REST API examples:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-jql/#api-rest-api-3-jql-parse-post

My python code (which works as expected):

``````import requests
from requests.auth import HTTPBasicAuth
import json

url = "https://my-url.com/rest/api/2/search"
auth = HTTPBasicAuth("user1", "pwd1")
"Accept": "application/json",
"Content-Type": "application/json"
}
"jql": "my-query-string"
}
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
``````

I’m trying to transform this to a `golang` code as below:

``````package main
import (
"io/ioutil"
"fmt"
"log"
"time"
"net/http"
"net/url"
}
func main() {
timeout := time.Duration(500 * time.Second)
client := http.Client{
Timeout: timeout,
}
req, err := http.NewRequest("POST", "https://my-url.com/rest/api/2/search", nil)
if err != nil {
log.Fatalln(err)
}
req.SetBasicAuth("user1", "pwd1")
q := url.Values{}
req.URL.RawQuery = q.Encode()
fmt.Println(req.URL.String())
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()

if err != nil {
log.Fatalln(err)
}
log.Println(string(data))
``````

The code builds with no issues. When I run the `go` code, I get this error:

``````   2021/04/17 19:36:31 {"errorMessages":("No content to map to Object due to end of input")}
``````

I have 2 questions :

``````a. How can I fix the above error ?
b. I also want to include concurrency in the same code, i.e the same POST request will actually be executed for 5 different query strings (concurrently) and fetch the results, how can i achieve that ?
``````

## anydice – How can I calculate expected Stunt Points per attack when FIRST dropping a d6?

Here’s an example anydice function which calculates this kind of result:

``````function: stunt DICE:s STUNT:n DC:n {
if 1@DICE + 2@DICE + STUNT < DC {
result: 0
}
loop X over {1..#DICE-1}{
if (X@DICE = (X+1)@DICE | X@DICE = STUNT | (X+1)@DICE = STUNT) & X@DICE + (X+1)@DICE + STUNT >= DC { result: STUNT }
}
result: 0
}
``````

Let’s walk through it.

We invoke the function by calling `(stunt Xd6 1d6 DC)`, where `Xd6` is our dice pool, the other `1d6` is our stunt die, and `DC` is the target we need to roll on the dice. When the function runs, the rolled dice pool will be cast to a sequence, which anydice will helpfully automatically sort from highest to lowest.

The first `if` statement in the function checks to see whether the roll can possibly succeed – we take the two highest dice from the dice pool and the stunt die and see if they are less than the target number. If so, we immediately return `0` as it not possible to succeed on the roll.

Then we start iterating over the pool using a `loop` in order to check for any doubles, starting with the first two dice. If any two of the two dice under consideration and the stunt die are equal to each other, and the total of those two dice and the stunt die is enough to beat the target DC, the test has succeeded with stunt points – we return the value of the stunt die.

We know that any two dice in the sequence must be adjacent to each other in order to have a chance of being doubles, because the sequence has been sorted already, so don’t need to exhaustively check every possible combination from the sequence – stepping along it in adjacent pairs, using `X@DICE` and `(X+1)@DICE`, is good enough.

Otherwise, if we get all the way through the dice pool without finding any doubles that also beat the target DC, we return `0` to indicate the test has succeeded with no stunt points.

Here’s a screencap of some sample output from the function:

Interesting modifications to make to the function might be to return `-1` instead of `0` if the test fails, which will show you a distribution which indicates both the likelihood of a specific number of stunt points and the likelihood of passing at all (though it will skew the averages), or to return `d{}` (the “empty die”) to produce a distribution ignoring rolls that fail (i.e. how many stunt points are we likely to get if we succeed?).

## Fragment shader not working as expected

I am porting the following shader into Godot. The results seem not correct though. Apart from the wrong colours there seems to be no change with time. What is the problem with it?

``````shader_type canvas_item;

const float DELTA = 0.00001;
const float TAU = 6.28318530718;
const float NOISE_TEXTURE_SIZE = 256.0;
const float NOISE_TEXTURE_PIXEL_COUNT = (NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE);

uniform vec4 vColor: color;

// MAIN CONTROLLER UNIFORMS
uniform float intensity = 1.;       // overall effect intensity, 0-1 (no upper limit)
uniform float rngSeed = .0;         // seed offset (changes configuration around)
uniform sampler2D noiseTexture;     // noise texture sampler

//TUNING
uniform float lineSpeed = .01;          // line speed
uniform float lineDrift = .1;           // horizontal line drifting
uniform float lineResolution = 1.;      // line resolution
uniform float lineVertShift = .0;       // wave phase offset of horizontal lines
uniform float lineShift = .004;         // horizontal shift
uniform float jumbleness = .2;          // amount of "block" glitchiness
uniform float jumbleResolution = .2;    // resolution of blocks
uniform float jumbleShift = .15;        // texture shift by blocks
uniform float jumbleSpeed = 1.;         // speed of block variation
uniform float dispersion = .0025;       // color channel horizontal dispersion
uniform float channelShift = .004;      // horizontal RGB shift
uniform float noiseLevel = .5;          // level of noise
uniform float shakiness = .5;           // horizontal shakiness
//

float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

vec4 extractRed(vec4 col){
return vec4(col.r, 0., 0., col.a);
}

vec4 extractGreen(vec4 col){
return vec4(0., col.g, 0., col.a);
}

vec4 extractBlue(vec4 col){
return vec4(0., 0., col.b, col.a);
}

// Replacement for the mirror address mode, hopefully nobody needs filtering.
vec2 mirror(vec2 v) {
return abs((fract((v * 0.5) + 0.5) * 2.0) - 1.0);
}

vec2 downsample(vec2 v, vec2 res) {
// Division by zero protected by uniform getters.
return floor(v * res) / res;
}

// Fetches four random values from an RGBA noise texture
vec4 whiteNoise(vec2 coord, vec2 texelOffset, vec2 resolution) {
vec2 offset = downsample(vec2(rngSeed * NOISE_TEXTURE_SIZE, rngSeed) + texelOffset, vec2(NOISE_TEXTURE_SIZE));
vec2 ratio = resolution / vec2(NOISE_TEXTURE_SIZE);
return texture(noiseTexture, (coord * ratio) + offset);
}

// Fetch noise texture texel based on single offset in the (0-1) range
vec4 random(float dataOffset) {
vec2 halfTexelSize = vec2((0.5 / NOISE_TEXTURE_SIZE));
float offset = rngSeed + dataOffset;
return texture(noiseTexture, vec2(offset * NOISE_TEXTURE_SIZE, offset) + halfTexelSize);
}

// Jumble coord generation
vec2 jumble(vec2 coord, float time, vec2 resolution){
// Static branch.
if ((jumbleShift * jumbleness * jumbleResolution) < DELTA) {
return vec2(0.0);
}

vec2 gridCoords = (coord * jumbleResolution) / (NOISE_TEXTURE_SIZE * 0.0245);
float jumbleTime = mod(floor(time * 0.02 * jumbleSpeed), NOISE_TEXTURE_PIXEL_COUNT);
vec2 offset = random(jumbleTime / NOISE_TEXTURE_PIXEL_COUNT).ga * jumbleResolution;
vec4 cellRandomValues = whiteNoise(gridCoords, vec2(jumbleResolution * -10.0) + offset, resolution);
return (cellRandomValues.ra - 0.5) * jumbleShift * floor(min(0.99999, cellRandomValues.b) + jumbleness);
}

// Horizontal line offset generation
float lineOffset(vec2 coord, vec2 uv, float time, vec2 resolution) {
// Static branch.
if (lineShift < DELTA) {
return 0.0;
}

// Wave offsets
vec2 waveHeights = vec2(50.0 * lineResolution, 25.0 * lineResolution);
vec4 lineRandom = whiteNoise(downsample(uv.yy, waveHeights), vec2(0.0), resolution);
float driftTime = uv.y * resolution.y * 2.778;

// XY: big waves, ZW: drift waves
vec4 waveTimes = (vec4(downsample(lineRandom.ra * TAU, waveHeights) * 80.0, driftTime + 2.0, (driftTime * 0.1) + 1.0) + (time * lineSpeed)) + (lineVertShift * TAU);
vec4 waveLineOffsets = vec4(sin(waveTimes.x), cos(waveTimes.y), sin(waveTimes.z), cos(waveTimes.w));
waveLineOffsets.xy *= ((whiteNoise(waveTimes.xy, vec2(0.0), resolution).gb - 0.5) * shakiness) + 1.0;
waveLineOffsets.zw *= lineDrift;
return dot(waveLineOffsets, vec4(1.0));
}

void fragment()
{
vec3 randomValues = vec3(rand(vec2(TIME, 0.0)), rand(vec2(TIME, 0.0)), rand(vec2(TIME, 0.0)));
vec2 resolution = 1.0 / SCREEN_PIXEL_SIZE;
vec2 uv = FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE).xy;

// Sample random high-frequency noise
vec4 randomHiFreq = whiteNoise(uv, randomValues.xy, resolution);

// Apply line offsets
vec2 offsetCoords = uv;
offsetCoords.x += ((((2.0 * randomValues.z) - 1.0) * shakiness * lineSpeed) + lineOffset(offsetCoords, uv, TIME, resolution)) * lineShift * intensity;

// Apply jumbles
offsetCoords += jumble(offsetCoords, TIME, resolution) * intensity * intensity * 0.25;

// Channel split
vec2 shiftFactors = (channelShift + (randomHiFreq.rg * dispersion)) * intensity;
vec4 outColour;

// Static branch.
if (((channelShift + dispersion) * intensity) < DELTA) {
outColour = texture(SCREEN_TEXTURE, mirror(offsetCoords));
} else {
outColour = extractRed(texture(SCREEN_TEXTURE, mirror(offsetCoords + vec2(shiftFactors.r, 0.0)))) + extractBlue(texture(SCREEN_TEXTURE, mirror(offsetCoords + vec2(-shiftFactors.g, 0.0)))) + extractGreen(texture(SCREEN_TEXTURE, mirror(offsetCoords)));
}

outColour.rgb *= (vec3(.55, .5, .4) * randomHiFreq.gab * intensity * noiseLevel) + 1.0;

// COLOR = vColor * outColour;
COLOR = outColour;
}
``````

## sha – Can I truncate a hash value and keep (the expected amount) of collision resistance?

I’m building a URL-shortening tool. For an arbitrary link, I need to produce a fixed-length slug which will index the full URL in a database. For prettiness reasons, I’d like to keep the slug reasonably short (8 alphanumerical characters seems reasonable).

It seems obvious to me that using a hash function with output to hex is an easy way of generating such a slug without having to worry about collisions. I am not expecting more than a million links to ever be posted (it’s not a public tool), so I don’t need anything like the kind of collision resistance a normal hashing algorithm would provide. Unfortunately, the hash values tend to be rather long – even MD5 uses 32 hex characters (I also don’t know how to square this with the fact that it produces a 128 bit value and 16^32 is much bigger than that).

Suppose I took some collision-resistant hash function like SHA-512, and I take the 128 character output:

``````ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
``````

and truncate it to just eight:

``````ddaf35a
``````

I have two (probably naive) questions:

1. Why does the 512 bit digest take 128 hex characters and not log_{16}(512)? Or, the other way round, can I cram 16^8 bits of entropy into eight hex characters (or any short alphanumeric string)?
2. Assuming 1. is something obvious I don’t see, does truncating a 128 character hash to 8 characters behave “like an 8-character hash function”? In other words, other than accounting for the reduced size of the hash space, are collisions more likely than you would expect from a hash function with a digest of that length?

## error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__atribute__’ before ‘*’ token como resolver?

``````Pilha *criarPilha(){
Pilha *pi;
pi = (Pilha*) malloc(sizeof(Pilha));
if (pi != NULL){
*pi = NULL;
}
pi->vet = (int *) malloc(sizeof(int)*MAX);
if (pi->vet == NULL){
return NULL;
}
pi->topo1=-1;
pi->topo2=MAX;
return pi;
}
``````

Não faço ideia do que esteja errado com esse código, podem me ajudar? é pra uma prova e tenho que entregar amanhã

O tipo Pilha é a struct

``````
struct elemento {
int *vet;
int topo1;
int topo2;
int total;

}

typedef struct elemento Pilha;

``````

## nodes – peer does not offer the expected services

I am working on setting up a node and a normal consumer just to understand how all this works and I have the node up and running and my normal consumer. I see the connection is accepted on both ends but then I get the following message and I am not sure what this is related to and can’t find any documentation. Has anyone run into this before?

I generated the fixed seeds by using the generate_seeds.py using my node public ip.

``````peer=0 does not offer the expected services (00000405 offered, 00000009 expected)
``````

I tracked down the error to this code

`````` if (!pfrom->fInbound && !pfrom->fFeeler && !pfrom->m_manual_connection && !HasAllDesirableServiceFlags(nServices))
{
LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnectingn", pfrom->GetId(), nServices, GetDesirableServiceFlags(nServices));

...
``````

## permissions – Runuser Not Return Expected Results

There are two accounts in my linux computer, appuser and root. For testing purpose I wroto below code into /home/appuser/.profile

``````export key=value
``````

then as root I execute below commands separately:

`````` 1. runuser -l appuser -c "echo key=\$key"

expected： key=value
result:    key=

2. runuser -l appuser -c "/home/appuser/test.sh"

test.py includes only two lines:

#!/bin/bash
echo "key=\$key"

expected： key=value
result:    key=value
``````

Why can’t the first command return the correct result?? Is that because .profile is not sourced during execution? why?

## probability theory – Estimate Expected Value with Density Bound

Summary:

For a finite family of random variables $$(X^{i})_{ileq N}$$, we have the density estimate
$$p_t(y) leq int_0^infty C(frac{1}{sqrt{t}}+e^{epsilon y^2})e^{-frac{(x-y)^2}{ct}}dx.$$
for (small) $$epsilon>0$$, $$tin(0,infty)$$ and constants $$c,C>0$$. This is an estimate on the density of the probability of $$X^{i}$$ taking value $$yinmathbb{R}$$.

Is there a short explanation why
$$mathbb{E}((|X^{1}|+frac{1}{N}sum_{1leq jleq N} |X^{j}|)^4)

More elaborate:

Situation:

We have

1. A number of stochastic processes $$X^{1},dots,X^{N}$$ (i.e. for each of those $$X_t^{i}$$ is a random variable in each $$tin(0,infty)$$) with values in $$mathbb{R}$$. We assume $$X^{i}$$ to start in $$mathbb{R}_+$$.
2. An upper bound for the transition density $$mathfrak{p}_t(x,y)$$ of the process, so we have an upper bound for the density of the probability of $$X_t^{i}=y$$, when $$X_0^{i}=x$$ (i.e. $$X^{i}$$ starts in $$x$$ and ends up at $$y$$ in time point $$t$$).
3. The upper bound has the formula
$$mathfrak{p}_t(x,y)leq C(frac{1}{sqrt{t}}+e^{epsilon y^2})e^{-frac{(x-y)^2}{ct}},$$
for (small) $$epsilon>0$$ and constants $$c,C>0$$.

Question:

I’d like to prove that
$$mathbb{E}((|X_t^{1}|+frac{1}{N}sum_{i=1}^N |X_t^{i}|)^4)

Problem:
I don’t think that I can simply “insert” the density estimate. I know that, by integrating over x I get the actual density $$p_t(y)$$, i.e.
$$p_t(y)=int_0^infty mathfrak{p}_t(x,y)dx.$$
Is there a way to conclude the existence of the fourth moment of this sum from the bounded density?

## script – Alt Stack is not working as expected

I have a scenario as follows:

• In a company, there is a manager and three employees. The multisig signature will be redeemed by the manager combined with one of the employees.
• However, only the manager, or only the employees with enough number of signatures will not be able to redeem the transaction
• The order of the signatures should not matter
• Assume my_public_key is manager_public_key

My solution was: `[OP_2DUP, my_public_key, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, my_public_key, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG] `

So I tried to shorten the script in order to have less bit in a transaction by using alt-stack.

My suggested solution is just to duplicate the my_public_key and push it into the alt-stack and whenever I need it later, I can pop it from the alt-stack and use it. So by the final script I should deduct the script by one public key.

Suggested solution: `[OP_2DUP, my_public_key, OP_DUP, OP_TOALTSTACK, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, OP_FROMALTSTACK, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG]`

My suggested solution gives reference error.
I would be happy if anyone can help me.

Error:
{“error”: “Error validating transaction: Rejected script for input 0 referencing 5f026fb3260c809d446740917bca4aa0e8633f64ec86fc8a4c5e23979f1578ba at 0..”}

Input script:
[OP_0, manager_sig,employee_sig]

## google sheets – Gsheets Query Importrange not giving expected results

I’m having an issue with the Query(Importrange) function of Google Sheets.

I’m using the following formula

`=Query(IMPORTRANGE('Importrangelink,"'Sheetname'!X1:AA130"),"select Col1,Col2,Col3 where Col4 = 'No'")`

This works however if I extend the selection to AA131 (There is Data in AA131) then all I get returned are the headers. Alternatively if I instead of inputting X1:AA130 , put X:AA then again all I get are the headers.

Would someone know why this is as I have another sheet with this formula requesting the full columns and it works as expected

`=Query(IMPORTRANGE('Importrangelink',"'Sheetname'!A:F"),"select * where Col6 = 'Yes'")`