text:
Q: iPhone combine audio files I have been searching for the answer and have not been able to find it -- obviously ;)
Here is what I have -- I have a list of words.  Each word is saved as a wav file on the iPhone.  In my app, the user will pick words and I would like to put the words together to make a sentence.
I have not been able to determine how to combine multiple wav files together, in sequence, to create the entire sentence as a single file.
I have figured out, through examples, how to play the files together as one file -- but the example mixes them -- I need to basically append them to each other.  I have tried to append them to each other and remove the header information from all but the first file, but this process does not work.  The file is the correct length, but only plays the content of the first file.
I think the correct path is to use AudioFileReadPacketData to read the files and AudioFileWritePacketData write the info into a new file.  This has proven difficult...
Does anyone have experience with the Audio API's and could provide some sample code?
Ok -- more research into the matter... looks like the correct function is the Audio Queue Offline Render.  There is some sample code provided by Apple (AQOfflineRenderTest).  The reason for the Offline Render is because you are able to attach an output buffer to the render and save it to a file.  More to come as I progress with the project...
Ok -- three days and no real progress....
I am trying to combine the three .wav files into the destination .wav file.  Right now when you run this code, the first file is saved into the destination.
Any Ideas?
This source code uses the iPublicUtility classes provided from Apple -- they are able to be downloaded in several projects.  One is the projects is aurioTouch.
Here is my code (place it in a .cpp file and reference the CombineAudioFiles in a normal Objective C source file):
// standard includes
#include <AudioToolbox/AudioQueue.h>
#include <AudioToolbox/AudioFile.h>
#include <AudioToolbox/ExtendedAudioFile.h>

// helpers
#include "CAXException.h"
#include "CAStreamBasicDescription.h"

#define kNumberOfBuffers 3
#define kMaxNumberOfFiles 3

// the application specific info we keep track of
struct AQTestInfo
{
    AudioFileID                     mAudioFile[kMaxNumberOfFiles];
    CAStreamBasicDescription        mDataFormat[kMaxNumberOfFiles];
    AudioQueueRef                   mQueue[kMaxNumberOfFiles];
    AudioQueueBufferRef             mBuffer[kNumberOfBuffers];
    UInt32                          mNumberOfAudioFiles;
    UInt32                          mCurrentAudioFile;
    UInt32                          mbufferByteSize;
    SInt64                          mCurrentPacket;
    UInt32                          mNumPacketsToRead;
    AudioStreamPacketDescription    *mPacketDescs;
    bool                            mFlushed;
    bool                            mDone;
};

#pragma mark- Helper Functions
// ***********************
// CalculateBytesForTime Utility Function

// we only use time here as a guideline
// we are really trying to get somewhere between 16K and 64K buffers, but not allocate too much if we don't need it
void CalculateBytesForTime (CAStreamBasicDescription &inDesc, UInt32 inMaxPacketSize, Float64 inSeconds, UInt32 *outBufferSize, UInt32 *outNumPackets)
{
    static const int maxBufferSize = 0x10000;   // limit size to 64K
    static const int minBufferSize = 0x4000;    // limit size to 16K

    if (inDesc.mFramesPerPacket) {
        Float64 numPacketsForTime = inDesc.mSampleRate / inDesc.mFramesPerPacket * inSeconds;
        *outBufferSize = numPacketsForTime * inMaxPacketSize;
    } else {
        // if frames per packet is zero, then the codec has no predictable packet == time
        // so we can't tailor this (we don't know how many Packets represent a time period
        // we'll just return a default buffer size
        *outBufferSize = maxBufferSize > inMaxPacketSize ? maxBufferSize : inMaxPacketSize;
    }

    // we're going to limit our size to our default
    if (*outBufferSize > maxBufferSize && *outBufferSize > inMaxPacketSize) {
        *outBufferSize = maxBufferSize;
    } else {
        // also make sure we're not too small - we don't want to go the disk for too small chunks
        if (*outBufferSize < minBufferSize) {
            *outBufferSize = minBufferSize;
        }
    }

    *outNumPackets = *outBufferSize / inMaxPacketSize;
}

#pragma mark- AQOutputCallback
// ***********************
// AudioQueueOutputCallback function used to push data into the audio queue

static void AQTestBufferCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer)
{
    AQTestInfo * myInfo = (AQTestInfo *)inUserData;
    if (myInfo->mDone) return;

    UInt32 numBytes;
    UInt32 nPackets = myInfo->mNumPacketsToRead;
    OSStatus result = AudioFileReadPackets(myInfo->mAudioFile[myInfo->mCurrentAudioFile],      // The audio file from which packets of audio data are to be read.
                                           false,                   // Set to true to cache the data. Otherwise, set to false.
                                           &numBytes,               // On output, a pointer to the number of bytes actually returned.
                                           myInfo->mPacketDescs,    // A pointer to an array of packet descriptions that have been allocated.
                                           myInfo->mCurrentPacket,  // The packet index of the first packet you want to be returned.
                                           &nPackets,               // On input, a pointer to the number of packets to read. On output, the number of packets actually read.
                                           inCompleteAQBuffer->mAudioData); // A pointer to user-allocated memory.
    if (result) {
        DebugMessageN1 ("Error reading from file: %d\n", (int)result);
        exit(1);
    }

    // we have some data
    if (nPackets > 0) {
        inCompleteAQBuffer->mAudioDataByteSize = numBytes;

        result = AudioQueueEnqueueBuffer(inAQ,                                  // The audio queue that owns the audio queue buffer.
                                         inCompleteAQBuffer,                    // The audio queue buffer to add to the buffer queue.
                                         (myInfo->mPacketDescs ? nPackets : 0), // The number of packets of audio data in the inBuffer parameter. See Docs.
                                         myInfo->mPacketDescs);                 // An array of packet descriptions. Or NULL. See Docs.
        if (result) {
            DebugMessageN1 ("Error enqueuing buffer: %d\n", (int)result);
            exit(1);
        }

        myInfo->mCurrentPacket += nPackets;

    } else {
        // **** This ensures that we flush the queue when done -- ensures you get all the data out ****

        if (!myInfo->mFlushed) {
            result = AudioQueueFlush(myInfo->mQueue[myInfo->mCurrentAudioFile]);

            if (result) {
                DebugMessageN1("AudioQueueFlush failed: %d", (int)result);
                exit(1);
            }

            myInfo->mFlushed = true;
        }

        result = AudioQueueStop(myInfo->mQueue[myInfo->mCurrentAudioFile], false);
        if (result) {
            DebugMessageN1("AudioQueueStop(false) failed: %d", (int)result);
            exit(1);
        }

        // reading nPackets == 0 is our EOF condition
        myInfo->mDone = true;
    }
}

// ***********************
#pragma mark- Main Render Function

