problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps,
struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *flags,
vpx_img_fmt_t *img_fmt)
{
VPxContext av_unused *ctx = avctx->priv_data;
#ifdef VPX_IMG_FMT_HIGHBITDEPTH
enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
#endif
switch (avctx->pix_fmt) {
case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUVA420P:
enccfg->g_profile = 0;
*img_fmt = VPX_IMG_FMT_I420;
return 0;
case AV_PIX_FMT_YUV422P:
enccfg->g_profile = 1;
*img_fmt = VPX_IMG_FMT_I422;
return 0;
#if VPX_IMAGE_ABI_VERSION >= 3
case AV_PIX_FMT_YUV440P:
enccfg->g_profile = 1;
*img_fmt = VPX_IMG_FMT_I440;
return 0;
case AV_PIX_FMT_GBRP:
ctx->vpx_cs = VPX_CS_SRGB;
#endif
case AV_PIX_FMT_YUV444P:
enccfg->g_profile = 1;
*img_fmt = VPX_IMG_FMT_I444;
return 0;
#ifdef VPX_IMG_FMT_HIGHBITDEPTH
case AV_PIX_FMT_YUV420P10:
case AV_PIX_FMT_YUV420P12:
if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
enccfg->g_bit_depth = enccfg->g_input_bit_depth =
avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
enccfg->g_profile = 2;
*img_fmt = VPX_IMG_FMT_I42016;
*flags |= VPX_CODEC_USE_HIGHBITDEPTH;
return 0;
}
break;
case AV_PIX_FMT_YUV422P10:
case AV_PIX_FMT_YUV422P12:
if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
enccfg->g_bit_depth = enccfg->g_input_bit_depth =
avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12;
enccfg->g_profile = 3;
*img_fmt = VPX_IMG_FMT_I42216;
*flags |= VPX_CODEC_USE_HIGHBITDEPTH;
return 0;
}
break;
#if VPX_IMAGE_ABI_VERSION >= 3
case AV_PIX_FMT_YUV440P10:
case AV_PIX_FMT_YUV440P12:
if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
enccfg->g_bit_depth = enccfg->g_input_bit_depth =
avctx->pix_fmt == AV_PIX_FMT_YUV440P10 ? 10 : 12;
enccfg->g_profile = 3;
*img_fmt = VPX_IMG_FMT_I44016;
*flags |= VPX_CODEC_USE_HIGHBITDEPTH;
return 0;
}
break;
case AV_PIX_FMT_GBRP10:
case AV_PIX_FMT_GBRP12:
ctx->vpx_cs = VPX_CS_SRGB;
#endif
case AV_PIX_FMT_YUV444P10:
case AV_PIX_FMT_YUV444P12:
if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
enccfg->g_bit_depth = enccfg->g_input_bit_depth =
avctx->pix_fmt == AV_PIX_FMT_YUV444P10 ||
avctx->pix_fmt == AV_PIX_FMT_GBRP10 ? 10 : 12;
enccfg->g_profile = 3;
*img_fmt = VPX_IMG_FMT_I44416;
*flags |= VPX_CODEC_USE_HIGHBITDEPTH;
return 0;
}
break;
#endif
default:
break;
}
av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
return AVERROR_INVALIDDATA;
}
| 1threat |
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
AVDictionary *opts, AVDictionary *opts2)
{
HLSContext *c = s->priv_data;
AVDictionary *tmp = NULL;
const char *proto_name = avio_find_protocol_name(url);
int ret;
av_dict_copy(&tmp, opts, 0);
av_dict_copy(&tmp, opts2, 0);
if (!proto_name)
return AVERROR_INVALIDDATA;
if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL))
return AVERROR_INVALIDDATA;
if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
;
else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
return AVERROR_INVALIDDATA;
ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);
if (ret >= 0) {
void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb;
update_options(&c->cookies, "cookies", u);
av_dict_set(&opts, "cookies", c->cookies, 0);
}
av_dict_free(&tmp);
return ret;
}
| 1threat |
Convert Javascript number to two decimal places : <p>I know there have been many threads on this topic but none seem to answer my question directly. I want to convert a number to two decimal places no matter the length. So 0.5 should turn into 0.50, and 5.3145 should go to 5.31. Most importantly, I also need to keep the number as a number datatype. I know toFixed(2) will create two decimal places, but this also turns the number into a string. If I wrap the toFixed(2) with a parseInt function (e.g. parseInt(amount.toFixed(2))) then 0.5 seems to be converted to "0.50", and then back to 0.5 with out the trailing zero. Adding a second layer of parentheses doesn't solve the problem either. Any ideas?? Thank you in advance!</p>
| 0debug |
How to bypass keyboard input verification using JS : Example
<textarea id="keystroke-auth-textarea" data-js="keystroke-auth-input" spellcheck="false" class="c-keystroke-auth-textarea"></textarea>
[enter image description here][1]
[1]: http://i.stack.imgur.com/voqxF.png | 0debug |
why does this code segment System.out.print('a'+' '); print 129? : <p>why does this code segment System.out.print('a'+' '); print 129?</p>
<pre><code>void main()
{
System.out.print('a'+' ');
}
</code></pre>
| 0debug |
Where is Visual Studio storing Publish Profiles? : <p>I have a corrupted Publish profile. </p>
<p>I need to delete it. My other computer is fine, so I know it is local.</p>
<p>I have tried:</p>
<ol>
<li><p>Clean checkout of codebase from Git (so nothing is local in my code directories).</p></li>
<li><p>Deleting <code>C:/Users/<user>/AppData/Local/VisualStudio</code></p></li>
<li>Deleting <code>C:/Users/<user>/AppData/Roaming/VisualStudio</code></li>
<li>Full text search of Profile Name 'MunicipalAgenda' through Registry</li>
<li>Full Text search through machine. </li>
<li>Creation of a new Windows User for Visual Studio Development.</li>
</ol>
<p>Despite all of this, VS.NET is hanging onto that corrupted Publish profile.</p>
<p>Honestly I am at wits' end, and my next drastic step is to do a fresh reinstall of Windows 10. <strong>Please help before it comes to that!!!</strong></p>
<p><a href="https://i.stack.imgur.com/AH6nK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AH6nK.png" alt="enter image description here"></a></p>
| 0debug |
static int raw_open_common(BlockDriverState *bs, QDict *options,
int bdrv_flags, int open_flags, Error **errp)
{
BDRVRawState *s = bs->opaque;
QemuOpts *opts;
Error *local_err = NULL;
const char *filename = NULL;
const char *str;
BlockdevAioOptions aio, aio_default;
int fd, ret;
struct stat st;
OnOffAuto locking;
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
filename = qemu_opt_get(opts, "filename");
ret = raw_normalize_devicepath(&filename);
if (ret != 0) {
error_setg_errno(errp, -ret, "Could not normalize device path");
aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO)
? BLOCKDEV_AIO_OPTIONS_NATIVE
: BLOCKDEV_AIO_OPTIONS_THREADS;
aio = qapi_enum_parse(&BlockdevAioOptions_lookup,
qemu_opt_get(opts, "aio"),
aio_default, &local_err);
s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
locking = qapi_enum_parse(&OnOffAuto_lookup,
qemu_opt_get(opts, "locking"),
ON_OFF_AUTO_AUTO, &local_err);
switch (locking) {
case ON_OFF_AUTO_ON:
s->use_lock = true;
if (!qemu_has_ofd_lock()) {
fprintf(stderr,
"File lock requested but OFD locking syscall is "
"unavailable, falling back to POSIX file locks.\n"
"Due to the implementation, locks can be lost "
"unexpectedly.\n");
break;
case ON_OFF_AUTO_OFF:
s->use_lock = false;
break;
case ON_OFF_AUTO_AUTO:
s->use_lock = qemu_has_ofd_lock();
break;
default:
abort();
s->open_flags = open_flags;
raw_parse_flags(bdrv_flags, &s->open_flags);
s->fd = -1;
fd = qemu_open(filename, s->open_flags, 0644);
if (fd < 0) {
ret = -errno;
error_setg_errno(errp, errno, "Could not open '%s'", filename);
if (ret == -EROFS) {
ret = -EACCES;
s->fd = fd;
s->lock_fd = -1;
if (s->use_lock) {
fd = qemu_open(filename, s->open_flags);
if (fd < 0) {
ret = -errno;
error_setg_errno(errp, errno, "Could not open '%s' for locking",
filename);
qemu_close(s->fd);
s->lock_fd = fd;
s->perm = 0;
s->shared_perm = BLK_PERM_ALL;
#ifdef CONFIG_LINUX_AIO
if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) {
error_setg(errp, "aio=native was specified, but it requires "
"cache.direct=on, which was not specified.");
#else
if (s->use_linux_aio) {
error_setg(errp, "aio=native was specified, but is not supported "
"in this build.");
#endif
s->has_discard = true;
s->has_write_zeroes = true;
bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP;
if ((bs->open_flags & BDRV_O_NOCACHE) != 0) {
s->needs_alignment = true;
if (fstat(s->fd, &st) < 0) {
ret = -errno;
error_setg_errno(errp, errno, "Could not stat file");
if (S_ISREG(st.st_mode)) {
s->discard_zeroes = true;
s->has_fallocate = true;
if (S_ISBLK(st.st_mode)) {
#ifdef BLKDISCARDZEROES
unsigned int arg;
if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) {
s->discard_zeroes = true;
#endif
#ifdef __linux__
if (!(bs->open_flags & BDRV_O_NOCACHE)) {
s->discard_zeroes = false;
s->has_write_zeroes = false;
#endif
#ifdef __FreeBSD__
if (S_ISCHR(st.st_mode)) {
s->needs_alignment = true;
#endif
#ifdef CONFIG_XFS
if (platform_test_xfs_fd(s->fd)) {
s->is_xfs = true;
#endif
ret = 0;
fail:
if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
unlink(filename);
qemu_opts_del(opts);
return ret; | 1threat |
AWS CodePipeline, build failed & getting error as YAML_FILE_ERROR M : <p>I'm new to AWS CodePipeline and never had past experience with any continuous integration tool like Jenkins, etc. I have created a new AWS CodePipeline <strong>as AWS CodeCommit (Code repository) -> CodeBuild (not docker, and environment is NodeJS 7)-> AWS CodeDeploy.</strong> Everything is on AWS only. It is an Angular2 project which is running finally deployed on EC2 instances (Windows server 2008). From my local machine, I'm able to commit my code to AWS CodeCommit through active IAM user (Git access) and then I can see CodePipleline starts functioning where Source is fine (green in color) but next step i.e. Build fails (red in color). When I click on its details, I can see following error log :-</p>
<p><a href="https://forums.aws.amazon.com/" rel="noreferrer">https://forums.aws.amazon.com/</a> 2016/12/23 18:21:16 Waiting for agent
<a href="https://forums.aws.amazon.com/" rel="noreferrer">https://forums.aws.amazon.com/</a> 2016/12/23 18:21:36 Phase is DOWNLOAD_SOURCE
<a href="https://forums.aws.amazon.com/" rel="noreferrer">https://forums.aws.amazon.com/</a> 2016/12/23 18:21:38 Phase complete: DOWNLOAD_SOURCE Success: false
<strong><a href="https://forums.aws.amazon.com/" rel="noreferrer">https://forums.aws.amazon.com/</a> 2016/12/23 18:21:38 Phase context status code: YAML_FILE_ERROR Message: YAML file does not exist
<a href="https://forums.aws.amazon.com/" rel="noreferrer">https://forums.aws.amazon.com/</a> 2016/12/23 18:21:38 Runtime error (YAML file does not exist)</strong></p>
<p>Can somebody please guide me on this error? I do not know what does this YAML file means. I googled but nothing relevant found in terms of my NodeJS Angular project.</p>
<p>Thank you,
Vinod Kumar</p>
| 0debug |
Regex: how to check string contains blocks separated by commas : <p>I need to validate an input field, which should contains blocks separated by commas,and maximum is 50 blocks, each block must be 8 characters long, only number and letter be allowed.</p>
<p>Examples: 1F223142,23FH2324,3232UD23</p>
<p>I searched but I cannot find a matching one, so how should my regex be ? </p>
| 0debug |
Flipping a plot 180 degrees in R : <p>I was wondering if there is a way to <strong>flip the below plot 180 degrees in R?</strong></p>
<pre><code>par(pin=c(7,.5))
curve(dnorm(x), -3, 3, bty="n", ann=F, axes=F)
axis(1, mgp=c(1, -.35, 0), tcl=F )
</code></pre>
| 0debug |
Could not set unknown property 'useAndroidX' for object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension : <p>I want to add a library that i've found on github but it required androidx.I found out that i should put these:</p>
<pre><code>android.useAndroidX=true
android.enableJetifier=true
</code></pre>
<p>here</p>
<pre><code>defaultConfig {
applicationId "com.kolydas.greeksinbrno"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
android.useAndroidX=true
android.enableJetifier=true
}
</code></pre>
<p>But i got this error</p>
<blockquote>
<p>Could not set unknown property 'useAndroidX' for object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.</p>
</blockquote>
| 0debug |
void memory_region_init_iommu(MemoryRegion *mr,
Object *owner,
const MemoryRegionIOMMUOps *ops,
const char *name,
uint64_t size)
{
memory_region_init(mr, owner, name, size);
mr->iommu_ops = ops,
mr->terminates = true;
notifier_list_init(&mr->iommu_notify);
}
| 1threat |
How to treat a section of a list as one number in python? : <p>For example in x = [0, 1, 2, 3, 4, 5, 6] if I then wanted to use digits x[0, 1, 2, 3] as 0123 how would I do it?</p>
| 0debug |
real_parse_asm_rulebook(AVFormatContext *s, AVStream *orig_st,
const char *p)
{
const char *end;
int n_rules, odd = 0;
AVStream *st;
if (*p == '\"') p++;
for (n_rules = 0; s->nb_streams < MAX_STREAMS;) {
if (!(end = strchr(p, ';')))
break;
if (!odd && end != p) {
if (n_rules > 0)
st = add_dstream(s, orig_st);
else
st = orig_st;
real_parse_asm_rule(st, p, end);
n_rules++;
}
p = end + 1;
odd ^= 1;
}
}
| 1threat |
Excel Date format to number in JAVA : <p>I have a question:</p>
<p>I have the current date in a cell with date format like:</p>
<pre><code>5/12/2018
</code></pre>
<p>When I formatting this cell to a number (right click -> cell format -> number), I got this:</p>
<pre><code>43439,67
</code></pre>
<p>How can I get this number in Java? I tried:</p>
<pre><code>Date fecha = new Date();
System.out.println(fecha.getTime());
</code></pre>
<p>The result was:</p>
<pre><code>1544043888569
</code></pre>
| 0debug |
How to parcelable object : <p>I am trying to learn parcelable .Earlier I was using get and set function but now I am using parcelable to pass the object to other class I made the passdata class and implemented the parcelable but how I can add the list to the class object.</p>
<pre><code>class Passdata implements Parcelable {
private String title,album;
private long duration;
private Uri data,album_art;
public String getTitle() {
return title;
}
void setTitle(String title) {
this.title = title;
}
public String getAlbum() {
return album;
}
void setAlbum(String album) {
this.album = album;
}
public long getDuration() {
return duration;
}
void setDuration(long duration) {
this.duration = duration;
}
public Uri getData() {
return data;
}
void setData(Uri data) {
this.data = data;
}
public Uri getAlbum_art() {
return album_art;
}
void setAlbum_art(Uri album_art) {
this.album_art = album_art;
}
Passdata(Parcel in) {
title = in.readString();
album = in.readString();
duration = in.readLong();
data = in.readParcelable(Uri.class.getClassLoader());
album_art = in.readParcelable(Uri.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeString(album);
dest.writeLong(duration);
dest.writeParcelable(data, flags);
dest.writeParcelable(album_art, flags);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Passdata> CREATOR = new Creator<Passdata>() {
@Override
public Passdata createFromParcel(Parcel in) {
return new Passdata(in);
}
@Override
public Passdata[] newArray(int size) {
return new Passdata[size];
}
};
}
</code></pre>
<p>how can I add the object like this</p>
<pre><code> do {
int audioTitle = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
int audioartist = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
int audioduration = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
int audiodata = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
int audioalbum = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
int audioalbumid = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
Passdata info = new Passdata();
info.setData(Uri.parse(audioCursor.getString(audiodata)));
info.setTitle(audioCursor.getString(audioTitle));
info.setDuration(audioCursor.getLong(audioduration));
// info.setArtist(audioCursor.getString(audioartist));
info.setAlbum(audioCursor.getString(audioalbum));
info.setAlbum_art(ContentUris.withAppendedId(albumArtUri, audioCursor.getLong(audioalbumid)));
audioList.add(info);
}
</code></pre>
<p>I am getting error in the place were I am creating the passdata object
how to fix this??</p>
| 0debug |
static void vpb_sic_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
k->init = vpb_sic_init;
dc->no_user = 1;
dc->vmsd = &vmstate_vpb_sic;
}
| 1threat |
static void pcnet_aprom_writeb(void *opaque, uint32_t addr, uint32_t val)
{
PCNetState *s = opaque;
#ifdef PCNET_DEBUG
printf("pcnet_aprom_writeb addr=0x%08x val=0x%02x\n", addr, val);
#endif
if (pcnet_bcr_readw(s,2) & 0x100)
s->prom[addr & 15] = val;
}
| 1threat |
static void pixel_format_message (VncState *vs) {
char pad[3] = { 0, 0, 0 };
vnc_write_u8(vs, vs->depth * 8);
if (vs->depth == 4) vnc_write_u8(vs, 24);
else vnc_write_u8(vs, vs->depth * 8);
#ifdef WORDS_BIGENDIAN
vnc_write_u8(vs, 1);
#else
vnc_write_u8(vs, 0);
#endif
vnc_write_u8(vs, 1);
if (vs->depth == 4) {
vnc_write_u16(vs, 0xFF);
vnc_write_u16(vs, 0xFF);
vnc_write_u16(vs, 0xFF);
vnc_write_u8(vs, 16);
vnc_write_u8(vs, 8);
vnc_write_u8(vs, 0);
vs->send_hextile_tile = send_hextile_tile_32;
} else if (vs->depth == 2) {
vnc_write_u16(vs, 31);
vnc_write_u16(vs, 63);
vnc_write_u16(vs, 31);
vnc_write_u8(vs, 11);
vnc_write_u8(vs, 5);
vnc_write_u8(vs, 0);
vs->send_hextile_tile = send_hextile_tile_16;
} else if (vs->depth == 1) {
vnc_write_u16(vs, 7);
vnc_write_u16(vs, 7);
vnc_write_u16(vs, 3);
vnc_write_u8(vs, 5);
vnc_write_u8(vs, 2);
vnc_write_u8(vs, 0);
vs->send_hextile_tile = send_hextile_tile_8;
}
vs->client_red_max = vs->server_red_max;
vs->client_green_max = vs->server_green_max;
vs->client_blue_max = vs->server_blue_max;
vs->client_red_shift = vs->server_red_shift;
vs->client_green_shift = vs->server_green_shift;
vs->client_blue_shift = vs->server_blue_shift;
vs->pix_bpp = vs->depth * 8;
vs->write_pixels = vnc_write_pixels_copy;
vnc_write(vs, pad, 3);
}
| 1threat |
python3 absolute import error : I meet a problem in python3 absolute import, here is my project structure:
`
-project_dir
-src
__init__.py
index.py
-handler
__init__.py
base_handler.py
`
in `index.py` I import `base_handler.BaseHandler` like this:
`from src.handler.base_handler import BaseHandler`
and an error occurs:
`ModuleNotFoundError: No module named 'src'`
The strange thing is, when I move `index.py` out of `src` folder, this error whill disappear:
`
-project_dir
index.py
-src
__init__.py
-handler
__init__.py
base_handler.py
`
Now in `index.py` I can import `BaseHanlder` like this:
`from src.handler.base_handler import BaseHandler`
anyone can tell me why this happens? thx
| 0debug |
Auto Generate alphanumeric Unique Id with C# with sql server : Need to create employee record based on branch
I have a scenario, where if branch combo box value is selected xyz branch then
ID starts with XYZ-0001
if combo box value is selected abc branch then
ID starts with ABC-0001 and then so on
Please suggest any idea on how to create this format. | 0debug |
static void emulate_spapr_hypercall(CPUPPCState *env)
{
env->gpr[3] = spapr_hypercall(env, env->gpr[3], &env->gpr[4]);
}
| 1threat |
static bool memory_region_dispatch_write(MemoryRegion *mr,
hwaddr addr,
uint64_t data,
unsigned size)
{
if (!memory_region_access_valid(mr, addr, size, true)) {
unassigned_mem_write(mr, addr, data, size);
return true;
}
adjust_endianness(mr, &data, size);
if (mr->ops->write) {
access_with_adjusted_size(addr, &data, size,
mr->ops->impl.min_access_size,
mr->ops->impl.max_access_size,
memory_region_write_accessor, mr);
} else {
access_with_adjusted_size(addr, &data, size, 1, 4,
memory_region_oldmmio_write_accessor, mr);
}
return false;
}
| 1threat |
how to check memeber of structure is empty if a vector is defined of structure type :
struct A { int rollno; int emplyno; };
------------------------------------------------------------------------
int main() { vector<A> obj; obj.push_back({10,112}); if (obj.rollno ==0) // error { cout<<"rollno is empty"<<endl; } } | 0debug |
static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIDiskReq *r;
r = scsi_find_request(s, tag);
if (!r) {
BADF("Bad buffer tag 0x%x\n", tag);
return NULL;
}
return (uint8_t *)r->iov.iov_base;
}
| 1threat |
Style both parent and child element in css : <p>I have the following structure...</p>
<pre><code><a href="#" class="brand-logo">
<img src="../static/images/logo_wpc-sm.png" alt="WPC Logo" class="wpc-logo"/>
</a>
</code></pre>
<p>And I have the following css code...</p>
<pre><code>.brand-logo {
height: 100%;
}
.wpc-logo {
height: 100%;
}
</code></pre>
<p>My question: It is a way I can style both in one css code?</p>
| 0debug |
Save Screenshot option is missing in Android Studio 3.1 : <p>I have updated android studio from 3.0.1 to 3.1,now there is no option for directly view the XML file
in Android studio 3.0.1 there is option for Save Screenshot
<a href="https://i.stack.imgur.com/CNLo7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CNLo7.png" alt="enter image description here"></a></p>
<p>Now in update android studio version to 3.1,it's missing</p>
<p><a href="https://i.stack.imgur.com/rgXiR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rgXiR.png" alt="enter image description here"></a></p>
<p>is it moved to any other place?</p>
| 0debug |
Python battleship game index out of range error (BEGINNER) : I just started coding about a week ago. I'm trying to code a very simple battleship game. Its doing what I want it to do, but I get an index out of range error about 1 in 10 times when I test it. Any suggestions?
Thanks :)
from random import randint, choice
x_cor = [0,1,2,3,4,5]
y_cor = [0,1,2,3,4]
def create_board():
row = [["O" for i in x_cor] for x in y_cor]
return row
board = create_board()
def create_ship(board):
board[choice(x_cor)][choice(y_cor)] = "*"
return board
world = create_ship(board)
for i in world:
print(" ".join(i)) | 0debug |
def substract_elements(test_tup1, test_tup2):
res = tuple(tuple(a - b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | 0debug |
static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p,
int line_num, FFServerStream **pstream)
{
char arg[1024], arg2[1024];
FFServerStream *stream;
int val;
av_assert0(pstream);
stream = *pstream;
if (!av_strcasecmp(cmd, "<Stream")) {
char *q;
FFServerStream *s;
stream = av_mallocz(sizeof(FFServerStream));
if (!stream)
return AVERROR(ENOMEM);
config->dummy_actx = avcodec_alloc_context3(NULL);
config->dummy_vctx = avcodec_alloc_context3(NULL);
if (!config->dummy_vctx || !config->dummy_actx) {
av_free(stream);
avcodec_free_context(&config->dummy_vctx);
avcodec_free_context(&config->dummy_actx);
return AVERROR(ENOMEM);
}
config->dummy_actx->codec_type = AVMEDIA_TYPE_AUDIO;
config->dummy_vctx->codec_type = AVMEDIA_TYPE_VIDEO;
ffserver_get_arg(stream->filename, sizeof(stream->filename), p);
q = strrchr(stream->filename, '>');
if (q)
*q = '\0';
for (s = config->first_stream; s; s = s->next) {
if (!strcmp(stream->filename, s->filename))
ERROR("Stream '%s' already registered\n", s->filename);
}
stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
if (stream->fmt) {
config->guessed_audio_codec_id = stream->fmt->audio_codec;
config->guessed_video_codec_id = stream->fmt->video_codec;
} else {
config->guessed_audio_codec_id = AV_CODEC_ID_NONE;
config->guessed_video_codec_id = AV_CODEC_ID_NONE;
}
*pstream = stream;
return 0;
}
av_assert0(stream);
if (!av_strcasecmp(cmd, "Feed")) {
FFServerStream *sfeed;
ffserver_get_arg(arg, sizeof(arg), p);
sfeed = config->first_feed;
while (sfeed) {
if (!strcmp(sfeed->filename, arg))
break;
sfeed = sfeed->next_feed;
}
if (!sfeed)
ERROR("Feed with name '%s' for stream '%s' is not defined\n", arg,
stream->filename);
else
stream->feed = sfeed;
} else if (!av_strcasecmp(cmd, "Format")) {
ffserver_get_arg(arg, sizeof(arg), p);
if (!strcmp(arg, "status")) {
stream->stream_type = STREAM_TYPE_STATUS;
stream->fmt = NULL;
} else {
stream->stream_type = STREAM_TYPE_LIVE;
if (!strcmp(arg, "jpeg"))
strcpy(arg, "mjpeg");
stream->fmt = ffserver_guess_format(arg, NULL, NULL);
if (!stream->fmt)
ERROR("Unknown Format: %s\n", arg);
}
if (stream->fmt) {
config->guessed_audio_codec_id = stream->fmt->audio_codec;
config->guessed_video_codec_id = stream->fmt->video_codec;
}
} else if (!av_strcasecmp(cmd, "InputFormat")) {
ffserver_get_arg(arg, sizeof(arg), p);
stream->ifmt = av_find_input_format(arg);
if (!stream->ifmt)
ERROR("Unknown input format: %s\n", arg);
} else if (!av_strcasecmp(cmd, "FaviconURL")) {
if (stream->stream_type == STREAM_TYPE_STATUS)
ffserver_get_arg(stream->feed_filename,
sizeof(stream->feed_filename), p);
else
ERROR("FaviconURL only permitted for status streams\n");
} else if (!av_strcasecmp(cmd, "Author") ||
!av_strcasecmp(cmd, "Comment") ||
!av_strcasecmp(cmd, "Copyright") ||
!av_strcasecmp(cmd, "Title")) {
char key[32];
int i;
ffserver_get_arg(arg, sizeof(arg), p);
for (i = 0; i < strlen(cmd); i++)
key[i] = av_tolower(cmd[i]);
key[i] = 0;
WARNING("'%s' option in configuration file is deprecated, "
"use 'Metadata %s VALUE' instead\n", cmd, key);
if (av_dict_set(&stream->metadata, key, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "Metadata")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_get_arg(arg2, sizeof(arg2), p);
if (av_dict_set(&stream->metadata, arg, arg2, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "Preroll")) {
ffserver_get_arg(arg, sizeof(arg), p);
stream->prebuffer = atof(arg) * 1000;
} else if (!av_strcasecmp(cmd, "StartSendOnKey")) {
stream->send_on_key = 1;
} else if (!av_strcasecmp(cmd, "AudioCodec")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_codec(config->dummy_actx, arg, config, line_num);
} else if (!av_strcasecmp(cmd, "VideoCodec")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_codec(config->dummy_vctx, arg, config, line_num);
} else if (!av_strcasecmp(cmd, "MaxTime")) {
ffserver_get_arg(arg, sizeof(arg), p);
stream->max_time = atof(arg) * 1000;
} else if (!av_strcasecmp(cmd, "AudioBitRate")) {
float f;
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(&f, arg, 1000, 0, FLT_MAX, config, line_num,
"Invalid %s: %s\n", cmd, arg);
if (av_dict_set_int(&config->audio_conf, cmd, lrintf(f), 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "AudioChannels")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 8, config, line_num,
"Invalid %s: %s, valid range is 1-8.", cmd, arg);
if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "AudioSampleRate")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 0, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBitRateRange")) {
int minrate, maxrate;
ffserver_get_arg(arg, sizeof(arg), p);
if (sscanf(arg, "%d-%d", &minrate, &maxrate) == 2) {
if (av_dict_set_int(&config->video_conf, "VideoBitRateRangeMin", minrate, 0) < 0 ||
av_dict_set_int(&config->video_conf, "VideoBitRateRangeMax", maxrate, 0) < 0)
goto nomem;
} else
ERROR("Incorrect format for VideoBitRateRange -- should be "
"<min>-<max>: %s\n", arg);
} else if (!av_strcasecmp(cmd, "Debug")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "Strict")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBufferSize")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 8*1024, 0, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBitRateTolerance")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 1000, INT_MIN, INT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBitRate")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 1000, 0, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoSize")) {
int ret, w, h;
ffserver_get_arg(arg, sizeof(arg), p);
ret = av_parse_video_size(&w, &h, arg);
if (ret < 0)
ERROR("Invalid video size '%s'\n", arg);
else if ((w % 2) || (h % 2))
WARNING("Image size is not a multiple of 2\n");
if (av_dict_set_int(&config->video_conf, "VideoSizeWidth", w, 0) < 0 ||
av_dict_set_int(&config->video_conf, "VideoSizeHeight", h, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoFrameRate")) {
AVRational frame_rate;
ffserver_get_arg(arg, sizeof(arg), p);
if (av_parse_video_rate(&frame_rate, arg) < 0) {
ERROR("Incorrect frame rate: %s\n", arg);
} else {
if (av_dict_set_int(&config->video_conf, "VideoFrameRateNum", frame_rate.num, 0) < 0 ||
av_dict_set_int(&config->video_conf, "VideoFrameRateDen", frame_rate.den, 0) < 0)
goto nomem;
}
} else if (!av_strcasecmp(cmd, "PixelFormat")) {
enum AVPixelFormat pix_fmt;
ffserver_get_arg(arg, sizeof(arg), p);
pix_fmt = av_get_pix_fmt(arg);
if (pix_fmt == AV_PIX_FMT_NONE)
ERROR("Unknown pixel format: %s\n", arg);
if (av_dict_set_int(&config->video_conf, cmd, pix_fmt, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoGopSize")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
"Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoIntraOnly")) {
if (av_dict_set(&config->video_conf, cmd, "1", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoHighQuality")) {
if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "Video4MotionVector")) {
if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "AVOptionVideo") ||
!av_strcasecmp(cmd, "AVOptionAudio")) {
int ret;
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_get_arg(arg2, sizeof(arg2), p);
if (!av_strcasecmp(cmd, "AVOptionVideo"))
ret = ffserver_save_avoption(config->dummy_vctx, arg, arg2, &config->video_opts,
AV_OPT_FLAG_VIDEO_PARAM ,config, line_num);
else
ret = ffserver_save_avoption(config->dummy_actx, arg, arg2, &config->audio_opts,
AV_OPT_FLAG_AUDIO_PARAM ,config, line_num);
if (ret < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "AVPresetVideo") ||
!av_strcasecmp(cmd, "AVPresetAudio")) {
ffserver_get_arg(arg, sizeof(arg), p);
if (!av_strcasecmp(cmd, "AVPresetVideo"))
ffserver_opt_preset(arg, config->dummy_vctx, config, line_num);
else
ffserver_opt_preset(arg, config->dummy_actx, config, line_num);
} else if (!av_strcasecmp(cmd, "VideoTag")) {
ffserver_get_arg(arg, sizeof(arg), p);
if (strlen(arg) == 4) {
if (av_dict_set(&config->video_conf, "VideoTag", "arg", 0) < 0)
goto nomem;
}
} else if (!av_strcasecmp(cmd, "BitExact")) {
if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "DctFastint")) {
if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "IdctSimple")) {
if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "Qscale")) {
ffserver_get_arg(arg, sizeof(arg), p);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQDiff")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
"%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQMax")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
"%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQMin")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
"%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "LumiMask")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "DarkMask")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem;
} else if (!av_strcasecmp(cmd, "NoVideo")) {
config->no_video = 1;
} else if (!av_strcasecmp(cmd, "NoAudio")) {
config->no_audio = 1;
} else if (!av_strcasecmp(cmd, "ACL")) {
ffserver_parse_acl_row(stream, NULL, NULL, *p, config->filename,
line_num);
} else if (!av_strcasecmp(cmd, "DynamicACL")) {
ffserver_get_arg(stream->dynamic_acl, sizeof(stream->dynamic_acl), p);
} else if (!av_strcasecmp(cmd, "RTSPOption")) {
ffserver_get_arg(arg, sizeof(arg), p);
av_freep(&stream->rtsp_option);
stream->rtsp_option = av_strdup(arg);
} else if (!av_strcasecmp(cmd, "MulticastAddress")) {
ffserver_get_arg(arg, sizeof(arg), p);
if (resolve_host(&stream->multicast_ip, arg))
ERROR("Invalid host/IP address: %s\n", arg);
stream->is_multicast = 1;
stream->loop = 1;
} else if (!av_strcasecmp(cmd, "MulticastPort")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
"Invalid MulticastPort: %s\n", arg);
stream->multicast_port = val;
} else if (!av_strcasecmp(cmd, "MulticastTTL")) {
ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config,
line_num, "Invalid MulticastTTL: %s\n", arg);
stream->multicast_ttl = val;
} else if (!av_strcasecmp(cmd, "NoLoop")) {
stream->loop = 0;
} else if (!av_strcasecmp(cmd, "</Stream>")) {
if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm")) {
if (config->dummy_actx->codec_id == AV_CODEC_ID_NONE)
config->dummy_actx->codec_id = config->guessed_audio_codec_id;
if (!config->no_audio && config->dummy_actx->codec_id != AV_CODEC_ID_NONE) {
AVCodecContext *audio_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_actx->codec_id));
ffserver_apply_stream_config(audio_enc, config->audio_conf, &config->audio_opts);
add_codec(stream, audio_enc);
}
if (config->dummy_vctx->codec_id == AV_CODEC_ID_NONE)
config->dummy_vctx->codec_id = config->guessed_video_codec_id;
if (!config->no_video && config->dummy_vctx->codec_id != AV_CODEC_ID_NONE) {
AVCodecContext *video_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_vctx->codec_id));
ffserver_apply_stream_config(video_enc, config->video_conf, &config->video_opts);
add_codec(stream, video_enc);
}
}
av_dict_free(&config->video_opts);
av_dict_free(&config->video_conf);
av_dict_free(&config->audio_opts);
av_dict_free(&config->audio_conf);
avcodec_free_context(&config->dummy_vctx);
avcodec_free_context(&config->dummy_actx);
*pstream = NULL;
} else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
ffserver_get_arg(stream->feed_filename, sizeof(stream->feed_filename),
p);
} else {
ERROR("Invalid entry '%s' inside <Stream></Stream>\n", cmd);
}
return 0;
nomem:
av_log(NULL, AV_LOG_ERROR, "Out of memory. Aborting.\n");
av_dict_free(&config->video_opts);
av_dict_free(&config->video_conf);
av_dict_free(&config->audio_opts);
av_dict_free(&config->audio_conf);
avcodec_free_context(&config->dummy_vctx);
avcodec_free_context(&config->dummy_actx);
return AVERROR(ENOMEM);
}
| 1threat |
SQL - Generate a CTE by using every 3 characters from a value as rows : data example: '255002001255255001255001004002255007002'
There is a formula that every 3 characters belongs to a group, and within those 3 characters, the number belongs to a id. For example, the first 3 characters '255' belong to group 1 and 255 is related to an id in another table.
I need to store every 3 characters in the value above that comes from a table. I want to use a CTE that stores this information so I can reference it in a query to generate a report. Its a third party database so I only have read access.
I thought of using SUBSTRING(tablevalue, 1,3), but dont know how to keep doing it for the entire value
*First post, still learning how to phrase my question | 0debug |
Create implementation of Java class dynamically based on provided dependencies at runtime : <p>I'm trying to determine the best way to create a new instance of a class based on which classes are available on the classpath at runtime.</p>
<p>For example, I have a library that requires a JSON response to be parsed in multiple classes. The library has the following interface:</p>
<p><code>JsonParser.java</code>:</p>
<pre><code>public interface JsonParser {
<T> T fromJson(String json, Class<T> type);
<T> String toJson(T object);
}
</code></pre>
<p>This class has multiple implementations, i.e. <code>GsonJsonParser</code>, <code>JacksonJsonParser</code>, <code>Jackson2JsonParser</code>, and currently, the user of the library is required to "pick" their implementation to be used based on which library they've included in their project. For example:</p>
<pre><code>JsonParser parser = new GsonJsonParser();
SomeService service = new SomeService(parser);
</code></pre>
<p>What I'd like to do, is dynamically pick up which library is on the classpath, and create the proper instance, so that the user of the library doesn't have to think about it (or even have to know the internal implementation of another class parses JSON).</p>
<p>I'm considering something similar to the following:</p>
<pre><code>try {
Class.forName("com.google.gson.Gson");
return new GsonJsonParser();
} catch (ClassNotFoundException e) {
// Gson isn't on classpath, try next implementation
}
try {
Class.forName("com.fasterxml.jackson.databind.ObjectMapper");
return new Jackson2JsonParser();
} catch (ClassNotFoundException e) {
// Jackson 2 was not found, try next implementation
}
// repeated for all implementations
throw new IllegalStateException("You must include either Gson or Jackson on your classpath to utilize this library");
</code></pre>
<p>Would this be an appropriate solution? It seems kind of like a hack, as well as uses exceptions to control the flow.</p>
<p>Is there a better way to do this?</p>
| 0debug |
static void pl061_save(QEMUFile *f, void *opaque)
{
pl061_state *s = (pl061_state *)opaque;
qemu_put_be32(f, s->locked);
qemu_put_be32(f, s->data);
qemu_put_be32(f, s->old_data);
qemu_put_be32(f, s->dir);
qemu_put_be32(f, s->isense);
qemu_put_be32(f, s->ibe);
qemu_put_be32(f, s->iev);
qemu_put_be32(f, s->im);
qemu_put_be32(f, s->istate);
qemu_put_be32(f, s->afsel);
qemu_put_be32(f, s->dr2r);
qemu_put_be32(f, s->dr4r);
qemu_put_be32(f, s->dr8r);
qemu_put_be32(f, s->odr);
qemu_put_be32(f, s->pur);
qemu_put_be32(f, s->pdr);
qemu_put_be32(f, s->slr);
qemu_put_be32(f, s->den);
qemu_put_be32(f, s->cr);
qemu_put_be32(f, s->float_high);
}
| 1threat |
ActiveStorage File Attachment Validation : <p>Is there a way to validate attachments with ActiveStorage? For example, if I want to validate the content type or the file size?</p>
<p>Something like Paperclip's approach would be great!</p>
<pre><code> validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/
validates_attachment_size :logo, less_than: 1.megabytes
</code></pre>
| 0debug |
Need help in Java Exception : How to use Exception in java. I have two different Exception here which is "e" and "e1" and I do not understand about this part. What is the difference between "e" and "e1".
Code 1:
catch(ClassNotFoundException | SQLException e){
System.out.println(e);
Code 2:
catch (Exception e1) {
label.setText("SQL Error");
System.err.println(e1);
| 0debug |
Print OutPut In C# : i was trying to do this output in c#, but i don't know how to do it, please help me if you know about this:
i need this output:
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
i tried this code but not Worked:
int y, z;
for (z = 1; z <= 5; z++)
{
for ( y = 5 ; y >= z; y--)
{
Console.Write(y);
}
Console.WriteLine( );
}
Console.ReadLine();
}
| 0debug |
How to create a blog with only index.html, style.css and script.js files? : <p>Inspiration for blog listing pages:
<a href="https://blog.hubspot.com/marketing" rel="nofollow noreferrer">https://blog.hubspot.com/marketing</a></p>
<p><a href="https://www.igomoon.com/blog" rel="nofollow noreferrer">https://www.igomoon.com/blog</a></p>
<p>I only want to know from where should I start? from the beginning of the first line code? or Can import sample codes and edit them? </p>
<p>Should I develop index.html and style.css first? and after that script.js?</p>
| 0debug |
What is volatile variable in Pytorch : <p>What is volatile attribute of a Variable in Pytorch? Here's a sample code for defining a variable in PyTorch.</p>
<pre><code>datatensor = Variable(data, volatile=True)
</code></pre>
| 0debug |
Testing MutationObserver with Jest : <p>I wrote a script with the main purpose of adding new elements to some table's cells.</p>
<p>The test is done with something like that:</p>
<pre><code>document.body.innerHTML = `
<body>
<div id="${containerID}">
<table>
<tr id="meta-1"><td> </td></tr>
<tr id="meta-2"><td> </td></tr>
<tr id="meta-3"><td> </td></tr>
<tr id="no-meta-1"><td> </td></tr>
</table>
</div>
</body>
`;
const element = document.querySelector(`#${containerID}`);
const subject = new WPMLCFInfoHelper(containerID);
subject.addInfo();
expect(mockWPMLCFInfoInit).toHaveBeenCalledTimes(3);
</code></pre>
<p><code>mockWPMLCFInfoInit</code>, when called, is what tells me that the element has been added to the cell.</p>
<p>Part of the code is using MutationObserver to call again <code>mockWPMLCFInfoInit</code> when a new row is added to a table:</p>
<pre><code>new MutationObserver((mutations) => {
mutations.map((mutation) => {
mutation.addedNodes && Array.from(mutation.addedNodes).filter((node) => {
console.log('New row added');
return node.tagName.toLowerCase() === 'tr';
}).map((element) => WPMLCFInfoHelper.addInfo(element))
});
}).observe(metasTable, {
subtree: true,
childList: true
});
</code></pre>
<p><code>WPMLCFInfoHelper.addInfo</code> is the real version of <code>mockWPMLCFInfoInit</code> (which is a mocked method, of course).</p>
<p>From the above test, if add something like that...</p>
<pre><code>const table = element.querySelector(`table`);
var row = table.insertRow(0);
</code></pre>
<p><code>console.log('New row added');</code> never gets called.
To be sure, I've also tried adding the required cells in the new row.</p>
<p>Of course, a manual test is telling me that the code works.</p>
<p>Searching around, my understanding is that MutationObserver is not supported and <a href="https://github.com/facebook/jest/issues/580" rel="noreferrer">there is no plan to support it</a>.</p>
<p>Fair enough, but in this case, how can I test this part of my code? Except manually, that is :)</p>
| 0debug |
static int qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov)
{
int i;
for (i = 0; i < qiov->niov; i++) {
if ((uintptr_t) qiov->iov[i].iov_base % bs->buffer_alignment) {
return 0;
}
}
return 1;
}
| 1threat |
How to get am pm from the date time string using moment js : <p>I have a string as <code>Mon 03-Jul-2017, 11:00 AM/PM</code> and I have to convert this into a string like <code>11:00 AM/PM</code> using moment js.</p>
<p>The problem here is that I am unable to get <code>AM</code> or <code>PM</code> from the date time string.</p>
<p>I am doing this:</p>
<pre><code>moment(Mon 03-Jul-2017, 11:00 AM, 'dd-mm-yyyy hh:mm').format('hh:mm A')
</code></pre>
<p>and it is working fine as I am getting <code>11:00 AM</code> but if the string has <code>PM</code> in it it is still giving <code>AM</code> in the output.</p>
<p>like this <code>moment(Mon 03-Jul-2017, 11:00 PM, 'dd-mm-yyyy hh:mm').format('hh:mm A')</code> is also giving <code>11:00 AM</code> in output instead of <code>11:00 PM</code></p>
| 0debug |
Plot projection of feasible region of linear programming in Matlab : Consider a linear programming in Matlab
`A x >= b`, `Aeq x = beq`, and `lb<=x<=ub`. I want to plot the feasibility region only for the first **three** (or, **two**) elements of the vector `x`.
I found some codes that can plot the feasibility region (for example, [here][1]) provided that `x` is a `2x1` or `3x1` vector.
Instead, in my case `x` is a `10x1` vector. However, I want to plot the feasibility region only for the first three (or, two) elements of `x`. I think this is basically the projection of the feasibility region along the first three (or, two) dimensions.
Is there any code allowing to do that in Matlab? If not, could you advise on how to proceed?
[1]: https://uk.mathworks.com/matlabcentral/fileexchange/9261-plot-2d-3d-region?s_tid=mwa_osa_a | 0debug |
static int scsi_write_data(SCSIRequest *req)
{
SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
uint32_t n;
assert(r->req.aiocb == NULL);
n = r->iov.iov_len / 512;
if (n) {
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->qiov, n,
scsi_write_complete, r);
if (r->req.aiocb == NULL) {
scsi_write_complete(r, -EIO);
}
} else {
scsi_write_complete(r, 0);
}
return 0;
}
| 1threat |
I have a problem with Laravel, when i try to logout users I get Method Illuminate\Database\Query\Builder::pullCache does not exist : <p>Help... I Recently upgraded Laravel from 5.5 to >> 5.6 and now when I logout I get...</p>
<p>Arguments</p>
<blockquote>
<blockquote>
<p>Method Illuminate\Database\Query\Builder::pullCache does not exist.</p>
</blockquote>
</blockquote>
<pre class="lang-php prettyprint-override"><code> /**
* Handle dynamic method calls into the method.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (static::hasMacro($method)) {
return $this->macroCall($method, $parameters);
}
if (Str::startsWith($method, 'where')) {
return $this->dynamicWhere($method, $parameters);
}
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
</code></pre>
| 0debug |
overloading >> in class with instream : <p>i have the following code:</p>
<pre><code>class someclass
{
private :
unsinged char a;
public :
...
}
</code></pre>
<p>I want to use </p>
<pre><code>std::istream& operator>>(std::istream &in, someclass &x)
{
in>>x.a;
return in;
}
int main()
{
someclass test;
std::cin>>test;
return 0;
}
</code></pre>
<p>My problem is that, as a user, I want to insert an integer between 0-255. However, it only accepts single chars. How am I supposed to "cast" it to integers only?</p>
<p>Thank you.</p>
<p>Greetings.</p>
| 0debug |
static int tcp_set_msgfds(CharDriverState *chr, int *fds, int num)
{
TCPCharDriver *s = chr->opaque;
g_free(s->write_msgfds);
if (num) {
s->write_msgfds = g_malloc(num * sizeof(int));
memcpy(s->write_msgfds, fds, num * sizeof(int));
}
s->write_msgfds_num = num;
return 0;
}
| 1threat |
Can I initialize char type variable after declaration? : <p>Hello this is the introductory programmer, well I guess I'm not even a programmer yet because I'm still learning basic grammars.</p>
<p>Here is my question. Can I initialize char type variable after declaration in c++? Or is it only possible to initialize char at the point of declaring?</p>
| 0debug |
Android O Developer Preview emulator always OFFLINE : <p>I'm trying to test my app against the Android O developer preview. I can download and run the emulator, but when deploying my app, it always comes up as "[OFFLINE]". If I go ahead and try to deploy anyway, I get the following output:</p>
<pre><code>com.android.ddmlib.AdbCommandRejectedException: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.
Error while Installing APK
</code></pre>
<p>I've tried restarting ADB as suggested in the output above. Also, I never get a confirmation dialog in the emulator. Emulators for other versions. eg. Nougat 7.1 work fine.</p>
<p>I'm running Android Studio 3.0 Canary 1 (the standard channel doesn't work either). </p>
| 0debug |
How to get the xapth of the following phrase where I only have the ID which changes depending upon the user? : To get the xpath where the id changes depending upon the user logged in.
<td class="dataCell" id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:j_id148" colspan="1" width="3%">
<span id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:stsGetRatePlan">
<span id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:stsGetRatePlan.start" style="display: none">
<img src="/resource/1307120499000/zqu__ajaxLoading" height="18" width="18">
</span>
<span id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:stsGetRatePlan.stop">
<span id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:panProductSelectComplete" onclick="A4J.AJAX.Submit('j_id0:mainForm',event,{'similarityGroupingId':'j_id0:mainForm:j_id36:j_id147:tblProduct:13:j_id149','parameters':{'j_id0:mainForm:j_id36:j_id147:tblProduct:13:j_id149':'j_id0:mainForm:j_id36:j_id147:tblProduct:13:j_id149','selProduct':'a0f6000000386vMAAQ'} ,'status':'j_id0:mainForm:j_id36:j_id147:tblProduct:13:stsGetRatePlan'} )">
<img id="j_id0:mainForm:j_id36:j_id147:tblProduct:13:imgRadioBtnUnchk" src="/resource/1307120499000/zqu__radioBtnUnChk" height="18" width="18">
</span>
</span>
</span>
</td> | 0debug |
iOS Universal Device App with SpriteKit, how to scale nodes for all views? : <p>I want to make a <strong><em>landscape</em> app</strong> to be <strong>universal</strong>, so that the sprite nodes scale proportionally to whatever view size is running the app. I'd like an <em>entirely programmatic</em> solution because I don't like the IB. </p>
<p>My game is pretty simple, and I don't need scrolling or zooming of any kind, so the whole game will always be present and take up the entire view.</p>
<p>Is it possible that what I'm looking for is to change the size of the scene to always fit the view? If so, can you explain this thoroughly because I've tried changing this section of my view controller</p>
<pre><code> if let scene = GameScene(fileNamed:"GameScene")
</code></pre>
<p>to be the constructor method that takes size as a parameter but Xcode doesn't like that.</p>
<hr>
<p><strong>Things I've tried</strong></p>
<ol>
<li>Using fractions of self.view.bounds.width/height. This usually makes all iPhones look good, but on iPads stretches and skews nodes and the boundary box around thew view.</li>
<li>Changing the scaleMode among all four types. I'd like to keep good practice and feel like .AspectFill (default) is the one I should make my app work with, but open to suggestions. Note; I don't want black edges on any device, just the entire view displayed/scaled proportionally.</li>
<li>Applying programmatic constraints. Now I'm fairly new to this and don't understand constraints completely, but no tutorials I've seen even from RayWenderlich talk about constraints on nodes so I didn't delve to deep in this.</li>
<li><p>Using a method like this to convert points among views. This actually worked pretty well for point positioning of nodes, and if possible I would like this method to work out, but then I still have the problem of sizes of nodes. Also when I build for iPad with this method the view seems to start off as portrait and the nodes look fine but then I have to manually switch it to landscape and the sprites and view boundaries once again get messed up. Here's the method:</p>
<pre><code>func convert(point: CGPoint)->CGPoint {
return self.view!.convertPoint(CGPoint(x: point.x, y:self.view!.frame.height-point.y), toScene:self)
}
</code></pre></li>
<li><p>Countless vid tutorials on RW and everywhere else on internet.</p></li>
</ol>
<p>Thanks in advance! I appreciate the help. I know this topic is weird because a lot of people ask questions about it but everyone's situation seems to be different enough that one solution doesn't fit all.</p>
| 0debug |
Is there any reason why you would need to use `Environment.NewLine` instead of `backslash n` in Xamarin code? : Here's an example of my code:
Shell.Current.DisplayAlert($"Stop Quiz {Settings.Quiz}",
$"{Environment.NewLine}You tapped the {target} icon at the bottom of this page. The quiz will be stopped and you will be taken to the {target} screen.{Environment.NewLine}{Environment.NewLine}Please confirm{Environment.NewLine}",
"OK", "Cancel") == true)
What I am wondering, is why use `Environment.NewLine` instead of `backslash n`
| 0debug |
query = 'SELECT * FROM customers WHERE email = ' + email_input | 1threat |
textarea live character counting + Preview not working : <p>I am trying to get live character count + live preview of an textarea usign pure JS no Jquery, but getting some error. Here my code</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var wpcomment = document.getElementById('text');
wpcomment.onkeyup = wpcomment.onkeypress = function(){
document.getElementById('DrevCom').innerHTML = this.value;
}
function count()
{
var total=document.getElementById("text").value;
total=total.replace(/\s/g, '');
document.getElementById("total").innerHTML="Total Characters:"+total.length;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><textarea id="text" onkeyup="count();" placeholder="Add comments:"></textarea>
<p id="total">Total Characters:0</p>
<div id="DrevCom"></div></code></pre>
</div>
</div>
</p>
| 0debug |
How can I change the project in BigQuery : <p>When configuring the Big-Query command line tool I was asked to set up a default project. However, now I have many projects and I can't happen to find how do I switch from one project to the other. Does someone know how to navigate the projects using the command line? Thanks in advance!</p>
<p>G</p>
| 0debug |
static void vnc_client_write(void *opaque)
{
long ret;
VncState *vs = opaque;
#ifdef CONFIG_VNC_TLS
if (vs->tls_session) {
ret = gnutls_write(vs->tls_session, vs->output.buffer, vs->output.offset);
if (ret < 0) {
if (ret == GNUTLS_E_AGAIN)
errno = EAGAIN;
else
errno = EIO;
ret = -1;
}
} else
#endif
ret = send(vs->csock, vs->output.buffer, vs->output.offset, 0);
ret = vnc_client_io_error(vs, ret, socket_error());
if (!ret)
return;
memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));
vs->output.offset -= ret;
if (vs->output.offset == 0) {
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
}
}
| 1threat |
pandas shift converts my column from integer to float. : <p><code>shift</code> converts my column from integer to float. It turns out that <code>np.nan</code> is float only. Is there any ways to keep shifted column as integer?</p>
<pre><code>df = pd.DataFrame({"a":range(5)})
df['b'] = df['a'].shift(1)
df['a']
# 0 0
# 1 1
# 2 2
# 3 3
# 4 4
# Name: a, dtype: int64
df['b']
# 0 NaN
# 1 0
# 2 1
# 3 2
# 4 3
# Name: b, dtype: float64
</code></pre>
| 0debug |
static void rtsp_parse_rtp_info(RTSPState *rt, const char *p)
{
int read = 0;
char key[20], value[1024], url[1024] = "";
uint32_t seq = 0, rtptime = 0;
for (;;) {
p += strspn(p, SPACE_CHARS);
if (!*p)
break;
get_word_sep(key, sizeof(key), "=", &p);
if (*p != '=')
break;
p++;
get_word_sep(value, sizeof(value), ";, ", &p);
read++;
if (!strcmp(key, "url"))
av_strlcpy(url, value, sizeof(url));
else if (!strcmp(key, "seq"))
seq = strtol(value, NULL, 10);
else if (!strcmp(key, "rtptime"))
rtptime = strtol(value, NULL, 10);
if (*p == ',') {
handle_rtp_info(rt, url, seq, rtptime);
url[0] = '\0';
seq = rtptime = 0;
read = 0;
}
if (*p)
p++;
}
if (read > 0)
handle_rtp_info(rt, url, seq, rtptime);
}
| 1threat |
Inherited layout in ASP.NET MVC : <p>I have default layout _Layout.cshtml for the most pages. However for some group of pages I would like to have slightly modified default layout. I know I could just copy that file a modified it a bit, but it would mean to duplicate the code and maintain two layout with 99% of same code.</p>
<p>I would like to inherit the layout from the default like this:</p>
<p>LayoutInherited.cshtml:</p>
<pre><code>Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.BodyContentClassSpecial = "";
@section header{
<style>
#body-content {
width: 90%;
margin: 0 auto;
}
</style>
</code></pre>
<p>}</p>
<p>It is possible to do something like this?</p>
| 0debug |
static void test_bh_delete_from_cb_many(void)
{
BHTestData data1 = { .n = 0, .max = 1 };
BHTestData data2 = { .n = 0, .max = 3 };
BHTestData data3 = { .n = 0, .max = 2 };
BHTestData data4 = { .n = 0, .max = 4 };
data1.bh = aio_bh_new(ctx, bh_delete_cb, &data1);
data2.bh = aio_bh_new(ctx, bh_delete_cb, &data2);
data3.bh = aio_bh_new(ctx, bh_delete_cb, &data3);
data4.bh = aio_bh_new(ctx, bh_delete_cb, &data4);
qemu_bh_schedule(data1.bh);
qemu_bh_schedule(data2.bh);
qemu_bh_schedule(data3.bh);
qemu_bh_schedule(data4.bh);
g_assert_cmpint(data1.n, ==, 0);
g_assert_cmpint(data2.n, ==, 0);
g_assert_cmpint(data3.n, ==, 0);
g_assert_cmpint(data4.n, ==, 0);
g_assert(aio_poll(ctx, false));
g_assert_cmpint(data1.n, ==, 1);
g_assert_cmpint(data2.n, ==, 1);
g_assert_cmpint(data3.n, ==, 1);
g_assert_cmpint(data4.n, ==, 1);
g_assert(data1.bh == NULL);
wait_for_aio();
g_assert_cmpint(data1.n, ==, data1.max);
g_assert_cmpint(data2.n, ==, data2.max);
g_assert_cmpint(data3.n, ==, data3.max);
g_assert_cmpint(data4.n, ==, data4.max);
g_assert(data1.bh == NULL);
g_assert(data2.bh == NULL);
g_assert(data3.bh == NULL);
g_assert(data4.bh == NULL);
}
| 1threat |
Can I use Java 7 with Vert.x any version ? : I need to use Vert.x as per requirement. Need to implement vert.x + java 7 . Is it
Just want to know , Can I Implement Vert.X with Java 1.7, as Vert.X have lambda expression (i.e. not supported by Java 7) , So Is it compulsory Vert.X + Java 8 or Vert.X provided some alternative of Lambda Expression or lower version of Vert.X is Compatible with Java 7.
Thanks in advance. | 0debug |
codewar.com, i meet difficulty.Without correct return.But i use console.log() have correct value.i feel no good.Can you help me? : when i do code pratice in codewar.com, i meet difficulty.Without incorrect return.But i use console.log() have correct value.i feel no good.Can you help me?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
function findN(m,n = 1,v = 0){
if(m == 1){
return n;
}else if(v < m){
v += n * n * n;
n++;
let newN = n - 1;
if(v == m){
console.log(newN);
return newN;
}
newN = null;
findN(m,n,v);
}else if(v > m){
return -1;
}
}
findN(4183059834009);
<!-- end snippet -->
| 0debug |
Formatting local time in java : <p>I'm creating my JavaFX application and I need to use time label every time new list cell is created. I need to put the string with current time in <code>HH:MM</code> format directly into Label constructor which takes <code>String</code> as a parameter.</p>
<p>I found and used <code>java.util.Date</code>'s:</p>
<pre><code>Label timeLabel = new Label(new SimpleDateFormat("HH:MM").format(new Date()));
</code></pre>
<p>but it shows the wrong time zone, so I'm going to use <code>java.time</code> and <code>LocalTime</code> class.</p>
<p>Is there any way to achieve same string result in one line?
Thank You for your help :)</p>
| 0debug |
void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
{
int ln = s->nbits;
long i, j;
long nblocks, nloops;
FFTComplex *p, *cptr;
asm volatile(
"movaps %0, %%xmm4 \n\t"
"movaps %1, %%xmm5 \n\t"
::"m"(*p1p1m1m1),
"m"(*(s->inverse ? p1p1m1p1 : p1p1p1m1))
);
i = 8 << ln;
asm volatile(
"1: \n\t"
"sub $32, %0 \n\t"
"movaps (%0,%1), %%xmm0 \n\t"
"movaps %%xmm0, %%xmm1 \n\t"
"shufps $0x4E, %%xmm0, %%xmm0 \n\t"
"xorps %%xmm4, %%xmm1 \n\t"
"addps %%xmm1, %%xmm0 \n\t"
"movaps 16(%0,%1), %%xmm2 \n\t"
"movaps %%xmm2, %%xmm3 \n\t"
"shufps $0x4E, %%xmm2, %%xmm2 \n\t"
"xorps %%xmm4, %%xmm3 \n\t"
"addps %%xmm3, %%xmm2 \n\t"
"shufps $0xB4, %%xmm2, %%xmm2 \n\t"
"xorps %%xmm5, %%xmm2 \n\t"
"movaps %%xmm0, %%xmm1 \n\t"
"addps %%xmm2, %%xmm0 \n\t"
"subps %%xmm2, %%xmm1 \n\t"
"movaps %%xmm0, (%0,%1) \n\t"
"movaps %%xmm1, 16(%0,%1) \n\t"
"jg 1b \n\t"
:"+r"(i)
:"r"(z)
);
nblocks = 1 << (ln-3);
nloops = 1 << 2;
cptr = s->exptab1;
do {
p = z;
j = nblocks;
do {
i = nloops*8;
asm volatile(
"1: \n\t"
"sub $16, %0 \n\t"
"movaps (%2,%0), %%xmm1 \n\t"
"movaps (%1,%0), %%xmm0 \n\t"
"movaps %%xmm1, %%xmm2 \n\t"
"shufps $0xA0, %%xmm1, %%xmm1 \n\t"
"shufps $0xF5, %%xmm2, %%xmm2 \n\t"
"mulps (%3,%0,2), %%xmm1 \n\t"
"mulps 16(%3,%0,2), %%xmm2 \n\t"
"addps %%xmm2, %%xmm1 \n\t"
"movaps %%xmm0, %%xmm3 \n\t"
"addps %%xmm1, %%xmm0 \n\t"
"subps %%xmm1, %%xmm3 \n\t"
"movaps %%xmm0, (%1,%0) \n\t"
"movaps %%xmm3, (%2,%0) \n\t"
"jg 1b \n\t"
:"+r"(i)
:"r"(p), "r"(p + nloops), "r"(cptr)
);
p += nloops*2;
} while (--j);
cptr += nloops*2;
nblocks >>= 1;
nloops <<= 1;
} while (nblocks != 0);
}
| 1threat |
.NET Scheduled Timer - Cross-thread operation not valid : <p>I'm using the Schedule timer <a href="https://www.codeproject.com/Articles/6507/NET-Scheduled-Timer?fid=36218&df=90&mpp=25&sort=Position&spc=Relaxed&prof=True&view=Normal&fr=1#xx0xx" rel="nofollow noreferrer">www.codeproject.com</a></p>
<p>But, when working with the listview I received the error below:</p>
<p><strong>Cross-thread operation not valid: Control 'lsViewIm' accessed from a thread other than the thread it was created on.</strong></p>
<p>Here's my code:
This is for my button to execute the timer:</p>
<pre><code>delegate void TickHandler(string Profile);
private void btnStart_Click(object sender, EventArgs e)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
if(ConfigurationManager.AppSettings.AllKeys.Contains("Stock-Enable"))
{
if (config.AppSettings.Settings["Stock-Enable"].Value.ToString() == "Y")
{
main.oWriteText(lsViewIm, "Reading... " + DateTime.Now.ToString(), Color.Black, false, "logs");
IScheduledItem Item = GetSchedStock();
_AlarmTimer.Stop();
_AlarmTimer.ClearJobs();
_AlarmTimer.AddJob(Item, new TickHandler(updateStocks), "Woo1");
_AlarmTimer.Start();
}
}
}
private ScheduleTimer _AlarmTimer = new ScheduleTimer();
private IScheduledItem GetSchedStock()
{
return new ScheduledTime("ByMinute", "1");
}
</code></pre>
<p>This code will show details to ListView:</p>
<pre><code>public void oWriteText(ListView lsView, string txt, Color? oColor = null, Boolean isStored = false, string oFile = "logs")
{
ListViewItem addItem = lsView.Items.Add(txt);
lsView.EnsureVisible(lsView.Items.Count - 1);
addItem.SubItems[0].ForeColor = oColor ?? Color.Black;
lsView.Refresh();
}
</code></pre>
<p>And this is my method, and will put here the rest of the code here.</p>
<pre><code>public void updateStocks(string Profile)
{
oWriteText(lsViewIm, DateTime.Now.ToString(), Color.Black, false, "logs");
return;
}
</code></pre>
| 0debug |
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
AVCodecContext *codec, int size, int big_endian)
{
int id;
uint64_t bitrate;
if (size < 14) {
avpriv_request_sample(codec, "wav header size < 14");
return AVERROR_INVALIDDATA;
}
codec->codec_type = AVMEDIA_TYPE_AUDIO;
if (!big_endian) {
id = avio_rl16(pb);
codec->channels = avio_rl16(pb);
codec->sample_rate = avio_rl32(pb);
bitrate = avio_rl32(pb) * 8;
codec->block_align = avio_rl16(pb);
} else {
id = avio_rb16(pb);
codec->channels = avio_rb16(pb);
codec->sample_rate = avio_rb32(pb);
bitrate = avio_rb32(pb) * 8;
codec->block_align = avio_rb16(pb);
}
if (size == 14) {
codec->bits_per_coded_sample = 8;
} else {
if (!big_endian) {
codec->bits_per_coded_sample = avio_rl16(pb);
} else {
codec->bits_per_coded_sample = avio_rb16(pb);
}
}
if (id == 0xFFFE) {
codec->codec_tag = 0;
} else {
codec->codec_tag = id;
codec->codec_id = ff_wav_codec_get_id(id,
codec->bits_per_coded_sample);
}
if (size >= 18) {
int cbSize = avio_rl16(pb);
if (big_endian) {
avpriv_report_missing_feature(codec, "WAVEFORMATEX support for RIFX files\n");
return AVERROR_PATCHWELCOME;
}
size -= 18;
cbSize = FFMIN(size, cbSize);
if (cbSize >= 22 && id == 0xfffe) {
parse_waveformatex(pb, codec);
cbSize -= 22;
size -= 22;
}
if (cbSize > 0) {
av_freep(&codec->extradata);
if (ff_get_extradata(codec, pb, cbSize) < 0)
return AVERROR(ENOMEM);
size -= cbSize;
}
if (size > 0)
avio_skip(pb, size);
}
if (bitrate > INT_MAX) {
if (s->error_recognition & AV_EF_EXPLODE) {
av_log(s, AV_LOG_ERROR,
"The bitrate %"PRIu64" is too large.\n",
bitrate);
return AVERROR_INVALIDDATA;
} else {
av_log(s, AV_LOG_WARNING,
"The bitrate %"PRIu64" is too large, resetting to 0.",
bitrate);
codec->bit_rate = 0;
}
} else {
codec->bit_rate = bitrate;
}
if (codec->sample_rate <= 0) {
av_log(s, AV_LOG_ERROR,
"Invalid sample rate: %d\n", codec->sample_rate);
return AVERROR_INVALIDDATA;
}
if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {
codec->channels = 0;
codec->sample_rate = 0;
}
if (codec->codec_id == AV_CODEC_ID_ADPCM_G726 && codec->sample_rate)
codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;
return 0;
}
| 1threat |
i design a class an base pointer is created but it give error when i try to acces a derived function through base pointer : i create base pointer and pass address of dervied object to it..but an error displayed when i tried to acces a function names fun() through that pointer.. why this code gives error?help me plz
#include<iostream>
using namespace std;
class Base
{
public:
virtual void fun ()
{
cout << "Base::fun()"<< endl;
}
};
class Derived : public Base
{
public:
virtual void fun ( int x )
{
cout << "Derived::fun(), x = " << x << endl;
}
};
int main()
{
Derived d1;
Base *bp = &d1;
bp->fun(5);
return 0;
} | 0debug |
Custon Navigation bar transparent with back button : I want to show only button buttton with transparent nav bar on google map just like uber app | 0debug |
how to develop library management system as web application by using java technology : "I'm a little bit confused that how I should start to develop a web application for the library management system by using the MVC design pattern."
"My requirement is admin can manage librarians and librarians can manage books and students."
"how I need to start working on it whether first, I should create a view or controller(servlet) or model?"
"I have to save admin email and password explicitly in the database or I have to give an option to admin that first register if I will give register option to admin then anyone might be the admin please tell me which is the better way to do it?"
"I have created a servlet and redirecting to a JSP page in which I took one body tag inside body tag I have taken two different form tag inside both form tag I have taken div tag one for admin and librarian login but I'm facing a problem as I am able to give input text in admin email and password field form but in librarian form I am not able to give user input in text field what I need to do overcome from this problem."
"If it is not possible to take two form tag inside one body then how I can create two login form in one Html page one for admin and librarian."
"Please see the below code and help out."
`Admin.java
package admin;
import java.io.IOException;
public class Admin extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
RequestDispatcher dispatcher=request.getRequestDispatcher("home.jsp");
dispatcher.forward(request, response);
} }
`
`<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Home</title>
</head>
<body>
<form action="" >
<div align="left" class="adm">
<h1>Admin Login</h1>
Email address:<input type="text" name="email"></br>
Password:<input type="password" name="pasword"></br>
<input type="button" value="Login">
</div>
</form>
<form action="">
<div align="right">
<h2>Librarian Login</h2>
Lemail address:<input type="text" name="lemail"/></br>
password:<input type="password" name="pass"></br>
<input type="button" value="Login">
</div>
</form>
</body>
</html>' | 0debug |
How can i upload and retrieve images from my xcode swift application through firebase? : What i want to do-
I want to upload image from one of my view controller to Firebase and then i want to load the uploaded image to another view controller. Also I want this process to go on for infinite users. I have no idea how to do this ? | 0debug |
Tensorflow: 'module' object has no attribute 'scalar_summary' : <p>I tried to run the following code to test my TensorBoard, however, when I ran the program, there is an error said:</p>
<pre><code>'module' object has no attribute 'scalar_summary'
</code></pre>
<p>I want to know how can I fix this issue, thanks.</p>
<p>The following is the system info:</p>
<ul>
<li>Operating System: Ubuntu 16.04 LTS</li>
<li>Tensorflow version: 0.12rc (master)</li>
<li>Running environment: Jupyter Notebook</li>
</ul>
<p><strong>Test program and Output:</strong>
<a href="https://i.stack.imgur.com/qgt9G.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qgt9G.png" alt="enter image description here"></a></p>
| 0debug |
void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
{
gamepad_state *s;
int i;
s = (gamepad_state *)g_malloc0(sizeof (gamepad_state));
s->buttons = (gamepad_button *)g_malloc0(n * sizeof (gamepad_button));
for (i = 0; i < n; i++) {
s->buttons[i].irq = irq[i];
s->buttons[i].keycode = keycode[i];
}
s->num_buttons = n;
qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
vmstate_register(NULL, -1, &vmstate_stellaris_gamepad, s);
}
| 1threat |
static int msrle_decode_init(AVCodecContext *avctx)
{
MsrleContext *s = (MsrleContext *)avctx->priv_data;
int i, j;
unsigned char *palette;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
avctx->has_b_frames = 0;
s->frame.data[0] = s->prev_frame.data[0] = NULL;
palette = (unsigned char *)s->avctx->extradata;
memset (s->palette, 0, 256 * 4);
for (i = 0, j = 0; i < s->avctx->extradata_size / 4; i++, j += 4)
s->palette[i] =
(palette[j + 2] << 16) |
(palette[j + 1] << 8) |
(palette[j + 0] << 0);
return 0;
}
| 1threat |
On line 12- cube(number) = (Indentation Error). How to fix it. Please : Please help me. I have no idea how to fix the indentation error in line 12.
def cube(number):
number=n
cube(n)=n**3
return cube(n)
def by_three(number):
number=n
if n%3==0:
cube(number)
return cube(number)
else:
return False
| 0debug |
cursor.execute('SELECT * FROM users WHERE username = ' + user_input) | 1threat |
static const char *target_parse_constraint(TCGArgConstraint *ct,
const char *ct_str, TCGType type)
{
switch (*ct_str++) {
case 'r':
ct->ct |= TCG_CT_REG;
tcg_regset_set32(ct->u.regs, 0, 0xffff);
break;
case 'L':
ct->ct |= TCG_CT_REG;
tcg_regset_set32(ct->u.regs, 0, 0xffff);
tcg_regset_reset_reg (ct->u.regs, TCG_REG_R2);
tcg_regset_reset_reg (ct->u.regs, TCG_REG_R3);
tcg_regset_reset_reg (ct->u.regs, TCG_REG_R4);
break;
case 'a':
ct->ct |= TCG_CT_REG;
tcg_regset_clear(ct->u.regs);
tcg_regset_set_reg(ct->u.regs, TCG_REG_R2);
break;
case 'b':
ct->ct |= TCG_CT_REG;
tcg_regset_clear(ct->u.regs);
tcg_regset_set_reg(ct->u.regs, TCG_REG_R3);
break;
case 'A':
ct->ct |= TCG_CT_CONST_S33;
break;
case 'I':
ct->ct |= TCG_CT_CONST_S16;
break;
case 'J':
ct->ct |= TCG_CT_CONST_S32;
break;
case 'O':
ct->ct |= TCG_CT_CONST_ORI;
break;
case 'X':
ct->ct |= TCG_CT_CONST_XORI;
break;
case 'C':
ct->ct |= TCG_CT_CONST_U31;
break;
case 'Z':
ct->ct |= TCG_CT_CONST_ZERO;
break;
default:
return NULL;
}
return ct_str;
}
| 1threat |
static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
{
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
int i;
for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
uint8_t c = toupper(val[i]);
if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
(c == ' ')) {
ms->loadparm[i] = c;
} else {
error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
c, c);
return;
}
}
for (; i < sizeof(ms->loadparm); i++) {
ms->loadparm[i] = ' ';
}
}
| 1threat |
I want a vba which will swtch column datas without switching the blank cell, : i have 2 columns A and B
I want to copy the Column A data in Column B, there are few blank cells in A, but the Blank cell of 'A' Should not change the Data in column B. only the cells which have data, change the data in B. | 0debug |
def re_order(A):
k = 0
for i in A:
if i:
A[k] = i
k = k + 1
for i in range(k, len(A)):
A[i] = 0
return A | 0debug |
cant apply border img float right : <p>I'm not good in html, css, i want to apply boarder to dev, which contains image in right </p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.amount-2 {
border: 3px solid #4CAF50;
padding: 5px;
width: 70%;
float:left;
}
.sample {
float: right;
width: 30%;
margin-top: -100px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="amount-2">
Files must be less than 2 MB.
Allowed file types: png gif jpg jpeg.
Images must be between 200x200 and 800x1400 pixels.
Web page addresses and e-mail addresses turn into links automatically.
Lines and paragraphs break automatically.
<img class="sample" src="https://gallery.yopriceville.com/var/albums/Free-Clipart-Pictures/Cartoons-PNG/Cute_Bunny_Cartoon_Transparent_Clip_Art_Image.png?m=1478318101" alt="Pineapple" width="150" height="200">
</div></code></pre>
</div>
</div>
</p>
<p>I dont want to fix the heights </p>
| 0debug |
static int nbd_negotiate_options(NBDClient *client)
{
uint32_t flags;
bool fixedNewstyle = false;
if (nbd_negotiate_read(client->ioc, &flags, sizeof(flags)) !=
sizeof(flags)) {
LOG("read failed");
return -EIO;
}
TRACE("Checking client flags");
be32_to_cpus(&flags);
if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) {
TRACE("Client supports fixed newstyle handshake");
fixedNewstyle = true;
flags &= ~NBD_FLAG_C_FIXED_NEWSTYLE;
}
if (flags != 0) {
TRACE("Unknown client flags 0x%" PRIx32 " received", flags);
return -EIO;
}
while (1) {
int ret;
uint32_t clientflags, length;
uint64_t magic;
if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) !=
sizeof(magic)) {
LOG("read failed");
return -EINVAL;
}
TRACE("Checking opts magic");
if (magic != be64_to_cpu(NBD_OPTS_MAGIC)) {
LOG("Bad magic received");
return -EINVAL;
}
if (nbd_negotiate_read(client->ioc, &clientflags,
sizeof(clientflags)) != sizeof(clientflags)) {
LOG("read failed");
return -EINVAL;
}
clientflags = be32_to_cpu(clientflags);
if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) !=
sizeof(length)) {
LOG("read failed");
return -EINVAL;
}
length = be32_to_cpu(length);
TRACE("Checking option 0x%" PRIx32, clientflags);
if (client->tlscreds &&
client->ioc == (QIOChannel *)client->sioc) {
QIOChannel *tioc;
if (!fixedNewstyle) {
TRACE("Unsupported option 0x%" PRIx32, clientflags);
return -EINVAL;
}
switch (clientflags) {
case NBD_OPT_STARTTLS:
tioc = nbd_negotiate_handle_starttls(client, length);
if (!tioc) {
return -EIO;
}
object_unref(OBJECT(client->ioc));
client->ioc = QIO_CHANNEL(tioc);
break;
case NBD_OPT_EXPORT_NAME:
TRACE("Option 0x%x not permitted before TLS", clientflags);
return -EINVAL;
default:
TRACE("Option 0x%" PRIx32 " not permitted before TLS",
clientflags);
if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
return -EIO;
}
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_TLS_REQD,
clientflags);
break;
}
} else if (fixedNewstyle) {
switch (clientflags) {
case NBD_OPT_LIST:
ret = nbd_negotiate_handle_list(client, length);
if (ret < 0) {
return ret;
}
break;
case NBD_OPT_ABORT:
return -EINVAL;
case NBD_OPT_EXPORT_NAME:
return nbd_negotiate_handle_export_name(client, length);
case NBD_OPT_STARTTLS:
if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
return -EIO;
}
if (client->tlscreds) {
TRACE("TLS already enabled");
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_INVALID,
clientflags);
} else {
TRACE("TLS not configured");
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_POLICY,
clientflags);
}
break;
default:
TRACE("Unsupported option 0x%" PRIx32, clientflags);
if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
return -EIO;
}
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP,
clientflags);
break;
}
} else {
switch (clientflags) {
case NBD_OPT_EXPORT_NAME:
return nbd_negotiate_handle_export_name(client, length);
default:
TRACE("Unsupported option 0x%" PRIx32, clientflags);
return -EINVAL;
}
}
}
}
| 1threat |
GUI development with Python : <p>I want to BUILD a client-side app with Python (ex: Atom Text-Editor). However, I do not want to use Tkinter, I prefer to know how to write it from scratch, or some decent frameworks for doing so</p>
| 0debug |
what is wrong with exp(1 - 1j).real : <p><a href="https://i.stack.imgur.com/Ngum8.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>I do not how to tackle with the exponent function with complex in power<a href="https://i.stack.imgur.com/Ngum8.png" rel="nofollow noreferrer">enter image description here</a></p>
| 0debug |
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
{
AVCodecContext *avctx = s->avctx;
DCAContext *dca = avctx->priv_data;
DCAExssAsset *asset = &dca->exss.assets[0];
DCAXllChSet *p = &s->chset[0], *c;
enum AVMatrixEncoding matrix_encoding = AV_MATRIX_ENCODING_NONE;
int i, j, k, ret, shift, nsamples, request_mask;
int ch_remap[DCA_SPEAKER_COUNT];
if (dca->packet & DCA_PACKET_RECOVERY) {
for (i = 0, c = s->chset; i < s->nchsets; i++, c++) {
if (i < s->nactivechsets)
force_lossy_output(s, c);
if (!c->primary_chset)
c->dmix_embedded = 0;
}
s->scalable_lsbs = 0;
s->fixed_lsb_width = 0;
}
s->output_mask = 0;
for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
chs_filter_band_data(s, c, 0);
if (c->residual_encode != (1 << c->nchannels) - 1
&& (ret = combine_residual_frame(s, c)) < 0)
return ret;
if (s->scalable_lsbs)
chs_assemble_msbs_lsbs(s, c, 0);
if (c->nfreqbands > 1) {
chs_filter_band_data(s, c, 1);
chs_assemble_msbs_lsbs(s, c, 1);
}
s->output_mask |= c->ch_mask;
}
for (i = 1, c = &s->chset[1]; i < s->nchsets; i++, c++) {
if (!is_hier_dmix_chset(c))
continue;
if (i >= s->nactivechsets) {
for (j = 0; j < c->nfreqbands; j++)
if (c->bands[j].dmix_embedded)
scale_down_mix(s, c, j);
break;
}
for (j = 0; j < c->nfreqbands; j++)
if (c->bands[j].dmix_embedded)
undo_down_mix(s, c, j);
}
if (s->nfreqbands > 1) {
for (i = 0; i < s->nactivechsets; i++)
if ((ret = chs_assemble_freq_bands(s, &s->chset[i])) < 0)
return ret;
}
if (dca->request_channel_layout) {
if (s->output_mask & DCA_SPEAKER_MASK_Lss) {
s->output_samples[DCA_SPEAKER_Ls] = s->output_samples[DCA_SPEAKER_Lss];
s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Lss) | DCA_SPEAKER_MASK_Ls;
}
if (s->output_mask & DCA_SPEAKER_MASK_Rss) {
s->output_samples[DCA_SPEAKER_Rs] = s->output_samples[DCA_SPEAKER_Rss];
s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Rss) | DCA_SPEAKER_MASK_Rs;
}
}
if (dca->request_channel_layout == DCA_SPEAKER_LAYOUT_STEREO
&& DCA_HAS_STEREO(s->output_mask) && p->dmix_embedded
&& (p->dmix_type == DCA_DMIX_TYPE_LoRo ||
p->dmix_type == DCA_DMIX_TYPE_LtRt))
request_mask = DCA_SPEAKER_LAYOUT_STEREO;
else
request_mask = s->output_mask;
if (!ff_dca_set_channel_layout(avctx, ch_remap, request_mask))
return AVERROR(EINVAL);
avctx->sample_rate = p->freq << (s->nfreqbands - 1);
switch (p->storage_bit_res) {
case 16:
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
shift = 16 - p->pcm_bit_res;
break;
case 20:
case 24:
avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
shift = 24 - p->pcm_bit_res;
break;
default:
return AVERROR(EINVAL);
}
avctx->bits_per_raw_sample = p->storage_bit_res;
avctx->profile = FF_PROFILE_DTS_HD_MA;
avctx->bit_rate = 0;
frame->nb_samples = nsamples = s->nframesamples << (s->nfreqbands - 1);
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
if (request_mask != s->output_mask) {
ff_dca_downmix_to_stereo_fixed(s->dcadsp, s->output_samples,
p->dmix_coeff, nsamples,
s->output_mask);
}
for (i = 0; i < avctx->channels; i++) {
int32_t *samples = s->output_samples[ch_remap[i]];
if (frame->format == AV_SAMPLE_FMT_S16P) {
int16_t *plane = (int16_t *)frame->extended_data[i];
for (k = 0; k < nsamples; k++)
plane[k] = av_clip_int16(samples[k] * (1 << shift));
} else {
int32_t *plane = (int32_t *)frame->extended_data[i];
for (k = 0; k < nsamples; k++)
plane[k] = clip23(samples[k] * (1 << shift)) * (1 << 8);
}
}
if (!asset->one_to_one_map_ch_to_spkr) {
if (asset->representation_type == DCA_REPR_TYPE_LtRt)
matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
else if (asset->representation_type == DCA_REPR_TYPE_LhRh)
matrix_encoding = AV_MATRIX_ENCODING_DOLBYHEADPHONE;
} else if (request_mask != s->output_mask && p->dmix_type == DCA_DMIX_TYPE_LtRt) {
matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
}
if ((ret = ff_side_data_update_matrix_encoding(frame, matrix_encoding)) < 0)
return ret;
return 0;
}
| 1threat |
static int usb_hid_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
HIDState *hs = &us->hid;
int ret;
ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
if (ret >= 0) {
return ret;
}
ret = 0;
switch (request) {
case DeviceRequest | USB_REQ_GET_INTERFACE:
data[0] = 0;
ret = 1;
break;
case DeviceOutRequest | USB_REQ_SET_INTERFACE:
ret = 0;
break;
case InterfaceRequest | USB_REQ_GET_DESCRIPTOR:
switch (value >> 8) {
case 0x22:
if (hs->kind == HID_MOUSE) {
memcpy(data, qemu_mouse_hid_report_descriptor,
sizeof(qemu_mouse_hid_report_descriptor));
ret = sizeof(qemu_mouse_hid_report_descriptor);
} else if (hs->kind == HID_TABLET) {
memcpy(data, qemu_tablet_hid_report_descriptor,
sizeof(qemu_tablet_hid_report_descriptor));
ret = sizeof(qemu_tablet_hid_report_descriptor);
} else if (hs->kind == HID_KEYBOARD) {
memcpy(data, qemu_keyboard_hid_report_descriptor,
sizeof(qemu_keyboard_hid_report_descriptor));
ret = sizeof(qemu_keyboard_hid_report_descriptor);
}
break;
default:
goto fail;
}
break;
case GET_REPORT:
if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
ret = hid_pointer_poll(hs, data, length);
} else if (hs->kind == HID_KEYBOARD) {
ret = hid_keyboard_poll(hs, data, length);
}
us->changed = hs->n > 0;
break;
case SET_REPORT:
if (hs->kind == HID_KEYBOARD) {
ret = hid_keyboard_write(hs, data, length);
} else {
goto fail;
}
break;
case GET_PROTOCOL:
if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) {
goto fail;
}
ret = 1;
data[0] = us->protocol;
break;
case SET_PROTOCOL:
if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) {
goto fail;
}
ret = 0;
us->protocol = value;
break;
case GET_IDLE:
ret = 1;
data[0] = us->idle;
break;
case SET_IDLE:
us->idle = (uint8_t) (value >> 8);
usb_hid_set_next_idle(us, qemu_get_clock_ns(vm_clock));
ret = 0;
break;
default:
fail:
ret = USB_RET_STALL;
break;
}
return ret;
}
| 1threat |
How to store all html input value : I want store html input values somewhere when i click on save button, so when i'll reload page or reload browser they would be same as i left. i don't know how to do it. I'm newbie in Javascript and MySQL.
HTML Code:
<p>
<input type="text" id="name1" class="input-class" disabled="true" value="Cigarette" />
<input type="number" id="input1" class="input-class" value="1" /> - Amount
<input type="number" id="input2" class="input-class" value="1" /> <input type="button" value="Sold" onClick="gamokleba()" />
<br>
<input type="text" id="name2" class="input-class" disabled="true" value="Winston" />
<input type="number" id="input11" class="input-class" value="1" /> - Amount
<input type="number" id="input21" class="input-class" value="1" /> <input type="button" value="Sold" onClick="gamokleba2()" />
</p>
<input type="button" value="Save All Value" onClick="..." />
JAVASCRIPT Code:
function gamokleba (value) {
document.getElementById('input1').value = document.getElementById('input1').value - document.getElementById('input2').value;
}
function gamokleba2 (value) {
document.getElementById('input11').value = document.getElementById('input11').value - document.getElementById('input21').value;
}
Please help me. Sorry for noob question. | 0debug |
Read a specific value from javascript hashmap : <p>I am trying a very basic javascript map example </p>
<pre><code> var map1 = {'myKey1':11, 'mykey2':22};
var t = map1['mykey1'];
alert(t);
</code></pre>
<p>But the alert always gives me 'undefined', it should give me '11'</p>
<p>please guide what i am doing wrong</p>
| 0debug |
import heapq
def nth_super_ugly_number(n, primes):
uglies = [1]
def gen(prime):
for ugly in uglies:
yield ugly * prime
merged = heapq.merge(*map(gen, primes))
while len(uglies) < n:
ugly = next(merged)
if ugly != uglies[-1]:
uglies.append(ugly)
return uglies[-1] | 0debug |
static int decode_p_picture_header(VC9Context *v)
{
int lowquant, pqindex;
pqindex = get_bits(&v->gb, 5);
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = pquant_table[0][pqindex];
else
{
v->pq = pquant_table[v->quantizer_mode-1][pqindex];
}
if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits(&v->gb, 1);
av_log(v->avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n",
v->pq, v->halfpq);
if (v->extended_mv == 1) v->mvrange = get_prefix(&v->gb, 0, 3);
#if HAS_ADVANCED_PROFILE
if (v->profile > PROFILE_MAIN)
{
if (v->postprocflag) v->postproc = get_bits(&v->gb, 1);
}
else
#endif
if (v->multires) v->respic = get_bits(&v->gb, 2);
lowquant = (v->pquantizer>12) ? 0 : 1;
v->mv_mode = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 4)];
if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
{
v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 3)];
v->lumscale = get_bits(&v->gb, 6);
v->lumshift = get_bits(&v->gb, 6);
}
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV)
|| v->mv_mode == MV_PMODE_MIXED_MV)
{
if (bitplane_decoding(v->mv_type_mb_plane, v->width_mb,
v->height_mb, v) < 0)
return -1;
}
if (bitplane_decoding(v->skip_mb_plane, v->width_mb,
v->height_mb, v) < 0)
return -1;
v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)];
v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)];
if (v->dquant)
{
av_log(v->avctx, AV_LOG_INFO, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
if (v->vstransform)
{
v->ttmbf = get_bits(&v->gb, 1);
if (v->ttmbf)
{
v->ttfrm = get_bits(&v->gb, 2);
av_log(v->avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
(v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
}
}
return 0;
}
| 1threat |
static void pc_compat_2_1(MachineState *machine)
{
PCMachineState *pcms = PC_MACHINE(machine);
pc_compat_2_2(machine);
pcms->enforce_aligned_dimm = false;
smbios_uuid_encoded = false;
x86_cpu_change_kvm_default("svm", NULL);
}
| 1threat |
What is the benefit of Sigils in Perl? : <p>I understand the rules with sigils. I can make hashes from lists, and pass refs around with the mediocre-ist of them. What I don't understand are the <em>benefits</em> sigils provide in Perl. </p>
<p>Some of the reasons I've heard are:</p>
<ul>
<li>String Interpolation
<ul>
<li>Ruby has the "#{myVar}" syntax, which solves almost <em>all</em> of these issues, including having full expressions without having to resort to the "@{[$count + 1]}" syntactical hack.</li>
</ul></li>
<li>Readibility
<ul>
<li>IDEs. And any text editor worth its weight in salt has syntax highlighting.</li>
</ul></li>
<li>Allowing for variable subNamespacing
<ul>
<li>Allowing me to declare $foo and @foo as two different variables will only lead to ruin in the future. </li>
</ul></li>
</ul>
<p>One <em>very</em> helpful feature in a programming language is consistency. My curiosity drives me to ask if I declare a list as "@foos", and a counter "$count", how does it make sense to need to access elements by saying "$foos[$count]"? Oh! But I may use the "@" if I'm reading elements out into list context; so saying "@foos[$idx1, $idx2]" now makes sense! I can tell from looking at the sigil that I'm going to be reading an array instead of a single scalar!</p>
<ul>
<li>I can still tell I'm reading a single element by saying "foos[count]"</li>
<li>I can still tell I'm reading multiple elements by saying "foos[idx1, idx2]". </li>
<li>I can still tell I'm reading a single value by saying "foos{key}"</li>
<li>I can still tell I'm reading multiple values by saying "foos{key1, key2}"</li>
</ul>
<p>This same pattern holds true for almost any case I can think of. The meaning of what is being done is clear no matter which sigil is being used, or none for that matter. The only difference is that I have to keep track of the context and be sure to keep sigils in line <em>as well</em>; </p>
| 0debug |
Rock Paper Scissor Python : <p>I'm Learning Python and coded rock, paper and scissor game.</p>
<p>I'm using IDLE in Ubuntu for this. The code has compiled fine but still i'm unable to get this running. IDLE is running fine in this system. PLease help me resolve this.</p>
<p>Thanks in advance</p>
<pre><code>#!/usr/bin/env python2
import time
import random
rock = 1
paper = 2
scissors = 3
names = {rock:"rock", paper:"Paper",scissors: "Scissors"}
rules = {rock: scissors, paper: rock,scissors: paper}
player_score = 0
computer_score = 0
def start():
print "Start"
while game():
pass
scores()
def game():
player = move()
computer = random.randint(1,3)
result(player,computer)
return play_again()
def move():
while True:
print
player = raw_input("Rock = 1 paper = 2 scissor = 3")
try:
player = int(player)
if player in (1,2,3):
return player
except ValueError:
pass
print "Enter number"
def result(player,computer):
print "Computer threw {0}!".format(names[computer])
if player == computer:
print ("Tie")
else:
if rules(player) == computer:
print("You win")
player_score += 1
else:
print("Computer wins")
computer_score += 1
def play_again():
answer = raw_input("Play Again")
if answer in ("y" "Y"):
return answer
else:
print ("Thanks")
def scores():
global player_score, computer_score
print "Player", player_score
print "Computer", computer_score
start()
</code></pre>
| 0debug |
What is the difference between a reducer and middleware? : <p>I'm having a little trouble understanding the difference of application between a reducer and middleware. A number of sites describe middleware even giving precise definitions:</p>
<blockquote>
<p>It provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.</p>
</blockquote>
<p>Or:</p>
<blockquote>
<p>Middleware is created by composing functionality that wraps separate cross-cutting concerns which are not part of your main execution task.</p>
</blockquote>
<p>But from these all I understand is that there <em>is</em> a difference, just not <em>what</em>. From what I can tell, the difference is that one takes an action and passes that action on, and the other takes an action and a state and "passes the state on". But you still have access to the store in the midddleware. So store and action both go through the middleware and then reducers. So a reducer could perform logging.</p>
<p>While logging seems like an obvious application for middleware, there are more ambiguous examples. For example, writing in some trivial authentication into a module, you could use a middleware function to take an action sent by a user and determine their level of authentication:</p>
<pre><code>import { getAuthLevel } from './auth';
export default store => next => action => {
return next({...action, auth: getAuthLevel(action.clientId)});
}
</code></pre>
<p>You might have a bunch of users like this:</p>
<pre><code>{
users: [{
clientId: 'bobsUnqiueClientId',
user: 'Bob',
password: 'ilikecats',
authlevel: 'OVERLORD'
}, {
clientId: 'anotherUniqueClientId',
user: 'Alice',
password: 'boblikescats',
authlevel: 'MINION'
}]}
</code></pre>
<p>Then you might have actions that correspond to different authentication levels. You could map that using middleware, but you'd need to know more specific details about the actions going through and it seems like more "execution-related" code. But then it doesn't need to know anything about the state. It just needs to decide which actions to forward on to the reducers.</p>
<p>So? Would such code go in a reducer or in middleware? And can anyone provide other specific examples that clarify the difference between the two?</p>
| 0debug |
react js maximum update depth exceeded : Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
Received `true` for a non-boolean attribute `width`.
Each child in an array or iterator should have a unique "key" prop.
Failed prop type: Invalid prop `border` supplied to `Box`
my errors list
İmportant error is first error
| 0debug |
Find a part of a string using python? : <p>For example:</p>
<pre><code>string = "abcdefghi"
separated = "abc" + x + "ghi"
x = ???
</code></pre>
<p>I want to find x, using any string.</p>
| 0debug |
Missing comma error ,while inserting clob value in table : CREATE TABLE fcc_consistency_check
(cons_id VARCHAR2(30),
cons_desc VARCHAR2(4000),
cons_query CLOB,
module_id VARCHAR2(2),
main_tab_name VARCHAR2(30),
hist_tab_name VARCHAR2(30),
col_name VARCHAR2(4000),
col_type VARCHAR2(4000),
check_reqd VARCHAR2(1)
);
INSERT INTO fcc_consistency_check
VALUES ('CHK_BC003','Missing records in contract_event_log','select a.CONTRACT_REF_NO ,a.Latest_Event_Seq_No,
c.PREV_WORKING_DAY from cstb_contract A ,sttm_dates c
where module_code = 'BC'
and c.Branch_code='000'
and not exists (select * from cstb_contract_event_log B
where a.contract_ref_no = b.contract_ref_no
and latest_event_seq_no = event_seq_no);',
'BC','BCCC_EVENT_LOG_MISREC','BCCC_EVENT_LOG_MISREC_HISTORY','CONTRACT_REF_NO,LATEST_EVENT_SEQ_NO,EOD_DATE','VARCHAR2(16),NUMBER,DATE','Y');
Not able to insert clob value, getting error missing comma, when i try to insert individual column value then i found that ,error is throwing for column cons_query .
| 0debug |
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
SgiContext *s = avctx->priv_data;
const AVFrame * const p = frame;
PutByteContext pbc;
uint8_t *in_buf, *encode_buf;
int x, y, z, length, tablesize, ret;
unsigned int width, height, depth, dimension;
unsigned int bytes_per_channel, pixmax, put_be;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
#if FF_API_CODER_TYPE
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->coder_type == FF_CODER_TYPE_RAW)
s->rle = 0;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
width = avctx->width;
height = avctx->height;
bytes_per_channel = 1;
pixmax = 0xFF;
put_be = HAVE_BIGENDIAN;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_GRAY8:
dimension = SGI_SINGLE_CHAN;
depth = SGI_GRAYSCALE;
break;
case AV_PIX_FMT_RGB24:
dimension = SGI_MULTI_CHAN;
depth = SGI_RGB;
break;
case AV_PIX_FMT_RGBA:
dimension = SGI_MULTI_CHAN;
depth = SGI_RGBA;
break;
case AV_PIX_FMT_GRAY16LE:
put_be = !HAVE_BIGENDIAN;
case AV_PIX_FMT_GRAY16BE:
bytes_per_channel = 2;
pixmax = 0xFFFF;
dimension = SGI_SINGLE_CHAN;
depth = SGI_GRAYSCALE;
break;
case AV_PIX_FMT_RGB48LE:
put_be = !HAVE_BIGENDIAN;
case AV_PIX_FMT_RGB48BE:
bytes_per_channel = 2;
pixmax = 0xFFFF;
dimension = SGI_MULTI_CHAN;
depth = SGI_RGB;
break;
case AV_PIX_FMT_RGBA64LE:
put_be = !HAVE_BIGENDIAN;
case AV_PIX_FMT_RGBA64BE:
bytes_per_channel = 2;
pixmax = 0xFFFF;
dimension = SGI_MULTI_CHAN;
depth = SGI_RGBA;
break;
default:
return AVERROR_INVALIDDATA;
}
tablesize = depth * height * 4;
length = SGI_HEADER_SIZE;
if (!s->rle)
length += depth * height * width;
else
length += tablesize * 2 + depth * height * (2 * width + 1);
if ((ret = ff_alloc_packet(pkt, bytes_per_channel * length)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", length);
return ret;
}
bytestream2_init_writer(&pbc, pkt->data, pkt->size);
bytestream2_put_be16(&pbc, SGI_MAGIC);
bytestream2_put_byte(&pbc, s->rle);
bytestream2_put_byte(&pbc, bytes_per_channel);
bytestream2_put_be16(&pbc, dimension);
bytestream2_put_be16(&pbc, width);
bytestream2_put_be16(&pbc, height);
bytestream2_put_be16(&pbc, depth);
bytestream2_put_be32(&pbc, 0L);
bytestream2_put_be32(&pbc, pixmax);
bytestream2_put_be32(&pbc, 0L);
bytestream2_skip_p(&pbc, 80);
bytestream2_put_be32(&pbc, 0L);
bytestream2_skip_p(&pbc, 404);
if (s->rle) {
PutByteContext taboff_pcb, tablen_pcb;
bytestream2_init_writer(&taboff_pcb, pbc.buffer, tablesize);
bytestream2_skip_p(&pbc, tablesize);
bytestream2_init_writer(&tablen_pcb, pbc.buffer, tablesize);
bytestream2_skip_p(&pbc, tablesize);
if (!(encode_buf = av_malloc(width * bytes_per_channel)))
return AVERROR(ENOMEM);
for (z = 0; z < depth; z++) {
in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel;
for (y = 0; y < height; y++) {
bytestream2_put_be32(&taboff_pcb, bytestream2_tell_p(&pbc));
for (x = 0; x < width * bytes_per_channel; x += bytes_per_channel)
encode_buf[x] = in_buf[depth * x];
length = sgi_rle_encode(&pbc, encode_buf, width,
bytes_per_channel);
if (length < 1) {
av_free(encode_buf);
return AVERROR_INVALIDDATA;
}
bytestream2_put_be32(&tablen_pcb, length);
in_buf -= p->linesize[0];
}
}
av_free(encode_buf);
} else {
for (z = 0; z < depth; z++) {
in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel;
for (y = 0; y < height; y++) {
for (x = 0; x < width * depth; x += depth)
if (bytes_per_channel == 1)
bytestream2_put_byte(&pbc, in_buf[x]);
else
if (put_be)
bytestream2_put_be16(&pbc, ((uint16_t *)in_buf)[x]);
else
bytestream2_put_le16(&pbc, ((uint16_t *)in_buf)[x]);
in_buf -= p->linesize[0];
}
}
}
pkt->size = bytestream2_tell_p(&pbc);
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
}
| 1threat |
how to chenge c# built in event behaviour : There is a built event known as BeforeInstall now this event is not firing correctly, it fires when the msi install wizard has begun install and by then it is too late for my pre-requisites to be installed, how do you go about changing the behavior of a built in event or shall i implement my own event with an handler?
| 0debug |
Swapping strings : <p>Have written a routine to swap strings , the first routine fails where as the second routine correctly swaps . Need to know the reason for the same they seem to do the same thing not sure why the second one works perfectly not the first .</p>
<p><strong>First Method</strong> </p>
<pre><code>void swap(char *str1, char *str2)
{
char *temp = str1;
str1 = str2;
str2 = temp;
}
</code></pre>
<p><strong>Second Method</strong> </p>
<pre><code>void swap(char **str1, char **str2)
{
char *temp = *str1;
*str1 = *str2;
*str2 = temp;
}
</code></pre>
| 0debug |
query = 'SELECT * FROM customers WHERE email = ' + email_input | 1threat |
def sort_on_occurence(lst):
dct = {}
for i, j in lst:
dct.setdefault(i, []).append(j)
return ([(i, *dict.fromkeys(j), len(j))
for i, j in dct.items()]) | 0debug |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.