mysql – Why my code only return 1 row? Leetcode#626

You are using an agregate function which causes the result to collapse to single row.
Possible solution:

SELECT 
(CASE WHEN mod(s.id,2)=0 THEN s.id-1
WHEN mod(s.id,2)=1 AND s.id != maxid.maxid THEN s.id+1
END) AS id,
s.student
FROM seat s
join (select max(s.id) as maxId from seat) as maxId on 1=1
ORDER BY id

You are using it in the SELECT, not CONDITIONAL (WHERE).
Now, the question you ask is a good one and i would have to refresh my knowledge of inner workings of SQL.

I think its because the moment it hits MAX, its collapses the result set, as it doesnt “see” a need to return all rows.

Simply said, the query processor doesnt care if its a condition in case statement or value to be returned. It’s there and thats that.

Aggregation function without group by is a mysql thing, and not SQL standard, so the behaviour is specific to MySQL.

A c++ program to take the size and components of an Array from user and return the reversed Array

I have written this code that should take the size and components of the array from the user and then return the reverse of the Array but not able to identify and fix the error.
My best guess is that the while loop is causing trouble, but I am not sure.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


// function to reverse given array
void reverseArray(int arr(), int start, int end){

while (start<=end){
    int temp = arr(start);
    arr(start) = arr(end);
    arr(end) = temp;
    start++;
    end--;
       
}

}


// function to print given array
void printArray(int arr(), int size){
   for (int i = 0; i < size; i++)
   cout << arr(i) << " ";
}


int main() {
    int n;
    cin >> n;
    int mainarray() = {n} ; 
    n = sizeof(mainarray);

    for (int i=0; i<n; i++) {
        cin >> mainarray(i);
    }

reverseArray(mainarray , 0, n-1);
printArray(mainarray ,n);

    return 0;
}

python – The view insertemp.views.Insertrecord didn’t return an HttpResponse object. It returned None instead?

views.py
from django.shortcuts import render
from insertemp.models import Empinsert
from django.contrib import messages

def  Insertrecord(request):
    if request.method == 'POST':
        if request.POST.get('empname') and request.POST.get('email') and request.POST.get('country'):
            saverecord=Empinsert()
            saverecord.empname=request.POST.get('empname')
            saverecord.email=request.POST.get('email')
            saverecord.country=request.POST.get('country')
            saverecord.save()
            messages.SUCCESS(request,'your detail saved succeccfullt.......!')
            return render(request,"index.html")
    else:
            return render(request,"index.html")
urls.py
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = (
    
    path('', views.Insertrecord),

)
models.py
from django.db import models
class Empinsert(models.Model):

    empname=models.CharField(max_length=100)
    email=models.CharField(max_length=100)
    country=models.CharField(max_length=100)
    class meta:
        db_table="newemployeetable1"