#if __cplusplus
extern "C" {
#endif

void CombineAudioFiles(CFURLRef sourceURL1, CFURLRef sourceURL2, CFURLRef sourceURL3, CFURLRef destinationURL)
{
    // main audio queue code
    try {
        AQTestInfo myInfo;

        myInfo.mDone = false;
        myInfo.mFlushed = false;
        myInfo.mCurrentPacket = 0;
        myInfo.mCurrentAudioFile = 0;

        // get the source file
        XThrowIfError(AudioFileOpenURL(sourceURL1, 0x01/*fsRdPerm*/, 0/*inFileTypeHint*/, &myInfo.mAudioFile[0]), "AudioFileOpen failed");
        XThrowIfError(AudioFileOpenURL(sourceURL2, 0x01/*fsRdPerm*/, 0/*inFileTypeHint*/, &myInfo.mAudioFile[1]), "AudioFileOpen failed");
        XThrowIfError(AudioFileOpenURL(sourceURL3, 0x01/*fsRdPerm*/, 0/*inFileTypeHint*/, &myInfo.mAudioFile[2]), "AudioFileOpen failed");

        UInt32 size = sizeof(myInfo.mDataFormat[myInfo.mCurrentAudioFile]);
        XThrowIfError(AudioFileGetProperty(myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyDataFormat, &size, &myInfo.mDataFormat[myInfo.mCurrentAudioFile]), "couldn't get file's data format");

        printf ("File format: "); myInfo.mDataFormat[myInfo.mCurrentAudioFile].Print();

        // create a new audio queue output
        XThrowIfError(AudioQueueNewOutput(&myInfo.mDataFormat[myInfo.mCurrentAudioFile],   // The data format of the audio to play. For linear PCM, only interleaved formats are supported.
                                          AQTestBufferCallback,     // A callback function to use with the playback audio queue.
                                          &myInfo,                  // A custom data structure for use with the callback function.
                                          CFRunLoopGetCurrent(),    // The event loop on which the callback function pointed to by the inCallbackProc parameter is to be called.
                                                                    // If you specify NULL, the callback is invoked on one of the audio queue's internal threads.
                                          kCFRunLoopCommonModes,    // The run loop mode in which to invoke the callback function specified in the inCallbackProc parameter.
                                          0,                        // Reserved for future use. Must be 0.
                                          &myInfo.mQueue[myInfo.mCurrentAudioFile]),       // On output, the newly created playback audio queue object.
                                          "AudioQueueNew failed");

        UInt32 bufferByteSize;

        // we need to calculate how many packets we read at a time and how big a buffer we need
        // we base this on the size of the packets in the file and an approximate duration for each buffer
        {
            bool isFormatVBR = (myInfo.mDataFormat[myInfo.mCurrentAudioFile].mBytesPerPacket == 0 || myInfo.mDataFormat[myInfo.mCurrentAudioFile].mFramesPerPacket == 0);

            // first check to see what the max size of a packet is - if it is bigger
            // than our allocation default size, that needs to become larger
            UInt32 maxPacketSize;
            size = sizeof(maxPacketSize);
            XThrowIfError(AudioFileGetProperty(myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyPacketSizeUpperBound, &size, &maxPacketSize), "couldn't get file's max packet size");

            // adjust buffer size to represent about a second of audio based on this format
            CalculateBytesForTime(myInfo.mDataFormat[myInfo.mCurrentAudioFile], maxPacketSize, 1.0/*seconds*/, &bufferByteSize, &myInfo.mNumPacketsToRead);

            if (isFormatVBR) {
                myInfo.mPacketDescs = new AudioStreamPacketDescription [myInfo.mNumPacketsToRead];
            } else {
                myInfo.mPacketDescs = NULL; // we don't provide packet descriptions for constant bit rate formats (like linear PCM)
            }

            printf ("Buffer Byte Size: %d, Num Packets to Read: %d\n", (int)bufferByteSize, (int)myInfo.mNumPacketsToRead);
        }

        // if the file has a magic cookie, we should get it and set it on the AQ
        size = sizeof(UInt32);
        OSStatus result = AudioFileGetPropertyInfo (myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyMagicCookieData, &size, NULL);

        if (!result && size) {
            char* cookie = new char [size];
            XThrowIfError (AudioFileGetProperty (myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyMagicCookieData, &size, cookie), "get cookie from file");
            XThrowIfError (AudioQueueSetProperty(myInfo.mQueue[myInfo.mCurrentAudioFile], kAudioQueueProperty_MagicCookie, cookie, size), "set cookie on queue");
            delete [] cookie;
        }

        // channel layout?
        OSStatus err = AudioFileGetPropertyInfo(myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyChannelLayout, &size, NULL);
        AudioChannelLayout *acl = NULL;
        if (err == noErr && size > 0) {
            acl = (AudioChannelLayout *)malloc(size);
            XThrowIfError(AudioFileGetProperty(myInfo.mAudioFile[myInfo.mCurrentAudioFile], kAudioFilePropertyChannelLayout, &size, acl), "get audio file's channel layout");
            XThrowIfError(AudioQueueSetProperty(myInfo.mQueue[myInfo.mCurrentAudioFile], kAudioQueueProperty_ChannelLayout, acl, size), "set channel layout on queue");
        }

        //allocate the input read buffer
        XThrowIfError(AudioQueueAllocateBuffer(myInfo.mQueue[myInfo.mCurrentAudioFile], bufferByteSize, &myInfo.mBuffer[myInfo.mCurrentAudioFile]), "AudioQueueAllocateBuffer");

        // prepare a canonical interleaved capture format
        CAStreamBasicDescription captureFormat;
        captureFormat.mSampleRate = myInfo.mDataFormat[myInfo.mCurrentAudioFile].mSampleRate;
        captureFormat.SetAUCanonical(myInfo.mDataFormat[myInfo.mCurrentAudioFile].mChannelsPerFrame, true); // interleaved
        XThrowIfError(AudioQueueSetOfflineRenderFormat(myInfo.mQueue[myInfo.mCurrentAudioFile], &captureFormat, acl), "set offline render format");

        ExtAudioFileRef captureFile;

        // prepare a 16-bit int file format, sample channel count and sample rate
        CAStreamBasicDescription dstFormat;
        dstFormat.mSampleRate = myInfo.mDataFormat[myInfo.mCurrentAudioFile].mSampleRate;
        dstFormat.mChannelsPerFrame = myInfo.mDataFormat[myInfo.mCurrentAudioFile].mChannelsPerFrame;
        dstFormat.mFormatID = kAudioFormatLinearPCM;
        dstFormat.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; // little-endian
        dstFormat.mBitsPerChannel = 16;
        dstFormat.mBytesPerPacket = dstFormat.mBytesPerFrame = 2 * dstFormat.mChannelsPerFrame;
        dstFormat.mFramesPerPacket = 1;

        // create the capture file
        XThrowIfError(ExtAudioFileCreateWithURL(destinationURL, kAudioFileCAFType, &dstFormat, acl, kAudioFileFlags_EraseFile, &captureFile), "ExtAudioFileCreateWithURL");

        // set the capture file's client format to be the canonical format from the queue
        XThrowIfError(ExtAudioFileSetProperty(captureFile, kExtAudioFileProperty_ClientDataFormat, sizeof(AudioStreamBasicDescription), &captureFormat), "set ExtAudioFile client format");

        // allocate the capture buffer, just keep it at half the size of the enqueue buffer
        // we don't ever want to pull any faster than we can push data in for render
        // this 2:1 ratio keeps the AQ Offline Render happy
        const UInt32 captureBufferByteSize = bufferByteSize / 2;

        AudioQueueBufferRef captureBuffer;
        AudioBufferList captureABL;

        XThrowIfError(AudioQueueAllocateBuffer(myInfo.mQueue[myInfo.mCurrentAudioFile], captureBufferByteSize, &captureBuffer), "AudioQueueAllocateBuffer");

        captureABL.mNumberBuffers = 1;
        captureABL.mBuffers[0].mData = captureBuffer->mAudioData;
        captureABL.mBuffers[0].mNumberChannels = captureFormat.mChannelsPerFrame;

        // lets start playing now - stop is called in the AQTestBufferCallback when there's
        // no more to read from the file
        XThrowIfError(AudioQueueStart(myInfo.mQueue[myInfo.mCurrentAudioFile], NULL), "AudioQueueStart failed");

        AudioTimeStamp ts;
        ts.mFlags = kAudioTimeStampSampleTimeValid;
        ts.mSampleTime = 0;

        // we need to call this once asking for 0 frames
        XThrowIfError(AudioQueueOfflineRender(myInfo.mQueue[myInfo.mCurrentAudioFile], &ts, captureBuffer, 0), "AudioQueueOfflineRender");

        // we need to enqueue a buffer after the queue has started
        AQTestBufferCallback(&myInfo, myInfo.mQueue[myInfo.mCurrentAudioFile], myInfo.mBuffer[myInfo.mCurrentAudioFile]);

        while (true) {
            UInt32 reqFrames = captureBufferByteSize / captureFormat.mBytesPerFrame;

            XThrowIfError(AudioQueueOfflineRender(myInfo.mQueue[myInfo.mCurrentAudioFile], &ts, captureBuffer, reqFrames), "AudioQueueOfflineRender");

            captureABL.mBuffers[0].mData = captureBuffer->mAudioData;
            captureABL.mBuffers[0].mDataByteSize = captureBuffer->mAudioDataByteSize;
            UInt32 writeFrames = captureABL.mBuffers[0].mDataByteSize / captureFormat.mBytesPerFrame;

            printf("t = %.f: AudioQueueOfflineRender:  req %d fr/%d bytes, got %d fr/%d bytes\n", ts.mSampleTime, (int)reqFrames, (int)captureBufferByteSize, writeFrames, (int)captureABL.mBuffers[0].mDataByteSize);

            XThrowIfError(ExtAudioFileWrite(captureFile, writeFrames, &captureABL), "ExtAudioFileWrite");

            if (myInfo.mFlushed) break;

            ts.mSampleTime += writeFrames;
        }

        CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);

        XThrowIfError(AudioQueueDispose(myInfo.mQueue[myInfo.mCurrentAudioFile], true), "AudioQueueDispose(true) failed");
        XThrowIfError(AudioFileClose(myInfo.mAudioFile[myInfo.mCurrentAudioFile]), "AudioQueueDispose(false) failed");
        XThrowIfError(ExtAudioFileDispose(captureFile), "ExtAudioFileDispose failed");

        if (myInfo.mPacketDescs) delete [] myInfo.mPacketDescs;
        if (acl) free(acl);
    }
    catch (CAXException e) {
        char buf[256];
        fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
    }

    return;
}

#if __cplusplus
}
#endif

A: Ok -- found an answer for this issue -- will only work with wav files...
I used NSData to concatenate each file into the master data.  I then rewrote the header (first 44 bytes) according to the wav file specifications.
This process worked well... the most complex part of the process was to rewrite the header info... but once that was figured out, things work well using this process.

A: actually if you use mp3 you don't even need to rewrite the headers i've learned. you can
NSURL *soundFilePath = [[NSURL alloc] initFileURLWithPath: path1];
NSData *sound1Data = [[NSData alloc] initWithContentsOfURL: soundFilePath];
soundFilePath = [[NSURL alloc] initFileURLWithPath: path2];
NSData *sound2Data = [[NSData alloc] initWithContentsOfURL: soundFilePath];

NSMutableData *sounds = [NSMutableData alloc];
[sounds appendData:sound1Data];
[sounds appendData:sound2Data];

[[NSFileManager defaultManager] createFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"tmp.mp3"] contents:sounds attributes:nil]

and you're all set.

A: NSString    *fileNamePath = @"sound_record.aiff";
NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths  objectAtIndex:0];
NSString    *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath];
NSURL *audioUrl = [NSURL fileURLWithPath:oldappSettingsPath];

NSString    *fileNamePath1 = @"output.mp4";
NSArray   *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString  *documentsDirectory1 = [paths1  objectAtIndex:0];
NSString    *oldappSettingsPath1 = [documentsDirectory1 stringByAppendingPathComponent:fileNamePath1];
NSLog(@"oldpath=%@",oldappSettingsPath);
NSURL *videoUrl = [NSURL fileURLWithPath:oldappSettingsPath1];

if (avPlayer.duration >0.00000) {

    NSLog(@"HII SOMEDATA");
    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioUrl options:nil];
    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoUrl options:nil];

    AVMutableComposition* mixComposition = [AVMutableComposition composition];

    NSLog(@"audio =%@",audioAsset);
    AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];

    AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];

    AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough];

    NSString* videoName = @"export.mov";

    NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName];
    NSURL    *exportUrl = [NSURL fileURLWithPath:exportPath];

    if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
    {
        [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    }

    _assetExport.outputFileType = @"com.apple.quicktime-movie";
    NSLog(@"file type %@",_assetExport.outputFileType);
    _assetExport.outputURL = exportUrl;
    _assetExport.shouldOptimizeForNetworkUse = YES;

    [_assetExport exportAsynchronouslyWithCompletionHandler:
     ^(void ) {

         NSString   *fileNamePath = @"sound_record.mov";
         NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
         NSString  *documentsDirectory = [paths  objectAtIndex:0];
         NSString   *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath];

         if ([[NSFileManager defaultManager] fileExistsAtPath:oldappSettingsPath]) {

             NSFileManager *fileManager = [NSFileManager defaultManager];
             [fileManager removeItemAtPath: oldappSettingsPath error:NULL];

         }

         NSURL *documentDirectoryURL = [NSURL fileURLWithPath:oldappSettingsPath];
         [[NSFileManager defaultManager] copyItemAtURL:exportUrl toURL:documentDirectoryURL error:nil];
         [audioAsset release];
         [videoAsset release];
         [_assetExport release];

     }
     ];


text:
Q: how to get a sorted result from mysql query? I am trying to get a sorted result from a MySQL query and I don't have any idea of making the query.
I have a example MySQL table as follows :
 id | cat_type
 1  |  free
 2  |  free
 3  |  free
 4  |  free
 5  |  paid
 6  |  paid
... |  ...
... |  ...
... |  ...
   and it goes on.

The result should be as follows from the above table :
 id | cat_type
 1  | free
 2  | free
 5  | paid

 3  | free
 4  | free
 6  | paid

