problem
stringlengths
26
131k
labels
class label
2 classes
How to delete lines in a file based on an the indices in a list : I have a txt file which is of this format: 1 2 [2, 3, 5] 2 5 [3, 4] 5 6 [4, 5] 4 9 [1, 6] I need to write a programme such that it would delete the lines having the first column equals to the indices in the list of each line. but, if a line has been processed, then it is safe. For example, when it goes to the first line, read the list first, the indices inside is 2, 3 and 5. so it would delete line with first column 2, 3 and 5. so the second and third line are deleted. when it comes to the fourth line, it has indices 1 and 6. However, this time, line 1 has been processed so it would not delete the first line but the line starts with 6.
0debug
from itertools import groupby def group_element(test_list): res = dict() for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]): res[key] = [ele[0] for ele in val] return (res)
0debug
static av_cold int cuvid_decode_init(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; AVCUDADeviceContext *device_hwctx; AVHWDeviceContext *device_ctx; AVHWFramesContext *hwframe_ctx; CUVIDPARSERPARAMS cuparseinfo; CUVIDEOFORMATEX cuparse_ext; CUVIDSOURCEDATAPACKET seq_pkt; CUdevice device; CUcontext cuda_ctx = NULL; CUcontext dummy; const AVBitStreamFilter *bsf; int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; ret = ff_get_format(avctx, pix_fmts); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret); return ret; } ctx->frame_queue = av_fifo_alloc(MAX_FRAME_COUNT * sizeof(CUVIDPARSERDISPINFO)); if (!ctx->frame_queue) { ret = AVERROR(ENOMEM); goto error; } avctx->pix_fmt = ret; if (avctx->hw_frames_ctx) { ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx); if (!ctx->hwframe) { ret = AVERROR(ENOMEM); goto error; } hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data; ctx->hwdevice = av_buffer_ref(hwframe_ctx->device_ref); if (!ctx->hwdevice) { ret = AVERROR(ENOMEM); goto error; } device_ctx = hwframe_ctx->device_ctx; device_hwctx = device_ctx->hwctx; cuda_ctx = device_hwctx->cuda_ctx; } else { ctx->hwdevice = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_CUDA); if (!ctx->hwdevice) { av_log(avctx, AV_LOG_ERROR, "Error allocating hwdevice\n"); ret = AVERROR(ENOMEM); goto error; } ret = CHECK_CU(cuInit(0)); if (ret < 0) goto error; ret = CHECK_CU(cuDeviceGet(&device, 0)); if (ret < 0) goto error; ret = CHECK_CU(cuCtxCreate(&cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, device)); if (ret < 0) goto error; device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data; device_ctx->free = cuvid_ctx_free; device_hwctx = device_ctx->hwctx; device_hwctx->cuda_ctx = cuda_ctx; ret = CHECK_CU(cuCtxPopCurrent(&dummy)); if (ret < 0) goto error; ret = av_hwdevice_ctx_init(ctx->hwdevice); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "av_hwdevice_ctx_init failed\n"); goto error; } ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice); if (!ctx->hwframe) { av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n"); ret = AVERROR(ENOMEM); goto error; } } memset(&cuparseinfo, 0, sizeof(cuparseinfo)); memset(&cuparse_ext, 0, sizeof(cuparse_ext)); memset(&seq_pkt, 0, sizeof(seq_pkt)); cuparseinfo.pExtVideoInfo = &cuparse_ext; switch (avctx->codec->id) { #if CONFIG_H264_CUVID_DECODER case AV_CODEC_ID_H264: cuparseinfo.CodecType = cudaVideoCodec_H264; #if CONFIG_HEVC_CUVID_DECODER case AV_CODEC_ID_HEVC: cuparseinfo.CodecType = cudaVideoCodec_HEVC; #if CONFIG_MJPEG_CUVID_DECODER case AV_CODEC_ID_MJPEG: cuparseinfo.CodecType = cudaVideoCodec_JPEG; #if CONFIG_MPEG1_CUVID_DECODER case AV_CODEC_ID_MPEG1VIDEO: cuparseinfo.CodecType = cudaVideoCodec_MPEG1; #if CONFIG_MPEG2_CUVID_DECODER case AV_CODEC_ID_MPEG2VIDEO: cuparseinfo.CodecType = cudaVideoCodec_MPEG2; #if CONFIG_MPEG4_CUVID_DECODER case AV_CODEC_ID_MPEG4: #if CONFIG_VP8_CUVID_DECODER case AV_CODEC_ID_VP8: cuparseinfo.CodecType = cudaVideoCodec_VP8; #if CONFIG_VP9_CUVID_DECODER case AV_CODEC_ID_VP9: cuparseinfo.CodecType = cudaVideoCodec_VP9; #if CONFIG_VC1_CUVID_DECODER case AV_CODEC_ID_VC1: cuparseinfo.CodecType = cudaVideoCodec_VC1; default: av_log(avctx, AV_LOG_ERROR, "Invalid CUVID codec!\n"); return AVERROR_BUG; } if (avctx->codec->id == AV_CODEC_ID_H264 || avctx->codec->id == AV_CODEC_ID_HEVC) { if (avctx->codec->id == AV_CODEC_ID_H264) bsf = av_bsf_get_by_name("h264_mp4toannexb"); else bsf = av_bsf_get_by_name("hevc_mp4toannexb"); if (!bsf) { ret = AVERROR_BSF_NOT_FOUND; goto error; } if (ret = av_bsf_alloc(bsf, &ctx->bsf)) { goto error; } if (((ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx)) < 0) || ((ret = av_bsf_init(ctx->bsf)) < 0)) { av_bsf_free(&ctx->bsf); goto error; } cuparse_ext.format.seqhdr_data_length = ctx->bsf->par_out->extradata_size; memcpy(cuparse_ext.raw_seqhdr_data, ctx->bsf->par_out->extradata, FFMIN(sizeof(cuparse_ext.raw_seqhdr_data), ctx->bsf->par_out->extradata_size)); } else if (avctx->extradata_size > 0) { cuparse_ext.format.seqhdr_data_length = avctx->extradata_size; memcpy(cuparse_ext.raw_seqhdr_data, avctx->extradata, FFMIN(sizeof(cuparse_ext.raw_seqhdr_data), avctx->extradata_size)); } cuparseinfo.ulMaxNumDecodeSurfaces = MAX_FRAME_COUNT; cuparseinfo.ulMaxDisplayDelay = 4; cuparseinfo.pUserData = avctx; cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence; cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode; cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display; ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); if (ret < 0) goto error; ret = cuvid_test_dummy_decoder(avctx, &cuparseinfo); if (ret < 0) goto error; ret = CHECK_CU(cuvidCreateVideoParser(&ctx->cuparser, &cuparseinfo)); if (ret < 0) goto error; seq_pkt.payload = cuparse_ext.raw_seqhdr_data; seq_pkt.payload_size = cuparse_ext.format.seqhdr_data_length; if (seq_pkt.payload && seq_pkt.payload_size) { ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &seq_pkt)); if (ret < 0) goto error; } ret = CHECK_CU(cuCtxPopCurrent(&dummy)); if (ret < 0) goto error; return 0; error: cuvid_decode_end(avctx); return ret; }
1threat
Union Two DataFrames of Different Types Spark : In my recent project, i need to union two dataframes of different sizes. For example: Here is my sample data: df1: name number address kevin 101 NZ gevin 102 CA here all the fields are of type String. df2: name number address kevin [101,102] NZ gevin [102,103] CA Here name and address are type string and number is of type array<string>. Now i need to union these two dataframes. My expexcted outcome is like: name number address kevin 101 NZ gevin 102 CA kevin [101,102] NZ gevin [102,103] CA final df types should be same as the df2(string, array<string>, string). Thanks in Advance.
0debug
Why can't I cast a function pointer to (void *)? : <p>I have a function that takes a string, an array of strings, and an array of pointers, and looks for the string in the array of strings, and returns the corresponding pointer from the array of pointers. Since I use this for several different things, the pointer array is declared as an array of (void *), and the caller should know what kind of pointers are actually there (and hence what kind of a pointer it gets back as the return value).</p> <p>When I pass in an array of function pointers, however, I get a warning when I compile with <code>-Wpedantic</code>:</p> <p>clang:</p> <pre><code>test.c:40:8: warning: assigning to 'voidfunc' (aka 'void (*)(void)') from 'void *' converts between void pointer and function pointer [-Wpedantic] </code></pre> <p>gcc:</p> <pre><code>test.c:40:8: warning: ISO C forbids assignment between function pointer and ‘void *’ [-Wpedantic] fptr = find_ptr("quux", name_list, (void **)ptr_list, </code></pre> <p>Here's a test file, which despite the warning does correctly print "quux":</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; void foo(void) { puts("foo"); } void bar(void) { puts("bar"); } void quux(void) { puts("quux"); } typedef void (* voidfunc)(void); voidfunc ptr_list[] = {foo, bar, quux}; char *name_list[] = {"foo", "bar", "quux"}; void *find_ptr(char *name, char *names[], void *ptrs[], int length) { int i; for (i = 0; i &lt; length; i++) { if (strcmp(name, names[i]) == 0) { return ptrs[i]; } } return NULL; } int main() { voidfunc fptr; fptr = find_ptr("quux", name_list, (void **)ptr_list, sizeof(ptr_list) / sizeof(ptr_list[0])); fptr(); return 0; } </code></pre> <p>Is there any way to fix the warning, other than not compiling with <code>-Wpedantic</code>, or duplicating my find_ptr function, once for function pointers and once for non-function pointers? Is there a better way to achieve what I'm trying to do?</p>
0debug
Working with variables within javascript console.log function : <p>I am seeing sort of strange behaviour with javascript. I am new to this language, but from what I can see, if you increment a variable (or change it in any way) from within a console.log() method, this actually globally changes the variable.</p> <pre><code>var a = 0; console.log(a); //prints 0 console.log(a++); //prints 0, a becomes 1 console.log(a++); //prints 1, a becomes 2 console.log(a++); //prints 2, a becomes 3 console.log(a); //prints 3 </code></pre> <p>Is this something peculiar to javascript? I would have thought that the variable would not get affected globally and that the last print statement would show a as being 0.</p>
0debug
RSpec: Is there a not for `and change`, e.g. `and_not to change`? : <p>I find the <code>.and</code> method very useful for chaining many expectations.</p> <pre><code>expect { click_button 'Update Boilerplate' @boilerplate_original.reload } .to change { @boilerplate_original.title }.to('A new boilerplate') .and change { @boilerplate_original.intro }.to('Some nice introduction') </code></pre> <p>Is there something that let's me check for <strong>no change</strong>?</p> <pre><code>.and_not change { @boilerplate_original.intro } </code></pre> <p>Something like that? I couldn't find anything, and it's hard to search on Google for something like "and not".</p>
0debug
How to Change Html Element Text Using CSS - Help a Brother Out : all! I hope i can make myself as clear as possible, I'm a real newbie when it comes to CSS and HTML, but I'm trying my best searching on the net. I'm trying to translate a website using Google Inspect and save the changes on my pc. So far I've been able to do it using an extension called "Stylebot". What I got so far is this: For this text: <div class="_35oZDD6pOLbfsDeSjB48Da"> <h1>Dashboard</h1> <div class="KnPkTluaZGwNajQrPdUXK title-help-wrapper"> <div class="_1kb2R813ulFuiel2ebkDj3 title-help"> <div class="_3Ow41suot3IX3Reh-6Xs4Y title-help-content"> <div> </div> </div> </div> </div> </div> I was able to change this in css doing this: ._35oZDD6pOLbfsDeSjB48Da h1 { display: none; } ._35oZDD6pOLbfsDeSjB48Da:after { content: "Painel de Controle"; margin: 0; min-width: 0; font-size: 24px; font-weight: 400; color: #3c4858; } And it worked perfectly fine. But my question is: How can I edit the text "Dashboard" here: <a data-test-id="nav-link-dashboard" class="_35y4mNBXV8raOLGtBvhTmr O6aRKDJKQc5N9t_-J7iyI" href="/fb1117682158281014/dashboard"> <div class="row middle-xs p-y-sm"> <div class="text-center _3eiyvN-y_YD9WeLYpjiJJO col-auto" style="flex: 0 0 65px; width: 65px;"> <i class="i-dashboard"> </i> </div> <div class="p-r-sm col-auto col-grow"> <span class="uO-IdjD0GZlRnQ66I7sbe"> <!-- react-text: 40 -->Dashboard<!-- /react-text --> </span> </div> </div> </a> Is there a way to edit this, using CSS path? Or something else? Thanks a lot!
0debug
void ff_xvmc_decode_mb(MpegEncContext *s) { XvMCMacroBlock *mv_block; struct xvmc_pix_fmt *render; int i, cbp, blocks_per_mb; const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; if (s->encoding) { av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n"); return; } if (!s->mb_intra) { s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision; } s->mb_skipped = 0; s->current_picture.qscale_table[mb_xy] = s->qscale; render = (struct xvmc_pix_fmt*)s->current_picture.f->data[2]; assert(render); assert(render->xvmc_id == AV_XVMC_ID); assert(render->mv_blocks); mv_block = &render->mv_blocks[render->start_mv_blocks_num + render->filled_mv_blocks_num]; mv_block->x = s->mb_x; mv_block->y = s->mb_y; mv_block->dct_type = s->interlaced_dct; if (s->mb_intra) { mv_block->macroblock_type = XVMC_MB_TYPE_INTRA; } else { mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN; if (s->mv_dir & MV_DIR_FORWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_FORWARD; mv_block->PMV[0][0][0] = s->mv[0][0][0]; mv_block->PMV[0][0][1] = s->mv[0][0][1]; mv_block->PMV[1][0][0] = s->mv[0][1][0]; mv_block->PMV[1][0][1] = s->mv[0][1][1]; } if (s->mv_dir & MV_DIR_BACKWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_BACKWARD; mv_block->PMV[0][1][0] = s->mv[1][0][0]; mv_block->PMV[0][1][1] = s->mv[1][0][1]; mv_block->PMV[1][1][0] = s->mv[1][1][0]; mv_block->PMV[1][1][1] = s->mv[1][1][1]; } switch(s->mv_type) { case MV_TYPE_16X16: mv_block->motion_type = XVMC_PREDICTION_FRAME; break; case MV_TYPE_16X8: mv_block->motion_type = XVMC_PREDICTION_16x8; break; case MV_TYPE_FIELD: mv_block->motion_type = XVMC_PREDICTION_FIELD; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][1] <<= 1; mv_block->PMV[1][0][1] <<= 1; mv_block->PMV[0][1][1] <<= 1; mv_block->PMV[1][1][1] <<= 1; } break; case MV_TYPE_DMV: mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][0] = s->mv[0][0][0]; mv_block->PMV[0][0][1] = s->mv[0][0][1] << 1; mv_block->PMV[0][1][0] = s->mv[0][0][0]; mv_block->PMV[0][1][1] = s->mv[0][0][1] << 1; mv_block->PMV[1][0][0] = s->mv[0][2][0]; mv_block->PMV[1][0][1] = s->mv[0][2][1] << 1; mv_block->PMV[1][1][0] = s->mv[0][3][0]; mv_block->PMV[1][1][1] = s->mv[0][3][1] << 1; } else { mv_block->PMV[0][1][0] = s->mv[0][2][0]; mv_block->PMV[0][1][1] = s->mv[0][2][1]; } break; default: assert(0); } mv_block->motion_vertical_field_select = 0; if (s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8) { mv_block->motion_vertical_field_select |= s->field_select[0][0]; mv_block->motion_vertical_field_select |= s->field_select[1][0] << 1; mv_block->motion_vertical_field_select |= s->field_select[0][1] << 2; mv_block->motion_vertical_field_select |= s->field_select[1][1] << 3; } } mv_block->index = render->next_free_data_block_num; blocks_per_mb = 6; if (s->chroma_format >= 2) { blocks_per_mb = 4 + (1 << s->chroma_format); } cbp = 0; for (i = 0; i < blocks_per_mb; i++) { cbp += cbp; if (s->block_last_index[i] >= 0) cbp++; } if (s->avctx->flags & AV_CODEC_FLAG_GRAY) { if (s->mb_intra) { for (i = 4; i < blocks_per_mb; i++) { memset(s->pblocks[i], 0, sizeof(*s->pblocks[i])); if (!render->unsigned_intra) *s->pblocks[i][0] = 1 << 10; } } else { cbp &= 0xf << (blocks_per_mb - 4); blocks_per_mb = 4; } } mv_block->coded_block_pattern = cbp; if (cbp == 0) mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN; for (i = 0; i < blocks_per_mb; i++) { if (s->block_last_index[i] >= 0) { if (s->mb_intra && (render->idct || !render->unsigned_intra)) *s->pblocks[i][0] -= 1 << 10; if (!render->idct) { s->idsp.idct(*s->pblocks[i]); } if (s->avctx->xvmc_acceleration == 1) { memcpy(&render->data_blocks[render->next_free_data_block_num*64], s->pblocks[i], sizeof(*s->pblocks[i])); } render->next_free_data_block_num++; } } render->filled_mv_blocks_num++; assert(render->filled_mv_blocks_num <= render->allocated_mv_blocks); assert(render->next_free_data_block_num <= render->allocated_data_blocks); if (render->filled_mv_blocks_num == render->allocated_mv_blocks) ff_mpeg_draw_horiz_band(s, 0, 0); }
1threat
Why have confliting properties for the same class? : I am examining a third party CSS file, and I am coming across the same class that has the same property set multiple times but with different values each time, I cannot figure out why this is, could someone please shed some light on this? Example below, the `vertical-align` property is set twice: .tabulator .tabulator-header .tabulator-col { display: inline-block; position: relative; box-sizing: border-box; border-right: 1px solid #aaa; background: #e6e6e6; text-align: left; vertical-align: bottom; overflow: hidden; } .tabulator .tabulator-row .tabulator-cell { display: inline-block; position: relative; box-sizing: border-box; padding: 4px; border-right: 1px solid #aaa; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
0debug
How to derived a new column using value_counts for one column with another columns : <p>I have dataframe which consists with many columns. </p> <pre><code>df2 TargetDescription Output_media_duration 0 VMN 4.0 16x9 25 - 1920x1080, 1280x720, 960x540... NaN 1 VMN 4.0 16x9 25 - 1920x1080, 1280x720, 960x540... NaN 2 XDCAM HD NTSC 1920x1080 MXF 8CA 661.120000 3 VMN 4.0 16x9 29.97 - 1920x1080, 1280x720, 960x... 285.647686 4 VMN 4.0 16x9 29.97 - 1920x1080, 1280x720, 960x... 402.697303 5 VMN 4.0 16x9 29.97 - 1920x1080, 1280x720, 960x... 269.597070 6 VMN 4.0 16x9 29.97 - 1920x1080, 1280x720, 960x... 307.059607 7 Caption QC HD MOV 2CA 2516.096917 8 QT Proxy 640x360 2997 12CA NaN 9 XDCAM HD NTSC 1920x1080 MXF 8CA 1414.785215 10 Caption QC HD MOV 2CA 1295.027067 11 QT Proxy 640x360 2398 4CA 2524.980792 12 Caption QC HD MOV 2CA 120.820700 13 Caption QC HD MOV 2CA 2516.096917 </code></pre> <p>Now I want to get one new dataframe which would show me like this </p> <pre><code>TargetDescription format_duration 1 VMN 4.0 16x9 25 - 1920x1080, 1280x720, 960x540... NaN 2 XDCAM HD NTSC 1920x1080 MXF 8CA 661.120000 3 VMN 4.0 16x9 29.97 - 1920x1080, 1280x720, 960x... 1656.561906 4 Caption QC HD MOV 2CA 2516.096917 5 QT Proxy 640x360 2997 12CA NaN 6 Caption QC HD MOV 2CA 2636.917 </code></pre> <p>How can I achieve this in pandas,thanks in advance</p>
0debug
Variable in loop on Python don't change : <p>I can't understand why in loop variable don't change, but I explicitly try it. So here is my code:</p> <pre><code>a=[1,2,3] b=["a","b","c"] d=[a,b] for i in d: for a in i: a*2 print(a) </code></pre> <p>And when I run I see :</p> <pre><code>1 2 3 a b c </code></pre> <p>Instead expected:</p> <pre><code>2 4 6 aa bb cc </code></pre>
0debug
static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) { int idx = 0; BlockBackend *new_blk = NULL; Error *local_err = NULL; char *desc = NULL; int64_t total_size = 0, filesize; char *adapter_type = NULL; char *backing_file = NULL; char *hw_version = NULL; char *fmt = NULL; int ret = 0; bool flat, split, compress; GString *ext_desc_lines; char *path = g_malloc0(PATH_MAX); char *prefix = g_malloc0(PATH_MAX); char *postfix = g_malloc0(PATH_MAX); char *desc_line = g_malloc0(BUF_SIZE); char *ext_filename = g_malloc0(PATH_MAX); char *desc_filename = g_malloc0(PATH_MAX); const int64_t split_size = 0x80000000; const char *desc_extent_line; char *parent_desc_line = g_malloc0(BUF_SIZE); uint32_t parent_cid = 0xffffffff; uint32_t number_heads = 16; bool zeroed_grain = false; uint32_t desc_offset = 0, desc_len; const char desc_template[] = "# Disk DescriptorFile\n" "version=1\n" "CID=%" PRIx32 "\n" "parentCID=%" PRIx32 "\n" "createType=\"%s\"\n" "%s" "\n" "# Extent description\n" "%s" "\n" "# The Disk Data Base\n" "#DDB\n" "\n" "ddb.virtualHWVersion = \"%s\"\n" "ddb.geometry.cylinders = \"%" PRId64 "\"\n" "ddb.geometry.heads = \"%" PRIu32 "\"\n" "ddb.geometry.sectors = \"63\"\n" "ddb.adapterType = \"%s\"\n"; ext_desc_lines = g_string_new(NULL); if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp)) { ret = -EINVAL; goto exit; } total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); hw_version = qemu_opt_get_del(opts, BLOCK_OPT_HWVERSION); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) { if (strcmp(hw_version, "undefined")) { error_setg(errp, "compat6 cannot be enabled with hwversion set"); ret = -EINVAL; goto exit; } g_free(hw_version); hw_version = g_strdup("6"); } if (strcmp(hw_version, "undefined") == 0) { g_free(hw_version); hw_version = g_strdup("4"); } fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) { zeroed_grain = true; } if (!adapter_type) { adapter_type = g_strdup("ide"); } else if (strcmp(adapter_type, "ide") && strcmp(adapter_type, "buslogic") && strcmp(adapter_type, "lsilogic") && strcmp(adapter_type, "legacyESX")) { error_setg(errp, "Unknown adapter type: '%s'", adapter_type); ret = -EINVAL; goto exit; } if (strcmp(adapter_type, "ide") != 0) { number_heads = 255; } if (!fmt) { fmt = g_strdup("monolithicSparse"); } else if (strcmp(fmt, "monolithicFlat") && strcmp(fmt, "monolithicSparse") && strcmp(fmt, "twoGbMaxExtentSparse") && strcmp(fmt, "twoGbMaxExtentFlat") && strcmp(fmt, "streamOptimized")) { error_setg(errp, "Unknown subformat: '%s'", fmt); ret = -EINVAL; goto exit; } split = !(strcmp(fmt, "twoGbMaxExtentFlat") && strcmp(fmt, "twoGbMaxExtentSparse")); flat = !(strcmp(fmt, "monolithicFlat") && strcmp(fmt, "twoGbMaxExtentFlat")); compress = !strcmp(fmt, "streamOptimized"); if (flat) { desc_extent_line = "RW %" PRId64 " FLAT \"%s\" 0\n"; } else { desc_extent_line = "RW %" PRId64 " SPARSE \"%s\"\n"; } if (flat && backing_file) { error_setg(errp, "Flat image can't have backing file"); ret = -ENOTSUP; goto exit; } if (flat && zeroed_grain) { error_setg(errp, "Flat image can't enable zeroed grain"); ret = -ENOTSUP; goto exit; } if (backing_file) { BlockBackend *blk; char *full_backing = g_new0(char, PATH_MAX); bdrv_get_full_backing_filename_from_filename(filename, backing_file, full_backing, PATH_MAX, &local_err); if (local_err) { g_free(full_backing); error_propagate(errp, local_err); ret = -ENOENT; goto exit; } blk = blk_new_open(full_backing, NULL, NULL, BDRV_O_NO_BACKING, errp); g_free(full_backing); if (blk == NULL) { ret = -EIO; goto exit; } if (strcmp(blk_bs(blk)->drv->format_name, "vmdk")) { blk_unref(blk); ret = -EINVAL; goto exit; } parent_cid = vmdk_read_cid(blk_bs(blk), 0); blk_unref(blk); snprintf(parent_desc_line, BUF_SIZE, "parentFileNameHint=\"%s\"", backing_file); } filesize = total_size; while (filesize > 0) { int64_t size = filesize; if (split && size > split_size) { size = split_size; } if (split) { snprintf(desc_filename, PATH_MAX, "%s-%c%03d%s", prefix, flat ? 'f' : 's', ++idx, postfix); } else if (flat) { snprintf(desc_filename, PATH_MAX, "%s-flat%s", prefix, postfix); } else { snprintf(desc_filename, PATH_MAX, "%s%s", prefix, postfix); } snprintf(ext_filename, PATH_MAX, "%s%s", path, desc_filename); if (vmdk_create_extent(ext_filename, size, flat, compress, zeroed_grain, opts, errp)) { ret = -EINVAL; goto exit; } filesize -= size; snprintf(desc_line, BUF_SIZE, desc_extent_line, size / BDRV_SECTOR_SIZE, desc_filename); g_string_append(ext_desc_lines, desc_line); } desc = g_strdup_printf(desc_template, g_random_int(), parent_cid, fmt, parent_desc_line, ext_desc_lines->str, hw_version, total_size / (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE), number_heads, adapter_type); desc_len = strlen(desc); if (!split && !flat) { desc_offset = 0x200; } else { ret = bdrv_create_file(filename, opts, &local_err); if (ret < 0) { error_propagate(errp, local_err); goto exit; } } new_blk = blk_new_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, &local_err); if (new_blk == NULL) { error_propagate(errp, local_err); ret = -EIO; goto exit; } blk_set_allow_write_beyond_eof(new_blk, true); ret = blk_pwrite(new_blk, desc_offset, desc, desc_len, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not write description"); goto exit; } if (desc_offset == 0) { ret = blk_truncate(new_blk, desc_len, PREALLOC_MODE_OFF, errp); } exit: if (new_blk) { blk_unref(new_blk); } g_free(adapter_type); g_free(backing_file); g_free(hw_version); g_free(fmt); g_free(desc); g_free(path); g_free(prefix); g_free(postfix); g_free(desc_line); g_free(ext_filename); g_free(desc_filename); g_free(parent_desc_line); g_string_free(ext_desc_lines, true); return ret; }
1threat
static void fill_caches(H264Context *h, int mb_type, int for_deblock){ MpegEncContext * const s = &h->s; const int mb_xy= h->mb_xy; int topleft_xy, top_xy, topright_xy, left_xy[2]; int topleft_type, top_type, topright_type, left_type[2]; int * left_block; int topleft_partition= -1; int i; top_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[top_xy]) && !FRAME_MBAFF) return; topleft_xy = top_xy - 1; topright_xy= top_xy + 1; left_xy[1] = left_xy[0] = mb_xy-1; left_block = left_block_options[0]; if(FRAME_MBAFF){ const int pair_xy = s->mb_x + (s->mb_y & ~1)*s->mb_stride; const int top_pair_xy = pair_xy - s->mb_stride; const int topleft_pair_xy = top_pair_xy - 1; const int topright_pair_xy = top_pair_xy + 1; const int topleft_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]); const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]); const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]); const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]); const int curr_mb_frame_flag = !IS_INTERLACED(mb_type); const int bottom = (s->mb_y & 1); tprintf(s->avctx, "fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag); if (bottom ? !curr_mb_frame_flag : (!curr_mb_frame_flag && !top_mb_frame_flag) ) { top_xy -= s->mb_stride; } if (bottom ? !curr_mb_frame_flag : (!curr_mb_frame_flag && !topleft_mb_frame_flag) ) { topleft_xy -= s->mb_stride; } else if(bottom && curr_mb_frame_flag && !left_mb_frame_flag) { topleft_xy += s->mb_stride; topleft_partition = 0; } if (bottom ? !curr_mb_frame_flag : (!curr_mb_frame_flag && !topright_mb_frame_flag) ) { topright_xy -= s->mb_stride; } if (left_mb_frame_flag != curr_mb_frame_flag) { left_xy[1] = left_xy[0] = pair_xy - 1; if (curr_mb_frame_flag) { if (bottom) { left_block = left_block_options[1]; } else { left_block= left_block_options[2]; } } else { left_xy[1] += s->mb_stride; left_block = left_block_options[3]; } } } h->top_mb_xy = top_xy; h->left_mb_xy[0] = left_xy[0]; h->left_mb_xy[1] = left_xy[1]; if(for_deblock){ topleft_type = 0; topright_type = 0; top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0; left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0; left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0; if(FRAME_MBAFF && !IS_INTRA(mb_type)){ int list; for(list=0; list<h->list_count; list++){ if(USES_LIST(mb_type,list)){ uint32_t *src = (uint32_t*)s->current_picture.motion_val[list][h->mb2b_xy[mb_xy]]; uint32_t *dst = (uint32_t*)h->mv_cache[list][scan8[0]]; int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]]; for(i=0; i<4; i++, dst+=8, src+=h->b_stride){ dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; } *(uint32_t*)&h->ref_cache[list][scan8[ 0]] = *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = pack16to32(ref[0],ref[1])*0x0101; ref += h->b8_stride; *(uint32_t*)&h->ref_cache[list][scan8[ 8]] = *(uint32_t*)&h->ref_cache[list][scan8[10]] = pack16to32(ref[0],ref[1])*0x0101; }else{ fill_rectangle(&h-> mv_cache[list][scan8[ 0]], 4, 4, 8, 0, 4); fill_rectangle(&h->ref_cache[list][scan8[ 0]], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1); } } } }else{ topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; } if(IS_INTRA(mb_type)){ h->topleft_samples_available= h->top_samples_available= h->left_samples_available= 0xFFFF; h->topright_samples_available= 0xEEEA; if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){ h->topleft_samples_available= 0xB3FF; h->top_samples_available= 0x33FF; h->topright_samples_available= 0x26EA; } for(i=0; i<2; i++){ if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred)) h->topleft_samples_available&= 0x7FFF; if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred)) h->topright_samples_available&= 0xFBFF; if(IS_INTRA4x4(mb_type)){ if(IS_INTRA4x4(top_type)){ h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; }else{ int pred; if(!top_type || (IS_INTER(top_type) && h->pps.constrained_intra_pred)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode_cache[7+8*0]= pred; } for(i=0; i<2; i++){ if(IS_INTRA4x4(left_type[i])){ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; }else{ int pred; if(!left_type[i] || (IS_INTER(left_type[i]) && h->pps.constrained_intra_pred)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; } } } } if(top_type){ h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][4]; h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][5]; h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][6]; h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][9]; h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][12]; h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; }else{ h->non_zero_count_cache[4+8*0]= h->non_zero_count_cache[5+8*0]= h->non_zero_count_cache[6+8*0]= h->non_zero_count_cache[7+8*0]= h->non_zero_count_cache[1+8*0]= h->non_zero_count_cache[2+8*0]= h->non_zero_count_cache[1+8*3]= h->non_zero_count_cache[2+8*3]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; } for (i=0; i<2; i++) { if(left_type[i]){ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[0+2*i]]; h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[1+2*i]]; h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[4+2*i]]; h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[5+2*i]]; }else{ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count_cache[0+8*4 + 8*i]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; } } if( h->pps.cabac ) { if(top_type) { h->top_cbp = h->cbp_table[top_xy]; } else if(IS_INTRA(mb_type)) { h->top_cbp = 0x1C0; } else { h->top_cbp = 0; } if (left_type[0]) { h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0; } else if(IS_INTRA(mb_type)) { h->left_cbp = 0x1C0; } else { h->left_cbp = 0; } if (left_type[0]) { h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1; } if (left_type[1]) { h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3; } } #if 1 if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ int list; for(list=0; list<h->list_count; list++){ if(!USES_LIST(mb_type, list) && !IS_DIRECT(mb_type) && !h->deblocking_filter){ continue; } h->mv_cache_clean[list]= 0; if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0]; *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1]; *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2]; *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3]; h->ref_cache[list][scan8[0] + 0 - 1*8]= h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; h->ref_cache[list][scan8[0] + 2 - 1*8]= h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; }else{ *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0; *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101; } for(i=0; i<2; i++){ int cache_idx = scan8[0] - 1 + i*2*8; if(USES_LIST(left_type[i], list)){ const int b_xy= h->mb2b_xy[left_xy[i]] + 3; const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1; *(uint32_t*)h->mv_cache[list][cache_idx ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]; *(uint32_t*)h->mv_cache[list][cache_idx+8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]; h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)]; h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)]; }else{ *(uint32_t*)h->mv_cache [list][cache_idx ]= *(uint32_t*)h->mv_cache [list][cache_idx+8]= 0; h->ref_cache[list][cache_idx ]= h->ref_cache[list][cache_idx+8]= left_type[i] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if((for_deblock || (IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)) && !FRAME_MBAFF) continue; if(USES_LIST(topleft_type, list)){ const int b_xy = h->mb2b_xy[topleft_xy] + 3 + h->b_stride + (topleft_partition & 2*h->b_stride); const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (topleft_partition & h->b8_stride); *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0; h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if(USES_LIST(topright_type, list)){ const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0; h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if((IS_SKIP(mb_type) || IS_DIRECT(mb_type)) && !FRAME_MBAFF) continue; h->ref_cache[list][scan8[5 ]+1] = h->ref_cache[list][scan8[7 ]+1] = h->ref_cache[list][scan8[13]+1] = h->ref_cache[list][scan8[4 ]] = h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= *(uint32_t*)h->mv_cache [list][scan8[13]+1]= *(uint32_t*)h->mv_cache [list][scan8[4 ]]= *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; if( h->pps.cabac ) { if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; *(uint32_t*)h->mvd_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 0]; *(uint32_t*)h->mvd_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 1]; *(uint32_t*)h->mvd_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 2]; *(uint32_t*)h->mvd_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 3]; }else{ *(uint32_t*)h->mvd_cache [list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mvd_cache [list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mvd_cache [list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mvd_cache [list][scan8[0] + 3 - 1*8]= 0; } if(USES_LIST(left_type[0], list)){ const int b_xy= h->mb2b_xy[left_xy[0]] + 3; *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[0]]; *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[1]]; }else{ *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 0*8]= *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 1*8]= 0; } if(USES_LIST(left_type[1], list)){ const int b_xy= h->mb2b_xy[left_xy[1]] + 3; *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[2]]; *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[3]]; }else{ *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]= *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0; } *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; if(h->slice_type_nos == FF_B_TYPE){ fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); if(IS_DIRECT(top_type)){ *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; }else if(IS_8X8(top_type)){ int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; }else{ *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0; } if(IS_DIRECT(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= 1; else if(IS_8X8(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)]; else h->direct_cache[scan8[0] - 1 + 0*8]= 0; if(IS_DIRECT(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= 1; else if(IS_8X8(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)]; else h->direct_cache[scan8[0] - 1 + 2*8]= 0; } } if(FRAME_MBAFF){ #define MAP_MVS\ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) if(MB_FIELD){ #define MAP_F2F(idx, mb_type)\ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] <<= 1;\ h->mv_cache[list][idx][1] /= 2;\ h->mvd_cache[list][idx][1] /= 2;\ } MAP_MVS #undef MAP_F2F }else{ #define MAP_F2F(idx, mb_type)\ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] >>= 1;\ h->mv_cache[list][idx][1] <<= 1;\ h->mvd_cache[list][idx][1] <<= 1;\ } MAP_MVS #undef MAP_F2F } } } } #endif h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); }
1threat
AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle, int packet_size) { AVFormatContext *rtpctx; int ret; AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); if (!rtp_format) return NULL; rtpctx = avformat_alloc_context(); if (!rtpctx) return NULL; rtpctx->oformat = rtp_format; if (!av_new_stream(rtpctx, 0)) { av_free(rtpctx); return NULL; } rtpctx->max_delay = s->max_delay; rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; rtpctx->start_time_realtime = s->start_time_realtime; av_free(rtpctx->streams[0]->codec); rtpctx->streams[0]->codec = st->codec; if (handle) { url_fdopen(&rtpctx->pb, handle); } else url_open_dyn_packet_buf(&rtpctx->pb, packet_size); ret = av_write_header(rtpctx); if (ret) { if (handle) { url_fclose(rtpctx->pb); } else { uint8_t *ptr; url_close_dyn_buf(rtpctx->pb, &ptr); av_free(ptr); } av_free(rtpctx->streams[0]); av_free(rtpctx); return NULL; } st->time_base = rtpctx->streams[0]->time_base; return rtpctx; }
1threat
Locking scroll position in FlatList (and ScrollView) : <p>I'm trying to create a FlatList that keeps the current scroll position locked and does not change by new items that are inserted at the top of the list.</p> <p>I've created an <a href="https://snack.expo.io/ryUcWZ1fW" rel="noreferrer">expo snack</a> to demonstrate my intention.</p> <p>The snack presents a ScrollView with green items, and a black item at the end. When the app launch it scrolls to the bottom of the list. After five seconds 10 items are inserted at the top, and the scroll position is changing according to the total size of these items.</p> <p>This is the code of the expo snack:</p> <pre><code>import React, { Component } from 'react'; import { View, FlatList } from 'react-native'; const renderItem = ({ item }) =&gt; { let backgroundColor; if (item == 10) { backgroundColor = "black" } else { backgroundColor = item % 2 == 0 ? 'green' : 'blue' } return ( &lt;View style={{ width: 200, height: 50, backgroundColor, margin: 10, }} /&gt; ); }; const MyList = class extends Component { componentDidMount() { setTimeout(() =&gt; this.ref.scrollToEnd({ animated: false }), 500); } render() { return ( &lt;FlatList ref={r =&gt; this.ref = r} data={this.props.data} renderItem={this.props.renderItem} /&gt; ); } }; export default class App extends Component { constructor(props) { super(props); this.state = { items: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10], }; } componentDidMount() { const items = [...this.state.items]; items.unshift(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); setTimeout(() =&gt; this.setState({ items }), 5000); } render() { return &lt;MyList renderItem={renderItem} data={this.state.items} /&gt;; } } </code></pre> <p>I want to keep the scroll position locked, meaning - when items are inserted the scroll position will not change (or at least in a way the user doesn't know anything happened)</p> <p>Is there a way to do it with the current API of FlatList and ScrollView? What's needed to be implemented to achieve this feature?</p>
0debug
static int send_extradata(APNGDemuxContext *ctx, AVPacket *pkt) { if (!ctx->extra_data_updated) { uint8_t *side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, ctx->extra_data_size); if (!side_data) return AVERROR(ENOMEM); memcpy(side_data, ctx->extra_data, ctx->extra_data_size); ctx->extra_data_updated = 1; } return 0; }
1threat
static int adaptive_cb_search(const int16_t *adapt_cb, float *work, const float *coefs, float *data) { int i, best_vect; float score, gain, best_score, best_gain; float exc[BLOCKSIZE]; gain = best_score = 0; for (i = BLOCKSIZE / 2; i <= BUFFERSIZE; i++) { create_adapt_vect(exc, adapt_cb, i); get_match_score(work, coefs, exc, NULL, NULL, data, &score, &gain); if (score > best_score) { best_score = score; best_vect = i; best_gain = gain; } } if (!best_score) return 0; create_adapt_vect(exc, adapt_cb, best_vect); ff_celp_lp_synthesis_filterf(work, coefs, exc, BLOCKSIZE, LPC_ORDER); for (i = 0; i < BLOCKSIZE; i++) data[i] -= best_gain * work[i]; return best_vect - BLOCKSIZE / 2 + 1; }
1threat
Check if value tuple is default : <p>How to check if a System.ValueTuple is default? Rough example:</p> <pre><code>(string foo, string bar) MyMethod() =&gt; default; // Later var result = MyMethod(); if (result is default){ } // doesnt work </code></pre> <p>I can return a default value in <code>MyMethod</code> using <code>default</code> syntax of C# 7.2. I cannot check for default case back? These are what I tried:</p> <pre><code>result is default result == default result is default(string, string) result == default(string, string) </code></pre>
0debug
python decimal shift customize : I am pretty new to python. I have a question about how to shift decimal based on demand. There is a list of amount which have two distinc values(option, amount). The option has three numbers 0, 1, 2. 0 means that you should shift the decimal over zero spaces (there is no amount greater than 1 dollar), 1 means that you should shift the decimal right to left by 1 place. and 2 means by 2 places. Such as the amount is 1234, if the option is 2, then the amount should be 12.34, if the option is 1, the amount should be 1.234. The code is below: amounts=[(1,2345),(0,3345),(2,1223)] for x in range(len(amounts): amount=Decimal(amounts[x][1]).shitf(-len(amounts[x][1] But I got error and not sure how to solve this.
0debug
static int parse_tonal(DCALbrDecoder *s, int group) { unsigned int amp[DCA_LBR_CHANNELS_TOTAL]; unsigned int phs[DCA_LBR_CHANNELS_TOTAL]; unsigned int diff, main_amp, shift; int sf, sf_idx, ch, main_ch, freq; int ch_nbits = av_ceil_log2(s->nchannels_total); for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) { sf_idx = ((s->framenum << group) + sf) & 31; s->tonal_bounds[group][sf_idx][0] = s->ntones; for (freq = 1;; freq++) { if (get_bits_left(&s->gb) < 1) { av_log(s->avctx, AV_LOG_ERROR, "Tonal group chunk too short\n"); return -1; } diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 2); if (diff >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) { av_log(s->avctx, AV_LOG_ERROR, "Invalid tonal frequency diff\n"); return -1; } diff = get_bitsz(&s->gb, diff >> 2) + ff_dca_fst_amp[diff]; if (diff <= 1) break; freq += diff - 2; if (freq >> (5 - group) > s->nsubbands * 4 - 5) { av_log(s->avctx, AV_LOG_ERROR, "Invalid spectral line offset\n"); return -1; } main_ch = get_bitsz(&s->gb, ch_nbits); main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 2) + s->tonal_scf[ff_dca_freq_to_sb[freq >> (7 - group)]] + s->limited_range - 2; amp[main_ch] = main_amp < AMP_MAX ? main_amp : 0; phs[main_ch] = get_bits(&s->gb, 3); for (ch = 0; ch < s->nchannels_total; ch++) { if (ch == main_ch) continue; if (get_bits1(&s->gb)) { amp[ch] = amp[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_damp, 1); phs[ch] = phs[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_dph, 1); } else { amp[ch] = 0; phs[ch] = 0; } } if (amp[main_ch]) { DCALbrTone *t = &s->tones[s->ntones]; s->ntones = (s->ntones + 1) & (DCA_LBR_TONES - 1); t->x_freq = freq >> (5 - group); t->f_delt = (freq & ((1 << (5 - group)) - 1)) << group; t->ph_rot = 256 - (t->x_freq & 1) * 128 - t->f_delt * 4; shift = ff_dca_ph0_shift[(t->x_freq & 3) * 2 + (freq & 1)] - ((t->ph_rot << (5 - group)) - t->ph_rot); for (ch = 0; ch < s->nchannels; ch++) { t->amp[ch] = amp[ch] < AMP_MAX ? amp[ch] : 0; t->phs[ch] = 128 - phs[ch] * 32 + shift; } } } s->tonal_bounds[group][sf_idx][1] = s->ntones; } return 0; }
1threat
static off_t read_off(int fd, int64_t offset) { uint64_t buffer; if (pread(fd, &buffer, 8, offset) < 8) return 0; return be64_to_cpu(buffer); }
1threat
Error launching application on Android SDK built for x86 : <p>There are a least a dozen previously compiled and running flutter applets that suddenly will not compile under Android Studio or Intellij.</p> <p>Even if i build a new default Flutter app i get this crash error:</p> <p>Clearly something has changed .. plugins/dependencies have been upgraded/updated and the .gradle and .idea directories removed ... and projects rebuilt .. but nothing gets past this:</p> <pre><code>Launching lib/main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... Gradle task 'assembleDebug'... Built build/app/outputs/apk/debug/app-debug.apk. cmd: Can't find service: activity Installing build/app/outputs/apk/app.apk... Error: ADB exited with exit code 1 adb: failed to install/home/jedaa/workspace/flutter_apps/studio/flutter_apprescue/build/app/outputs/apk/app.apk: cmd: Can't find service: package Error launching application on Android SDK built for x86. </code></pre>
0debug
check key is present in python dictionary : <p>Below is the "data" dict</p> <pre><code>{' node2': {'Status': ' online', 'TU': ' 900', 'Link': ' up', 'Port': ' a0a-180', 'MTU': ' 9000'}, ' node1': {'Status': ' online', 'TU': ' 900', 'Link': ' up', 'Port': ' a0a-180', 'MTU': ' 9000'}} </code></pre> <p>I am trying key node2 is present or not in data dict in below code but it is not working. Please help</p> <pre><code>if 'node2' in data: print "node2 Present" else: print "node2Not present" </code></pre>
0debug
static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { SVQ1Context * const s = avctx->priv_data; AVFrame *pict = data; AVFrame * const p= (AVFrame*)&s->picture; AVFrame temp; int i; if(avctx->pix_fmt != PIX_FMT_YUV410P){ av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); return -1; } if(!s->current_picture.data[0]){ avctx->get_buffer(avctx, &s->current_picture); avctx->get_buffer(avctx, &s->last_picture); } temp= s->current_picture; s->current_picture= s->last_picture; s->last_picture= temp; init_put_bits(&s->pb, buf, buf_size); *p = *pict; p->pict_type = avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE; p->key_frame = p->pict_type == I_TYPE; svq1_write_header(s, p->pict_type); for(i=0; i<3; i++){ svq1_encode_plane(s, i, s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i], s->frame_width / (i?4:1), s->frame_height / (i?4:1), s->picture.linesize[i], s->current_picture.linesize[i]); } while(put_bits_count(&s->pb) & 31) put_bits(&s->pb, 1, 0); flush_put_bits(&s->pb); return (put_bits_count(&s->pb) / 8); }
1threat
How to interpret mysqldump output? : <p>My intent is to extract the triggers, functions, and stored procedures from a database, edit them, and add them to another database.</p> <p>Below is a partial output from <code>mysqldump</code>. I understand how the database is updated with the <code>DROP</code>, <code>CREATE</code>, and<code>INSERT INTO</code> statements, but don't understand the triggers. I expected the following:</p> <pre><code>CREATE TRIGGER users_BINS BEFORE INSERT ON users FOR EACH ROW if(IFNULL(NEW.idPublic, 0) = 0) THEN INSERT INTO _inc_accounts (type, accountsId, idPublic) values ("users",NEW.accountsId,1) ON DUPLICATE KEY UPDATE idPublic = idPublic + 1; SET NEW.idPublic=(SELECT idPublic FROM _inc_accounts WHERE accountsId=NEW.accountsId AND type="users"); END IF; </code></pre> <p>What does <code>/*!50003</code> mean? I thought it was some comment which would mean the <code>CREATE</code> for the trigger isn't present, but I must be misinterpreting the output. How should one interpret a mysqldump output?</p> <p><code>mysqldump -u username-ppassword --routines mydb</code></p> <pre><code>-- -- Table structure for table `users` -- DROP TABLE IF EXISTS `users`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `idPublic` int(11) NOT NULL, `accountsId` int(11) NOT NULL, `firstname` varchar(45) NOT NULL, `lastname` varchar(45) NOT NULL, `email` varchar(45) NOT NULL, `username` varchar(45) NOT NULL, `password` char(255) NOT NULL COMMENT 'Password currently uses bcrypt and only requires 60 characters, but may change over time.', `tsCreated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `osTicketId` int(11) NOT NULL, `phone` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uniqueEmail` (`accountsId`,`email`), UNIQUE KEY `uniqueUsername` (`accountsId`,`username`), KEY `fk_users_accounts1_idx` (`accountsId`), CONSTRAINT `fk_users_accounts1` FOREIGN KEY (`accountsId`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `users` -- LOCK TABLES `users` WRITE; /*!40000 ALTER TABLE `users` DISABLE KEYS */; INSERT INTO `users` VALUES (xxx /*!40000 ALTER TABLE `users` ENABLE KEYS */; UNLOCK TABLES; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`michael`@`12.34.56.78`*/ /*!50003 TRIGGER `users_BINS` BEFORE INSERT ON `users` FOR EACH ROW BEGIN if(IFNULL(NEW.idPublic, 0) = 0) THEN INSERT INTO _inc_accounts (type, accountsId, idPublic) values ("users",NEW.accountsId,1) ON DUPLICATE KEY UPDATE idPublic = idPublic + 1; SET NEW.idPublic=(SELECT idPublic FROM _inc_accounts WHERE accountsId=NEW.accountsId AND type="users"); END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; </code></pre>
0debug
static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx) { AVStream *stream = fmt_ctx->streams[stream_idx]; AVCodecContext *dec_ctx; AVCodec *dec; char val_str[128]; AVRational display_aspect_ratio; struct print_buf pbuf = {.s = NULL}; print_section_header("stream"); print_int("index", stream->index); if ((dec_ctx = stream->codec)) { if ((dec = dec_ctx->codec)) { print_str("codec_name", dec->name); print_str("codec_long_name", dec->long_name); } else { print_str("codec_name", "unknown"); } print_str("codec_type", av_x_if_null(av_get_media_type_string(dec_ctx->codec_type), "unknown")); print_fmt("codec_time_base", "%d/%d", dec_ctx->time_base.num, dec_ctx->time_base.den); av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag); print_str("codec_tag_string", val_str); print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag); switch (dec_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: print_int("width", dec_ctx->width); print_int("height", dec_ctx->height); print_int("has_b_frames", dec_ctx->has_b_frames); if (dec_ctx->sample_aspect_ratio.num) { print_fmt("sample_aspect_ratio", "%d:%d", dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den); av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, dec_ctx->width * dec_ctx->sample_aspect_ratio.num, dec_ctx->height * dec_ctx->sample_aspect_ratio.den, 1024*1024); print_fmt("display_aspect_ratio", "%d:%d", display_aspect_ratio.num, display_aspect_ratio.den); } print_str("pix_fmt", av_x_if_null(av_get_pix_fmt_name(dec_ctx->pix_fmt), "unknown")); print_int("level", dec_ctx->level); break; case AVMEDIA_TYPE_AUDIO: print_str("sample_fmt", av_x_if_null(av_get_sample_fmt_name(dec_ctx->sample_fmt), "unknown")); print_val("sample_rate", dec_ctx->sample_rate, unit_hertz_str); print_int("channels", dec_ctx->channels); print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id)); break; } } else { print_str("codec_type", "unknown"); } if (dec_ctx->codec && dec_ctx->codec->priv_class) { const AVOption *opt = NULL; while (opt = av_opt_next(dec_ctx->priv_data,opt)) { uint8_t *str; if (opt->flags) continue; if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) { print_str(opt->name, str); av_free(str); } } } if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt("id", "0x%x", stream->id); print_fmt("r_frame_rate", "%d/%d", stream->r_frame_rate.num, stream->r_frame_rate.den); print_fmt("avg_frame_rate", "%d/%d", stream->avg_frame_rate.num, stream->avg_frame_rate.den); print_fmt("time_base", "%d/%d", stream->time_base.num, stream->time_base.den); print_time("start_time", stream->start_time, &stream->time_base); print_time("duration", stream->duration, &stream->time_base); if (stream->nb_frames) print_fmt("nb_frames", "%"PRId64, stream->nb_frames); show_tags(stream->metadata); print_section_footer("stream"); av_free(pbuf.s); fflush(stdout); }
1threat
static int mpegts_init(AVFormatContext *s) { MpegTSWrite *ts = s->priv_data; MpegTSWriteStream *ts_st; MpegTSService *service; AVStream *st, *pcr_st = NULL; AVDictionaryEntry *title, *provider; int i, j; const char *service_name; const char *provider_name; int *pids; int ret; if (s->max_delay < 0) s->max_delay = 0; ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14; ts->tsid = ts->transport_stream_id; ts->onid = ts->original_network_id; if (!s->nb_programs) { title = av_dict_get(s->metadata, "service_name", NULL, 0); if (!title) title = av_dict_get(s->metadata, "title", NULL, 0); service_name = title ? title->value : DEFAULT_SERVICE_NAME; provider = av_dict_get(s->metadata, "service_provider", NULL, 0); provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME; service = mpegts_add_service(ts, ts->service_id, provider_name, service_name); if (!service) return AVERROR(ENOMEM); service->pmt.write_packet = section_write_packet; service->pmt.opaque = s; service->pmt.cc = 15; service->pmt.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT; } else { for (i = 0; i < s->nb_programs; i++) { AVProgram *program = s->programs[i]; title = av_dict_get(program->metadata, "service_name", NULL, 0); if (!title) title = av_dict_get(program->metadata, "title", NULL, 0); service_name = title ? title->value : DEFAULT_SERVICE_NAME; provider = av_dict_get(program->metadata, "service_provider", NULL, 0); provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME; service = mpegts_add_service(ts, program->id, provider_name, service_name); if (!service) return AVERROR(ENOMEM); service->pmt.write_packet = section_write_packet; service->pmt.opaque = s; service->pmt.cc = 15; service->pmt.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT; service->program = program; } } ts->pat.pid = PAT_PID; ts->pat.cc = 15; ts->pat.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT; ts->pat.write_packet = section_write_packet; ts->pat.opaque = s; ts->sdt.pid = SDT_PID; ts->sdt.cc = 15; ts->sdt.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT; ts->sdt.write_packet = section_write_packet; ts->sdt.opaque = s; pids = av_malloc_array(s->nb_streams, sizeof(*pids)); if (!pids) { ret = AVERROR(ENOMEM); goto fail; } for (i = 0; i < s->nb_streams; i++) { AVProgram *program; st = s->streams[i]; ts_st = av_mallocz(sizeof(MpegTSWriteStream)); if (!ts_st) { ret = AVERROR(ENOMEM); goto fail; } st->priv_data = ts_st; ts_st->user_tb = st->time_base; avpriv_set_pts_info(st, 33, 1, 90000); ts_st->payload = av_mallocz(ts->pes_payload_size); if (!ts_st->payload) { ret = AVERROR(ENOMEM); goto fail; } program = av_find_program_from_stream(s, NULL, i); if (program) { for (j = 0; j < ts->nb_services; j++) { if (ts->services[j]->program == program) { service = ts->services[j]; break; } } } ts_st->service = service; if (st->id < 16) { ts_st->pid = ts->start_pid + i; } else if (st->id < 0x1FFF) { ts_st->pid = st->id; } else { av_log(s, AV_LOG_ERROR, "Invalid stream id %d, must be less than 8191\n", st->id); ret = AVERROR(EINVAL); goto fail; } if (ts_st->pid == service->pmt.pid) { av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid); ret = AVERROR(EINVAL); goto fail; } for (j = 0; j < i; j++) { if (pids[j] == ts_st->pid) { av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid); ret = AVERROR(EINVAL); goto fail; } } pids[i] = ts_st->pid; ts_st->payload_pts = AV_NOPTS_VALUE; ts_st->payload_dts = AV_NOPTS_VALUE; ts_st->first_pts_check = 1; ts_st->cc = 15; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && service->pcr_pid == 0x1fff) { service->pcr_pid = ts_st->pid; pcr_st = st; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { AVStream *ast; ts_st->amux = avformat_alloc_context(); if (!ts_st->amux) { ret = AVERROR(ENOMEM); goto fail; } ts_st->amux->oformat = av_guess_format((ts->flags & MPEGTS_FLAG_AAC_LATM) ? "latm" : "adts", NULL, NULL); if (!ts_st->amux->oformat) { ret = AVERROR(EINVAL); goto fail; } if (!(ast = avformat_new_stream(ts_st->amux, NULL))) { ret = AVERROR(ENOMEM); goto fail; } ret = avcodec_parameters_copy(ast->codecpar, st->codecpar); if (ret != 0) goto fail; ast->time_base = st->time_base; ret = avformat_write_header(ts_st->amux, NULL); if (ret < 0) goto fail; } if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { ts_st->opus_pending_trim_start = st->codecpar->initial_padding * 48000 / st->codecpar->sample_rate; } } av_freep(&pids); if (service->pcr_pid == 0x1fff && s->nb_streams > 0) { pcr_st = s->streams[0]; ts_st = pcr_st->priv_data; service->pcr_pid = ts_st->pid; } else ts_st = pcr_st->priv_data; if (ts->mux_rate > 1) { service->pcr_packet_period = (int64_t)ts->mux_rate * ts->pcr_period / (TS_PACKET_SIZE * 8 * 1000); ts->sdt_packet_period = (int64_t)ts->mux_rate * SDT_RETRANS_TIME / (TS_PACKET_SIZE * 8 * 1000); ts->pat_packet_period = (int64_t)ts->mux_rate * PAT_RETRANS_TIME / (TS_PACKET_SIZE * 8 * 1000); if (ts->copyts < 1) ts->first_pcr = av_rescale(s->max_delay, PCR_TIME_BASE, AV_TIME_BASE); } else { ts->sdt_packet_period = 200; ts->pat_packet_period = 40; if (pcr_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { int frame_size = av_get_audio_frame_duration2(pcr_st->codecpar, 0); if (!frame_size) { av_log(s, AV_LOG_WARNING, "frame size not set\n"); service->pcr_packet_period = pcr_st->codecpar->sample_rate / (10 * 512); } else { service->pcr_packet_period = pcr_st->codecpar->sample_rate / (10 * frame_size); } } else { service->pcr_packet_period = ts_st->user_tb.den / (10 * ts_st->user_tb.num); } if (!service->pcr_packet_period) service->pcr_packet_period = 1; } ts->last_pat_ts = AV_NOPTS_VALUE; ts->last_sdt_ts = AV_NOPTS_VALUE; if (ts->pat_period < INT_MAX/2) { ts->pat_packet_period = INT_MAX; } if (ts->sdt_period < INT_MAX/2) { ts->sdt_packet_period = INT_MAX; } service->pcr_packet_count = service->pcr_packet_period; ts->pat_packet_count = ts->pat_packet_period - 1; ts->sdt_packet_count = ts->sdt_packet_period - 1; if (ts->mux_rate == 1) av_log(s, AV_LOG_VERBOSE, "muxrate VBR, "); else av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate); av_log(s, AV_LOG_VERBOSE, "pcr every %d pkts, sdt every %d, pat/pmt every %d pkts\n", service->pcr_packet_period, ts->sdt_packet_period, ts->pat_packet_period); if (ts->m2ts_mode == -1) { if (av_match_ext(s->filename, "m2ts")) { ts->m2ts_mode = 1; } else { ts->m2ts_mode = 0; } } return 0; fail: av_freep(&pids); return ret; }
1threat
GCP load balancer backend status unknown : <p>I'm flabbergasted.</p> <p>I have a staging and production environment. Both environments have the same deployments, services, ingress, firewall rules, and both serve a <code>200</code> on <code>/</code>. </p> <p>However, after turning on the staging environment and provisioning the same ingress, the staging service fails with <code>Some backend services are in UNKNOWN state</code>. Production is still live.</p> <p>Both the frontend and backend pods are ready on GKE. I've manually tested the health checks and they pass when I visit <code>/</code>.</p> <p>I see nothing in the logs or gcp docs pointing in the right direction. What could I have possibly broken?</p> <p><code>ingress.yaml</code>:</p> <pre><code>apiVersion: extensions/v1beta1 kind: Ingress metadata: name: fanout-ingress annotations: kubernetes.io/ingress.global-static-ip-name: "STATIC-IP" spec: backend: serviceName: frontend servicePort: 8080 tls: - hosts: - &lt;DOMAIN&gt; secretName: staging-tls rules: - host: &lt;DOMAIN&gt; http: paths: - path: /* backend: serviceName: frontend servicePort: 8080 - path: /backend/* backend: serviceName: backend servicePort: 8080 </code></pre> <p><code>frontend.yaml</code>:</p> <pre><code>apiVersion: v1 kind: Service metadata: labels: app: frontend name: frontend namespace: default spec: ports: - nodePort: 30664 port: 8080 protocol: TCP targetPort: 8080 selector: app: frontend type: NodePort --- apiVersion: extensions/v1beta1 kind: Deployment metadata: generation: 15 labels: app: frontend name: frontend namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 selector: matchLabels: app: frontend minReadySeconds: 5 template: metadata: labels: app: frontend spec: containers: - image: &lt;our-image&gt; name: frontend ports: - containerPort: 8080 protocol: TCP readinessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 60 periodSeconds: 30 timeoutSeconds: 3 livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 60 periodSeconds: 30 timeoutSeconds: 3 </code></pre>
0debug
Regular Expression For Parsing JSON Objects : <p>I have a Json file containing text as such:</p> <pre><code>{ title1: { x: "abc", y: "def" } , title2:{ x: "{{abc}}", y: "{{def}}" }, } </code></pre> <p>I want to first get the title1 title2 ,... groups. And after that, for each group, I want to get the x:..., y:... parts. I try to do this in two steps. For the first step, I used the following regexp:</p> <pre><code>[\s\S]*:\s*{(((?!}\s*,)[\s\S])*) </code></pre> <p>I am trying to say that find <code>:</code> followed by optional white space and then <code>{</code>. Then, continue until you see <code>}</code> followed by optional whitespace and <code>,</code>. But it finds the whole text as a match instead of title1 and title2 parts separately. What is wrong with it? </p>
0debug
static void flush_packet(AVFormatContext *ctx, int stream_index, int last_pkt) { MpegMuxContext *s = ctx->priv_data; StreamInfo *stream = ctx->streams[stream_index]->priv_data; uint8_t *buf_ptr; int size, payload_size, startcode, id, len, stuffing_size, i, header_len; int64_t timestamp; uint8_t buffer[128]; int last = last_pkt ? 4 : 0; id = stream->id; timestamp = stream->start_pts; #if 0 printf("packet ID=%2x PTS=%0.3f\n", id, timestamp / 90000.0); #endif buf_ptr = buffer; if (((s->packet_number % s->pack_header_freq) == 0)) { size = put_pack_header(ctx, buf_ptr, timestamp); buf_ptr += size; if ((s->packet_number % s->system_header_freq) == 0) { size = put_system_header(ctx, buf_ptr); buf_ptr += size; } } size = buf_ptr - buffer; put_buffer(&ctx->pb, buffer, size); if (s->is_mpeg2) { header_len = 8; } else { header_len = 5; } payload_size = s->packet_size - (size + 6 + header_len + last); if (id < 0xc0) { startcode = PRIVATE_STREAM_1; payload_size -= 4; } else { startcode = 0x100 + id; } stuffing_size = payload_size - stream->buffer_ptr; if (stuffing_size < 0) stuffing_size = 0; put_be32(&ctx->pb, startcode); put_be16(&ctx->pb, payload_size + header_len); for(i=0;i<stuffing_size;i++) put_byte(&ctx->pb, 0xff); if (s->is_mpeg2) { put_byte(&ctx->pb, 0x80); put_byte(&ctx->pb, 0x80); put_byte(&ctx->pb, 0x05); } put_byte(&ctx->pb, (0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1); put_be16(&ctx->pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1)); put_be16(&ctx->pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1)); if (startcode == PRIVATE_STREAM_1) { put_byte(&ctx->pb, id); if (id >= 0x80 && id <= 0xbf) { put_byte(&ctx->pb, 1); put_byte(&ctx->pb, 0); put_byte(&ctx->pb, 2); } } if (last_pkt) { put_be32(&ctx->pb, ISO_11172_END_CODE); } put_buffer(&ctx->pb, stream->buffer, payload_size - stuffing_size); put_flush_packet(&ctx->pb); len = stream->buffer_ptr - payload_size; if (len < 0) len = 0; memmove(stream->buffer, stream->buffer + stream->buffer_ptr - len, len); stream->buffer_ptr = len; s->packet_number++; stream->packet_number++; stream->start_pts = -1; }
1threat
View is not rerendered in Nested ForEach loop : <p>I have the following component that renders a grid of semi transparent characters:</p> <pre class="lang-swift prettyprint-override"><code> var body: some View { VStack{ Text("\(self.settings.numRows) x \(self.settings.numColumns)") ForEach(0..&lt;self.settings.numRows){ i in Spacer() HStack{ ForEach(0..&lt;self.settings.numColumns){ j in Spacer() // why do I get an error when I try to multiply i * j self.getSymbol(index:j) Spacer() } } Spacer() } } } </code></pre> <p><code>settings</code> is an EnvironmentObject</p> <p>Whenever <code>settings</code> is updated the Text in the outermost <code>VStack</code> is correctly updated. However, the rest of the view is not updated (Grid has same dimenstions as before). Why is this?</p> <p>Second question: Why is it not possible to access the <code>i</code> in the inner <code>ForEach</code>-loop and pass it as a argument to the function?</p> <p>I get an error at the outer <code>ForEach</code>-loop:</p> <blockquote> <p>Generic parameter 'Data' could not be inferred</p> </blockquote>
0debug
How to connect to a unknown secure wifi network via cmd : <p>I want to know if there is some possibility to connect to a unknow secure wifi network? Because right know I tried something but apparently I just connect to the wifi network that I connected until now. </p> <p>something like this: netsh wlan connect wifi_name</p> <p>But if I want to connect to wifi_name2 that I didn't use right until now, I can connect to it.</p> <p>And I know that somewhere I must specified the password. I don't want to connect from windows tool but from cmd window.</p> <p>Is there a way to do it?</p> <p>Thanks in advance.</p>
0debug
How to mapping an array to another array in efficient way : <p>For these 4 array, a1 a2 a3 </p> <pre><code>a1 = [5,3,0,2,4,2,...,...] a2 = [5,3,0,2,4,2,...,...] =&gt; store index number, correspond value is in b a3 = [5,3,0,2,4,2,...,...] b = [250,300,1,2,70,23,...,...] </code></pre> <p>I want to find an efficient way to generate an array like:</p> <pre><code> c1 = [23,2,250,1,70,1,...,...] c2 = [23,2,250,1,70,1,...,...] c3 = [23,2,250,1,70,1,...,...] </code></pre> <p>But using 3 Forloop solving this problem is too slow in my case. I want to find an efficient way to solve. For example, mapping 3 array at the same time.</p>
0debug
mysqli_query(): MySQL server has gone away : <p>I'm getting these errors:</p> <pre><code>Warning: mysqli_query(): MySQL server has gone away in (local db) Warning: mysqli_query(): Error reading result set's header in (local db) </code></pre> <p>I am establishing a connection at first:</p> <pre><code>$connection = new mysqli($server, $user, $pass, $db) or die("unable"); </code></pre> <p>Then this:</p> <pre><code>$sql = $connection-&gt;prepare("INSERT INTO comments (name,mail,homepage,comment,time) VALUES (?,?,?,?,?)"); $sql-&gt;bind_Param('sssss',$name,$mail,$homepage,$comment,$time); $sql-&gt;execute(); if($sql){ if(!addPics($connection, $image_content, $mime, $time)){ //other code } </code></pre> <p>addPics looks like this:</p> <pre><code>function addPics($connection, $image_content, $mime, $time){ $sql = $connection-&gt;prepare("INSERT INTO pictures (picture, mime, time) VALUES (?,?,?)"); $sql-&gt;bind_Param('sss',$image_content,$mime, $time); $sql-&gt;execute(); if($sql){ return true; } else { return false; } </code></pre> <p>Error occurs at the second sql->execute. My guess is that it's because I'm using the connection for several requests but my knowledge of PHP does not allow me to figure out a solution.</p> <p>Thank you!</p>
0debug
How to store image in a database using laravel and then display it : <p>I've seen some topics on stack about this question but none of them are exactly what i want. Mostly people are saying it's a bad idea to store image in a database. I know it but still I need to save an image in a database and be able to display it. please provide a code or some video how to do it. thanks in advance</p>
0debug
def tn_ap(a,n,d): tn = a + (n - 1) * d return tn
0debug
static int vncws_start_tls_handshake(VncState *vs) { int ret = gnutls_handshake(vs->tls.session); if (ret < 0) { if (!gnutls_error_is_fatal(ret)) { VNC_DEBUG("Handshake interrupted (blocking)\n"); if (!gnutls_record_get_direction(vs->tls.session)) { qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs); } else { qemu_set_fd_handler(vs->csock, NULL, vncws_tls_handshake_io, vs); } return 0; } VNC_DEBUG("Handshake failed %s\n", gnutls_strerror(ret)); vnc_client_error(vs); return -1; } if (vs->vd->tls.x509verify) { if (vnc_tls_validate_certificate(vs) < 0) { VNC_DEBUG("Client verification failed\n"); vnc_client_error(vs); return -1; } else { VNC_DEBUG("Client verification passed\n"); } } VNC_DEBUG("Handshake done, switching to TLS data mode\n"); qemu_set_fd_handler(vs->csock, vncws_handshake_read, NULL, vs); return 0; }
1threat
static void uhci_async_complete(USBPort *port, USBPacket *packet) { UHCIAsync *async = container_of(packet, UHCIAsync, packet); UHCIState *s = async->queue->uhci; if (async->isoc) { UHCI_TD td; uint32_t link = async->td; uint32_t int_mask = 0, val; pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); le32_to_cpus(&td.link); le32_to_cpus(&td.ctrl); le32_to_cpus(&td.token); le32_to_cpus(&td.buffer); uhci_async_unlink(async); uhci_complete_td(s, &td, async, &int_mask); s->pending_int_mask |= int_mask; val = cpu_to_le32(td.ctrl); pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); uhci_async_free(async); } else { async->done = 1; uhci_process_frame(s); } }
1threat
Convert String to Type unknown at compile time C# : Given a string and a type of number, I would like to check if the string can be converted to that type and would like the string to be converted to that type if possible. Bellow is the sudo code for what I am trying to do: public bool DataIsValid(string s, Type someNumType) { d = 0; // a class member variable if (s.CanBeConvertedTo(someNumType)) { d = (double)s; return true; } else { return false; } I'm always trying to convert a string to some type of number but I don't know what type. I've tried using a try/catch block with d = (double)Convert.ChangeType(s, someNumType); but this only works for doubles and not integers. Thanks in advance.
0debug
Angular 4 enable HTML5 validation : <p>I want to use HTML5 validation in Angular 4 rather than their form's based validation/reactive validation. I want to keep the validation running in the browser. </p> <p>It used to work in Angular 2, but since I've upgraded, I can't get even manually created forms without any angular directives to validate using HTML5.</p> <p>For instance, this won't validate in the browser at all:</p> <pre><code>&lt;form&gt; &lt;h2&gt;Phone Number Validation&lt;/h2&gt; &lt;label for="phonenum"&gt;Phone Number (format: xxxx-xxx-xxxx):&lt;/label&gt;&lt;br /&gt; &lt;input id="phonenum" type="tel" pattern="^\d{4}-\d{3}-\d{4}$" required&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code></pre>
0debug
Handling large file uploads with Flask : <p>What would be the best way to handle very large file uploads (1 GB +) with Flask?</p> <p>My application essentially takes multiple files assigns them one unique file number and then saves it on the server depending on where the user selected.</p> <p><strong>How can we run file uploads as a background task so the user does not have the browser spin for 1hour and can instead proceed to the next page right away?</strong></p> <ul> <li>Flask development server is able to take massive files (50gb took 1.5 hours, upload was quick but writing the file into a blank file was painfully slow)</li> <li>If I wrap the app with Twisted, the app crashes on large files</li> <li>I've tried using Celery with Redis but this doesn't seem to be an option with posted uploads</li> <li>I'm on Windows and have fewer options for webservers </li> </ul>
0debug
void qed_release(BDRVQEDState *s) { aio_context_release(bdrv_get_aio_context(s->bs)); }
1threat
Linked Lists - Insert Function Modification : The program should show the element to be inserted at a position greater than the current size of the linked list at the end. I have tried the following piece of code : (Changed == with >= ) if(pos >= 1) { newNode->next = start; start = newNode; } void insert(){ int i,pos; newNode = (node*)malloc(sizeof(node)); printf("\nEnter the data to insert : "); scanf("%d",&newNode->data); newNode->next = NULL; printf("\nEnter the position : "); scanf("%d",&pos); if(pos == 1){ newNode->next = start; start = newNode; } else{ for(temp = start,i = 1;temp != NULL;temp = temp->next,i++){ if(i == (pos - 1)){ newNode->next = temp->next; temp->next = newNode; break; } } } } I expect the output to show the node inserted at a position greater than the size of current linked list at the ending. The current code takes the input, however it doesn't display it at end.
0debug
Why dose this not save : Html: What the code needs to do is to save the informacion but it dose not! Please help with this <form> <h1>Email</h1> <input type="email" id="email2" required><br><br> <h1>Password</h1> <input type="password" id="myInput"> <input type="checkbox" onclick="myFunction()">Show Password<br><br> </form> <input type="Submit" onclick="signin()"> Javascript code: function signin(){ var y = document.getElementById("email2"); var x = document.getElementById("myInput"); if(y == email2 && x == myInput ){ window.open("account.html"); }else{ window.open('sign in.html'); }
0debug
Javascript - what does != -1 do in this function : <p>I understand practically all of this code except the lines noted below</p> <pre><code>function hasEvent(event, entry) { return entry.events.indexOf(event) != -1; /*?????????*/ } function tableFor(event, journal) { var table = [0, 0, 0, 0]; for (var i = 0; i &lt; journal.length; i++) { var entry = journal[i], index = 0; if (hasEvent(event, entry)) index += 1; if (entry.squirrel) index += 2; table[index] += 1; } return table; } console.log(tableFor("pizza", JOURNAL)); // → [76, 9, 4, 1] </code></pre> <p><code>JOURNAL</code> is an array. This function loops through it to find if any of the entries hold the value of pizza, and what the value of the property of <code>squirrel</code> is. Based on the results of those two checks, 1 is added to one of the 4 index in <code>table</code>. I guess I'm not understanding what the <code>hasEvent</code> function does, and how it interacts with the first <code>if</code> statement. </p> <p>For more details, code can be found about halfway through this page</p> <p><a href="http://eloquentjavascript.net/04_data.html" rel="nofollow noreferrer">http://eloquentjavascript.net/04_data.html</a></p>
0debug
cursor.execute('SELECT * FROM users WHERE username = ' + user_input)
1threat
What's the output of this program? Explain the answer too please : `void main() { printf("%d",-10 & 5); }` /*Why is the output of this program 4*/
0debug
static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW) { #if COMPILE_TEMPLATE_MMX if(!(c->flags & SWS_BITEXACT)) { if (c->flags & SWS_ACCURATE_RND) { if (uDest) { YSCALEYUV2YV12X_ACCURATE( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW) YSCALEYUV2YV12X_ACCURATE(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW) } if (CONFIG_SWSCALE_ALPHA && aDest) { YSCALEYUV2YV12X_ACCURATE( "0", ALP_MMX_FILTER_OFFSET, aDest, dstW) } YSCALEYUV2YV12X_ACCURATE("0", LUM_MMX_FILTER_OFFSET, dest, dstW) } else { if (uDest) { YSCALEYUV2YV12X( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW) YSCALEYUV2YV12X(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW) } if (CONFIG_SWSCALE_ALPHA && aDest) { YSCALEYUV2YV12X( "0", ALP_MMX_FILTER_OFFSET, aDest, dstW) } YSCALEYUV2YV12X("0", LUM_MMX_FILTER_OFFSET, dest, dstW) } return; } #endif #if COMPILE_TEMPLATE_ALTIVEC yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize, chrFilter, chrSrc, chrFilterSize, dest, uDest, vDest, dstW, chrDstW); #else yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize, chrFilter, chrSrc, chrFilterSize, alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW); #endif }
1threat
Compress and Encrypt (AES 256) excel files in (streams) in C# : <p>I need a package with encryption and compressions methods. </p> <p>Preferably compress/decompress and encrpyt/desencrypt large streams correctly.</p>
0debug
What's default TTL in Redis? : <p>I can't find anywhere online what is default TTL in Redis. I know that I can set TTL for specific SET, but don't know what is default TTL. Can someone tell me what default time to live is in Redis?</p>
0debug
static void handle_input(VirtIODevice *vdev, VirtQueue *vq) { VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev); size_t size; size = pop_an_elem(vrng); if (size) { rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); } }
1threat
Best practies CodeIgniter Templating : <p>I'm using CodeIgniter for few years for my PHP project. Now I'm thinking how improve my view folder structure, using best practies.</p> <p>I'll explain better. Basically I divide my webpage into 3 view: </p> <ul> <li>Header (/view/inc/header.php)</li> <li>SomeContent (/view/content_of_myView)</li> <li>Footer (/view/inc/footer.php)</li> </ul> <p>My question is very simple: is this the best way? Or there are differents method to generate an header, maybe loading dinamycally all css/js assets with versioning? I don't want to use any template engine, sincerely I don't like very much.</p>
0debug
concatenate 2 dates in SQL just like we do in Excel. I am using MS SQL server : In excel if we concat 2 dates for e.g 1/1/2015 and 7/1/2018 by using the formula =CONCAT(1/1/2015,"_",7/1/2018) the result is 42005_43282. Can we do the same thing in SQL?
0debug
static void pxa2xx_i2s_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; uint32_t *sample; switch (addr) { case SACR0: if (value & (1 << 3)) pxa2xx_i2s_reset(s); s->control[0] = value & 0xff3d; if (!s->enable && (value & 1) && s->tx_len) { for (sample = s->fifo; s->fifo_len > 0; s->fifo_len --, sample ++) s->codec_out(s->opaque, *sample); s->status &= ~(1 << 7); } if (value & (1 << 4)) printf("%s: Attempt to use special function\n", __FUNCTION__); s->enable = (value & 9) == 1; pxa2xx_i2s_update(s); break; case SACR1: s->control[1] = value & 0x0039; if (value & (1 << 5)) printf("%s: Attempt to use loopback function\n", __FUNCTION__); if (value & (1 << 4)) s->fifo_len = 0; pxa2xx_i2s_update(s); break; case SAIMR: s->mask = value & 0x0078; pxa2xx_i2s_update(s); break; case SAICR: s->status &= ~(value & (3 << 5)); pxa2xx_i2s_update(s); break; case SADIV: s->clk = value & 0x007f; break; case SADR: if (s->tx_len && s->enable) { s->tx_len --; pxa2xx_i2s_update(s); s->codec_out(s->opaque, value); } else if (s->fifo_len < 16) { s->fifo[s->fifo_len ++] = value; pxa2xx_i2s_update(s); } break; default: printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); } }
1threat
static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { G726Context *c = avctx->priv_data; const int16_t *samples = (const int16_t *)frame->data[0]; PutBitContext pb; int i, ret, out_size; out_size = (frame->nb_samples * c->code_size + 7) / 8; if ((ret = ff_alloc_packet2(avctx, avpkt, out_size))) return ret; init_put_bits(&pb, avpkt->data, avpkt->size); for (i = 0; i < frame->nb_samples; i++) put_bits(&pb, c->code_size, g726_encode(c, *samples++)); flush_put_bits(&pb); avpkt->size = out_size; *got_packet_ptr = 1; return 0; }
1threat
iscsi_synccache10_cb(struct iscsi_context *iscsi, int status, void *command_data, void *opaque) { IscsiAIOCB *acb = opaque; if (acb->canceled != 0) { qemu_aio_release(acb); scsi_free_scsi_task(acb->task); acb->task = NULL; return; } acb->status = 0; if (status < 0) { error_report("Failed to sync10 data on iSCSI lun. %s", iscsi_get_error(iscsi)); acb->status = -EIO; } iscsi_schedule_bh(acb); scsi_free_scsi_task(acb->task); acb->task = NULL; }
1threat
implement length() of string without using Built-in functions : <p>How can i get the length of a string in java without using any Built-in Functions neither using length() nor using any function</p>
0debug
Java: while loop, enter your next number or type "S" to stop : <p>I want the user to stop entering numbers whenever they feel like it. When I run it, it does not work the way I want it to. Thanks for all the help in advance.</p> <pre><code>private static void whileLoop3() { System.out.printf("%n%nExecuting whileLoop3...%n%n"); int count=0; int total=0; int average; int temp; //while loop 10 times while(count &lt; 10) { //input number from user temp = input.nextInt(); //add to total total += temp; //same as total = total + temp count++; //same as count = count + 10 } System.out.printf("Count is %d%n", count); average = total/count; System.out.printf("The average of your numbers is %d%n", average); System.out.printf("%nEnter your next number or \"S\" to stop: "); } </code></pre>
0debug
int floatx80_lt(floatx80 a, floatx80 b, float_status *status) { flag aSign, bSign; if ( ( ( extractFloatx80Exp( a ) == 0x7FFF ) && (uint64_t) ( extractFloatx80Frac( a )<<1 ) ) || ( ( extractFloatx80Exp( b ) == 0x7FFF ) && (uint64_t) ( extractFloatx80Frac( b )<<1 ) ) ) { float_raise(float_flag_invalid, status); return 0; } aSign = extractFloatx80Sign( a ); bSign = extractFloatx80Sign( b ); if ( aSign != bSign ) { return aSign && ( ( ( (uint16_t) ( ( a.high | b.high )<<1 ) ) | a.low | b.low ) != 0 ); } return aSign ? lt128( b.high, b.low, a.high, a.low ) : lt128( a.high, a.low, b.high, b.low ); }
1threat
xCode 8, Swift 3, iOS: Input lowercase letters to uppercase and vice-versa in textfield : I am using xCode 8 and Swift 3. I am creating app for iOS. How will I make inputted lowercase letters be automatically converted to uppercase letters in the text field and vice-versa? I thank those who can answer this question accordingly and relevantly.
0debug
static void pc_init_pci_1_4(QEMUMachineInitArgs *args) { pc_sysfw_flash_vs_rom_bug_compatible = true; has_pvpanic = false; x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE); pc_init_pci(args); }
1threat
ran into a issue with my java program : <p>So im pretty new to java and creating something for school. My problem is the last If statements i make compare strings and i understand that != or >= doesnt work but i dont understand what to use in place of it. any help?</p> <p>I've tried looking up the proper way to use that line but i just didnt really understand what exactly everyone was stating when comparing the 2 letters.</p> <pre><code>package Secrets_hw2p1; /** * * @author secrets */ //importing Scanner //import scanner import java.util.Scanner; public class secrets_hw2p1 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //Creating the Scanner object Scanner input = new Scanner (System.in); //getting students goal grade System.out.println("What is your Goal Letter Grade? "); String goalGrade = input.next(); //Enter assignment scores. and read scores System.out.println("Please enter in your two assignment scores followed" +"by your two exam scores one at a time followed by enter "); float assignment1 = input.nextFloat(); float assignment2 = input.nextFloat(); float exam1 = input.nextFloat(); float exam2 = input.nextFloat(); //calculations of averages double goal = assignment1 * .40 + assignment2 * .40 + exam1 * .30 + exam2 * 0.30; int grade; //Calculate Letter grade if (goal &gt;= 90) grade = 'A'; else if (goal &gt;= 80) grade = 'B'; else if (goal &gt;= 70) grade = 'C'; else grade = 'D'; //prompt the user for how they want there grade System.out.println("Press 1 to display letter grade or press 2 to" +"see if you met your goal "); double number = input.nextDouble(); //if user inputed 1 if (number == 1) System.out.println ("Final grade:" + grade); //if user inputed 2 if (number == 2) if (goalGrade != grade) System.out.println("You have not met or exceeded your goal" +" grade"); else if (c1.goalGrade &gt;= grade) System.out.println("You met or exceded your goal grade !"); } } </code></pre>
0debug
python split regex into multiple lines : <p>Just a simple question. Lets say i have a very long regex.</p> <pre><code>regex = "(foo|foo|foo|foo|bar|bar|bar)" </code></pre> <p>Now i want to split this regex into multiple lines. I tried</p> <pre><code>regex = "(foo|foo|foo|foo|\ bar|bar|bar)" </code></pre> <p>but this doesnt seems to work. I get different outputs. Any ideas?</p>
0debug
How do coroutines in Python compare to those in Lua? : <p>Support for coroutines in Lua is provided by <a href="https://www.lua.org/manual/5.3/manual.html#2.6" rel="noreferrer">functions in the <code>coroutine</code> table</a>, primarily <code>create</code>, <code>resume</code> and <code>yield</code>. The developers describe these coroutines as <a href="http://laser.inf.ethz.ch/2012/slides/Ierusalimschy/coroutines-4.pdf" rel="noreferrer">stackful, first-class and asymmetric</a>.</p> <p>Coroutines are also available in Python, either using <a href="https://www.python.org/dev/peps/pep-0342/" rel="noreferrer">enhanced generators</a> (and <a href="https://www.python.org/dev/peps/pep-0380/" rel="noreferrer"><code>yield from</code></a>) or, added in version 3.5, <a href="https://www.python.org/dev/peps/pep-0492/" rel="noreferrer"><code>async</code> and <code>await</code></a>.</p> <p>How do coroutines in Python compare to those in Lua? Are they also stackful, first-class and asymmetric?</p> <p>Why does Python require so many constructs (<code>async def</code>, <code>async with</code>, <code>async for</code>, <a href="https://www.python.org/dev/peps/pep-0530/" rel="noreferrer">asynchronous comprehensions</a>, ...) for coroutines, while Lua can provide them with just three built-in functions?</p>
0debug
static inline void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs) { #ifdef USE_LIVENESS_ANALYSIS if (!ts->indirect_base) { tcg_debug_assert(ts->val_type == TEMP_VAL_MEM || ts->fixed_reg); return; } #endif temp_sync(s, ts, allocated_regs); temp_dead(s, ts); }
1threat
how to fix the two button center and right side? im expecting the best answer without using "dp".please guide me : I'm creating login form and i would like to give back button as center and red button at right side. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/back" android:textColor="@color/white" android:id="@+id/button4" android:onClick="onBackClick" android:background="@color/l_green"/> <View android:layout_width="@dimen/activity_horizontal_margin" android:layout_height="match_parent"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/reg" android:textColor="@color/white" android:minWidth="130dp" android:id="@+id/button3" android:onClick="onSigninClick" android:background="@color/l_blue"/>
0debug
static int handle_packets(MpegTSContext *ts, int nb_packets) { AVFormatContext *s = ts->stream; uint8_t packet[TS_PACKET_SIZE]; int packet_num, ret = 0; if (avio_tell(s->pb) != ts->last_pos) { int i; av_dlog("Skipping after seek\n"); for (i = 0; i < NB_PID_MAX; i++) { if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) { PESContext *pes = ts->pids[i]->u.pes_filter.opaque; av_freep(&pes->buffer); ts->pids[i]->last_cc = -1; pes->data_index = 0; pes->state = MPEGTS_SKIP; } } } ts->stop_parse = 0; packet_num = 0; for(;;) { if (ts->stop_parse>0) break; packet_num++; if (nb_packets != 0 && packet_num >= nb_packets) break; ret = read_packet(s, packet, ts->raw_packet_size); if (ret != 0) break; ret = handle_packet(ts, packet); if (ret != 0) break; } ts->last_pos = avio_tell(s->pb); return ret; }
1threat
AWS API Gateway MTLS client auth : <p>Everytime I searched for <strong>Mutual Auth over SSL</strong> for <strong>AWS API Gateway</strong> I can only find MTLS between AWS API Gateway and Backend Services. But I'm looking to secure my AWS API Gateway endpoints itself with <strong>MTLS (client auth)</strong>. </p> <p>For instance, I have a backed service QueryCustomer which I have proxied through AWS API Gateway. Now I can put an SSL Cert on API Gateway but it's usual 1-way SSL. What I want to achieve is to have an MTLS with client auth where the consumer of APIs from AWS API Gateway first have to exchange their public certificates which we configure on the <strong>AWS truststores</strong> and AWS public certificates will be stored on API consumer end as well. </p> <p>Now during the handshake as with other API Gateways and application servers should there be a property which says something like this AWS API Gateway endpoint '<strong>requires client auth</strong>' so that only if API consumer's public cert is in API Gateway truststore should be authenticated to access the endpoint, otherwise just throw normal SSL handshake error.</p> <p>Can someone advise if this is achievable on AWS API Gateway?</p>
0debug
static int latm_decode_frame(AVCodecContext *avctx, void *out, int *got_frame_ptr, AVPacket *avpkt) { struct LATMContext *latmctx = avctx->priv_data; int muxlength, err; GetBitContext gb; init_get_bits(&gb, avpkt->data, avpkt->size * 8); if (get_bits(&gb, 11) != LOAS_SYNC_WORD) return AVERROR_INVALIDDATA; muxlength = get_bits(&gb, 13) + 3; if (muxlength > avpkt->size) return AVERROR_INVALIDDATA; if ((err = read_audio_mux_element(latmctx, &gb)) < 0) return err; if (!latmctx->initialized) { if (!avctx->extradata) { *got_frame_ptr = 0; return avpkt->size; } else { push_output_configuration(&latmctx->aac_ctx); if ((err = decode_audio_specific_config( &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.oc[1].m4ac, avctx->extradata, avctx->extradata_size*8, 1)) < 0) { pop_output_configuration(&latmctx->aac_ctx); return err; } latmctx->initialized = 1; } } if (show_bits(&gb, 12) == 0xfff) { av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "ADTS header detected, probably as result of configuration " "misparsing\n"); return AVERROR_INVALIDDATA; } if ((err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb)) < 0) return err; return muxlength; }
1threat
URI-based Versioning for AWS API Gateway : <p>I am struggling to understand how AWS API Gateway wants me to organise my APIs such that versioning is straightforward. For example, let's say I have a simple API for getting words from a dictionary, optionally filtering the results by a query parameter. I'd like to have v1 of this be available at:</p> <pre><code>https://&lt;my-domain&gt;/v1/names?starts-with=&lt;value&gt; </code></pre> <p>However, the closest I can get API Gateway is at</p> <pre><code>https://&lt;my-domain&gt;/names/v1?starts-with=&lt;value&gt; </code></pre> <p>... which is quite backwards.</p> <p>What I've got in the console is "Names API" with a "v1" resource supporting a GET method. I also have my custom domain setup to map a base path of "names" to "Names API" and stage "test". The Base path must be unique so putting "v1" there is only a short-term win; once I create my second API (e.g. Numbers API) it'll have a v1, too, and I won't be able to create a second mapping.</p> <p>Any and all help is greatly appreciated as I'm out of ideas now.</p>
0debug
Is it possible "extend" ThemeData in Flutter : <p>I might very well be missing something as I'm so new to flutter, but I'm finding ThemeData's options very limited (at least with my understanding of how to implement it). </p> <p>If you look at this random design below from MaterialUp, I'd want to model something <em>roughly</em> like: </p> <p><code> Themedata.cyclingColor = Color.pink; ThemeData.runningColor = Color.green; </code></p> <p>That way everywhere in my app I can reference cycling, running, swimming, gym colors (Or whatever colors make sense in the context of my app/design) and keep things consistent.</p> <p><a href="https://i.stack.imgur.com/HEgVW.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/HEgVW.jpg" alt="Random design from MaterialUp"></a></p> <p>Is there a recommended way to achieve this currently in Flutter? What are my options? </p>
0debug
Java join() concept : <p>See my code in with <a href="http://collabedit.com/92yma" rel="nofollow">link</a>. My understanding with join concept is that if I created a thread "t2" in main thread. And I am writing like t2.join(). Than first all things under run method of t object will be executed than execution of main thread will be started back. But if I have created one more thread "t1" in main thread before "t2". At that time "t2"'s execution should be done first and than "t1"'s. Correct? But if you see in my linked code. t1 and t2 runs simultaneously. Why is it so? </p>
0debug
Adding business logic to a spring-data-rest application : <p>I have been experimenting with spring-data-rest (SDR) and am really impressed with how quickly I can build a rest api. My application is based around the following repository which gives me GET /attachements and POST /attachements </p> <pre><code>package com.deepskyblue.attachment.repository; import java.util.List; import org.springframework.data.repository.Repository; import com.deepskyblue.attachment.domain.Attachment; public interface AttachmentRepository extends Repository&lt;Attachment, Long&gt; { List&lt;Attachment&gt; findAll(); Attachment save(Attachment attachment); } </code></pre> <p>One thing I am confused about though is how I add custom business logic. SDR seems great if I just want a rest API to my data, however a traditional Spring application would normally have a service tier where I can have business logic. Is there a way of adding this business logic with SDR?</p>
0debug
Swift: print() not working : I started coding on Swift couple days ago. This is my code right here, I can't find what is the problem. When I press button on simulator it doesn't print anything. import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func PressButton(_ sender: UIButton){ print("Something") } }
0debug
Efficiently determining whether a point is inside a triangle or on the edge : **How to determine whether a point lies inside of a triangle or on the edge efficiently, if possible with O(1) time.** Context: - The plane is two dimensional - Triangle is set according to three coordinate pairs `Coord(int x, int y)` - The bounds for coordinates are: [-2,000,000 , 2,000,000 ] - Triangle coordinates are assumed to be a valid triangle mesh - Test point is also an integer. Visual example: [Image link][1] Format example: Triangle a(Coord(50000,50000),Coord(-4000,2000), Coord(300000,150000)); // Point Result a.test_point( 60000, 45000) // G true a.test_point( 289500, 145500) // F true a.test_point( 292000, 146000) // E false a.test_point(-292000,-146000) //-E false a.test_point( 260000, 134000) // D true [1]: https://i.stack.imgur.com/FFhx1.png
0debug
What happens when an object is assigned to a value in c++ : <p>Check the following code:</p> <pre><code>#include&lt;iostream&gt; using namespace std; class example { public: int number; example() { cout&lt;&lt;"1"; number = 1; } example(int value) { cout&lt;&lt;"2"; number = value; } int getNumber() { cout&lt;&lt;"3"; return number; } }; int main() { example e; e = 10; cout&lt;&lt;e.getNumber(); return 0; } </code></pre> <p>What is the output of the above code. Also, I want to know what happens when an object is directly assigned to a value. How will the compiler interpret it?</p>
0debug
what is a rescue image? : I am trying to learn how to make my own os from here:http://wiki.osdev.org/Bare_Bones but somewhere there it says that I have to use the `grub-mkrescue` command. I was doing some research around internet to understand what does that command do and found in the [grub official documentation][1] this sentence: > The program grub-mkrescue generates a bootable GRUB rescue image But I don't know what a rescue image is. [1]: https://www.gnu.org/software/grub/manual/grub/html_node/Invoking-grub_002dmkrescue.html#Invoking-grub_002dmkrescue
0debug
void pvpanic_init(ISABus *bus) { isa_create_simple(bus, TYPE_ISA_PVPANIC_DEVICE); }
1threat
Stop working when running : <p>i wrote this code for my university project but it stop working when i try to run it. can any one please help me where the problem is? i guess its the pointers but i dont know where its wrong for t and z if u want to try it use 20 and 5 and when i enter them it stop working instead of giving me outputs it should give 2 .txt file including some numbers</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; int main() { int t; int z; double deltaz; double deltat; double beta; double mv=0; ofstream out1("Time-setllment.txt"); ofstream out2("isochrones.txt"); cout&lt;&lt;"Enter time step(&gt;9&amp;integer only):"; cin&gt;&gt;t; cout&lt;&lt;endl&lt;&lt;"Enter height step(integer only):"; cin&gt;&gt;z; cout&lt;&lt;endl; double **u = new double * [z+1]; for (int i=0;i&lt;z;i++) u[i]=new double [t+1]; double *s = new double [t+1]; mv = (0.00000003*365*24*3600)/(2*10); deltaz = 20/z; deltat = 50/t; beta = (2*deltat)/(deltaz*deltaz); if (beta&gt;0.5) cout&lt;&lt;"Beta is more than 0.5 :|"&lt;&lt;endl; else { for (int i=0;i&lt;z+1;i++) { if (i==0 || i==z) { for (int j=0;j&lt;t+1;j++) u[i][j] = 0; } else { u[i][0]=70-3.5*(i*deltaz); } } for (int j=1;j&lt;t;j++) { for (int i=1;i&lt;z;i++) { u[i][j] = u[i][j-1]+beta*(u[i-1][j-1]+u[i+1][j-1]-2*u[i][j-1]); } } for (int j=1;j&lt;t+1;j++) { double sigmau=0; for (int i=1;i&lt;z;i++) { sigmau +=u[i][j]; } s[j]=mv*(35*20-deltaz*((u[0][j]+u[z][j])/2+sigmau)); } out1&lt;&lt;"Time \t Settlment \n"; for (int j=1;j&lt;t+1;j++) { out1&lt;&lt;j*deltat&lt;&lt;"\t"&lt;&lt;s[j]&lt;&lt;"\n"; } out2&lt;&lt;"Depth \t"; for (int j=0;j&lt;t+1;j++) { out2&lt;&lt;"t(year)="&lt;&lt;j*deltat&lt;&lt;"\t"; } out2&lt;&lt;"\n"; for (int i=0;i&lt;z+1;i++) { out2&lt;&lt;i*deltaz&lt;&lt;"\t"; for (int j=0;j&lt;t+1;j++) { out2&lt;&lt;u[i][j]&lt;&lt;"\t"; } } for (int i=0;i&lt;z+1;i++) delete []u[i]; delete []u; delete []s; } return 0; } </code></pre>
0debug
VLANState *qemu_find_vlan(int id, int allocate) { VLANState **pvlan, *vlan; for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { if (vlan->id == id) return vlan; } if (!allocate) { return NULL; } vlan = qemu_mallocz(sizeof(VLANState)); vlan->id = id; TAILQ_INIT(&vlan->send_queue); vlan->next = NULL; pvlan = &first_vlan; while (*pvlan != NULL) pvlan = &(*pvlan)->next; *pvlan = vlan; return vlan; }
1threat
float32 int64_to_float32( int64 a STATUS_PARAM ) { flag zSign; uint64 absA; int8 shiftCount; if ( a == 0 ) return 0; zSign = ( a < 0 ); absA = zSign ? - a : a; shiftCount = countLeadingZeros64( absA ) - 40; if ( 0 <= shiftCount ) { return packFloat32( zSign, 0x95 - shiftCount, absA<<shiftCount ); } else { shiftCount += 7; if ( shiftCount < 0 ) { shift64RightJamming( absA, - shiftCount, &absA ); } else { absA <<= shiftCount; } return roundAndPackFloat32( zSign, 0x9C - shiftCount, absA STATUS_VAR ); } }
1threat
How to sort results in PHP? : <pre><code> foreach($domainCheckResults as $domainCheckResult) { switch($domainCheckResult-&gt;status) { case Transip_DomainService::AVAILABILITY_INYOURACCOUNT: $result .= "&lt;p style='color:red;'&gt;".$domainCheckResult-&gt;domainName."&lt;/p&gt;"; break; case Transip_DomainService::AVAILABILITY_UNAVAILABLE: $result .= "&lt;p style='color:red;'&gt;".$domainCheckResult-&gt;domainName."&lt;/p&gt;"; break; case Transip_DomainService::AVAILABILITY_FREE: $result .= "&lt;p style='color:#1aff1a;'&gt;".$domainCheckResult-&gt;domainName." "."&lt;a href='ticket.php'&gt;&lt;img src='img/next.png' alt='house' width='20' height='20' align='right' title='domein aanvragen?'&gt;&lt;/a&gt;"."&lt;/p&gt;"; break; case Transip_DomainService::AVAILABILITY_NOTFREE: $result .= "&lt;p style='color:#ff9933;'&gt;".$domainCheckResult-&gt;domainName." "."&lt;a href='contactform.php'&gt;&lt;img src='img/65.png' alt='house' width='20' height='20' align='right' title='domein laten verhuizen?'&gt;&lt;/a&gt;"."&lt;/p&gt;"; break; } } </code></pre> <p>So I have 4 possible results for domain availability. I have a array with 20 domains and when I get the results I get them in the sorting of my array. But How can I sort is on availability, so the once that are free all at the top and the once that are not free for whatever reason down? What can I use? I used the sort() tag but that won`t help.</p>
0debug
Put keys from dictionary to new list based on other lists : <p>I am a total beginner on python and wondering if this is possible? </p> <pre><code>businessideas = { "DeliDelivery": ['bread'], "Ikea": ['sofa','table'], 'Volvo': ['car','window'], 'saab' : ['window'] } carkeywords = ['car', 'engine'] furniturekeywords = ['sofa', 'bookshell'] bakerykeywords = ['bread', 'flour', 'cookies'] carkeywords_competitors = [] furniturekeywords_competitors = [] bakerykeywords_competitors = [] </code></pre> <p>I want to create a function that puts every dictionary-key in a competitors list if they have a common value. So for an example the key Ikea has the elements sofa and table. Then the function should see that the value sofa is a duplicate to of furniturekeywords elements. Then the funtion should put the key Ikea in the list furniturekeywords_competitors. If it would have the same value as carkeywords the function would have put the key in carkeywords_competitors. </p>
0debug
Getting Java Play framework to cache Ebean entities using memcached : <p>I am running <a href="https://www.playframework.com" rel="noreferrer">Java Play framework</a> version v2.6.1 and using <a href="http://ebean-orm.github.io/" rel="noreferrer">Ebean</a> for persistence. My intention is to get <a href="http://ebean-orm.github.io/docs/features/l2caching/using-bean-cache" rel="noreferrer">bean caching</a> going using <a href="https://github.com/mumoshu/play2-memcached" rel="noreferrer">play2-memcached</a> plugin.</p> <p><strong>What have I done so far?</strong></p> <ul> <li>installed <code>memcached</code> on localhost and enabled verbose logging.</li> <li>replaced <code>ehcache</code> dependency with <code>cacheApi</code> in <code>libraryDependencies</code> in <code>build.sbt</code> (this, I assume, should remove Ehcache completely).</li> <li>added <code>"com.github.mumoshu" %% "play2-memcached-play26" % "0.9.0",</code> to <code>libraryDependencies</code> in <code>build.sbt</code></li> <li>added <code>"Spy Repository" at "http://files.couchbase.com/maven2",</code> to <code>resolvers</code> in <code>build.sbt</code></li> <li>added following entries to application conf:</li> </ul> <p><code>play.modules.disabled += "play.api.cache.ehcache.EhCacheModule" play.modules.enabled+="com.github.mumoshu.play2.memcached.MemcachedModule" play.cache.defaultCache=default play.cache.bindCaches=["db-cache", "user-cache", "session-cache"] memcached.host="127.0.0.1:11211" </code> </p> <ul> <li>took my entity and made it implement <code>Serializable</code>, also added <code>@com.avaje.ebean.annotation.Cache</code> annotation.</li> <li>enabled SQL logging</li> </ul> <p><strong>What works?</strong></p> <ul> <li>loading entity with <code>Entity.find.byId(id)</code> results SQL <code>SELECT</code>. Loading it again with different request results no SQL statements.</li> <li>opening browser to localhost:11211 shows errors in syslog -- this is to make sure memcached is running and I can see requests appearing</li> <li>making memory dump I can see that cache related classes from <code>com.github.mumoshu</code> are loaded.</li> </ul> <p><strong>What doesn't work?</strong></p> <ul> <li>I expect cached objects to be sent to memcached (on read and/or update). This is not happening - there are no memcached logs related to this. Neither there are any connections to port 11211 if I run <code>netstat -na | grep 11211</code>.</li> </ul> <p>Is there anything I'm missing?</p>
0debug
How to fix program that calculates minimum amount of coins in change : I have a homework assignment in which we have to write a program that outputs the change to be given by a vending machine using the lowest number of coins. E.g. £3.67 can be dispensed as 1x£2 + 1x£1 + 1x50p + 1x10p + 1x5p + 1x2p. However, my program is outputting the wrong numbers. I know there will probably be rounding issues, but I think the current issue is to do with my method of coding this. change=float(input("Input change")) twocount=0 onecount=0 halfcount=0 pttwocount=0 ptonecount=0 while change!=0: if change-2>-1: change=change-2 twocount+=1 else: if change-1>-1: change=change-1 onecount+=1 else: if change-0.5>-1: change=change-0.5 halfcount+=1 else: if change-0.2>-1: change=change-0.2 pttwocount+=1 else: if change-0.1>-1: change=change-0.1 ptonecount+=1 else: break print(twocount,onecount,halfcount,pttwocount,ptonecount) RESULTS: Input: 2.3 Output: 11010 i.e. 3.2 Input: 3.2 Output:20010 i.e. 4.2 Input: 2 Output: 10001 i.e. 2.1
0debug
Passing ngFor variable to an ngIf template : <p>How do I pass the current variable in an ngFor loop to ngIf, if it is using templates with then/else syntax?</p> <p>It appears that they pass through fine when used inline, but aren't accessible from a template, for example:</p> <pre><code>&lt;ul *ngFor="let number of numbers"&gt; &lt;ng-container *ngIf="number % 2 == 0; then even_tpl; else odd_tpl"&gt;&lt;&gt;/ng-container&gt; &lt;/ul&gt; &lt;ng-template #odd_tpl&gt; &lt;li&gt;Odd: {{number}}&lt;/li&gt; &lt;/ng-template&gt; &lt;ng-template #even_tpl&gt; &lt;li&gt;Even: {{number}}&lt;/li&gt; &lt;/ng-template&gt; </code></pre> <p>The templates don't seem to have access to <code>number</code> at all, but it works if used inline.</p> <p>A full example of the working and not-working versions in the following link: <a href="https://embed.plnkr.co/yyM6ew/" rel="noreferrer">plunkr</a></p>
0debug
void omap_badwidth_write32(void *opaque, target_phys_addr_t addr, uint32_t value) { OMAP_32B_REG(addr); cpu_physical_memory_write(addr, (void *) &value, 4); }
1threat
Code on generating possible ordered pairs upto a number and finding maximum value of binary operations of the pairs : I got a question at hackerrank which states that , a user should input a larger number (say 5) and a smaller number (say 4) . Then taking each pair from the oerdered list {1,2,3,4,5} , the binary and (&) , binary or(|) and bonary xor(^) are performed . Here , 10 such values of each binary operation are found . The maXIMUM value among the 10 values for a particular operation which is less than 4 , is to be printed . My code is as follows : #include <stdio.h> void main(){ int n,k,i,a,b; printf("ENTER VALUE OF n AND k:"); scanf("%d%d",&n,&k); int Aarr[n*(n-1)/2] , Oarr[n*(n-1)/2], Xarr[n*(n-1)/2]; for(a=1;a<=n;a++){ for(b=a+1;b<n;b++){ for(i=0;i<(n*(n-1)/2);i++){ Aarr[i]=(a&b); } for(i=0;i<(n*(n-1)/2);i++){ Oarr[i]=(a|b); } for(i=0;i<(n*(n-1)/2);i++){ Xarr[i]=(a^b); } } } int Amax=1,Omax=1,Xmax=1; for(i=0;i<(n*(n-1)/2);i++){ if((Aarr[i]>Amax)&&(Aarr[i]<k)){ Amax=Aarr[i]; } } for(i=0;i<(n*(n-1)/2);i++){ if((Oarr[i]>Omax)&&(Oarr[i]<k)){ Omax=Oarr[i]; } } for(i=0;i<(n*(n-1)/2);i++){ if((Xarr[i]>Xmax)&&(Xarr[i]<k)){ Xmax=Xarr[i]; } } printf("\n%d\n%d\n%d",Amax,Omax,Xmax); getchar(); } **EXPECTED OUTPUT:** 2 2 3 **MY OUTPUT:** 1 1 1 My code is run in the **CODE BLOCKS** IDE . The code just produces the values of Amax,Omax and Xmax as defined . I at first tried to find the all the possible ordered pairs and store them in an array . I think the condition applied to find the maximum value of a particular operation is correct . I've done many debuggings and at last have sought your help . I'm new to C programming . So , my code seem to be too long to you . Any help is appreciated , please . Thanks ...
0debug
Angular 4 circle dropdown menu? : I saw this in web.whatsapp.com [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/ZnhtR.png Is there a npm package for angular that make the exact menu? If is not. ¿How can I do it with css?
0debug
how to use apply family to average multiple conditional arguments in R : <p>This is a very large dataset and I'm trying to get away from writing for loops in R. Looking for a way to attack what I would usually use a nested loop to do. </p> <p>For each unique value in the confidence col., I need to extract the row indices for all other rows in the confidence col. that match that value. For example, the first occurrence, (50) would return 1,7,9. Then, using those indices, I want to average the values for the seqs column. Here, the first occurrence (50) would return 1980, 7357, and 3008 and then average these. The indented output would be a data frame with 2 columns: one with a list of unique values for confidence and one with a corresponding list of the average # seqs for each unique confidence value. </p> <h1>input</h1> <pre><code>#seqs confidence 1980 50 1088 52 1099 52 2000 42 7009 45 1092 48 7357 50 5909 42 3008 50 </code></pre> <h1>output</h1> <pre><code>ave.#seqs confidence 4115 50 1093.5 52 3954.5 42... </code></pre>
0debug
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { AVFilterContext *ctx = inlink->dst; TileContext *tile = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; if (tile->current) return 0; outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outlink->out_buf, picref); outlink->out_buf->video->w = outlink->w; outlink->out_buf->video->h = outlink->h; if (tile->margin || tile->padding) ff_fill_rectangle(&tile->draw, &tile->blank, outlink->out_buf->data, outlink->out_buf->linesize, 0, 0, outlink->w, outlink->h); return 0; }
1threat
how can I get the lattitude and longitude of someone in android as I just start working on android : actually I want to calculate distance between two user's coordinates .Is there anywhere that would be a good place for me to start with GPS feature on Android, or that has a good example of how to use GPS? I don't want anything deep, literally just how to retrieve and use current GPS coordinates. I'd like to start simple and build up from there.
0debug
Android Navigation Architecture Component: How to pass bundle data to startDestination : <p>I have an activity which has a <code>NavHostFragment</code>. The activity receives certain values in its intent. I want to pass this data to the first fragment i.e <code>startDestination</code> of the navigation graph. I couldn't find any documentation regarding this.</p> <p>I have already gone through <a href="https://stackoverflow.com/questions/50334550/navigation-architecture-component-passing-argument-data-to-the-startdestination">this question on SO</a> but I can't seem to find the <code>addDefaultArguments</code> method for <code>navController.getGraph()</code>.</p> <p>Is it possible to pass bundle to <code>startDestination</code>?</p>
0debug
Missing a using directive or an assembly reference for .ToList() : <p>I have this code in the class constructor.</p> <pre><code>this._images = images.Split('#').ToList(); </code></pre> <p>It has always worked, but now it gives this error:</p> <blockquote> <p>Error CS1061 'string[]' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?).</p> </blockquote> <p>What can I do to make it work?</p>
0debug
How to create playstore like shapes : <p><a href="https://i.stack.imgur.com/ymHW0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ymHW0.png" alt="Playstore like shapes"></a></p> <p>How to create these download, rating , Media &amp; Video and similar kind of shapes in android ? Is there any library available to do that ?</p> <p>Thanks in advance.</p>
0debug
How to blur google map with css : <p>I'm making a semi-transparent panel to overlay on my map, and I thought blurring the map underneath it would be a neat effect. I tried using CSS filters, namely <code>filter: blur(5px);</code>, however this only blurred the contents of the panel, not the map beneath it.</p> <p>Does anyone know of a way to achieve this effect?</p> <p>(Picture of simple div panel with no blurring, yet)</p> <p><a href="https://i.stack.imgur.com/0lDkQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0lDkQ.png" alt="Not blurred"></a></p>
0debug
jquery selector not returning array : <p>I thought jquery was returning an array when selecting something. But it does not look like that:</p> <p>With this html:</p> <pre><code>&lt;p&gt;A&lt;/p&gt; &lt;p&gt;B&lt;/p&gt; &lt;p&gt;C&lt;/p&gt; </code></pre> <p>And this js:</p> <pre><code>var p = $('p'); console.log(Array.isArray(p)); // result is false </code></pre> <p><a href="https://jsfiddle.net/xpvt214o/413986/" rel="nofollow noreferrer">See JSFiddle</a> Then the selected paragraphs are not in an array. Why is that?</p>
0debug
How do i restructure following code? : <p>I want to create an json structure with data which will get from an api call. I can generate the structure by using following code. But how can I restructure the code to remove nested call of function and loops.</p> <pre><code> var temp = { applications: [] }; api.getApplications(conceptId) .then((applications) =&gt; { for (var i = 0; i &lt; applications.length; i++) { (function(indexOfAppArr) { let applicationId = applications[indexOfAppArr].id; temp.applications.push({ id: applicationId, databases: [] }); api.getDbs(conceptId, applicationId) .then(databases =&gt; { for (var j = 0; j &lt; databases.length; j++) { (function(indexOfDatabasArr) { let databaseid = databases[indexOfDatabasArr].id; temp.applications[indexOfAppArr].databases.push({ id: databaseid, tabels: [] }); api. getSchema(conceptId, applicationId, databaseid). then(function(schemas) { for (var k = 0; k &lt; schemas.length; k++) { (function(indexofschemaarr) { let schemaid = schemas[indexofschemaarr].id; api.getTable(conceptId, schemaid) .then(function(tables) { console.log(tables); }) })(k) } }) })(j) } }) })(i) } }) </code></pre> <p>Here is the JSON structure which i want to create.</p> <pre><code> { applications:[{ id:'', databases:[{ id:'', tabels:[ { id:'', columnId:'' } ] }] }] }; </code></pre>
0debug
IOS Swift to retrieve data liner from webpage : Need help here.. my webpage displays a constructive data in a single line, specifically to let xcode to retrieve it. [{"long":"1234..45","lat":"345.12"}] this information is in a page Click here to see "www.gogrex.com/Sandbox/startloc.json" How do I retrieve it into my xcode as a JSON? I have looked thru many examples but still cannot solve it. thanks a million
0debug