settings.py
"""
Django settings for insertemp project.

Generated by 'django-admin startproject' using Django 3.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n7#@rb50!g7yh9_aw@eud++4zv4ee9zgxvrbf0my34pxu=avmc'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ()


# Application definition

INSTALLED_APPS = (
    'insertemp',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE = (
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',`enter code here`
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'insertemp.urls'
TEMPLATES = (
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS':(os.path.join(BASE_DIR, 'templates')),
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': (
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ),
        },
    },
)

WSGI_APPLICATION = 'insertemp.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME':'sampledb1',
        'USER':'root', 
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
        'OPTIONS':{
            'init_command':"SET sql_mode='STRICT_TRANS_TABLES'"
        }
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = (
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
)


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True




STATIC_URL = '/static/'

Custom shortcode render problem with return ”

I hope you all having a great day. I’m developing a video player plugin with custom shortcodes and stuff but I’m having a problem with the shortcode render. Currently, my shortcode content is rendered with echo which works fine but it doesn’t render inside the page content so I have to change it to return method somehow but it has foreach loops and if else statements inside it so I can’t just do return '<ul> '.foreach($x as $s){}.' </ul> '; and stuff, do you guys know a workaround for this? I’ve also tried to place everything inside a function and tried to render it inside return like this: return "http://wordpress.stackexchange.com/".renderdata()."http://wordpress.stackexchange.com/"; which works but again it doesn’t render inside the content.

Here’s my complete shortcode function

function vc_playlist_shortcode( $atts = array() ) {

    // add_action('wp_head', 'deregister_scripts');
    // add_action('wp_enqueue_scripts', 'deregister_scripts');
    // add_action('wp_footer', 'deregister_scripts');
   
    // get the shortcode attribute value
    extract(shortcode_atts(array(
     'id' => "http://wordpress.stackexchange.com/"
    ), $atts));

    $playlistdata = get_post_meta( $id, 'vc_playlist_data', true );
    

    // Filter the urls in playlist data and assign it to an array
    $playlisturls = array_filter($playlistdata, function($val){
        return filter_var($val, FILTER_VALIDATE_URL);  
    });
    // rebase the assigned array
    $counter = 0;
    $rebasedurls = array();

    foreach ($playlisturls as $key => $value) {
        $rebasedurls($counter) = $value;
        $counter++;
    }
    // trim the 'https://vimeo.com/' from the values and keep the ID only
    //$videoIDs = preg_replace('/(^0-9)/', "http://wordpress.stackexchange.com/", $rebasedurls);

   
    function videostatuschecker($x){
        $unlockedvideos = get_user_meta(wp_get_current_user()->ID, 'vc_unlocked_videos', false);

        if (in_array($x, $unlockedvideos)){
            return 'unlocked';  
        }
        else{
            return 'locked';
        }
    }
    // Serve the first video URL to browser so we can access it in our JS function
    echo '<script type="text/javascript">var vc_firstvideo = "http://wordpress.stackexchange.com/".$rebasedurls(0)."http://wordpress.stackexchange.com/"</script>';
    
    echo '<div class="vc-video-container">';
    //echo '<div class="vc-plyr" data-plyr-provider="vimeo" data-plyr-embed-id="http://wordpress.stackexchange.com/".$rebasedurls(0)."http://wordpress.stackexchange.com/"></div>';
    echo '<div id="vc-player"></div>';
    echo '<div class="plyr-playlist-wrapper">';
    echo '<ul class="plyr-playlist">';

    foreach($playlistdata as $data){
        
        if(! filter_var($data, FILTER_VALIDATE_URL)){   
            echo '<span class="plyr-playlist-chapter-title">'.$data.'</span>'; 
        }
        else{
            echo '<li class="http://wordpress.stackexchange.com/">';
            echo '<a class="plyr-playlist-link" href="javascript:void(0);" data-video-url="http://wordpress.stackexchange.com/". $data ."http://wordpress.stackexchange.com/" data-status="http://wordpress.stackexchange.com/".videostatuschecker($data)."http://wordpress.stackexchange.com/">';
            echo '<div class="plyr-playlist-thumbnail skeleton"><img class="plyr-miniposter" src="https://wordpress.stackexchange.com/" alt="thumbnail"></div>';
            echo '<span class="plyr-playlist-title skeleton"><span></span></span>';
            echo '</a>';
            echo '</li>';
        }               
    }

    echo '</ul>';
    echo '</div>';
    echo '</div>';
    echo '<div class="vc-meta-container">'; 
        echo '<button class="fav-video-button" data-video-url="http://wordpress.stackexchange.com/".$rebasedurls(0)."http://wordpress.stackexchange.com/">Zu Favoriten hinzufügen</button>';
        echo '<div class="autoplay-container"><span class="autoplay-title">Auto Play</span> <div class="toggly-container"> <input type="checkbox" id="autoplay-toggle"> <label class="toggly-label" for="autoplay-toggle"><i class="toggly"></i></label> </div></div>';
    echo '</div>';
    

    return "http://wordpress.stackexchange.com/";
    
}
add_shortcode('vc_playlist', 'vc_playlist_shortcode'); 

Any help is much appreciated, thank you.

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”

Transaction cancelled but bitcoin was not return back to my wallet

While your transaction may have been cancelled by whatever system you used, you have to wait for it to cancel out everywhere else too.

Since you only provided a destination wallet and not the actual transaction ID, it’s hard to provide much info. I do, however, see transactions going to the wallet you specified above without issue. It does look like your fee (8.93 sat/B on a 224byte trans) was well below a reasonable fee to be processed in a decent amount of time on the transactions that show up though..

I suggest leveraging https://bitcoinfees.21.co/ to ensure your transactions process in a decent amount of time in the future. Relying on a cancellation is unreliable.

To see your transaction ids, check the following links

https://blockchain.info/address/39j2nuZWr4F2hZ5wYDwQwZWzsTJC4H6ujn
https://blockexplorer.com/address/39j2nuZWr4F2hZ5wYDwQwZWzsTJC4H6ujn

you will notice the transaction IDs under the heading “transactions”

MySQL return rows ONLY if ALL the rows in another table have a specified value

I have two tables

efd_details
id
efd_detail_status
detail_id
status

Now the data looks like this:
efd_details
ID:1
ID:2
ID:3
ID:4
ID:5
efd_detail_status
DETAIL_ID:1, STATUS: ‘s’
DETAIL_ID:2, STATUS: ‘s’
DETAIL_ID:3, STATUS: ‘s’
DETAIL_ID:4, STATUS: null
DETAIL_ID:5, STATUS: ‘f’

What I need to do is get all the details (efd_details) ONLY if ALL the statuses in efd_detail_status = ‘s’. In the example above, I would retrieve ZERO records since two of the statuses are != ‘s’. If ALL the statuses = ‘s’ then return ALL rows from cms_efd.

I have tried variations of EXISTS and the following:

select e.*
  from cms.cms_efd e
where exists(select 1 
               from cms.cms_efd_status s 
              where s.detail_record_id = e.detail_record_id 
                and IFNULL(s.contrib_calc_status,'f') != 's'
             having count(e.detail_record_id)=count(s.detail_record_id))
    and e.earnings_file_id = 400676;

cms_efd
cms_efd_status
Appreciate the help.
-Branden

bitcoin core – Unable to return BlockHashes when I run this generatetoaddress

I have downloaded and fully synced with my Mac last Saturday, my Bitcoin Core version is v0.21.0 and my Bitcoin-Qt version 5.9.8.

I did run other RPC commands such as “getrpcinfo” and it did provide result:

{
“active_commands”: (
{
“method”: “getrpcinfo”,
“duration”: 72
}
),
“logpath”: “/Users/jsjs77/Library/Application Support/Bitcoin/debug.log”
}

“getbalance” –

{
“mine”: {
“trusted”: 0.00000000,
“untrusted_pending”: 0.00000000,
“immature”: 0.00000000
}
}

But then, when I want to run this “generatetoaddress nblocks “address” it does not provide block hash result:

generatetoaddress 11 1MDihWw2UfkYyAwrQDWNFbmaH6bx4NBFtL


(

)

I have tried the following methods:

bitcoin-cli generatetoaddress 11 1MDihWw2UfkYyAwrQDWNFbmaH6bx4NBFtL.


Method not found (code -32601)

and

bitcoin-cli -regtest generatetoaddress 11 1MDihWw2UfkYyAwrQDWNFbmaH6bx4NBFtL

Method not found (code -32601)

Is this got to do with the changes of latest version? I really need help. Thanks

enter image description here

KLM refused luggage return during 3 day delay

It is understandable that it is diffcult for them to sort the luggage out and give it to you, but according to the usual rules, they should be responsible for paying for your necessities, as well as the hotels and food, as the delay is their fault. It should be cheaper for them to get your luggage out than to pay for you buying new items, but they may have the choice in that (meaning they probably can choose to give you money instead).

Either way, they are responsible for your cost during the forced stay, and they are legally required to inform you about it. Contact them to get what they owe you, and file a complaint if they don’t want to.

Worst case you can buy some new wardrobe on their nickel, and have some paid vacation in the three days.

Turing machine without return equivalent to Finite Automaton, PushDown Automaton or Turing Machine?

Informally, a pushdown automaton has a way to store and use an infinite amount of memory (the stack). In a Turing machine, the only way to store an infinite amount of memory is to write it on the tape. But in a Turing machine without return, you cannot go back to the cells that you have already written, so that memory can never be used.

That means that a Turing machine without return cannot be “as powerful” as a pushdown automaton. The solution is a finite automaton.

If you want a more formal proof, you can start with the formal definition of a Turing machine without return, note that you can dismiss what you write on the tape (because you can’t go back), and construct a finite automaton that recognize the same language as the Turing machine.