... | free
... | free
... | paid
  and goes on(should be sorted)

The total result should be split as 3. In the first three result, first two should be free and the next one should be paid likewise all the remaining result should be sorted as two free and one paid.
The most important is that it should be sorted as two free and one paid.
Any idea how to accomplish this using a query?

A: I suppose you could do something like this from the command line/phpmyadmin:
Assuming the following table:
mysql> SELECT * FROM test;
+----+----------+
| id | cat_type |
+----+----------+
|  1 | free     |
|  2 | free     |
|  3 | free     |
|  4 | free     |
|  5 | paid     |
|  6 | paid     |
+----+----------+
6 rows in set (0.00 sec)

Make your custom ordering by selecting twice the table and using a variable as a counter:
mysql> SET @i := 0;
SET @j := 0.5;
SELECT id, cat_type FROM
(SELECT @i := @i + 1 as ordering, id, cat_type FROM test WHERE cat_type = 'free'
 UNION
 SELECT @j := @j + 2 as ordering, id, cat_type FROM test WHERE cat_type = 'paid')
AS base_table
ORDER BY ordering;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

+----+----------+
| id | cat_type |
+----+----------+
|  1 | free     |
|  2 | free     |
|  5 | paid     |
|  3 | free     |
|  4 | free     |
|  6 | paid     |
+----+----------+
6 rows in set (0.00 sec)

This is technically incorrect, as it could explore the original tables not in id order, but assuming you are using InnoDB, a full table scan in index order should be performed.
Also, this is terribly unoptimized:
+----+-------------------+------------+------+---------------+------+---------+------+------+-----------------+
| id | select_type       | table      | type | possible_keys | key  | key_len | ref  | rows | Extra           |
+----+-------------------+------------+------+---------------+------+---------+------+------+-----------------+
|  1 | PRIMARY           | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |   12 | Using filesort  |
|  2 | DERIVED           | test       | ALL  | NULL          | NULL | NULL    | NULL |    6 | Using where     |
|  3 | UNCACHEABLE UNION | test       | ALL  | NULL          | NULL | NULL    | NULL |    6 | Using where     |
| NULL | UNION RESULT      | <union2,3> | ALL  | NULL          | NULL | NULL    | NULL | NULL | Using temporary |
+----+-------------------+------------+------+---------------+------+---------+------+------+-----------------+
4 rows in set (0.00 sec)

To the point that if you wanted to do this in a large table, doing it programatically or using cursors would be a better idea.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Using ReactJS on Static Websites I am learning ReactJS and want to start using it on my existing websites by changing some of my static content to be on React, like the footer content and contact, however when I use JSX the contents don't appear but if I use raw react scripts they work
This Code doesn't execute anything
var Footer = React.createClass({
 render:function(){
     return Developed by Me
    }
});

ReactDOM.render(
 ,
 document.getElementById('bluevineCredits')
);

This code executes.
const title = createElement(
'a',
{
    id:'Bluevine Group',

    href:'//www.bluevinegroup.co.za'

},
'Developed and Maintained by Bluevine Group'
)

render(
title,
document.getElementById('bluevineCredits')
)


text:
Q: Generalised eigenvalues in the residual spectrum For an operator $T$ on a Hilbert space the residual spectrum is defined as the set of complex numbers $\lambda$ for which $(T-\lambda I)^{-1}$ exists but is not densely defined. The question is: could there be a complex number in the residual spectrum which is a generalised eigenvalue? By generalised eigenvalue I mean that there exists a sequence $\{x_n\}$ of unit vectors that satisfy:
$$
(T-\lambda I)x_n \longrightarrow 0.
$$
I was thinking about this from a physics point of view (discarding the fact that observables are assumed to be self adjoint) and wondering if one wanted to make an "observable" out of something which is hermitian but doesn't have an empty residual spectrum (like momentum on $L^2(0,\infty))$ would the problem be that for such operators the system could in principle collapse to some state with a complex spectral value associated to it? This spectral value would have to be in the residual spectrum because the continuous and point spectra of hermitian operators must be real.

A: Let $S : \mathcal H\to\mathcal H$ be any linear operator with non-closed range and $\ker S = \{0\}$ (for example $Sf = t\cdot f$ on $L^2(0,1)$ satisfies this). Now, let $M$ be any closed, proper infinite-dimensional subspace of $\mathcal H$ and let $V : \overline{\operatorname{ran}S}\to M$ be unitary. Then $T := VS$ satisfies the requirements.


text:
Q: Popup window does not dismiss on ouside touch when set mPopWindow.setBackgroundDrawable(null) I have 1 question/ issue, I have implemented Popup window in my project. I have check list in pop up window and having mandatory selection functionality. For this functionality I need to check whether user had selected any at least 1 item in list on back press,before dismiss of pop window. The problem is onKey listener fire only when I set   mPopWindow.setBackgroundDrawable(null); to my popup window. but at this time outside touch does not work at all. If remove mPopWindow.setBackgroundDrawable(null); and put mPopWindow.setBackgroundDrawable(new BitmapDrawable()); outside touch works but onBack press does not fire onKey listener. Any 1 know how to achieve both functionality onBackpress and outsid touch on popup window.

A: ok,I solved this problem.
change:
mPopupWindow.setBackgroundDrawable(null);
to:
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
bingo.


text:
Q: Fetch as Google not showing Waypoints.js on scroll animation SEO So #1 I'm sorry if this is not entirely programming, but I feel that it is, because I'm using programming to drive uniqueness to my webpage, but Google doesn't see it.  So it's a webmasters and a programming problem.
So I noticed that my main content underneath 4 reasons to choose LED Habitats did not show up in Fetch as Google as well as a few other sections. The site being brand new, so I'm not sure how this will be indexed.   What happens is, as the user scrolls the content is brought in using Waypoints and Animate.css  which offers an engaging yet simple user experience.  I'm just afraid that If the content doesn't show up in "Fetch as Google" in webmaster tools that this content will never be found / indexed by Google.
There are thousands of sites that use this library, I'm just curious what I'm doing wrong.. or what I can do.
Is there a way for me to keep the simple animations but keep Google Happy at the same time?
I took a screen shot of "Fetch as Google" and you can see blatant missing sections which are the sections animated by the waypoints library.  This being said, is there a way I can keep this library / animation yet have google find it..
Thanks for listening!

A: The most important thing to Google is to show him content, this content should not be loaded by JS, try to disable the JS from your browser and reload the page, if you see content you are ok, otherwise you should change the way you get the content.
Most of the animations are done using JS so Google won't see them specially in Fetch as Google.
Try the to disable the JS, if there is a content then you are OK.


text:
Q: ejabberd having issue about undefined function I am getting errors with XMPP on my Gentoo Hardened server. It runs and says it is running but when trying log many of these errors appear about a crash.
2019-11-01 10:56:54.748 [error] <0.563.0>@xmpp_idna:domain_utf8_to_ascii CRASH REPORT Process <0.563.0> with 0 neighbours exited with reason: call to undefined function xmpp_idna:domain_utf8_to_ascii(<<"XXXXXXXX">>) in p1_server:terminate/7 line 878

I suspect I have to install a dependency or something, or maybe the Gentoo ebuild is broken.
I recently updated ejabberd from 18.03 to 18.09 and this is when it started.
I am using dev-erlang/xmpp 1.4.2 on this system.

A: Looking at https://github.com/processone/xmpp/issues/42
xmpp_idna was removed from xmpp library in a commit from 22 September 2019, as released in version 1.4.2:
https://github.com/processone/xmpp/commit/f3517a9adaa4406c614e2234d3af10f1411196b9
So, when ejabberd 19.09 was released, the call to that function in ejabberd_pkix was rewritten, and the requirements were updated accordingly to 1.4.2 library
Now, you are mixing a very recent library, xmpp 1.4.2, with a very old ejabberd, 18.09


text:
Q: Norm with maximum of coefficients on polynomial ring
Given a non-archimedean normed field $(F,|\cdot|)$, show we can extend the norm to $F[x]$ by setting $|a_0+a_1x+\ldots+a_nx^n|\mapsto \max(|a_0|,|a_1|,\ldots,|a_n|).$

I am having trouble showing the multiplicativity of this extended norm. We have to show that
\begin{equation*}
\max_k \left\vert \sum_{i+j=k} a_ib_j \right\vert=\max_i |a_i|\cdot \max_j |b_j|.
\end{equation*}
Since $|-|$ is non-archimedean, we have
$$
\left\vert \sum_{i+j=k} a_ib_j \right\vert\leq \max_{\substack{i,j \\ i+j=k}} |a_i | |b_j| \leq \max_{i,j}|a_i| |b_j|=\max_i |a_i|\cdot \max_j |b_j|.
$$
Taking $\max_k$ on both sides gives one equality of what we need to show. However, I need to inspect when equalities occur.
Any hints?

A: Let
$$
f=a_0+a_1x+a_2x^2+\dots+a_nx^n
$$
and
$$
g=b_0+b_1x+b_2x^2+\dots+b_mx^m.
$$
Let $r$ be the smallest index such that $|a_r|=|f|$ and $s$ be the smallest index such that $|b_s|=|g|$.
Now, consider $|fg|$.  In particular, let's look at $|(fg)_{r+s}|$.  As you note,
$$
(fg)_{r+s}=\sum_{i=0}^{r+s}a_ib_{r+s-i}.
$$
We observe that $|a_rb_s|=|f||g|$.  Moreover, for $i\not=r$, $|a_ib_{r+s-i}|<|f||g|$ by the assumptions on $r$ and $s$ (either $i<r$ or $r+s-i<s$).  One of the properties of non-Archimedean norms states when the norm of a sum is equal to the maximum norm of the summands, this is exactly the current case.


text:
Q: Statistics ( cumulative frequency ) The question on my book is:
How many percent of the pupils got at least a $11$ on their French test??
How can i find it by look at that table ?
On that table there's absolute frequency, relative frquency, cumulative absolute frequency, cumulative relative frequency and also in percentage.
Where should I look to find out the students who got more then $11 $ points on their test?
Please help me !! i got maths exma son monday !!! :(

A: In principle, if you have all of this data you could look at any of the tables. In practice, the easiest method would be just to go to cumulative relative frequency, find the cumulative relative frequency at '11' points, then subtract it from 1.
This will give you the percentage of students who got more than 11 points - notice this is slightly different from the percentage of the pupils who got at least an 11: at least implies exactly 11 should also be included, so you'll have to add the percent who got exactly 11 points to the figure you obtained.


text:
Q: Include a bootstrap css file to a spring project jsp file i want to add bootstrap css files to my spring project.

this is the jsp file which should include the bootstrap css files.
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

        <title>Login</title>

Login With Database Application

        <form:form method="post" action="login" modelAttribute="loginuser">

                    Login ID
                    <input type="text" name="loginid" id="loginid" path="loginid" />

                    Password
                    <input type="password" name="password" id="password" path="password" />

            <button class="btn btn-primary"type="submit">Login</button>
            New User
        </form:form>

this is the xml configurartion file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.epic.logindb.controller"></context:component-scan>
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/users" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>

    <bean id="userlogin" class="com.epic.logindb.dao.UserLogin"></bean>
    <bean id="loginuser" class="com.epic.logindb.model.LoginUser"></bean>
    <bean id="user" class="com.epic.logindb.model.User"></bean>
    <bean id="edituser" class="com.epic.logindb.model.User"></bean>

</beans>

please can you help to integrate bootstrap files to this jsp file.

A: In your Spring MVC application all request are handled by DispatcherServlet, You must configure a Resource Handler for handling any static resources like Javascript files or CSS files.
Since you have included the MVC namespace in the spring config xml file you can use the following tag:
<mvc:resources mapping="/resources/**" location="path/resources/" />

What you are doing here is mapping all request with resources in URI to serve static files inside a folder called resources.
To link CSS in your JSP you can either use JSTL Tag:
<link rel="stylesheet" href='<c:url value="/resources/bootstrap/bootstrap.min.css" />' />

Or  without JSTL but make sure your webapp context is correct:
<link rel="stylesheet" href="/basecontext/resources/bootstrap/bootstrap.min.css" />


text:
Q: How to learn the order of content by machine learning? Data at hand: 1000 questionnaires with a finite database of questions, say 100 questions about name, gender, income etc. Each questionnaire contains 10 to 30 questions from this question database. The wording of a certain question remains identical across different questionnaires. The 100 questions have their unique label (Q1 to Q100) in the database.
Task: creating a new questionnaire. Assuming I know which questions (say 20 questions including Q1, Q5, Q10, Q22 etc) I need to ask on the new questionnaire, I need to know what order should I place these questions.
Machine learning question: how do I learn the patterns from the existing data to help myself order the 20 questions on my new questionnaire?

A: A simple but inaccurate solution would count the order of each question label on the existing data. Say Q1 appeared 300 times on the existing data and 70% of time it is the first question on the questionnaire, so I predict Q1 would have order = 1 on any new questionnaire.
Alternatively, I can compute the average order of each question on the existing data. Say Q1 has a mean order of 2.53 and Q10 has a mean order of 1.33. Then when I create a new questionnaire that contains both Q1 and Q10, Q1 will be placed after Q10.
The above methods fail to capture the relationship between the questions. For instance, maybe Q5 always appears after Q6. I hope the algorithm can capture hidden patterns like this.


text:
Q: Active device count seems low The Google Play Console Dashboard gives a count of active devices. My app is a push-notification based app which provides communities with notifications of important events. So on my back-end I track each devices' Firebase push token, so that the users can receive notifications for the things they subscribe to. Whenever my back-end pushes a notification to a user that has uninstalled the app, disabled push notifications, or no longer has an active device, Firebase will indicate that error in the response. That entry is then removed from the back-end.
Considering that on average my system sends out at least one notification per day, I have an almost real-time count of how many users have my app installed on Android (whether or not they are using / launching it), and also have push notifications enabled for my app. Thus if anything this represents a sub-set of all installs, because some users may have disabled push notifications.
Some days I gain new app installs, but the overall total of app installs may go down, as there is always a baseline attrition due to people switching devices and not reinstalling the app, app uninstalls, etc. So I am certain my end is working correctly in removing entries for installs I can no longer push notifications to, as my counts on occasion go down (again, meaning that day there were more uninstalls than installs).
Now my question. My back-end count of active app installs (those I can actually send push notifications to) is significantly higher than what Google Console Dashboard reports for my active app installs. I show around 20% more installs than Google. Why the discrepancy? Surely Firebase isn't allowing thousands of phantom push destinations that it can no longer actually push to? Is this based on some kind of privacy setting for some people? I know in the Apple App Store they specifically state that the active install counts are opt-in only.

A: This may be because Google Play Console only shows active installs for real users.
Firebase will be counting all the users which will include Google Bots used for Pre-Launch Reports as well as for reviewing the app to make sure it meets the policies.
Therefore, you will see a higher number in Firebase than Google Play Console.


text:
Q: VBA read file from specific string to end of file I am trying to use Microsoft Scripting Runtime to open a text file, look for a specific string of text, and then copy that line and everything below it until the end of the file and write that to excel. I don't need it formatted by column, just want it to appear as it is in the file.. Below is the code that I'm trying to use but I think I've made a few errors.
Sub readFile()
    Dim sFileName As String

    sFileName = "C:\Users\Jamie\Desktop\REPORT.txt"
    With New Scripting.FileSystemObject
        With .OpenTextFile(sFileName, ForWriting)
            If Mid(sFileName, 3, 6) = "PALLET" Then
                .ReadAll
                Do Until .AtEndOfStream
                Loop
            End If
        End With
    End With
End Sub

Here is an example of the REPORT.TXT
RANDOM DATA THAT'S NOT NEEDEDRANDOM DATA THAT'S NOT NEEDED
RANDOM DATA THAT'S NOT NEEDED
RANDOM DATA THAT'S NOT NEEDED
RANDOM DATA THAT'S NOT NEEDEDRANDOM DATA THAT'S NOT NEEDEDRANDOM DATA THAT'S NOT NEEDED
RANDOM DATA THAT'S NOT NEEDED

     PALLET INFORMATION
=================================
UNDER 5 HRS     5
6 to 10 HRS     20
11 to 15 HRS    45
OVER 20 HRS     12
=================================

Report Generated on 2/12/19 by IBM z/OS JBL.9897992

A: Here's your code refactored to achieve what you want.  It mainly shows how to use the FileSystemObject to read text files.  I suspect you'll want to make changes once you get to grips with reading the file data, to make placing the data into the sheet easier.
Version 1 - if file is small enough to read into a single string
Sub readFile()
    Dim sFileName As String
    Dim FileData As String
    Dim PalletData As String
    Dim idx As Long
    Dim LocationToPlaceData As Range

    sFileName = "C:\Data\Temp\Report.txt" '"C:\Users\Jamie\Desktop\REPORT.txt"
    With New Scripting.FileSystemObject
        With .OpenTextFile(sFileName, ForReading)
            FileData = .ReadAll
            .Close
        End With
    End With
    idx = InStr(FileData, "PALLET")
    If idx > 0 Then
        PalletData = Mid$(FileData, idx)
        'get location to place data - update to suit your needs
        Set LocationToPlaceData = ActiveSheet.Range("A1")

        'Place Data in a single cell
        LocationToPlaceData = PalletData
    End If
End Sub

Version 2 - if file is too big to read into a single string.
Sub readFile2()
    Dim sFileName As String
    Dim FileLine As String
    Dim PalletData As String
    Dim idx As Long
    Dim LocationToPlaceData As Range

    sFileName = "C:\Data\Temp\Report.txt" '"C:\Users\Jamie\Desktop\REPORT.txt"
    With New Scripting.FileSystemObject
        With .OpenTextFile(sFileName, ForReading)
            Do Until .AtEndOfStream
                FileLine = .ReadLine
                idx = InStr(FileLine, "PALLET")
                If idx > 0 Then
                    PalletData = Mid$(FileLine, idx)
                    Do Until .AtEndOfStream
                        PalletData = PalletData & vbCrLf & .ReadLine
                    Loop
                End If
            Loop
            .Close
        End With
    End With

    'get location to place data - update to suit your needs
    Set LocationToPlaceData = ActiveSheet.Range("A1")

    'Place Data in a single cell
    LocationToPlaceData = PalletData
End Sub


text:
Q: How to troubleshoot why the Endpoints in my service don't get updated? I have a Kubernetes cluster running on the Google Kubernetes Engine.
I have a deployment that I manually (by editing the hpa object) scaled up from 100 replicas to 300 replicas to do some load testing. When I was load testing the deployment by sending HTTP requests to the service, it seemed that not all pods were getting an equal amount of traffic, only around 100 pods were showing that they were processing traffic (by looking at their CPU-load, and our custom metrics). So my suspicion was that the service is not load balancing the requests among all the pods equally.
If I checked the deployment, I could see that all 300 replicas were ready.
$ k get deploy my-app --show-labels
NAME                DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       LABELS
my-app              300       300       300          300         21d       app=my-app

On the other hand, when I checked the service, I saw this:
$ k describe svc my-app
Name:              my-app
Namespace:         production
Labels:            app=my-app
Selector:          app=my-app
Type:              ClusterIP
IP:                10.40.9.201
Port:              http  80/TCP
TargetPort:        http/TCP
Endpoints:         10.36.0.5:80,10.36.1.5:80,10.36.100.5:80 + 114 more...
Port:              https  443/TCP
TargetPort:        https/TCP
Endpoints:         10.36.0.5:443,10.36.1.5:443,10.36.100.5:443 + 114 more...
Session Affinity:  None
Events:            <none>

What was strange to me is this part
Endpoints:         10.36.0.5:80,10.36.1.5:80,10.36.100.5:80 + 114 more...

I was expecting to see 300 endpoints there, is that assumption correct?
(I also found this post, which is about a similar issue, but there the author was experiencing only a few minutes delay until the endpoints were updated, but for me it didn't change even in half an hour.)
How could I troubleshoot what was going wrong? I read that this is done by the Endpoints controller, but I couldn't find any info about where to check its logs.
Update: We managed to reproduce this a couple more times. Sometimes it was less severe, for example 381 endpoints instead of 445. One interesting thing we noticed is that if we retrieved the details of the endpoints:
$ k describe endpoints my-app
Name:         my-app
Namespace:    production
Labels:       app=my-app
Annotations:  <none>
Subsets:
  Addresses:          10.36.0.5,10.36.1.5,10.36.10.5,...
  NotReadyAddresses:  10.36.199.5,10.36.209.5,10.36.239.2,...

Then a bunch of IPs were "stuck" in the NotReadyAddresses state (not the ones that were "missing" from the service though, if I summed the number of IPs in Addresses and NotReadyAddresses, that was still less than the total number of ready pods). Although I don't know if this is related at all, I couldn't find much info online about this NotReadyAddresses field.

A: It turned out that this is caused by using preemptible VMs in our node pools, it doesn't happen if the nodes are not preemtibles.
We couldn't figure out more details of the root cause, but using preemtibles as the nodes is not an officially supported scenario anyway, so we switched to regular VMs.

A: Pod IPs can be added to NotReadyAddresses if a health/readiness probe is failing. This will in turn cause the pod IP to fail to be automatically added to the endpoints, meaning that the kubernetes service can't connect to the pod.

A: I refer to your first try with 300 pods.
I would check the following:

*

*kubectl get po -l app=my-app  to see if you get a 300 item list. Your service says you have 300 available pods, which makes your issue very interesting to analyze.

*whether your pod/deployment manifest defined limit and request resources. This better helps scheduler.

*whether some of your nodes have taints incompatible with your pod/deployment manifest

*whether your pod/deploy manifest has liveness and readyness probes (please post them)

*whether you defined some resourceQuota object, which limit the creation of pods/deployments


text:
Q: got puzzled about promise in jQuery 1 the value can not change in promise
for example

var t = function(s) {
  var wait = function(dtd) {
    var dtd = $.Deferred();
    //new a Deferred object in function

    var tasks = function() {
      alert("complete!");
      s = s + "hhh";
      dtd.resolve(s); // change the state of deferred object
    };
    setTimeout(tasks, 5000);
    // return promise object
    return dtd.promise(s);
  };
}

var s = "hhh";
$.when(t(s))
  .then(function() {
    alert(s);
  }).then(function() {
    alert(s);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

I can only got "hhh" instead of "hhhhhh"...
2
How to invoke promise chain with different values?like a.then(b(c)).then(f(d))
I put all values in a object and then pass it on chain...

A: The alert in your $.when is alerting the global variable not the resolve in tasks
Also , you never call wait() and tasks() doesn't return anything.
The return of the promise only returns to wait() which never gets called. Returning to the inner function does not return to the outer function
Also you have no arguments in then() to receive the resolved data.
In order to get data to the second then, you need to return something from the first one

var t = function (s) {
    var wait = function () {
        var dtd = $.Deferred();
        //new a Deferred object in function

        var tasks = function () {
            alert("complete!");
            s = s + "hhh";
            dtd.resolve(s); // change the state of deferred object
        };
        setTimeout(tasks, 2000);
        // return promise object
        return dtd.promise();
    };
   // return the promise inside `wait`
   return wait()
}

var s = "hhh";
$.when(t(s)).then(function (resolvedData) {
    // return to the next then...just because we can
    return resolvedData; // must return something if want to access it in next then
}).then(function(previousThenData) {
    alert(previousThenData);// alert argument
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>


text:
Q: Google App Engine With Twilio: ImportError: No module named pytz I am trying to integrate Twilio with google app engine. I followed the instructions found here: http://twilio-python.readthedocs.org/en/latest/appengine.html.
When I try to run the app locally or deploy the app i get the error:
ImportError: No module named pytz

the error is coming from the path:
from twilio.rest import TwilioRestClient
from .rest.exceptions import TwilioRestException
from .resources
from .util
import pytz
ImportError: No module named pytz

I am have done a ton of research in to resolving my problems, but cannot seem to find a solution. I have used easy_install to reinstall the pytz .egg file, but that does not seem to do anything; even when i remove it from the easy_install.pth file andthen reinstall it. The weird thing is that if i access python from the command line, and try to import pytz, i get no error:
$ python
>>> import pytz

no error
any and all solution or tips would be appreciated! thanks in advance!
brandon

A: If you want to use 3rd party libraries not listed in this document: https://cloud.google.com/appengine/docs/python/tools/libraries27, You have to move the library dir to the root of your appengine project.
In this case you have to copy pytz library folder to the root of your appengine project.


text:
Q: Calculate the records for each calculations by month I have a bunch of count columns sent for each day, so I have to total those up for the entire month and then do the division to find the total count by month. how do I get the calculation of all three calculations by month
Below are the fields I'm trying to calculate, how do I total the records for the entire month:
CAST([Sid_Count] / NULLIF([Wrk_Count], 0) AS DECIMAL(18, 4)) AS Quality_Field,
CAST([Talk_Count] / NULLIF([Sid_Count], 0) AS DECIMAL(18, 4)) AS Utilization_Field,
CAST([Cell_Count] / NULLIF([Cell_No_Count] + Cell_No_Count, 0) AS DECIMAL(18, 4)) AS Consent_Field

Example of what I'm trying to see: Calculation from Jan 8th to Feb 8th
DateByMonth      Quality_Field          Utilization_Field       Consent_Field
2021-02-08       Total count by month   Total count by month    Total count by month

A: DECLARE @derivedDateStart DATE = '1/1/2015' --Set as far back as needed
DECLARE @derivedDateEnd DATE = getdate()
CREATE TABLE #tempDerivedMonth (tYear int, tMonth int)
WHILE @derivedDateStart < @derivedDateEnd
    BEGIN
        INSERT INTO #tempDerivedMonth(tYear, tMonth)
        SELECT YEAR(@derivedDateStart, MONTH(@derivedDateStart))

        SET DATEADD(m,1,@derivedDateStart)
    END

SELECT CONVERT(VARCHAR,CONVERT(DATE,CONVERT(VARCHAR,MONTH(myDate))+'/'+CONVERT(VARCHAR,DAY(getdate()))+'/'+CONVERT(VARCHAR,YEAR(myDate))),23)  AS DateByMonth,
SUM(CAST([Sid_Count] / NULLIF([Wrk_Count], 0) AS DECIMAL(18, 4))) AS Quality_Field,
SUM(CAST([Talk_Count]  / NULLIF([Sid_Count], 0)  AS DECIMAL(18, 4))) AS Utilization_Field,
SUM(CAST([Cell_Count] / NULLIF([Cell_No_Count] + Cell_No_Count, 0))  AS DECIMAL(18, 4)) AS Consent_Field
FROM YourTable yt
JOIN #tempDerivedMonth tdm
  ON tdm.tMonth = MONTH(myDate) AND tdm.tYear = YEAR(myDate) AND DAY(myDate) BETWEEN DAY(getdate()) and DATEADD(d,1,DATEADD(m,-1,getdate()))
GROUP BY CONVERT(VARCHAR,CONVERT(DATE,CONVERT(VARCHAR,MONTH(myDate))+'/'+CONVERT(VARCHAR,DAY(getdate()))+'/'+CONVERT(VARCHAR,YEAR(myDate))),23)

Assuming you have a date column named myDate your solution might look something like this (messier than I'd like).  To group by a derived month I think you'll need a calendar table, which is #tempDerivedMonth in example.  Summing your equations allows you to Group output in your From Statement.  Curious to know if this works for you.  (thanks Rachel for the prompt to expand on initial answer)


text:
Q: Find out if crossroad or 3-way-intersection I'm trying to find out the type of a crossroad / intersection in overpass by given coordinates (simple 4-way-crossroad or 3-way-intersection aka Y/T intersection).
Wanted to count the way-id's I'm getting via json later in program code (4 = simple crossroad, 3 = Y or T) using the following query:
http://overpass-turbo.eu/s/NyD
[out:json][timeout:15];
way["highway"](around:1,48.7986003,11.3759673);
foreach ->.w {
  node(w.w);(way(bn);- .w;)->.wd;
  out body geom;
};

Problem: This only works if a street ends at the crossroad / intersection or at least turns into another way-id.
In this example there's a street which reaches from north to south and east. The east way got another way-id so that's not a problem. But from north to south it's just one way (so only one id). Result: I'm counting 3 but it should be 4 for this type of crossroad.
How do I solve this problem or is there a better way to identify the type of a crossroad / intersection?
Thank you very much!

A: You have to look at the junction node, too.
Some examples:
If the node is part of two ways and..

*

*these ways have other nodes before and after this node ID then you have a 4-way-junction.

*only one way has other nodes before and after this node ID then you have a 3-way-junction

*none of these ways have other nodes before and after this node ID then it is not a junction. Instead, the way continues with a different ID.

If the node is part of n ways and it is the last or first node of all these ways then you have a n-way-junction.
There will be some more cases than the ones mentioned above. Take a sheet of paper, draw some ways and their nodes onto it to get a better visualization of the data.
I'm not sure if this simple approach will work for all cases, though.


text:
Q: Performing an async function before form post submission What I'm Trying To Do:
On my site I've created a registration form that I'd like to perform two actions upon submission:
1) Subscribe the user to a MailChimp EDM list (using just the Name, Email fields).
2) Store the complete form in Netlify by performing a POST action (all fields, particularly their messages)
Here's my form:
<form
  className={`contact-form ${submitError ? 'has-error' : ''}`}
  name={formName}
  method="POST"
  onSubmit={event => this.submitHandler(event)}
  action="/thank-you/"
  data-netlify="true"
  data-netlify-honeypot="bot-field"
>
   // Form fields
</form>

And here's my onSubmit handler:
submitHandler = async (event) => {
  const {
    email,
    fieldValues,
    submitting,
  } = this.state;
  if (submitting) return false;
  this.setState({
    submitting: true,
    submitError: false,
  });
  const result = await addToMailchimp(email, fieldValues);
  if (result.result === 'success') {
    // Inconsequential, as success should result in redirection to the success page
    this.setState({
      submitting: false,
    });
  } else {
    event.preventDefault(); // this SHOULD stop form submit?
    this.setState({
      errorMessage: decodeEntities(result.msg),
      submitError: true,
      submitting: false,
    });
  }
}

What's Happening Here:
As you can see in the code snippets, in order to achieve this I am attempting to first asynchronously subscribe the user to MailChimp with the fields they have submitted, and if I don't get a success message I break the submit operation with event.preventDefault();.
As a bonus, this is also useful for preventing repeat registrations, as I'll get a message back from MailChimp if they're already on the subscribe list.
The Issue:
However, what happens in the wild is that the form submits and redirects to the success page (/thank-you/) regardless of whether the subscribe operation finishes, is successful or unsuccessful.
I've got about 50% of form submissions resulting in MailChimp subscriptions, and the other half not. When I'm testing this on my end, sometimes I see a blink of the subscribe success / failure message just before the page redirects to the success page (/thank-you/).
It's worthwhile noting event.preventDefault(); works to break the form submit operation if it's executed at before the asynchronous / await function - so I'm guessing it's an issue with the time it takes to perform a subscribe operation.
Can anyone shed any light on what's happening here and a potential solution?

A: Can you preventDefault before the await, and then call submit() on the form after you get a success from the async call to addToMailchimp?
submitHandler = async (event) => {
  event.preventDefault()
  const form = e.target

  const {
    email,
    fieldValues,
    submitting,
  } = this.state;
  if (submitting) return false;
  this.setState({
    submitting: true,
    submitError: false,
  });
  const result = await addToMailchimp(email, fieldValues);
  if (result.result === 'success') {
    // Inconsequential, as success should result in redirection to the success page
    this.setState({
      submitting: false,
    });
    form.submit()
  } else {

    this.setState({
      errorMessage: decodeEntities(result.msg),
      submitError: true,
      submitting: false,
    });
  }
}

working codesandbox example


text:
Q: Alternative Almost Complex Structures Let $V$ be a real vector space. An almost complex structure on $V$ is a map $J : V \to V$ such that $J^2 = -\mathrm{id}_V$. An almost complex structure gives $V$ the structure of a complex vector space by defining $(a+bi)v = av + bJ(v)$. The idea behind this definition is that $J$ represents multiplication by $i$. What if you instead consider multiplication by other complex numbers?
Let $n > 2$ be a fixed positive integer and let $J : V \to V$ be such that $J^n = -\mathrm{id}_V$ which I will refer to as an alternative almost complex structure. One can regard $J$ as trying to capture multiplication by $\zeta = \exp\left(\frac{\pi i}{n}\right)$. In particular, as $\{1, \zeta\}$ is linearly independent over $\mathbb{R}$, it is a basis for $\mathbb{C}$ as a real vector space. One can then endow $V$ with a complex structure by defining $(a + b\zeta)v = av + bJ(v)$.

Do alternative almost complex structures give rise to the same results as the standard almost complex structures? In particular, in the case where we extend them to bundle endomorphisms of the tangent bundle of a manifold.
If not, what fails? If so, is dealing with almost complex structures easier than dealing with alternative almost complex structures?

A: I posted this question on MathOverflow and received an excellent answer there by Vladimir S Matveev. Anyone interested should check it out.


text:
Q: Adding line breaks between words to axis labels in ggplot I am looking for a way to add line breaks to my x-axis labels as currently they are too long.

Here is my code for one of several plots:
PortR_plot = ggplot(data=PortR, mapping = aes(x=Energy.Type, y=Scaled.Score, fill=Energy.Type))
  + labs(title="Portfolio R", x=('Energy Type'), y=('Scaled Score'))

PortR_plot + geom_boxplot()+ scale_x_discrete(limits=c('Battery storage',
  'Geothermal', 'Onshore Wind','Pumped Storage', 'Run of River Hydro', 'Small Storage Hydro','Solar'))
  + ylim(0,1)+ theme(text = element_text(size = 20))

I know that you can add breaks (\n) with scale_x_discrete but I am already using scale_x_discrete to display empty energy types that are not in the original dataset (PortR), and so when I add a line break there, for example:
scale_x_discrete(limits=c('Battery \n storage','Geothermal', etc etc

it doesn't work because then it does not match the name of the energy type in the dataset.
I have tried the method from this blog but it didn't result in any noticeable changes.
Any help would be greatly appreciated!
Edit: Adding sample of data
structure(list(Project = c("Batt_1", "Wind_2", "Wind_3", "Wind_4",
"Wind_5", "Wind_6", "Wind_7", "Wind_8", "Wind_9", "Hydro_1",
"Hydro_2", "Hydro_3"), Energy.Type = c("Battery storage",
"Onshore Wind", "Onshore Wind", "Onshore Wind", "Onshore Wind",
"Onshore Wind", "Onshore Wind", "Onshore Wind", "Onshore Wind",
"Small Storage Hydro", "Small Storage Hydro", "Small Storage Hydro"
), Scaled..T.FW. = c(0, 1.29, 1.19, 0.69, 1.14, 0.11, 0.9, 0.52,
1.02, 0.85, 0.83, 0.31)), row.names = c(NA, -12L), class = "data.frame")

Edit2: I think I may have forced a solution by adding a break (alt+enter) in excel before importing into R. Still would be interested to know the solution in R.
Edit3: I tried doing what Ronak showed but when I try to add additional energy types on the x-axis via scale_x_discrete(limits) I get a blank plot.

A: You can use stringr::str_wrap which will wrap the x-axis text. You may change the width parameter of str_wrap as per your choice.
library(ggplot2)

ggplot(df, aes(x = stringr::str_wrap(Energy.Type, 10),
               y=Scaled..T.FW., fill=Energy.Type)) +
  geom_boxplot() +
 labs(title="All Projects", x= 'Energy Type', y= 'Scaled Score')


text:
Q: google colab - Download files synchronously I am using this code snippet to download files from google colab:
from google.colab import files
files.download("sample_data/california_housing_train.csv")
print("done")

But the output is
done
Downloading "california_housing_train.csv"

The download function is asynchronous. This may not seem much but actually the function is being run in a loop so after starting download some external libraries are called in starting of next iteration and it clears the output. Also, I have tested it many times that in case the output is cleared before the file is downloaded, it will not download.
Also, please dont suggest downloading it from the file menu. There are going to be a lot of files so it has to be programmatically. Also, please dont suggest the method to zip it programmatically and then download it from file browser, as i have to download the files after each iteration bcz I am using a workaround for colab's "are you still there" but it stills considers my session idle and deleted runtime and all the files are lost.
Thank you in advance. Sorry for any grammatical errors.
Edit:
I have also tried using sleep method but that didn't work as sometimes the files take more time to load despite very very good internet connection compared to the size of the file. Keeping very high values of sleep() is not good as it is not the best way. still, if i find nothing else i will use sleep() only.

A: OK, so I found a temporary workaround which is not wholly programmable and may need manual downloading in cases where runtime gets deleted due to inactivity before executing whole program.
So, my idea is to mount google drive on the runtime and copy the files to a folder in google drive after each execution. In the end zip the folder in drive and download it by files.download(path to drive zip) . In case the runtime was not able to execute whole code and dies prematurely, the folder in the google drive will remain unlike it being deleted when runtime is destroyed, so we can go and manually download the folder from google drive.
If anyone else has a better solution, please let me know.


text:
Q: .NET BCL Change Analysis - Uses Beyond Sating Curiosity
This is part of a series of questions which focuses on the Abstraction Project, which aims to abstract the concepts used in language design in the form of a framework.  There is a sister project to Abstraction called OILexer, which aims to construct a parser from grammar files, without the use of code injection on matches.
Some other pages associated to these questions, related to structural typing, can be viewed here, and ease of use, found here, a question on writing the compiler compiler can be found here.  The meta-topic associated to an inquiry about the framework and the proper place to post can be found here.
One of the steps into this process was building my own ECMA-335 Metadata parser.  Since I tend to build tools to build tools, I recently decided to do an analytical top-down on the .NET Base Class Libraries.  The future goal will be utilizing it to construct libraries which represent the BCL to aid in rapid code generation (more on that later if someone cares.)

I wanted to get a basic idea of the overall versions of libraries within the .NET BCL, so I analyzed the Framework folder stored locally.  Doing this per framework version should reflect the end-user's system: right now I'm targeting myself.
The first step in this goal is to construct a class which conceptualizes a multi-versioned library and pulls in each iteration as needed.  The next step is pulling in all the types from each version and comparing the individual lists of types (oddly more work than it should be.)
The result is a fairly straight forward view of the BCL which breaks down the version a library was introduced, and displays which version new types were introduced, grouped by namespace.
This should be an exhaustive list which excludes types which were introduced with the library itself.  You can assume that if it isn't listed, it was there from the library's inception.  The view is very simple: +Type means it was added, -Type means it was removed Type->Assembly means it was relocated at that version.
The objective side of this is: if it's accurate, it gives you a basic breakdown of when a type was introduced, useful for determining the lowest version of .NET needed for a given piece of functionality.  The next step is member analysis which will make the first step look easy (mostly due to method signature comparison, since each parameter type will have to be reversioned and looked up.)
I'm curious if this analysis could later be used for an automated tool which could determine the lowest common framework version for an assembly as a whole (software being written by the compiler framework I'm writing, that is)?
Insight welcome.

PS: To those wondering why I don't use Reflection, attempt using
  Type.GetType(string) on any of these:
Microsoft.Win32.Registry, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Microsoft.Win32.Registry, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Microsoft.Win32.Registry, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

It won't fail, but you also won't get what you would expect, even trying to load the 2.0
  mscorlib by filename yields the 4.0 assembly.

Edit: I should add this analysis purely focuses on the publicly exposed elements.  The rationale for this is you shouldn't ever focus on the dependencies of the internal structure of the BCL since it can change without warning.  If you're writing a code generator and the expressions you synthesize rely on these types, your system is likely to be fragile as glass if something changes in the framework, like a patch that updates the 2.0 version's internal structure.  Due to how .NET binds its members in Common Intermediate Language, this is a very real likelihood.

A: From what I can tell, this analysis can be used to discern if the target framework has the functionality put forth on a given assembly.  If, for example, you specify version 2 of the framework, but rely on version 4 functionality, a detailed list of what's not valid could be created.  LINQ is a prime example of this, since it was introduced in version 3.5 of the framework.  I'll likely be including processor architecture/platform to the assembly identities so I can compare different platform versions of the .NET BCL to the primary BCL.  The individual changes are listed online but getting a comprehensive list seems difficult.
This can be done similarly to analyze the active intermediate assembly versus the previous build to potentially detect breaking changes (such as adding methods to an interface.)
Could also be used to help automate change logs, and generate an iterable view of a library for analysis tools to build off of.
I mention LINQ as a framework element, because on the compiler level, it could be supported as early as v2.0 of the framework, so long as the method patterns are present on the types involved.  Even things like async are available as early as that so long as the compiler has a means to express this functionality, if the user provided a Task<T> that met the pattern requirements, you should be okay.


text:
Q: When Quote id generated in magento? When Quote id generated in magento?
Is it generated:

*

*when customer got registered

*or when customer adds product to cart.

I have gone through many article but there is no clearance on it.

A: The quote id is generated when a product is added to cart.
Here's the workflow:
app/code/core/Magento/Checkout/controllers/CartController.php => addAction() method
$cart   = $this->_getCart();
...
$cart->save();

app/code/core/Magento/Checkout/Model/Cart.php => save() method
    $this->getQuote()->getBillingAddress();
    $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
    $this->getQuote()->collectTotals();
    $this->getQuote()->save();

app/code/core/Magento/Checkout/Model/Cart.php => getQuote() method
public function getQuote()
{
    if (!$this->hasData('quote')) {
        $this->setData('quote', $this->getCheckoutSession()->getQuote());
    }
    return $this->_getData('quote');
}

app/code/core/Magento/Checkout/Model/Session.php => getQuote() method
This is where the quote id is generated, you can see it creates a quote if the quote is null.
   if ($this->_quote === null) {
        /** @var $quote Mage_Sales_Model_Quote */
        $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
        if ($this->getQuoteId()) {
            if ($this->_loadInactive) {
                $quote->load($this->getQuoteId());
            } else {
                $quote->loadActive($this->getQuoteId());
            }
            if ($quote->getId()) {
                /**
                 * If current currency code of quote is not equal current currency code of store,
                 * need recalculate totals of quote. It is possible if customer use currency switcher or
                 * store switcher.
                 */
                if ($quote->getQuoteCurrencyCode() != Mage::app()->getStore()->getCurrentCurrencyCode()) {
                    $quote->setStore(Mage::app()->getStore());
                    $quote->collectTotals()->save();
                    /*
                     * We mast to create new quote object, because collectTotals()
                     * can to create links with other objects.
                     */
                    $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
                    $quote->load($this->getQuoteId());
                }
            } else {
                $this->setQuoteId(null);
            }
        }

        $customerSession = Mage::getSingleton('customer/session');

        if (!$this->getQuoteId()) {
            if ($customerSession->isLoggedIn() || $this->_customer) {
                $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
                $quote->loadByCustomer($customer);
                $this->setQuoteId($quote->getId());
            } else {
                $quote->setIsCheckoutCart(true);
                Mage::dispatchEvent('checkout_quote_init', array('quote'=>$quote));
            }
        }

        if ($this->getQuoteId()) {
            if ($customerSession->isLoggedIn() || $this->_customer) {
                $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
                $quote->setCustomer($customer);
            }
        }

        $quote->setStore(Mage::app()->getStore());
        $this->_quote = $quote;
    }

A: When you add any product in cart from site at that time quote entry is generated for you in related quote table.
main quote table is sales_flat_quote and each differnt item is store inside sales_flat_quote_item table.
when customer got registered at that time no quote id is generated.
Only for product add to cart process, all product info are saved in quote table.
Thanks.


text:
Q: Problems sending UDP with gsocket I'm fairly new to C programming and having some difficulties wrapping my brain around the usage of GSocket to send UDP messages.
The application I'm working on is extremely simple. I have GTK_ENTRY fields where the user can enter an IP address, port, and a message, and when they click a button it should send the message via UDP to the address and port specified.
This is my function so far:
static void send_message()
{
    GInetAddress *udpAddress;
    GSocketAddress *udpSocketAddress;
    GSocket *udpSocket;

    udpAddress = g_inet_address_new_from_string(gtk_entry_get_text (GTK_ENTRY (ipField)));
    guint16 udpPort = atoi(gtk_entry_get_text (GTK_ENTRY (portField)));

    udpSocketAddress = g_inet_socket_address_new(udpAddress, udpPort);

    udpSocket = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM, 17, NULL);

    const gchar *myMessage = gtk_entry_get_text (GTK_ENTRY (mainShowCommandField));
    g_socket_send (udpSocket, myMessage, sizeof(myMessage), NULL, NULL);
}

The program compiles without errors, but when I trigger the function, the message is not being sent.
I'm sure I'm missing something stupid, but any help would be greatly appreciated!!

A: You forgot to connect the socket. Do
g_socket_connect(udpSocket, udpSocketAddress, NULL, NULL);

Before calling g_socket_send. You also might want to add error checking to your code.


text:
Q: How to update item in session array in laravel I need update 1 item of my session , i send a new quantity from my form, $item['quantity'] change but not Session::get('details_evacuation_file')
It's the structure
    Session::push('details_evacuation_file', [
                  'id' => $p_temp->id,
                  'quantity' => 1,
                  'cost' => null,
                  'discount' => 0,
                  'product' => $p_temp
                ]);

My function
    public function update_quantity(Request $request) {
           $details = Session::get('details_evacuation_file', []);
            foreach ($details as $item) {
                if ($item['id'] == $request->input('id')) {
                    var_dump($item['quantity']);
                    $item['quantity'] = $request->input('quantity');
                    var_dump($request->input('quantity'));
                    var_dump($item['quantity']);
                }
            }
           session('details_evacuation_file', $details );
           var_dump(Session::get('details_evacuation_file'));
           die();
           return redirect()->back();
        }


text:
Q: Rendering a Rails view to string for email I'd like to send emails from a table every night at midnight, so I've created a model to track all communications to be sent.  This Communication model stores who the letter is to, from, and the contents of the letter to be sent as html.  The user enters a criteria to match for whom the letter is intended: state, country, favorite color, and so which returns a list of acceptable matches.
This list of acceptable matches is iterated across and a new Communication is generated for each.  How do I render the contents of a partial view to a string to store in the database for delivery at midnight.
@communication = Communication.new(params[:communication])
@communication.body = //Render Partial with local variables to string here

January 8, 2010: I've implemented the solution proposed by neutrino, and my code looks like this:
@communication.message_body = render_to_string(
  :partial => "letters/small_letter",
  :locals => { :quote => @quote})

The drawback to this approach is that it requires a context so it must be rendered within a controller, this rules out generating the email using a rake file.  As others have pointed out the approach of using a Communication model may introduce some unnecessary complexity.  At this time since the conditions I use to generate the list of recipients is never stored I've opted to continue to use a communication model.

A: you could try this (in the rails console):
  class StaticRender < ActionController::Base
    def self.render_erb(template_path, params)
      view = ActionView::Base.new(ActionController::Base.view_paths, {})
      class << view
        include ApplicationHelper
      end
      view.render(:file => "#{template_path}.html.haml", :locals => params, :layout => false)
    end
  end

 StaticRender.render_erb("home", {})

you need to have the view "home" for that....

A: As (almost) always in Rails, there's a method for that: ActionController::Base#render_to_string
In Rails 3, this method was moved to AbstractController::Rendering#render_to_string.

A: You may want to look at techniques to render a template outside of a controller, such as:
http://geek.swombat.com/rails-rendering-templates-outside-of-a-contro
That being said, it's probably better to make use of the built-in email sending class ActionMailer::Base which can render templates for you. Storing the parameters in your Communication model is probably better than storing your unrolled HTML, as these parameters can be serialized and later pushed back into a "send_X_notification" type call.
These can be built using the generator:
script/generate mailer communications_mailer

A: Have you tried action mailer? It will get your views rendered and provide active record support also.


text:
Q: Can't install MS SQL Server on Ubuntu 21.10 I am trying to install Microsoft SQL Server on Ubuntu 21.10 and I am getting an error. I noticed that Microsoft page doesn't mention 21; so maybe it's not possible yet. But Canonical announcement specifically mentions SQL Server support.
Anyway, when I run sudo apt install mssql-server I am getting the following:

The following packages have unmet dependencies:
mssql-server : Depends: libldap-2.4-2 but it is not installable

if I try to install libldap manually, it just says that unable to locate package. However, when I run sudo apt install libldap-2.4-2, I get something more interesting:
Package libldap-2.4-2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libldap-common

But how do I tell sql server installer to use it?
Maybe I am using a wrong repository? This guide still uses 20.04 - and there isn't much relevant under 21.

A: In order to anwser clearly and don't polemic with useless subjects in comments : it's the Microsoft role's to update their product in order to follow system evolution. By the time, we also seen that the OS create sort of aliases for compatibility too ; in instance and in state of the art : mssql seams not to be compatible with Ubuntu 21.10
The guide you used tell Ubuntu to use Ubuntu 20.04 repository, in order to have the right package, that's why it doesn't work natively in 21.10.
So, if you really want to continue to use Ubuntu 21.10 (as temporaly OS it is), you only can add the Ubuntu 20.04 repositories, which is a very not recommanded solution

A: You can install libldap2.4 on any Debian  based distros from the following link
https://packages.debian.org/buster/amd64/libldap-2.4-2/download

A: I've circumvented this issue by installing one of Microsoft provided Docker containers with SQL Server


text:
Q: Django Google social-auth ModuleNotFoundError at /oauth/login/google-oauth2/ I am currently trying to setup social login with social-auth in django for a web app. Whenever I click the button on the webpage that links to a google login, I get this error on the django webpage:
    ModuleNotFoundError at /oauth/login/google-oauth2/

No module named 'social_core.backends.google.GoogleOAuth2django'; 'social_core.backends.google' is not a package

Request Method:     GET
Request URL:    http://127.0.0.1:8000/oauth/login/google-oauth2/
Django Version:     3.0.5
Exception Type:     ModuleNotFoundError
Exception Value:

No module named 'social_core.backends.google.GoogleOAuth2django'; 'social_core.backends.google' is not a package

Exception Location:     C:\Users\isaac\OneDrive\Desktop\DeliverMeProj\venv\lib\site-packages\social_core\utils.py in import_module, line 56
Python Executable:  C:\Users\isaac\OneDrive\Desktop\DeliverMeProj\venv\Scripts\python.exe
Python Version:     3.8.2
Python Path:

['C:\\Users\\isaac\\OneDrive\\Desktop\\DeliverMeProj',
 'C:\\Program Files\\Python38\\python38.zip',
 'C:\\Program Files\\Python38\\DLLs',
 'C:\\Program Files\\Python38\\lib',
 'C:\\Program Files\\Python38',
 'C:\\Users\\isaac\\OneDrive\\Desktop\\DeliverMeProj\\venv',
 'C:\\Users\\isaac\\OneDrive\\Desktop\\DeliverMeProj\\venv\\lib\\site-packages',
 'C:\\Users\\isaac\\AppData\\Roaming\\Python\\Python38\\site-packages',
 'C:\\Program Files\\Python38\\lib\\site-packages']

Server time:    Sun, 26 Apr 2020 04:12:34 +0000

Any idea why this may be happening?

A: I actually figured this out. I was missing a comma in my AUTHENTICATIONBACKEND section.
So the problem looked like:
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2'
'django.contrib.auth.backends.ModelBackend',

)
And the solution is:
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',

)

A: Did you install python-social-auth module
Please try this pip install python-social-auth
Please refer here for more details.
Also make sure your settings.py files is having all the dependecies defined
You can try this  new library social_core as well.


text:
Q: Troubleshooting Windows Group Policy Permissions I have got stumped on a privileges issue on a Windows AD Domain.
I have a Windows Server 2008 Server (with Several Windows Server 2003 vms) which are all members of a domain (but in no way backup controllers etc - this is dealt with via another server). Some of these servers need administering by people who normally have just Domain USer rights, so I created a new group (VMAdmins) added them to it and started to build a specific GPO to be applied to the machines.
The VMs are in their own OU for Group Policy and Tidyness reasons and I have created a GPO linked to that specific OU.
I have assigned various privileges to test the theory under Computer Configuration>Windows Settings>Security Settings>Local Policies>USer Rights Assignment to the group mentioned above.
I have gpupdate /force and bounced the servers and run rsop.msc to determine the applied policy. The tool correctly shows the GPO that is being applied under 'Source GPO' and the group is listed as having that privilege.
However, the crux of the problem;
whoami /priv is inconsistent with what rsop.msc says, for example rsop says that the user has the Shutdown privilege, yet under whoami it says 'Disabled'.
Can anyone shed some light onto why this might be happening?
Many thanks,
Tom

A: whoami /priv shows the current STATE of the privilege, not the actual privilege.  You'll see the same thing using the "administrator" of the domain's account.  It gets "enabled' when you actually do it.
A good explanation is here:  http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/WhatIsAPrivilege.html
Quote from there:

The normal pattern of usage for a privilege can be demonstrated by an example. Say you want to reboot the system. You know that this is a privileged operation, so you reach up into your process token and try to enable SeShutdownPrivilege. If you've been granted this privilege by policy, your token should have it, and so you'll be permitted to enable it. If you haven't been granted this privilege, your attempt to enable it will fail, at which point you'll need to deal with the fact that you're not allowed to reboot the system (in a desktop app, you could inform the user of her lack of privilege with a message box, for example). Assuming you've succeeded in enabling the privilege, you'll call the Win32 function ExitWindowsEx to request a reboot. Finally, you should disable the privilege. Notice the pattern here: enable, use, disable—just like the policeman with his lightbar.
Because you're rebooting the system, you might argue that disabling the privilege is a waste of time. But just as you should never get lazy and allocate memory without freeing it, you should never enable a privilege without disabling it as soon as you're done using it. You never know who will cut and paste your code in another project! Besides, how does the routine know that the reboot will actually happen and that your program will actually exit? Often users initiate a reboot only to cancel it when they realize they need to save some work first. It's tough to know all these things deep down in a routine that's responsible for actually implementing the reboot. Make sure each of your security primitives (like privilege usage) follows best practices. Don't take shortcuts.
Some privileges are meant to be enabled all the time if they're granted. SeChangeNotifyPrivilege (also known as "Bypass Traverse Checking"3) and SeImpersonatePrivilege are notable examples. These are like the policeman's handgun — he's granted the right to carry it on the street, and he's never on the job without it. If you're granted any of these privileges by policy, the operating system will enable them by default in that first token you get at login time, so you shouldn't need to worry about messing with them at runtime. Many Win32 functions (but not all) incorporate the enabling and disabling of privileges as a convenience. Furthermore, I expect that, as the .NET Framework continues to abstract more of the Win32 API, you'll have less and less need to worry about enabling privileges manually. But this is a technical detail. Security policy will still control who can and cannot perform privileged operations, so you should be aware of the privileges defined by Windows so that you know what requirements your programs will have with respect to security policy.

A: Is Loopback Processing enabled?
Are you applying the Security Filtering to the right objects/users/groups?


text:
Q: Problems with NumberFormatException I have noticed a strange problem with my program that I just can not figure out. I have included the method that has been flagged up, and the Error that was given. What's confusing me is that I have duplicated this method about 40 times on other buttons, changing only the 'engtf4' to another source where needed. They work perfectly with no errors, yet are written exactly the same. Adding further confusion, the method is executed exactly as intended(even though the error message below is given)?
I have looked around the net for similar problems using keywords - java.lang.NumberFormatException: For input string: "", I did however notice that all the example sites I saw had reference to a particular value in qoute marks. For example, -java.lang.NumberFormatException: For input string: "2345". I would appreciate any help I could get, thanks.
METHOD SOURCE CODE:
if (a.getSource() == engBuy4){
    getItems();
q = engtf4.getText();
qq = Long.parseLong(q);  //////////// LINE 13086

if (qq > 1000000 || total > 1000000){
    Error.setText("You can ship a maximum of 1 million items.");
    engtf4.setText("");
}
if (qq <= 1000000 && total <= 1000000){
    if (qq > rem){
    Error.setText("You can ship " + rem + " more items");
    engtf4.setText("");
}
if (qq <= rem){
    buyShrEng();
    engtf4.setText("");
}
}

ERROR MESSAGE:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Long.parseLong(Unknown Source)
    at java.lang.Long.parseLong(Unknown Source)
    at DopeWars.DopeWars.mouseReleased(DopeWars.java:13086)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

A: Long.parseLong() throws a NumberFormatException if the passed string is not a parsable long value. In your case, you are passing an empty string (probably because the user did not enter anything in the input field). You can verify this easily:
...
Long.parseLong("");
...

java.lang.NumberFormatException: For input string: ""

You should always be prepared to catch this exception (besides empty strings, the exception is thrown if the user enters anything which is not a Long), and show an appropriate error message to the user, something like
try {
    qq = Long.parseLong(q);
} catch(NumberFormatException nfe) {
    // show error message like "The string ... you entered is not a number."
    ...
}

If you want to treat an empty string as 0 (if that is reasonable for your use case), you can do something like (still requires the try/catch block to catch any other invalid inputs):
try {
    long qq = 0;
    if (q != null && !q.isEmpty()) {
       qq = Long.parseLong(q);
    }

    ...

} catch(NumberFormatException nfe) {
    // show error message like "The string ... you entered is not a number."
    ...
}

In addition to that, instead of duplicating code dozens of times, you should check which are the variable parts of your code and replace them with variables, so that you can reuse the code instead of duplicating it.

A: It is raising the NumberFormatException, Since the argument passed to the parse() Method, is not parsable. What i mean to say is, input is invalid here.
Checkout the following link :)
http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html

A: It seems that the value entered is an empty string :java.lang.NumberFormatException: For input string: ""
So before parsing to long you should test if the string value is empty or not.
In any ways you should catch the java.lang.NumberFormatException to put a default value if the parse doesn't succeed

A: We cannot parse empty space or null to long.If we try that,the number format exception arise.
so before parsing add the if statement to check the value is present or not.
if(q!=null && !"".equals(q))
qq=Long.parse(q);

It's good to use exception handling in these situations


text:
Q: Bootstrap drupal multi-site in Aegir architecture I wrote PHP script which has to bootstrap ex1.mydrupalsite.pl
The sites are hosted using Aegir platform.
The structure looks like this:
/var/aegir/platforms/drupal-7.31/sites/ex1.mydrupalsite.pl
/var/aegir/platforms/drupal-7.31/sites/ex2.mydrupalsite.pl
# etc...

I've been trying:
define('DRUPAL_ROOT', '/var/aegir/platforms/drupal-7.31');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['HTTP_HOST'] = 'ex1.mydrupalsite.pl';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_NAME'] = '/' . basename(__FILE__);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

But no luck.

A: I did not find the answer for this anywhere, so after some effort, here is how to do this:
<?php
  # Set username and password
  $username = 'NAME';
  $password = 'PASSWORD';

  # Drupal Bootstrap code
  define('DRUPAL_ROOT', '/var/aegir/platforms/drupal_7');
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

  # My attempt at injecting variables for multisite stuff to fit aegir
  $variables['url'] = 'http://example.com/';

  $databases['default']['default'] = array(
    'driver' => 'mysql',
    'database' => 'mydb',
    'username' => 'myuser',
    'password' => 'mypass',
    'host' => 'localhost',
    'port' => '3306',
  );

  $db_url['default'] = 'mysql://sqluser:sqlpass@localhost:3306/sqldb';

  drupal_override_server_variables($variables);

  # Try to bootstrap
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  # Try to login
  $uid = FALSE;
  $account = user_load_by_name($username);
  if ($account) {
    // Allow alternate password hashing schemes.
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
    if (user_check_password($password, $account)) {
      // Successful authentication.
      $uid = $account->uid;

     // Update user to new password scheme if needed.
      if (user_needs_new_hash($account)) {
        user_save($account, array('pass' => $password));
      }
    }
  }
  debug($uid);

A: The problem is that in an Aegir installation, the database access information is -not- stored in settings.php, but in /var/aegir/config/server_master/apache/vhost.d/[sitename] as $_SERVER environment variables.  You need to specifically declare them in your script.
Or better yet, use "Drush scr" to run the script.  It'll do the bootstrapping work for you!  See http://www.oliverdavies.uk/blog/dont-bootstrap-drupal-use-drush/ for a more detailed explanation.


text:
Q: Rails active storage issue with deleting individual uploads I am saving some files to local storage via active storage. I am displaying them as links on my page. They could be pdfs, images, word docs etc. I want to have a link next to it to be able to delete the individual files but haven't gotten it to work yet. Here is what I have:
Projects Model:
class Project < ApplicationRecord

belongs_to :user

has_one :proj_status, :foreign_key => "status_id", :primary_key => 'status_id'

has_many_attached :uploads

end

Projects Show Page:
<%= link_to upload.filename, rails_blob_path(upload, disposition: :attachment) %>

<%= link_to 'Remove', delete_upload_project_url(upload.id), method: :delete, data: { confirm: 'Are you sure?' } %>

Projects Controller delete upload method:
def delete_upload

attachment = ActiveStorage::Attachment.find(params[:id])

attachment.purge # or use purge_later

redirect_back(fallback_location: projects_path)

end

I get the error:
No route matches [GET] "/projects/1/delete_upload"
I am thinking this is a routing issue but I haven't been able to get it to work yet.
Also here is my routes section:
resources :projects do

  member do

  delete :delete_upload

  end

end

Any thoughts or ideas on how to get this working?
Here is my rake routes for the projects section:
DELETE /projects/:id/delete_upload/:upload_id(.:format) projects#delete_upload

projects GET /projects(.:format) projects#index

POST /projects(.:format) projects#create

new_project GET /projects/new(.:format) projects#new

edit_project GET /projects/:id/edit(.:format) projects#edit

project GET /projects/:id(.:format) projects#show

PATCH /projects/:id(.:format) projects#update

PUT /projects/:id(.:format) projects#update

DELETE /projects/:id(.:format) projects#destroy

If anyone can help me with this I would appreciate it!

A: Your delete_upload_project_url method expect two variables: a project and an upload /projects/:id/delete_upload/:upload_id. You are only passing the upload id. Do something like delete_upload_project_url(project.id, upload.id).

A: Everything was set up correctly from the get go. The problem was that I had accidentally removed the include for application.js from my project. The lack of UJS reference was causing all requests to be gets instead of the delete in my case.