problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
How to store php blog post in mysql database with images and other html text format? : <p>I'm working on my php blog project.How can I store images from a blog post to a directory?
Blog post may contain strong, italic, web link,list, images and so on.
<br>(I'm php beginner. Thanks in advance.) </p>
| 0debug |
Pass Gradient Color to one view controller to other view controller : I am trying to pass gradient color of collectionview cell background to other viewcontroller of custom view. Anyone can help me if you have any idea about this.
| 0debug |
python - eror when using quotation marks : Every time i write some code with " and run it on terminal - it shows me eror - how can i fix that?
thanks
^
SyntaxError: invalid syntax
Radani:Books radani$ python 2.py
File "2.py", line 16
Print "what is 5 - 7?", 5-7
^
SyntaxError: invalid syntax | 0debug |
sum function returns inconsistent values when used with slicing : <pre><code>lst=[2,5]
sum(lst)
</code></pre>
<p>This returns 7 as expected</p>
<pre><code>lst[0]
</code></pre>
<p>This returns 2 as expected</p>
<pre><code>lst[1]
</code></pre>
<p>This returns 5 as expected</p>
<pre><code>sum(lst[0:-1])
</code></pre>
<p>why does this return 2 instead of 7??</p>
| 0debug |
Kibana: pie chart slices based on substring of a field : <p>I'm trying to create a pie chart visualization that will display the top 10 incoming requests.
I have a search query that filters only the incoming requests which have a field called messages which looks like the following:
"Incoming request /api/someaction".
How do I do the aggregation based on the /api/someaction part rather on the entire string (because then "Incoming" is counted as a term".</p>
<p>Or...can I create custom field which are, for example, a substring of another field?</p>
<p>Thanks</p>
| 0debug |
static void tcg_out_label(TCGContext *s, int label_index, tcg_insn_unit *ptr)
{
TCGLabel *l = &s->labels[label_index];
intptr_t value = (intptr_t)ptr;
TCGRelocation *r;
assert(!l->has_value);
for (r = l->u.first_reloc; r != NULL; r = r->next) {
patch_reloc(r->ptr, r->type, value, r->addend);
}
l->has_value = 1;
l->u.value_ptr = ptr;
}
| 1threat |
How to organize TypeScript interfaces : <p>I would like to know what the recommended way is to organize interface definitions in typescript. In my project I have many different classes. Each class can have a configuration interface. Currently I have gathered all of these interface definitions into one file <code>Interfaces.ts</code> and reference the file from various locations.</p>
<p>Is there a better way?</p>
<p>Example: <a href="https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts" rel="noreferrer">https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts</a></p>
| 0debug |
static int vid_probe(AVProbeData *p)
{
if (AV_RL32(p->buf) != MKTAG('V', 'I', 'D', 0))
return 0;
return AVPROBE_SCORE_MAX;
} | 1threat |
static int read_access_unit(AVCodecContext *avctx, void* data,
int *got_frame_ptr, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MLPDecodeContext *m = avctx->priv_data;
GetBitContext gb;
unsigned int length, substr;
unsigned int substream_start;
unsigned int header_size = 4;
unsigned int substr_header_size = 0;
uint8_t substream_parity_present[MAX_SUBSTREAMS];
uint16_t substream_data_len[MAX_SUBSTREAMS];
uint8_t parity_bits;
int ret;
if (buf_size < 4)
return 0;
length = (AV_RB16(buf) & 0xfff) * 2;
if (length < 4 || length > buf_size)
return AVERROR_INVALIDDATA;
init_get_bits(&gb, (buf + 4), (length - 4) * 8);
m->is_major_sync_unit = 0;
if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
if (read_major_sync(m, &gb) < 0)
goto error;
m->is_major_sync_unit = 1;
header_size += 28;
}
if (!m->params_valid) {
av_log(m->avctx, AV_LOG_WARNING,
"Stream parameters not seen; skipping frame.\n");
*got_frame_ptr = 0;
return length;
}
substream_start = 0;
for (substr = 0; substr < m->num_substreams; substr++) {
int extraword_present, checkdata_present, end, nonrestart_substr;
extraword_present = get_bits1(&gb);
nonrestart_substr = get_bits1(&gb);
checkdata_present = get_bits1(&gb);
skip_bits1(&gb);
end = get_bits(&gb, 12) * 2;
substr_header_size += 2;
if (extraword_present) {
if (m->avctx->codec_id == AV_CODEC_ID_MLP) {
av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n");
goto error;
}
skip_bits(&gb, 16);
substr_header_size += 2;
}
if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
goto error;
}
if (end + header_size + substr_header_size > length) {
av_log(m->avctx, AV_LOG_ERROR,
"Indicated length of substream %d data goes off end of "
"packet.\n", substr);
end = length - header_size - substr_header_size;
}
if (end < substream_start) {
av_log(avctx, AV_LOG_ERROR,
"Indicated end offset of substream %d data "
"is smaller than calculated start offset.\n",
substr);
goto error;
}
if (substr > m->max_decoded_substream)
continue;
substream_parity_present[substr] = checkdata_present;
substream_data_len[substr] = end - substream_start;
substream_start = end;
}
parity_bits = ff_mlp_calculate_parity(buf, 4);
parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);
if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
goto error;
}
buf += header_size + substr_header_size;
for (substr = 0; substr <= m->max_decoded_substream; substr++) {
SubStream *s = &m->substream[substr];
init_get_bits(&gb, buf, substream_data_len[substr] * 8);
m->matrix_changed = 0;
memset(m->filter_changed, 0, sizeof(m->filter_changed));
s->blockpos = 0;
do {
if (get_bits1(&gb)) {
if (get_bits1(&gb)) {
if (read_restart_header(m, &gb, buf, substr) < 0)
goto next_substr;
s->restart_seen = 1;
}
if (!s->restart_seen)
goto next_substr;
if (read_decoding_params(m, &gb, substr) < 0)
goto next_substr;
}
if (!s->restart_seen)
goto next_substr;
if ((ret = read_block_data(m, &gb, substr)) < 0)
return ret;
if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
goto substream_length_mismatch;
} while (!get_bits1(&gb));
skip_bits(&gb, (-get_bits_count(&gb)) & 15);
if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {
int shorten_by;
if (get_bits(&gb, 16) != 0xD234)
return AVERROR_INVALIDDATA;
shorten_by = get_bits(&gb, 16);
if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && shorten_by & 0x2000)
s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
else if (m->avctx->codec_id == AV_CODEC_ID_MLP && shorten_by != 0xD234)
return AVERROR_INVALIDDATA;
if (substr == m->max_decoded_substream)
av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
}
if (substream_parity_present[substr]) {
uint8_t parity, checksum;
if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)
goto substream_length_mismatch;
parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);
checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);
if ((get_bits(&gb, 8) ^ parity) != 0xa9 )
av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr);
if ( get_bits(&gb, 8) != checksum)
av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr);
}
if (substream_data_len[substr] * 8 != get_bits_count(&gb))
goto substream_length_mismatch;
next_substr:
if (!s->restart_seen)
av_log(m->avctx, AV_LOG_ERROR,
"No restart header present in substream %d.\n", substr);
buf += substream_data_len[substr];
}
rematrix_channels(m, m->max_decoded_substream);
if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)
return ret;
return length;
substream_length_mismatch:
av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
return AVERROR_INVALIDDATA;
error:
m->params_valid = 0;
return AVERROR_INVALIDDATA;
}
| 1threat |
Typescript optional chaining error: Expression expected.ts(1109) : <p>I am trying to do optional chaining in Typescript + React Native.</p>
<p>Let's say I have the following interfaces:</p>
<pre><code>interface Bar {
y: number
}
interface Foo {
x?: Bar
}
</code></pre>
<p>and I try to run the following:</p>
<pre><code> const test: Foo = {x: {y: 3}};
console.log(test.x?.y);
</code></pre>
<p>VSCode will show an error under the <code>?.</code> saying the following: <em>Expression expected.ts(1109)</em> </p>
<p>Do you have any idea why this is happening or how should I fix it? Thanks.</p>
| 0debug |
In WPF binding what does an empty {Binding} do : <p>In WPF binding what does an empty {Binding} do?<br/>
for example: <br/></p>
<pre><code><TextBlock Text='{Binding}' />
</code></pre>
<p>Is there an example where it is useful.</p>
| 0debug |
static void loadvm_postcopy_handle_run_bh(void *opaque)
{
Error *local_err = NULL;
HandleRunBhData *data = opaque;
cpu_synchronize_all_post_init();
qemu_announce_self();
bdrv_invalidate_cache_all(&local_err);
if (!local_err) {
blk_resume_after_migration(&local_err);
}
if (local_err) {
error_report_err(local_err);
local_err = NULL;
autostart = false;
}
trace_loadvm_postcopy_handle_run_cpu_sync();
cpu_synchronize_all_post_init();
trace_loadvm_postcopy_handle_run_vmstart();
if (autostart) {
vm_start();
} else {
runstate_set(RUN_STATE_PAUSED);
}
qemu_bh_delete(data->bh);
g_free(data);
}
| 1threat |
static void spr_write_601_ubatl (void *opaque, int sprn)
{
DisasContext *ctx = opaque;
gen_op_store_601_batl((sprn - SPR_IBAT0L) / 2);
RET_STOP(ctx);
}
| 1threat |
static void virtio_init_region_cache(VirtIODevice *vdev, int n)
{
VirtQueue *vq = &vdev->vq[n];
VRingMemoryRegionCaches *old = vq->vring.caches;
VRingMemoryRegionCaches *new;
hwaddr addr, size;
int event_size;
event_size = virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
addr = vq->vring.desc;
if (!addr) {
return;
}
new = g_new0(VRingMemoryRegionCaches, 1);
size = virtio_queue_get_desc_size(vdev, n);
address_space_cache_init(&new->desc, vdev->dma_as,
addr, size, false);
size = virtio_queue_get_used_size(vdev, n) + event_size;
address_space_cache_init(&new->used, vdev->dma_as,
vq->vring.used, size, true);
size = virtio_queue_get_avail_size(vdev, n) + event_size;
address_space_cache_init(&new->avail, vdev->dma_as,
vq->vring.avail, size, false);
atomic_rcu_set(&vq->vring.caches, new);
if (old) {
call_rcu(old, virtio_free_region_cache, rcu);
}
}
| 1threat |
DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
{
DeviceState *dev = NULL;
if (cirrus_vga_enabled) {
if (pci_bus) {
dev = pci_cirrus_vga_init(pci_bus);
} else {
dev = isa_cirrus_vga_init(get_system_memory());
}
} else if (vmsvga_enabled) {
if (pci_bus) {
dev = pci_vmsvga_init(pci_bus);
if (!dev) {
fprintf(stderr, "Warning: vmware_vga not available,"
" using standard VGA instead\n");
dev = pci_vga_init(pci_bus);
}
} else {
fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
}
#ifdef CONFIG_SPICE
} else if (qxl_enabled) {
if (pci_bus) {
dev = &pci_create_simple(pci_bus, -1, "qxl-vga")->qdev;
} else {
fprintf(stderr, "%s: qxl: no PCI bus\n", __FUNCTION__);
}
#endif
} else if (std_vga_enabled) {
if (pci_bus) {
dev = pci_vga_init(pci_bus);
} else {
dev = isa_vga_init(isa_bus);
}
}
return dev;
}
| 1threat |
static void tcg_out_bc(TCGContext *s, int bc, int label_index)
{
TCGLabel *l = &s->labels[label_index];
if (l->has_value) {
tcg_out32(s, bc | reloc_pc14_val(s->code_ptr, l->u.value_ptr));
} else {
tcg_out_reloc(s, s->code_ptr, R_PPC_REL14, label_index, 0);
tcg_out_bc_noaddr(s, bc);
}
}
| 1threat |
static void dec_barrel(DisasContext *dc)
{
TCGv t0;
bool s, t;
if ((dc->tb_flags & MSR_EE_FLAG)
&& (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
&& !dc->cpu->cfg.use_barrel) {
tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
t_gen_raise_exception(dc, EXCP_HW_EXCP);
return;
}
s = extract32(dc->imm, 10, 1);
t = extract32(dc->imm, 9, 1);
LOG_DIS("bs%s%s r%d r%d r%d\n",
s ? "l" : "r", t ? "a" : "l", dc->rd, dc->ra, dc->rb);
t0 = tcg_temp_new();
tcg_gen_mov_tl(t0, *(dec_alu_op_b(dc)));
tcg_gen_andi_tl(t0, t0, 31);
if (s) {
tcg_gen_shl_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
} else {
if (t) {
tcg_gen_sar_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
} else {
tcg_gen_shr_tl(cpu_R[dc->rd], cpu_R[dc->ra], t0);
}
}
} | 1threat |
static inline void t_gen_swapr(TCGv d, TCGv s)
{
struct {
int shift;
uint32_t mask;
} bitrev [] = {
{7, 0x80808080},
{5, 0x40404040},
{3, 0x20202020},
{1, 0x10101010},
{-1, 0x08080808},
{-3, 0x04040404},
{-5, 0x02020202},
{-7, 0x01010101}
};
int i;
TCGv t, org_s;
t = tcg_temp_new(TCG_TYPE_TL);
org_s = tcg_temp_new(TCG_TYPE_TL);
tcg_gen_mov_tl(org_s, s);
tcg_gen_shli_tl(t, org_s, bitrev[0].shift);
tcg_gen_andi_tl(d, t, bitrev[0].mask);
for (i = 1; i < sizeof bitrev / sizeof bitrev[0]; i++) {
if (bitrev[i].shift >= 0) {
tcg_gen_shli_tl(t, org_s, bitrev[i].shift);
} else {
tcg_gen_shri_tl(t, org_s, -bitrev[i].shift);
}
tcg_gen_andi_tl(t, t, bitrev[i].mask);
tcg_gen_or_tl(d, d, t);
}
tcg_temp_free(t);
tcg_temp_free(org_s);
}
| 1threat |
html, css, javascript - show/hide divs - one is shown than another should hidden : I want to create show/hide div's.
It is my code: [enter link description here][1]
But it don't works like I want.
I want that when "press button2" pressed than another div's are hidden.
It should show only one div.
Can You help me?
Thanks.
online123
| 0debug |
Print method "invalid syntax" reversing a string : <p>Trying to reverse a string in python and can't figure out what is wrong with my program that this is seen as invalid syntax. </p>
<pre><code>print(r)
^
SyntaxError: invalid syntax```
</code></pre>
<p>Thanks so much here is my code.</p>
<pre><code>
s = "Hello! my name is MangoKitty"
r = ''.join(reversed(s.split(''))
print(r)
</code></pre>
| 0debug |
bool tcg_cpu_exec(void)
{
int ret = 0;
if (next_cpu == NULL)
next_cpu = first_cpu;
for (; next_cpu != NULL; next_cpu = next_cpu->next_cpu) {
CPUState *env = cur_cpu = next_cpu;
qemu_clock_enable(vm_clock,
(cur_cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
if (qemu_alarm_pending())
break;
if (cpu_can_run(env))
ret = qemu_cpu_exec(env);
else if (env->stop)
break;
if (ret == EXCP_DEBUG) {
gdb_set_stop_cpu(env);
debug_requested = EXCP_DEBUG;
break;
}
}
return tcg_has_work();
}
| 1threat |
static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
{
int ret = 0;
int64_t total_size = 0;
BlockDriverState *bs;
IscsiLun *iscsilun = NULL;
QDict *bs_options;
bs = bdrv_new("", &error_abort);
total_size =
qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
bs->opaque = g_malloc0(sizeof(struct IscsiLun));
iscsilun = bs->opaque;
bs_options = qdict_new();
qdict_put(bs_options, "filename", qstring_from_str(filename));
ret = iscsi_open(bs, bs_options, 0, NULL);
QDECREF(bs_options);
if (ret != 0) {
goto out;
}
iscsi_detach_aio_context(bs);
if (iscsilun->type != TYPE_DISK) {
ret = -ENODEV;
goto out;
}
if (bs->total_sectors < total_size) {
ret = -ENOSPC;
goto out;
}
ret = 0;
out:
if (iscsilun->iscsi != NULL) {
iscsi_destroy_context(iscsilun->iscsi);
}
g_free(bs->opaque);
bs->opaque = NULL;
bdrv_unref(bs);
return ret;
}
| 1threat |
Ant Design - prevent table row click in specific column/area : <p>I'm using ant design table component. I have "actions" column that I don't want the onRowClick event will trigger in this column.</p>
<p>How can it be done?</p>
<p><a href="http://codepen.io/liron_e/pen/zZjVKZ?editors=001" rel="noreferrer">http://codepen.io/liron_e/pen/zZjVKZ?editors=001</a></p>
<pre><code>const { Table, Modal } = antd;
const confirm = (id) => {
Modal.confirm({
title: 'Confirm',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const info = (id) => {
Modal.info({
title: 'Info',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const columns = [
{
key: 'status',
title: 'text',
dataIndex: 'text'
}, {
key: 'actions',
title: 'actions',
dataIndex: 'id',
render: (id) => {
return (
<span>
<a href="#" onClick={() => confirm(id)}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
);
}
}
];
const dataSource = [
{
id: '1',
text: 'Hello'
},{
id: '123',
text: 'adsaddas'
},{
id: '123344',
text: 'cvbbcvb'
},{
id: '5665',
text: 'aasddasd'
},
];
ReactDOM.render(
<div>
<Table
columns={columns}
onRowClick={() => this.info()}
dataSource={dataSource}
/>
</div>
, mountNode);
</code></pre>
<p>As you can try when pressing on row the info modal would open.
When pressing some action the info <strong>and</strong> the confirm modals would open, and I would like that <strong>only confirm modal would open</strong>.</p>
<p>Thanks (:</p>
| 0debug |
Substitute all words following a pattern in javascript : Given the string below
"Hello this is a :sample string :hello"
i want to substitute :sample and :hello with something else.
How can i do this in javascript? | 0debug |
Error : [WinError 267] The directory name is invalid : **I tried this code in jupyter notebook, and this error occured.**
*Error : [WinError 267] The directory name is invalid: 'plantdisease/PlantVillage/Pepper__bell___Bacterial_spot/0022d6b7-d47c-4ee2-ae9a-392a53f48647___JR_B.Spot 8964.JPG/'*
I'm using python 3.6 in anaconda environment, I tried running this code but it showed error. I can't figure out what the problem is.The file location actually exists at the given location, still it shows invalid.
'''image_list, label_list = [], []
try:
print("[INFO] Loading images ...")
root_dir = listdir(directory_root)
for directory in root_dir :
# remove .DS_Store from list
if directory == ".DS_Store" :
root_dir.remove(directory)'''
for plant_folder in root_dir :
plant_disease_folder_list = listdir(f"{directory_root}/{plant_folder}")
for disease_folder in plant_disease_folder_list :
# remove .DS_Store from list
if disease_folder == ".DS_Store" :
plant_disease_folder_list.remove(disease_folder)
for plant_disease_folder in plant_disease_folder_list:
print(f"[INFO] Processing {plant_disease_folder} ...")
plant_disease_image_list = listdir(f"{directory_root}/{plant_folder}/{plant_disease_folder}/")
for single_plant_disease_image in plant_disease_image_list :
if single_plant_disease_image == ".DS_Store" :
plant_disease_image_list.remove(single_plant_disease_image)
for image in plant_disease_image_list[:200]:
image_directory = f"{directory_root}/{plant_folder}/{plant_disease_folder}/{image}"
if image_directory.endswith(".jpg") == True or image_directory.endswith(".JPG") == True:
image_list.append(convert_image_to_array(image_directory))
label_list.append(plant_disease_folder)
print("[INFO] Image loading completed")
except Exception as e:
print(f"Error : {e}")''' | 0debug |
weird symbols in electron javascript : <p>On this page in the example code constants are defined with <code>{}</code></p>
<p><a href="https://github.com/electron/electron/blob/master/docs/api/net.md" rel="nofollow noreferrer">https://github.com/electron/electron/blob/master/docs/api/net.md</a></p>
<pre><code>const {app} = require('electron')
</code></pre>
<p>What does <code>{name}</code> do compared to just <code>name</code>? </p>
<p>Also, I tried the code above with jquery and I an error "cannot read property request of undefined".</p>
<pre><code>jQuery(document).ready(function($){
const {net} = require('electron');
const request = net.request('https://github.com'); <- here
</code></pre>
| 0debug |
static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
int width, int height)
{
uint8_t *src_m1, *src_0, *src_p1, *src_p2;
int y;
uint8_t *buf;
buf = av_malloc(width);
src_m1 = src1;
memcpy(buf,src_m1,width);
src_0=&src_m1[src_wrap];
src_p1=&src_0[src_wrap];
src_p2=&src_p1[src_wrap];
for(y=0;y<(height-2);y+=2) {
deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
src_m1 = src_p1;
src_0 = src_p2;
src_p1 += 2*src_wrap;
src_p2 += 2*src_wrap;
}
deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
av_free(buf);
}
| 1threat |
static int enable_write_target(BDRVVVFATState *s)
{
BlockDriver *bdrv_qcow;
QEMUOptionParameter *options;
int ret;
int size = sector2cluster(s, s->sector_count);
s->used_clusters = calloc(size, 1);
array_init(&(s->commits), sizeof(commit_t));
s->qcow_filename = g_malloc(1024);
ret = get_tmp_filename(s->qcow_filename, 1024);
if (ret < 0) {
g_free(s->qcow_filename);
s->qcow_filename = NULL;
return ret;
}
bdrv_qcow = bdrv_find_format("qcow");
options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0)
return -1;
s->qcow = bdrv_new("");
if (s->qcow == NULL) {
return -1;
}
ret = bdrv_open(s->qcow, s->qcow_filename, NULL,
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
if (ret < 0) {
return ret;
}
#ifndef _WIN32
unlink(s->qcow_filename);
#endif
s->bs->backing_hd = calloc(sizeof(BlockDriverState), 1);
s->bs->backing_hd->drv = &vvfat_write_target;
s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
*(void**)s->bs->backing_hd->opaque = s;
return 0;
}
| 1threat |
static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
const char *name, int devfn,
Error **errp)
{
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
PCIConfigReadFunc *config_read = pc->config_read;
PCIConfigWriteFunc *config_write = pc->config_write;
Error *local_err = NULL;
AddressSpace *dma_as;
DeviceState *dev = DEVICE(pci_dev);
pci_dev->bus = bus;
if (pci_bus_is_root(bus) && bus->parent_dev && !pc->is_bridge) {
error_setg(errp,
"PCI: Only PCI/PCIe bridges can be plugged into %s",
bus->parent_dev->name);
return NULL;
}
if (devfn < 0) {
for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
devfn += PCI_FUNC_MAX) {
if (!bus->devices[devfn])
goto found;
}
error_setg(errp, "PCI: no slot/function available for %s, all in use",
name);
return NULL;
found: ;
} else if (bus->devices[devfn]) {
error_setg(errp, "PCI: slot %d function %d not available for %s,"
" in use by %s",
PCI_SLOT(devfn), PCI_FUNC(devfn), name,
bus->devices[devfn]->name);
return NULL;
} else if (dev->hotplugged &&
pci_get_function_0(pci_dev)) {
error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
" new func %s cannot be exposed to guest.",
PCI_SLOT(devfn),
bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
name);
return NULL;
}
pci_dev->devfn = devfn;
dma_as = pci_device_iommu_address_space(pci_dev);
memory_region_init_alias(&pci_dev->bus_master_enable_region,
OBJECT(pci_dev), "bus master",
dma_as->root, 0, memory_region_size(dma_as->root));
memory_region_set_enabled(&pci_dev->bus_master_enable_region, false);
address_space_init(&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region,
name);
pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
pci_dev->irq_state = 0;
pci_config_alloc(pci_dev);
pci_config_set_vendor_id(pci_dev->config, pc->vendor_id);
pci_config_set_device_id(pci_dev->config, pc->device_id);
pci_config_set_revision(pci_dev->config, pc->revision);
pci_config_set_class(pci_dev->config, pc->class_id);
if (!pc->is_bridge) {
if (pc->subsystem_vendor_id || pc->subsystem_id) {
pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID,
pc->subsystem_vendor_id);
pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID,
pc->subsystem_id);
} else {
pci_set_default_subsystem_id(pci_dev);
}
} else {
assert(!pc->subsystem_vendor_id);
assert(!pc->subsystem_id);
}
pci_init_cmask(pci_dev);
pci_init_wmask(pci_dev);
pci_init_w1cmask(pci_dev);
if (pc->is_bridge) {
pci_init_mask_bridge(pci_dev);
}
pci_init_multifunction(bus, pci_dev, &local_err);
if (local_err) {
error_propagate(errp, local_err);
do_pci_unregister_device(pci_dev);
return NULL;
}
if (!config_read)
config_read = pci_default_read_config;
if (!config_write)
config_write = pci_default_write_config;
pci_dev->config_read = config_read;
pci_dev->config_write = config_write;
bus->devices[devfn] = pci_dev;
pci_dev->version_id = 2;
return pci_dev;
} | 1threat |
How to solve a *missing ;* in a for loop : <p>Good afternoon,
The code below <em>should</em> represent the FizzBuzz game.</p>
<pre><code>for (var i = 0, i < 100, i++) {
if(((i % 3) == 0) && ((i % 5) = 0)) {document.write('FizzBuzz')}
else if( ((i % 3) == 0) && ((i % 5) != 0)) {document.write('Fizz')}
else if( (( i % 3 ) != 0) && ((i % 5) == 0) ) {document.write('Buzz')}
else {document.write(i)}
}
</code></pre>
<p>This is the error I got in Mozilla Firefox Debugger</p>
<pre><code>SyntaxError: missing ; after for-loop initialize 1.18.
</code></pre>
<p>I'm stuck.</p>
| 0debug |
create live wallpaper using unity3d? : <p>Can anyone tell me which asset I have to use to create a live wallpaper for android using <strong>unity3d</strong>? I'm using latest version of unity which is <strong>5.3.4</strong> .</p>
| 0debug |
static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
uint8_t *dest, long dstW, long dstY)
{
#ifdef HAVE_MMX
long dummy=0;
if(c->flags & SWS_ACCURATE_RND){
switch(c->dstFormat){
case PIX_FMT_RGB32:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
WRITEBGR32(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR24:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
"lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t"
"add %4, %%"REG_c" \n\t"
WRITEBGR24(%%REGc, %5, %%REGa)
:: "r" (&c->redDither),
"m" (dummy), "m" (dummy), "m" (dummy),
"r" (dest), "m" (dstW)
: "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
);
return;
case PIX_FMT_BGR555:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g5Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR15(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR565:
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g6Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR16(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_YUYV422:
YSCALEYUV2PACKEDX_ACCURATE
"psraw $3, %%mm3 \n\t"
"psraw $3, %%mm4 \n\t"
"psraw $3, %%mm1 \n\t"
"psraw $3, %%mm7 \n\t"
WRITEYUY2(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
}
}else{
switch(c->dstFormat)
{
case PIX_FMT_RGB32:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
WRITEBGR32(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR24:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
"lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t"
"add %4, %%"REG_c" \n\t"
WRITEBGR24(%%REGc, %5, %%REGa)
:: "r" (&c->redDither),
"m" (dummy), "m" (dummy), "m" (dummy),
"r" (dest), "m" (dstW)
: "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
);
return;
case PIX_FMT_BGR555:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g5Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR15(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_BGR565:
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
#ifdef DITHER1XBPP
"paddusb "MANGLE(b5Dither)", %%mm2\n\t"
"paddusb "MANGLE(g6Dither)", %%mm4\n\t"
"paddusb "MANGLE(r5Dither)", %%mm5\n\t"
#endif
WRITEBGR16(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
case PIX_FMT_YUYV422:
YSCALEYUV2PACKEDX
"psraw $3, %%mm3 \n\t"
"psraw $3, %%mm4 \n\t"
"psraw $3, %%mm1 \n\t"
"psraw $3, %%mm7 \n\t"
WRITEYUY2(%4, %5, %%REGa)
YSCALEYUV2PACKEDX_END
return;
}
}
#endif
#ifdef HAVE_ALTIVEC
if(c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA ||
c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 ||
c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB)
altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, dstW, dstY);
else
#endif
yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, dstW, dstY);
}
| 1threat |
How wait in a loop to execute a task ? Android :
for(int i=0; i < size; i++){
loadImageFromServer(i);
}
The `loadImageFromServer();` takes sometime to load image from server . Now I want the loop to wait for that time and then excited . How to do that ? | 0debug |
Accessing HTML code with c# : <p>I am currently working on a project where I want to manipulate a website with help of a a small program, preferably in c#. The idea is to go to facebook, xing etc. copy out all messages I received. I can then write an answer without having to open the website and navigating through it. Its more of a programming practice excercise then anything useful. </p>
<p>Now my question: I have programmed someting similar using cursor positions via VBA. As you can imagine, thats very fragile. I'd like to reference the HTML elements directly via their ID. I tried a macro addon (imacros), but that doesn't really meet my requirements. Do you guys have any good ideas?</p>
<p>Thanks ahead! </p>
| 0debug |
How does it call id with html? :
## Heading ##
<asp:LinkButton ID="lnkDelete" Font-Bold="true" ForeColor="Black"
runat="server" CommandName="Sil" OnClientClick="OpenPopup('<%#
Eval("YolcuId") %>')" Text="Sil"/>
----------
function OpenPopup(id)
{
$('#sill').modal();
$('#hfsilId').val(id);
} | 0debug |
Read JSON to pandas dataframe - ValueError: Mixing dicts with non-Series may lead to ambiguous ordering : <p>I am trying to read in the JSON structure below into pandas dataframe, but it throws out the error message: </p>
<blockquote>
<p>ValueError: Mixing dicts with non-Series may lead to ambiguous
ordering.</p>
</blockquote>
<p><strong>Json data:</strong></p>
<pre><code>{
"status": {
"statuscode": 200,
"statusmessage": "Everything OK"
},
"result": [{
"id": 22,
"club_id": 16182
}, {
"id": 23,
"club_id": 16182
}, {
"id": 24,
"club_id": 16182
}, {
"id": 25,
"club_id": 16182
}, {
"id": 26,
"club_id": 16182
}, {
"id": 27,
"club_id": 16182
}]
}
</code></pre>
<p>How do I get this right? I have tried the script below...</p>
<pre><code>j_df = pd.read_json('json_file.json')
j_df
with open(j_file) as jsonfile:
data = json.load(jsonfile)
</code></pre>
| 0debug |
static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
long i;
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
long a = *(long*)(src+i);
long b = *(long*)(dst+i);
*(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
}
for(; i<w; i++)
dst[i+0] += src[i+0];
}
| 1threat |
clear timage.canvas in delphi 7 : how to clear timage canvas, avoid duplicate image when changing input size? why nil command doesn't work?
this is my code
> unit outdoor;
>
> interface
>
> uses Windows, Messages, SysUtils, Variants, Classes, Graphics,
> Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls;
>
> type TOrderOD = class(TForm)
> GroupBox1: TGroupBox;
> Label1: TLabel;
> Label2: TLabel;
> Label3: TLabel;
> ODpj: TEdit;
> ODlb: TEdit;
> ODbhn: TComboBox;
> GroupBox2: TGroupBox;
> ODlipat: TComboBox;
> ODukPJ: TComboBox;
> ODukLB: TComboBox;
> Label4: TLabel;
> ODbnyk: TEdit;
> Label5: TLabel;
> Label6: TLabel;
> Button2: TButton;
> Button1: TButton;
> ODkelKI: TEdit;
> ODkelKA: TEdit;
> ODkelA: TEdit;
> StatusBar1: TStatusBar;
> Pinfo: TPanel;
> INFOord: TEdit;
> KelA: TRadioButton;
> kolA: TRadioButton;
> Label7: TLabel;
> ODkelB: TEdit;
> Label8: TLabel;
> Label9: TLabel;
> Label10: TLabel;
> FinAts: TGroupBox;
> FinBwh: TGroupBox;
> KolB: TRadioButton;
> KelB: TRadioButton;
> FinKiri: TGroupBox;
> KolKi: TRadioButton;
> KelKi: TRadioButton;
> FinKanan: TGroupBox;
> KolKA: TRadioButton;
> KelKA: TRadioButton;
> Image1: TImage;
> procedure FormCreate(Sender: TObject); private
> { Private declarations } public
> { Public declarations } end;
>
> var OrderOD: TOrderOD; var
> pj,lb,luas,banyak,atas,bawah,kiri,kanan,vwpj,vwlb : integer;
> bahan, finishing : string; var a:HRGN; implementation
>
> {$R *.dfm}
>
> procedure TOrderOD.FormCreate(Sender: TObject); begin pj :=
> StrToInt(ODpj.Text); lb := StrToInt(ODlb.Text); luas := pj
> * lb; banyak := StrToInt(ODbnyk.Text); atas := StrToInt(ODkelA.Text); bawah := StrToInt(ODkelB.Text); kiri
> := StrToInt(ODkelKI.Text); kanan := StrToInt(ODkelKA.Text); bahan
> := ODbhn.Text; finishing := ODlipat.Text; vwpj := pj * 10; vwlb
> := lb * 10;
>
> INFOord.Text := bahan + ' ' + 'Ukuran: ' + IntToStr(pj) + ' x ' +
> IntToStr(lb) + ' = ' + IntToStr(luas)
> + ' m2' + ' ' + finishing + ' ' + 'Keling' + ' ' + 'A ' + IntToStr(atas) + ' ' + 'B ' + IntToStr(bawah) + ' ' + 'Ki ' +
> IntToStr(kiri) + ' ' + 'Ka ' + IntToStr(kanan);
>
> image1.Canvas := nil; image1.Canvas.Pen.Color := clRed;
> image1.Canvas.Brush.Color := clBlue;
> image1.canvas.rectangle(10,10,vwpj,vwlb); end;
>
>
> end.
| 0debug |
static int adpcm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
const uint8_t *buf, int buf_size)
{
ADPCMContext *c = avctx->priv_data;
ADPCMChannelStatus *cs;
int n, m, channel, i;
int block_predictor[2];
short *samples;
short *samples_end;
const uint8_t *src;
int st;
unsigned char last_byte = 0;
unsigned char nibble;
int decode_top_nibble_next = 0;
int diff_channel;
uint32_t samples_in_chunk;
int32_t previous_left_sample, previous_right_sample;
int32_t current_left_sample, current_right_sample;
int32_t next_left_sample, next_right_sample;
int32_t coeff1l, coeff2l, coeff1r, coeff2r;
uint8_t shift_left, shift_right;
int count1, count2;
int coeff[2][2], shift[2];
if (!buf_size)
return 0;
if(*data_size/4 < buf_size + 8)
return -1;
samples = data;
samples_end= samples + *data_size/2;
*data_size= 0;
src = buf;
st = avctx->channels == 2 ? 1 : 0;
switch(avctx->codec->id) {
case CODEC_ID_ADPCM_IMA_QT:
n = (buf_size - 2);
channel = c->channel;
cs = &(c->status[channel]);
cs->predictor = (*src++) << 8;
cs->predictor |= (*src & 0x80);
cs->predictor &= 0xFF80;
if(cs->predictor & 0x8000)
cs->predictor -= 0x10000;
cs->predictor = av_clip_int16(cs->predictor);
cs->step_index = (*src++) & 0x7F;
if (cs->step_index > 88){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
cs->step_index = 88;
}
cs->step = step_table[cs->step_index];
if (st && channel)
samples++;
for(m=32; n>0 && m>0; n--, m--) {
*samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
samples += avctx->channels;
*samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3);
samples += avctx->channels;
src ++;
}
if(st) {
c->channel = (channel + 1) % 2;
if(!channel) {
return src - buf;
}
samples--;
}
break;
case CODEC_ID_ADPCM_IMA_WAV:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
for(i=0; i<avctx->channels; i++){
cs = &(c->status[i]);
cs->predictor = *samples++ = (int16_t)(src[0] + (src[1]<<8));
src+=2;
cs->step_index = *src++;
if (cs->step_index > 88){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
cs->step_index = 88;
}
if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]);
}
while(src < buf + buf_size){
for(m=0; m<4; m++){
for(i=0; i<=st; i++)
*samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
for(i=0; i<=st; i++)
*samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
src++;
}
src += 4*st;
}
break;
case CODEC_ID_ADPCM_4XM:
cs = &(c->status[0]);
c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
if(st){
c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
}
c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
if(st){
c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
}
if (cs->step_index < 0) cs->step_index = 0;
if (cs->step_index > 88) cs->step_index = 88;
m= (buf_size - (src - buf))>>st;
for(i=0; i<m; i++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
}
src += m<<st;
break;
case CODEC_ID_ADPCM_MS:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
n = buf_size - 7 * avctx->channels;
if (n < 0)
return -1;
block_predictor[0] = av_clip(*src++, 0, 7);
block_predictor[1] = 0;
if (st)
block_predictor[1] = av_clip(*src++, 0, 7);
c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
src+=2;
if (st){
c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
src+=2;
}
c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
src+=2;
if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
if (st) src+=2;
c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
src+=2;
if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
if (st) src+=2;
*samples++ = c->status[0].sample1;
if (st) *samples++ = c->status[1].sample1;
*samples++ = c->status[0].sample2;
if (st) *samples++ = c->status[1].sample2;
for(;n>0;n--) {
*samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 );
*samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
src ++;
}
break;
case CODEC_ID_ADPCM_IMA_DK4:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8));
c->status[0].step_index = src[2];
src += 4;
*samples++ = c->status[0].predictor;
if (st) {
c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8));
c->status[1].step_index = src[2];
src += 4;
*samples++ = c->status[1].predictor;
}
while (src < buf + buf_size) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] >> 4, 3);
if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1],
src[0] & 0x0F, 3);
else
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] & 0x0F, 3);
src++;
}
break;
case CODEC_ID_ADPCM_IMA_DK3:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
if(buf_size + 16 > (samples_end - samples)*3/8)
return -1;
c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8));
c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8));
c->status[0].step_index = src[14];
c->status[1].step_index = src[15];
src += 16;
diff_channel = c->status[1].predictor;
while (1) {
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
diff_channel = (diff_channel + c->status[1].predictor) / 2;
*samples++ = c->status[0].predictor + c->status[1].predictor;
*samples++ = c->status[0].predictor - c->status[1].predictor;
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
diff_channel = (diff_channel + c->status[1].predictor) / 2;
*samples++ = c->status[0].predictor + c->status[1].predictor;
*samples++ = c->status[0].predictor - c->status[1].predictor;
}
break;
case CODEC_ID_ADPCM_IMA_WS:
while (src < buf + buf_size) {
if (st) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] >> 4 , 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[1],
src[0] & 0x0F, 3);
} else {
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] >> 4 , 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] & 0x0F, 3);
}
src++;
}
break;
case CODEC_ID_ADPCM_XA:
while (buf_size >= 128) {
xa_decode(samples, src, &c->status[0], &c->status[1],
avctx->channels);
src += 128;
samples += 28 * 8;
buf_size -= 128;
}
break;
case CODEC_ID_ADPCM_IMA_EA_EACS:
samples_in_chunk = bytestream_get_le32(&src) >> (1-st);
if (samples_in_chunk > buf_size-4-(8<<st)) {
src += buf_size - 4;
break;
}
for (i=0; i<=st; i++)
c->status[i].step_index = bytestream_get_le32(&src);
for (i=0; i<=st; i++)
c->status[i].predictor = bytestream_get_le32(&src);
for (; samples_in_chunk; samples_in_chunk--, src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
}
break;
case CODEC_ID_ADPCM_IMA_EA_SEAD:
for (; src < buf+buf_size; src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
*samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
}
break;
case CODEC_ID_ADPCM_EA:
samples_in_chunk = AV_RL32(src);
if (samples_in_chunk >= ((buf_size - 12) * 2)) {
src += buf_size;
break;
}
src += 4;
current_left_sample = (int16_t)AV_RL16(src);
src += 2;
previous_left_sample = (int16_t)AV_RL16(src);
src += 2;
current_right_sample = (int16_t)AV_RL16(src);
src += 2;
previous_right_sample = (int16_t)AV_RL16(src);
src += 2;
for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
coeff1l = ea_adpcm_table[ *src >> 4 ];
coeff2l = ea_adpcm_table[(*src >> 4 ) + 4];
coeff1r = ea_adpcm_table[*src & 0x0F];
coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
src++;
shift_left = (*src >> 4 ) + 8;
shift_right = (*src & 0x0F) + 8;
src++;
for (count2 = 0; count2 < 28; count2++) {
next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left;
next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right;
src++;
next_left_sample = (next_left_sample +
(current_left_sample * coeff1l) +
(previous_left_sample * coeff2l) + 0x80) >> 8;
next_right_sample = (next_right_sample +
(current_right_sample * coeff1r) +
(previous_right_sample * coeff2r) + 0x80) >> 8;
previous_left_sample = current_left_sample;
current_left_sample = av_clip_int16(next_left_sample);
previous_right_sample = current_right_sample;
current_right_sample = av_clip_int16(next_right_sample);
*samples++ = (unsigned short)current_left_sample;
*samples++ = (unsigned short)current_right_sample;
}
}
break;
case CODEC_ID_ADPCM_EA_MAXIS_XA:
for(channel = 0; channel < avctx->channels; channel++) {
for (i=0; i<2; i++)
coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
shift[channel] = (*src & 0x0F) + 8;
src++;
}
for (count1 = 0; count1 < (buf_size - avctx->channels) / avctx->channels; count1++) {
for(i = 4; i >= 0; i-=4) {
for(channel = 0; channel < avctx->channels; channel++) {
int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel];
sample = (sample +
c->status[channel].sample1 * coeff[channel][0] +
c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
c->status[channel].sample2 = c->status[channel].sample1;
c->status[channel].sample1 = av_clip_int16(sample);
*samples++ = c->status[channel].sample1;
}
}
src+=avctx->channels;
}
break;
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_EA_R3: {
const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
int32_t previous_sample, current_sample, next_sample;
int32_t coeff1, coeff2;
uint8_t shift;
unsigned int channel;
uint16_t *samplesC;
const uint8_t *srcC;
samples_in_chunk = (big_endian ? bytestream_get_be32(&src)
: bytestream_get_le32(&src)) / 28;
if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) ||
28*samples_in_chunk*avctx->channels > samples_end-samples) {
src += buf_size - 4;
break;
}
for (channel=0; channel<avctx->channels; channel++) {
srcC = src + (big_endian ? bytestream_get_be32(&src)
: bytestream_get_le32(&src))
+ (avctx->channels-channel-1) * 4;
samplesC = samples + channel;
if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
current_sample = (int16_t)bytestream_get_le16(&srcC);
previous_sample = (int16_t)bytestream_get_le16(&srcC);
} else {
current_sample = c->status[channel].predictor;
previous_sample = c->status[channel].prev_sample;
}
for (count1=0; count1<samples_in_chunk; count1++) {
if (*srcC == 0xEE) {
srcC++;
current_sample = (int16_t)bytestream_get_be16(&srcC);
previous_sample = (int16_t)bytestream_get_be16(&srcC);
for (count2=0; count2<28; count2++) {
*samplesC = (int16_t)bytestream_get_be16(&srcC);
samplesC += avctx->channels;
}
} else {
coeff1 = ea_adpcm_table[ *srcC>>4 ];
coeff2 = ea_adpcm_table[(*srcC>>4) + 4];
shift = (*srcC++ & 0x0F) + 8;
for (count2=0; count2<28; count2++) {
if (count2 & 1)
next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift;
else
next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift;
next_sample += (current_sample * coeff1) +
(previous_sample * coeff2);
next_sample = av_clip_int16(next_sample >> 8);
previous_sample = current_sample;
current_sample = next_sample;
*samplesC = current_sample;
samplesC += avctx->channels;
}
}
}
if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
c->status[channel].predictor = current_sample;
c->status[channel].prev_sample = previous_sample;
}
}
src = src + buf_size - (4 + 4*avctx->channels);
samples += 28 * samples_in_chunk * avctx->channels;
break;
}
case CODEC_ID_ADPCM_EA_XAS:
if (samples_end-samples < 32*4*avctx->channels
|| buf_size < (4+15)*4*avctx->channels) {
src += buf_size;
break;
}
for (channel=0; channel<avctx->channels; channel++) {
int coeff[2][4], shift[4];
short *s2, *s = &samples[channel];
for (n=0; n<4; n++, s+=32*avctx->channels) {
for (i=0; i<2; i++)
coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];
shift[n] = (src[2]&0x0F) + 8;
for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)
s2[0] = (src[0]&0xF0) + (src[1]<<8);
}
for (m=2; m<32; m+=2) {
s = &samples[m*avctx->channels + channel];
for (n=0; n<4; n++, src++, s+=32*avctx->channels) {
for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n];
int pred = s2[-1*avctx->channels] * coeff[0][n]
+ s2[-2*avctx->channels] * coeff[1][n];
s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
}
}
}
}
samples += 32*4*avctx->channels;
break;
case CODEC_ID_ADPCM_IMA_AMV:
case CODEC_ID_ADPCM_IMA_SMJPEG:
c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
c->status[0].step_index = bytestream_get_le16(&src);
if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
src+=4;
while (src < buf + buf_size) {
char hi, lo;
lo = *src & 0x0F;
hi = *src >> 4;
if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
FFSWAP(char, hi, lo);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
lo, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
hi, 3);
src++;
}
break;
case CODEC_ID_ADPCM_CT:
while (src < buf + buf_size) {
if (st) {
*samples++ = adpcm_ct_expand_nibble(&c->status[0],
src[0] >> 4);
*samples++ = adpcm_ct_expand_nibble(&c->status[1],
src[0] & 0x0F);
} else {
*samples++ = adpcm_ct_expand_nibble(&c->status[0],
src[0] >> 4);
*samples++ = adpcm_ct_expand_nibble(&c->status[0],
src[0] & 0x0F);
}
src++;
}
break;
case CODEC_ID_ADPCM_SBPRO_4:
case CODEC_ID_ADPCM_SBPRO_3:
case CODEC_ID_ADPCM_SBPRO_2:
if (!c->status[0].step_index) {
*samples++ = 128 * (*src++ - 0x80);
if (st)
*samples++ = 128 * (*src++ - 0x80);
c->status[0].step_index = 1;
}
if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
while (src < buf + buf_size) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 4, 4, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x0F, 4, 0);
src++;
}
} else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
while (src < buf + buf_size && samples + 2 < samples_end) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 5 , 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
(src[0] >> 2) & 0x07, 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] & 0x03, 2, 0);
src++;
}
} else {
while (src < buf + buf_size && samples + 3 < samples_end) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 6 , 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
(src[0] >> 4) & 0x03, 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
(src[0] >> 2) & 0x03, 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x03, 2, 2);
src++;
}
}
break;
case CODEC_ID_ADPCM_SWF:
{
GetBitContext gb;
const int *table;
int k0, signmask, nb_bits, count;
int size = buf_size*8;
init_get_bits(&gb, buf, size);
read bits & initial values
nb_bits = get_bits(&gb, 2)+2;
av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits);
table = swf_index_tables[nb_bits-2];
k0 = 1 << (nb_bits-2);
signmask = 1 << (nb_bits-1);
while (get_bits_count(&gb) <= size - 22*avctx->channels) {
for (i = 0; i < avctx->channels; i++) {
*samples++ = c->status[i].predictor = get_sbits(&gb, 16);
c->status[i].step_index = get_bits(&gb, 6);
}
for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
int i;
for (i = 0; i < avctx->channels; i++) {
similar to IMA adpcm
int delta = get_bits(&gb, nb_bits);
int step = step_table[c->status[i].step_index];
long vpdiff = 0; vpdiff = (delta+0.5)*step/4
int k = k0;
do {
if (delta & k)
vpdiff += step;
step >>= 1;
k >>= 1;
} while(k);
vpdiff += step;
if (delta & signmask)
c->status[i].predictor -= vpdiff;
else
c->status[i].predictor += vpdiff;
c->status[i].step_index += table[delta & (~signmask)];
c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
c->status[i].predictor = av_clip_int16(c->status[i].predictor);
*samples++ = c->status[i].predictor;
if (samples >= samples_end) {
av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
return -1;
}
}
}
}
src += buf_size;
break;
}
case CODEC_ID_ADPCM_YAMAHA:
while (src < buf + buf_size) {
if (st) {
*samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
src[0] & 0x0F);
*samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
src[0] >> 4 );
} else {
*samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
src[0] & 0x0F);
*samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
src[0] >> 4 );
}
src++;
}
break;
case CODEC_ID_ADPCM_THP:
{
int table[2][16];
unsigned int samplecnt;
int prev[2][2];
int ch;
if (buf_size < 80) {
av_log(avctx, AV_LOG_ERROR, "frame too small\n");
return -1;
}
src+=4;
samplecnt = bytestream_get_be32(&src);
for (i = 0; i < 32; i++)
table[0][i] = (int16_t)bytestream_get_be16(&src);
for (i = 0; i < 4; i++)
prev[0][i] = (int16_t)bytestream_get_be16(&src);
if (samplecnt >= (samples_end - samples) / (st + 1)) {
av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
return -1;
}
for (ch = 0; ch <= st; ch++) {
samples = (unsigned short *) data + ch;
for (i = 0; i < samplecnt / 14; i++) {
int index = (*src >> 4) & 7;
unsigned int exp = 28 - (*src++ & 15);
int factor1 = table[ch][index * 2];
int factor2 = table[ch][index * 2 + 1];
for (n = 0; n < 14; n++) {
int32_t sampledat;
if(n&1) sampledat= *src++ <<28;
else sampledat= (*src&0xF0)<<24;
sampledat = ((prev[ch][0]*factor1
+ prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
*samples = av_clip_int16(sampledat);
prev[ch][1] = prev[ch][0];
prev[ch][0] = *samples++;
samples += st;
}
}
}
samples -= st;
break;
}
default:
return -1;
}
*data_size = (uint8_t *)samples - (uint8_t *)data;
return src - buf;
}
| 1threat |
if_start(Slirp *slirp)
{
uint64_t now = qemu_get_clock_ns(rt_clock);
int requeued = 0;
bool from_batchq = false;
struct mbuf *ifm, *ifqt;
DEBUG_CALL("if_start");
if (slirp->if_queued == 0)
return;
again:
if (!slirp_can_output(slirp->opaque))
return;
if (slirp->if_fastq.ifq_next != &slirp->if_fastq) {
ifm = slirp->if_fastq.ifq_next;
} else {
if (slirp->next_m != &slirp->if_batchq)
ifm = slirp->next_m;
else
ifm = slirp->if_batchq.ifq_next;
from_batchq = true;
}
slirp->if_queued--;
if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) {
requeued++;
goto out;
}
if (from_batchq) {
slirp->next_m = ifm->ifq_next;
}
ifqt = ifm->ifq_prev;
remque(ifm);
if (ifm->ifs_next != ifm) {
insque(ifm->ifs_next, ifqt);
ifs_remque(ifm);
}
if (ifm->ifq_so) {
if (--ifm->ifq_so->so_queued == 0)
ifm->ifq_so->so_nqueued = 0;
}
m_free(ifm);
out:
if (slirp->if_queued)
goto again;
slirp->if_queued = requeued;
}
| 1threat |
for loop for iteration in a string : #include <iostream>
#include<string>
using std::string;
int main()
{
string s("some string");
for (decltype(s.size()) index = 0; index != s.size() && !isspace(s[index]); ++index)
s[index] = toupper(s[index]);
std::cout << s << std::endl;
return 0;
}
\\can someone tell me how the "for" loop in the program helps in uppercasing the strings first word? please I'm stuck. thank you
| 0debug |
using 'vendored_frameworks' and 'source_files' for cocoapod using 'use_frameworks!' : <p>I'm building a cocoapod that basically contains a framework (private sources) and a view (open source) that rely on this framework, all made in Objective-C.</p>
<p>In the podspec I have the following lines :</p>
<ul>
<li>spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'</li>
<li>spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']</li>
</ul>
<p>When using the <code>use_frameworks!</code> syntax, I can't <code>#import MyFramework</code></p>
<p>I just don't understand what's happening. </p>
<p>Moreover, when I remove the <code>spec.source_files</code> line, I can <code>#import MyFramework</code> and it works perfectly, but of course I cannot use <code>MyView</code>.</p>
<p>What am I doing wrong ?</p>
| 0debug |
static void coroutine_fn send_pending_req(BDRVSheepdogState *s, uint64_t oid)
{
AIOReq *aio_req;
SheepdogAIOCB *acb;
while ((aio_req = find_pending_req(s, oid)) != NULL) {
acb = aio_req->aiocb;
QLIST_REMOVE(aio_req, aio_siblings);
QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, false,
acb->aiocb_type);
}
}
| 1threat |
Adding numbers with trailing zeros : Need some urgent help.
I have a number like 00001 and I want to keep adding 1 to it till i reach 00044
How can i do this in PHP?
I tried but it takes it as 1 not 00001
Thanks.
So basically i want is
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
.
.
.
.
| 0debug |
static void do_info_registers(Monitor *mon)
{
CPUState *env;
env = mon_get_cpu();
if (!env)
return;
#ifdef TARGET_I386
cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
X86_DUMP_FPU);
#else
cpu_dump_state(env, (FILE *)mon, monitor_fprintf,
0);
#endif
}
| 1threat |
Change elasticbeanstalk environment vpc : <p>I can't seem to find any documentation on this. How do I go about changing the VPC for an elasticbeanstalk environment? I have tried changing the security group from the current group to a group in the new VPC, but amazon returns the following error:</p>
<pre><code>SecurityGroups: Invalid option value: 'sg-a91f43d2' (Namespace: 'aws:autoscaling:launchconfiguration', OptionName: 'SecurityGroups'): The security group 'sg-a91f43d2' does not exist
</code></pre>
<p>The rule does exist, so I assume it is complaining because the rule is in a different VPC (which is the whole point).</p>
| 0debug |
How do run a task in background and even if app terminated in xamarin forms? : <p>I need to run a task at a specified time even if my app in the background or terminated in Xamarin Forms(Android and iOS). Please suggest me the best way to do it.</p>
| 0debug |
static int iscsi_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{
int ret = 0;
int64_t total_size = 0;
BlockDriverState *bs;
IscsiLun *iscsilun = NULL;
QDict *bs_options;
bs = bdrv_new("");
while (options && options->name) {
if (!strcmp(options->name, "size")) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
}
options++;
}
bs->opaque = g_malloc0(sizeof(struct IscsiLun));
iscsilun = bs->opaque;
bs_options = qdict_new();
qdict_put(bs_options, "filename", qstring_from_str(filename));
ret = iscsi_open(bs, bs_options, 0, NULL);
QDECREF(bs_options);
if (ret != 0) {
goto out;
}
if (iscsilun->nop_timer) {
timer_del(iscsilun->nop_timer);
timer_free(iscsilun->nop_timer);
}
if (iscsilun->type != TYPE_DISK) {
ret = -ENODEV;
goto out;
}
if (bs->total_sectors < total_size) {
ret = -ENOSPC;
goto out;
}
ret = 0;
out:
if (iscsilun->iscsi != NULL) {
iscsi_destroy_context(iscsilun->iscsi);
}
g_free(bs->opaque);
bs->opaque = NULL;
bdrv_unref(bs);
return ret;
}
| 1threat |
static always_inline void gen_farith3 (void *helper,
int ra, int rb, int rc)
{
if (unlikely(rc == 31))
return;
if (ra != 31) {
if (rb != 31)
tcg_gen_helper_1_2(helper, cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]);
else {
TCGv tmp = tcg_const_i64(0);
tcg_gen_helper_1_2(helper, cpu_fir[rc], cpu_fir[ra], tmp);
tcg_temp_free(tmp);
}
} else {
TCGv tmp = tcg_const_i64(0);
if (rb != 31)
tcg_gen_helper_1_2(helper, cpu_fir[rc], tmp, cpu_fir[rb]);
else
tcg_gen_helper_1_2(helper, cpu_fir[rc], tmp, tmp);
tcg_temp_free(tmp);
}
}
| 1threat |
Run artisan command in laravel 5 : <p>I have controller like this</p>
<pre><code> public function store(Request $request)
{
Artisan::call("php artisan infyom:scaffold {$request['name']} --fieldsFile=public/Product.json");
}
</code></pre>
<p>Show me error </p>
<blockquote>
<p>There are no commands defined in the "php artisan infyom" namespace.</p>
</blockquote>
<p>When I run this command in CMD it work correctly </p>
| 0debug |
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
const uint8_t *buf_end = avpkt->data + avpkt->size;
AVFrame * const p = data;
unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen;
uint8_t *ptr, *ptr2 = NULL;
const uint8_t *bufstart = buf;
int ret;
if (avpkt->size < 32)
return AVERROR_INVALIDDATA;
if (AV_RB32(buf) != RAS_MAGIC) {
av_log(avctx, AV_LOG_ERROR, "this is not sunras encoded data\n");
return AVERROR_INVALIDDATA;
}
w = AV_RB32(buf + 4);
h = AV_RB32(buf + 8);
depth = AV_RB32(buf + 12);
type = AV_RB32(buf + 20);
maptype = AV_RB32(buf + 24);
maplength = AV_RB32(buf + 28);
buf += 32;
if (type == RT_EXPERIMENTAL) {
avpriv_request_sample(avctx, "TIFF/IFF/EXPERIMENTAL (compression) type");
return AVERROR_PATCHWELCOME;
}
if (type > RT_FORMAT_IFF) {
av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n");
return AVERROR_INVALIDDATA;
}
if (maptype == RMT_RAW) {
avpriv_request_sample(avctx, "Unknown colormap type");
return AVERROR_PATCHWELCOME;
}
if (maptype > RMT_RAW) {
av_log(avctx, AV_LOG_ERROR, "invalid colormap type\n");
return AVERROR_INVALIDDATA;
}
if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) {
av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n");
return -1;
}
switch (depth) {
case 1:
avctx->pix_fmt = maplength ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_MONOWHITE;
break;
case 4:
avctx->pix_fmt = maplength ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_NONE;
break;
case 8:
avctx->pix_fmt = maplength ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
break;
case 24:
avctx->pix_fmt = (type == RT_FORMAT_RGB) ? AV_PIX_FMT_RGB24 : AV_PIX_FMT_BGR24;
break;
case 32:
avctx->pix_fmt = (type == RT_FORMAT_RGB) ? AV_PIX_FMT_0RGB : AV_PIX_FMT_0BGR;
break;
default:
av_log(avctx, AV_LOG_ERROR, "invalid depth\n");
return AVERROR_INVALIDDATA;
}
ret = ff_set_dimensions(avctx, w, h);
if (ret < 0)
return ret;
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
return ret;
p->pict_type = AV_PICTURE_TYPE_I;
if (buf_end - buf < maplength)
return AVERROR_INVALIDDATA;
if (depth > 8 && maplength) {
av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n");
} else if (maplength) {
unsigned int len = maplength / 3;
if (maplength % 3 || maplength > 768) {
av_log(avctx, AV_LOG_WARNING, "invalid colormap length\n");
return AVERROR_INVALIDDATA;
}
ptr = p->data[1];
for (x = 0; x < len; x++, ptr += 4)
*(uint32_t *)ptr = (0xFFU<<24) + (buf[x]<<16) + (buf[len+x]<<8) + buf[len+len+x];
}
buf += maplength;
if (maplength && depth < 8) {
ptr = ptr2 = av_malloc_array((w + 15), h);
if (!ptr)
return AVERROR(ENOMEM);
stride = (w + 15 >> 3) * depth;
} else {
ptr = p->data[0];
stride = p->linesize[0];
}
len = (depth * w + 7) >> 3;
alen = len + (len & 1);
if (type == RT_BYTE_ENCODED) {
int value, run;
uint8_t *end = ptr + h * stride;
x = 0;
while (ptr != end && buf < buf_end) {
run = 1;
if (buf_end - buf < 1)
return AVERROR_INVALIDDATA;
if ((value = *buf++) == RLE_TRIGGER) {
run = *buf++ + 1;
if (run != 1)
value = *buf++;
}
while (run--) {
if (x < len)
ptr[x] = value;
if (++x >= alen) {
x = 0;
ptr += stride;
if (ptr == end)
break;
}
}
}
} else {
for (y = 0; y < h; y++) {
if (buf_end - buf < len)
break;
memcpy(ptr, buf, len);
ptr += stride;
buf += alen;
}
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && depth < 8) {
uint8_t *ptr_free = ptr2;
ptr = p->data[0];
for (y=0; y<h; y++) {
for (x = 0; x < (w + 7 >> 3) * depth; x++) {
if (depth == 1) {
ptr[8*x] = ptr2[x] >> 7;
ptr[8*x+1] = ptr2[x] >> 6 & 1;
ptr[8*x+2] = ptr2[x] >> 5 & 1;
ptr[8*x+3] = ptr2[x] >> 4 & 1;
ptr[8*x+4] = ptr2[x] >> 3 & 1;
ptr[8*x+5] = ptr2[x] >> 2 & 1;
ptr[8*x+6] = ptr2[x] >> 1 & 1;
ptr[8*x+7] = ptr2[x] & 1;
} else {
ptr[2*x] = ptr2[x] >> 4;
ptr[2*x+1] = ptr2[x] & 0xF;
}
}
ptr += p->linesize[0];
ptr2 += (w + 15 >> 3) * depth;
}
av_freep(&ptr_free);
}
*got_frame = 1;
return buf - bufstart;
}
| 1threat |
static void block_migration_cancel(void *opaque)
{
blk_mig_cleanup();
}
| 1threat |
static void __attribute__((destructor)) coroutine_cleanup(void)
{
Coroutine *co;
Coroutine *tmp;
QSLIST_FOREACH_SAFE(co, &pool, pool_next, tmp) {
QSLIST_REMOVE_HEAD(&pool, pool_next);
qemu_coroutine_delete(co);
}
}
| 1threat |
db.execute('SELECT * FROM products WHERE product_id = ' + product_input) | 1threat |
Android ActivityThread.reportSizeConfigurations causes app to freeze with black screen and then crash : <p>I have a crash in my app. It happens for a lot of users and its multiple places in ActivityThread.java method reportSizeConfigurations. I dont know what this is used for, and why it freezes.</p>
<p>The freeze happens right after the splash screen (when the main activity is started) and is only happening on upgrading of the app. If you reinstall the application the problem goes away. Problem is, I cant tell all the users to reinstall the application... </p>
<p>Does anyone know what might cause this and why? It seems maybe to be connected with some DB handling, but thats just a guess.</p>
<p>Heres the stacktrace from Crashlytics:</p>
<pre><code>Fatal Exception: java.lang.IllegalArgumentException: reportSizeConfigurations: ActivityRecord not found for: Token{a28a055 null}
at android.os.Parcel.readException(Parcel.java:1697)
at android.os.Parcel.readException(Parcel.java:1646)
at android.app.ActivityManagerProxy.reportSizeConfigurations(ActivityManagerNative.java:8342)
at android.app.ActivityThread.reportSizeConfigurations(ActivityThread.java:3049)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2992)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
</code></pre>
<p>Heres the stacktrace from play store 'ANRs & crashes':</p>
<pre><code> "main" prio=5 tid=1 TimedWaiting
| group="main" sCount=1 dsCount=0 obj=0x74864f70 self=0x7f8b896a00
| sysTid=28578 nice=0 cgrp=default sched=0/0 handle=0x7f8f832a98
| state=S schedstat=( 237746089 66838748 1069 ) utm=18 stm=5 core=6 HZ=100
| stack=0x7fcdbf9000-0x7fcdbfb000 stackSize=8MB
| held mutexes=
at java.lang.Object.wait! (Native method)
- waiting on <0x0c54fb7b> (a java.lang.Object)
at java.lang.Thread.parkFor$ (Thread.java:2127)
- locked <0x0c54fb7b> (a java.lang.Object)
at sun.misc.Unsafe.park (Unsafe.java:325)
at java.util.concurrent.locks.LockSupport.parkNanos (LockSupport.java:201)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection (SQLiteConnectionPool.java:670)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection (SQLiteConnectionPool.java:348)
at android.database.sqlite.SQLiteSession.acquireConnection (SQLiteSession.java:894)
at android.database.sqlite.SQLiteSession.prepare (SQLiteSession.java:586)
at android.database.sqlite.SQLiteProgram.<init> (SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init> (SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:1318)
at android.database.sqlite.SQLiteQueryBuilder.query (SQLiteQueryBuilder.java:399)
at android.database.sqlite.SQLiteQueryBuilder.query (SQLiteQueryBuilder.java:294)
at com.norwegian.travelassistant.managers.storagemanager.StorageManager.query (StorageManager.java:1011)
at com.norwegian.travelassistant.managers.storagemanager.StorageManager.a (StorageManager.java:1218)
- locked <0x00f0bd98> (a java.lang.Object)
at com.norwegian.travelassistant.managers.storagemanager.StorageManager.a (StorageManager.java:1205)
at com.norwegian.travelassistant.managers.storagemanager.StorageManager.F (StorageManager.java:1812)
at com.norwegian.travelassistant.managers.e.a (LanguageManager.java:63)
at com.norwegian.travelassistant.managers.e.a (LanguageManager.java:84)
at com.norwegian.travelassistant.tabbar.TabsActivity.onCreate (TabsActivity.java:141)
at android.app.Activity.performCreate (Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2664)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2772)
at android.app.ActivityThread.-wrap12 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1515)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:241)
at android.app.ActivityThread.main (ActivityThread.java:6217)
at java.lang.reflect.Method.invoke! (Native method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:755)
</code></pre>
<p>Please tell if you need more info</p>
| 0debug |
preg_match with first instance : <p>I'm trying to grab a word(s) between the word "in" and "with" inside of a string. The problem is that I have another instance of "with", it will extend the wildcard.</p>
<p>Here is an example:</p>
<pre><code>$item = 'This is a car in red with new tires and with a radio';
$pattern = = '/in (.*) with/i';
preg_match($pattern, $item, $matches);
</code></pre>
<p>Returns:</p>
<pre><code>array(2) {
[0]=>
string(30) "in red with new tires and with"
[1]=>
string(22) "red with new tires and"
}
</code></pre>
<p>What I would like $matches[1] to be is 'red'</p>
| 0debug |
It is clear that the form does not appear. But how to remake? : It is clear that the form does not appear. But how to remake? Through the console, everything works.
void Form1_Load(object sender, EventArgs e)
{
String host = Dns.GetHostName();//name kompa
//ip pc
IPAddress ip = Dns.GetHostByName(host).AddressList[0];
const int port = 2222;
label1.Text = host;
label2.Text = "Π‘Π΅ΡΠ²Π΅Ρ Π·Π°ΠΏΡΡΠ΅Π½ Π½Π° " + ip.ToString() + ":" + port.ToString();
server.serversocket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
server.serversocket.Bind(new IPEndPoint(ip, port));
server.serversocket.Listen(100);
//ΠΎΡΠΈΠ±ΠΎΡΠΊΠ° Π² ΡΠΈΠΊΠ»Π΅
while (server.work)
{
MessageBox.Show("dsff");
Socket handle = server.serversocket.Accept();
richTextBox1.AppendText("Π½ΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅" + handle.RemoteEndPoint.ToString());
new user(handle);
} | 0debug |
on my list I want to detect when it's -1 or 0 in length otherwise i want it to give me the second [1] index : The function second_item below returns the second item in the list l.
However, what if l has length 0 or 1? Then taking the second item makes no sense and will result in an error.
Change the code so that it detects these cases and returns -1 for lists of length 0 or 1, rather than causing an error.
For any other list, the function should still return the second item.
**def second_item(l):
if len(l) <= 1:
return l
else:
return l[1]** | 0debug |
static QDict *do_info_vnc_client(Monitor *mon, VncState *client)
{
QDict *qdict;
qdict = qdict_new();
if (vnc_qdict_remote_addr(qdict, client->csock) < 0) {
QDECREF(qdict);
return NULL;
}
#ifdef CONFIG_VNC_TLS
if (client->tls.session &&
client->tls.dname) {
qdict_put(qdict, "x509_dname", qstring_from_str(client->tls.dname));
}
#endif
#ifdef CONFIG_VNC_SASL
if (client->sasl.conn &&
client->sasl.username) {
qdict_put(qdict, "sasl_username",
qstring_from_str(client->sasl.username));
}
#endif
return qdict;
}
| 1threat |
static void mem_info(Monitor *mon)
{
CPUState *env;
int l1, l2, prot, last_prot;
uint32_t pgd, pde, pte, start, end;
env = mon_get_cpu();
if (!env)
return;
if (!(env->cr[0] & CR0_PG_MASK)) {
monitor_printf(mon, "PG disabled\n");
return;
}
pgd = env->cr[3] & ~0xfff;
last_prot = 0;
start = -1;
for(l1 = 0; l1 < 1024; l1++) {
cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
pde = le32_to_cpu(pde);
end = l1 << 22;
if (pde & PG_PRESENT_MASK) {
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
mem_print(mon, &start, &last_prot, end, prot);
} else {
for(l2 = 0; l2 < 1024; l2++) {
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
(uint8_t *)&pte, 4);
pte = le32_to_cpu(pte);
end = (l1 << 22) + (l2 << 12);
if (pte & PG_PRESENT_MASK) {
prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
} else {
prot = 0;
}
mem_print(mon, &start, &last_prot, end, prot);
}
}
} else {
prot = 0;
mem_print(mon, &start, &last_prot, end, prot);
}
}
}
| 1threat |
SpringBoot How to find records by nested attributes : <p>I have a <strong>User</strong> model which has certain Attributes as depicted below</p>
<pre><code>/**
* The Class User.
*/
@Entity
@Table(name = "user")
public class User implements UserDetails {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 3961569938206826979L;
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
/** The first name. */
private String firstName;
/** The last name. */
private String lastName;
/** The username. */
@NotNull
@Size(min = 10, message = "username should have atleast 10 characters")
private String username;
/** The password. */
private String password;
/** The email. */
private String email;
/** The enabled. */
private boolean enabled;
/** The last password reset date. */
private ZonedDateTime lastPasswordResetDate;
/** The creation date. */
private ZonedDateTime creationDate;
/** The phone number. */
private String phoneNumber;
private String deviceId;
/** The authorities. */
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "user_authority", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "authority_id", referencedColumnName = "id"))
private List<Authority> authorities;
/**
* Gets the id.
*
* @return the id
*/
public long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(long id) {
this.id = id;
}
/**
* Gets the first name.
*
* @return the first name
*/
public String getFirstName() {
return firstName;
}
/**
* Sets the first name.
*
* @param firstName the new first name
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* Gets the last name.
*
* @return the last name
*/
public String getLastName() {
return lastName;
}
/**
* Sets the last name.
*
* @param lastName the new last name
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.core.userdetails.UserDetails#getPassword()
*/
public String getPassword() {
return password;
}
/**
* Sets the password.
*
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.core.userdetails.UserDetails#getAuthorities()
*/
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return authorities;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.core.userdetails.UserDetails#getUsername()
*/
@Override
public String getUsername() {
return username;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.core.userdetails.UserDetails#isAccountNonExpired
* ()
*/
@Override
public boolean isAccountNonExpired() {
return true;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.core.userdetails.UserDetails#isAccountNonLocked(
* )
*/
@Override
public boolean isAccountNonLocked() {
return true;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.core.userdetails.UserDetails#
* isCredentialsNonExpired()
*/
@Override
public boolean isCredentialsNonExpired() {
return true;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.core.userdetails.UserDetails#isEnabled()
*/
@Override
public boolean isEnabled() {
return enabled;
}
/**
* Gets the email.
*
* @return the email
*/
public String getEmail() {
return email;
}
/**
* Sets the email.
*
* @param email the new email
*/
public void setEmail(String email) {
this.email = email;
}
/**
* Gets the last password reset date.
*
* @return the last password reset date
*/
public ZonedDateTime getLastPasswordResetDate() {
return lastPasswordResetDate;
}
/**
* Sets the last password reset date.
*
* @param lastPasswordResetDate the new last password reset date
*/
public void setLastPasswordResetDate(ZonedDateTime lastPasswordResetDate) {
this.lastPasswordResetDate = lastPasswordResetDate;
}
/**
* Sets the enabled.
*
* @param enabled the new enabled
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Sets the authorities.
*
* @param authorities the new authorities
*/
public void setAuthorities(List<Authority> authorities) {
this.authorities = authorities;
}
/**
* Gets the creation date.
*
* @return the creation date
*/
public ZonedDateTime getCreationDate() {
return creationDate;
}
/**
* Sets the creation date.
*
* @param creationDate the new creation date
*/
public void setCreationDate(ZonedDateTime creationDate) {
this.creationDate = creationDate;
}
/**
* Gets the phone number.
*
* @return the phone number
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* Sets the phone number.
*
* @param phoneNumber the new phone number
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "User [id=" + id + ", email=" + email + ", firstName=" + firstName + ", lastName=" + lastName
+ ", password=" + password + ", enabled=" + enabled + ", lastPasswordResetDate=" + lastPasswordResetDate
+ ", authorities=" + authorities + "]";
}
}
</code></pre>
<p>The <strong>Authority</strong> model has following attributes :</p>
<pre><code>/**
* The Class Authority.
*/
@Entity
public class Authority implements GrantedAuthority
{
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -7546748403961204843L;
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
/** The name. */
@Enumerated(EnumType.STRING)
private UserRoleName name;
/* (non-Javadoc)
* @see org.springframework.security.core.GrantedAuthority#getAuthority()
*/
@Override
public String getAuthority()
{
return name.name();
}
/**
* Gets the id.
*
* @return the id
*/
public long getId()
{
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId( long id )
{
this.id = id;
}
/**
* Gets the roles.
*
* @return the roles
*/
@JsonIgnore
public UserRoleName getRoles()
{
return name;
}
/**
* Sets the roles.
*
* @param name the new roles
*/
public void setRoles( UserRoleName name )
{
this.name = name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName( UserRoleName name )
{
this.name = name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "Authority [id=" + id + ", name=" + name + "]";
}
}
</code></pre>
<p>Now I need to fetch user whose Role is <strong>ROLE_ADMIN</strong>. So do I first need to fetch the object of <strong>Authority</strong> having role as <strong>ROLE_ADMIN</strong> and then call <strong>findOneByAuthority</strong>, or is there something possible with one function?</p>
<p>I am comming from <strong>Django</strong> where fetching a record by nested attributes is very simple?
Someone can help me in this?</p>
| 0debug |
static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
uint32_t length,
Error **errp)
{
QIOChannel *ioc;
QIOChannelTLS *tioc;
struct NBDTLSHandshakeData data = { 0 };
trace_nbd_negotiate_handle_starttls();
ioc = client->ioc;
if (length) {
if (nbd_drop(ioc, length, errp) < 0) {
return NULL;
}
nbd_negotiate_send_rep_err(ioc, NBD_REP_ERR_INVALID, NBD_OPT_STARTTLS,
errp,
"OPT_STARTTLS should not have length");
return NULL;
}
if (nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK,
NBD_OPT_STARTTLS, errp) < 0) {
return NULL;
}
tioc = qio_channel_tls_new_server(ioc,
client->tlscreds,
client->tlsaclname,
errp);
if (!tioc) {
return NULL;
}
qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-server-tls");
trace_nbd_negotiate_handle_starttls_handshake();
data.loop = g_main_loop_new(g_main_context_default(), FALSE);
qio_channel_tls_handshake(tioc,
nbd_tls_handshake,
&data,
NULL);
if (!data.complete) {
g_main_loop_run(data.loop);
}
g_main_loop_unref(data.loop);
if (data.error) {
object_unref(OBJECT(tioc));
error_propagate(errp, data.error);
return NULL;
}
return QIO_CHANNEL(tioc);
}
| 1threat |
two columns layout using one container : I'm hoping you can help me with my html layout problem. See screenshot.
[Screenshot][1]
[1]: https://i.stack.imgur.com/HN3QJ.jpg
Adding a padding can solve this problem but it is not responsive for mobile devices. Is there a better way to this?
Thank you so much!
P.S: I'm using bootstrap.
| 0debug |
Layout with 3 columns of different sizes using Flex : <p>I have a section of the site that must contain three elements side by side. Each element has a minimum width. If the width of the screen is not sufficient to contain all three elements, those that do not fit, go into a new line.</p>
<p>To build this layout I used <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/" rel="noreferrer">Flex</a>.
<a href="https://plnkr.co/edit/jAtSd1aCn4Cz6B0VOXa6?p=preview" rel="noreferrer"><strong>Code</strong></a>.</p>
<p>html:</p>
<pre><code><main id='main'>
<div id='firstRow' class='row'>
<div id='col1C' class='col'>col1C title
<div id='col1Ccon'>col1Ccon content</div>
</div>
<div id='col2C' class='col'>col2C title
<div id='col2Ccon'>col2Ccon content</div>
</div>
<div id='col3C' class='col'>col3C title
<div id='col3Ccon'>col3Ccon content</div>
</div>
</div>
</main>
</code></pre>
<p>css:</p>
<pre><code>:root {
--w1Col: 478px;
--w2Col: 370px;
--w3Col: 350px;
--wSum3: calc(var(--w1Col) + var(--w2Col) + var(--w3Col));
}
html {
/*height: 100%;*/
}
body {
margin: 0;
font-size: 9pt;
font-family: 'Roboto', sans-serif;
font-weight: 300;
background-color: whitesmoke;
height: 100%;
display: flex;
flex-direction: column;
}
/***************************************************************
* Layout first row
*/
#main {
background-color: white;
/*border: 4px solid red;*/
color: black;
height: 100%;
flex-grow: 1; /* ability for a flex item to grow if necessary */
flex-shrink: 0; /* ability for a flex item to shrink if necessary */
flex-basis: auto; /* defines the default size of an element before the remaining space is distributed */
}
#firstRow {
background-color: white;
/*border: 1px solid black;*/
margin: 10px;
padding: 10px;
display: flex;
flex-direction: row; /* colums layout */
flex-wrap: wrap; /* wrap in multiple lines if it's necessary */
/*min-width: var(--wSum3);*/
/*justify-content: flex-end; defines the alignment along the main axis */
}
#firstRow .col {
/*border: 1px solid black;*/
flex: 1;
padding: 5px;
text-align: center;
}
#col1C {
background-color: green;
width: var(--w1Col);
min-width: var(--w1Col);
order: 1; /* column order */
flex-basis: 40%;/*var(--w1Col); column width */
justify-content: flex-end;
}
#col2C {
background-color: blue;
width: var(--w2Col);
min-width: var(--w2Col);
order: 2; /* column order */
flex-basis: 35%; /* var(--w2Col); column width */
justify-content: flex-end;
}
#col3C {
background-color: red;
width: var(--w3Col);
min-width: var(--w3Col);
order: 3; /* column order */
flex-basis: 25%; /*var(--w3Col); column width */
justify-content: flex-end;
}
#col1Ccon, #col2Ccon, #col3Ccon {
/*border: 1px solid black;*/
margin: 0 auto; /* center content */
}
#col1Ccon {
width: var(--w1Col);
background-color: lightgreen;
height: 200px;
}
#col2Ccon {
width: var(--w2Col);
background-color: lightblue;
height: 150px;
}
#col3Ccon {
width: var(--w3Col);
background-color: salmon;
height: 200px;
}
</code></pre>
<p>The code works but there are some tricks I would like to fix.</p>
<ol>
<li><p>the 3 columns all have the same width and I would like to be able to choose this width. This is because the first element has a minimum width greater than the other two, so the edge is smaller and aesthetically ugly. See <a href="https://jsfiddle.net/6rys2xe5/4/" rel="noreferrer">the same example</a>, I changed only colors</p></li>
<li><p>the remaining space now grows on both sides of the <code>col*Ccon</code> containers. Instead I would like to grow only on the left side of <code>col1Ccon</code> and on the right side <code>col3Ccon</code>. I would therefore like the contents of the site (<code>col1Ccon + col2Ccon + col3Ccon</code>) to always remain in the center of the page and what changes are the "border" that grow and decrease.</p></li>
</ol>
<p>I'm stuck and any suggestions are greatly appreciated. Thanks :)</p>
| 0debug |
cursor.execute('SELECT * FROM users WHERE username = ' + user_input) | 1threat |
API Testing In Golang : <p>I know that Golang has a <a href="https://www.golang-book.com/books/intro/12" rel="noreferrer">testing package</a> that allows for running unit tests. This seems to work well for internally calling Golang functions for unit tests but it seems that some people were trying to adapt it for <a href="http://dennissuratna.com/testing-in-go/" rel="noreferrer">API testing</a> as well.</p>
<p>Given to the great flexibility of automated testing frameworks like Node.js' Mocha with the Chai assertion library, for what kind of tests does it make sense to use Golang's testing package vs. something else?</p>
<p>Thanks.</p>
| 0debug |
Please check what is wrong in this mysql query i am getting the following error : <p>I am getting the following error:<br>
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
I tried to change the code but no use can any body help me please make this code workable.
My code is:</p>
<pre><code><?php
/*home page bannerrotator*/
$sql="SELECT homelb,bdetails1,bdetails2,abovefoo1,abovefoo2 FROM
adsettings WHERE NOT(hview1=hometotal AND hview2=bdtotal1 AND
hview3=bdtotal2 AND hview4=foototal1 AND hview5=foototal2) LIMIT 10";
$result=mysqli_query($connection,$sql);
$rows=mysqli_num_rows($result);
if($rows!=0)
{
$leaderboard = array();
$bd1=array();
$bd2=array();
$foo1=array();
$foo2=array();
$i=0;
while ($row = mysqli_fetch_assoc($result)) {
$leaderboard[i]=$row['homelb'];
$bd1[i]=$row['bdetails1'];
$bd2[i]=$row['bdetails2'];
$foo1[i]=$row['abovefoo1'];
$foo2[i]=$row['abovefoo2'];
i++;
}
shuffle($leaderboard);
shuffle($bd2);
shuffle($bd1);
shuffle($foo1);
shuffle($foo2);
}
else
{
$leaderboard[0]="Advertise Here";
$bd1[0]="Advertise Here";
$bd2[0]="Advertise Here";
$foo1[0]="Advertise Here";
$foo2[0]="Advertise Here";
}
/*login page adverts*/
?>
</code></pre>
| 0debug |
Web Chat to communicate with another web browser : <p>I have built and published a BOT (using Microsoft BOT Framework, LUIS and C#).
I am able to use web chat and communicate with my bot (in a web browser).</p>
<p>What I am trying to do is:</p>
<ul>
<li><p>Have the browser hosting my BOT drive the UI in another browser.</p>
<p>Ex. The user types in <code>"Show me all products less than $100"</code> in the web chat.</p>
<p>This should change the second browser's UI to show the relevant results.</p></li>
</ul>
<p>How would I go about achieving this ?
(<em>not too concerned about security at this point of time</em>).</p>
<p>Thank you so much in advance for your time and input.</p>
| 0debug |
def Find_Min(lst):
minList = min((x) for x in lst)
return minList | 0debug |
Google apps Script Learning : <p>I want to learn Google apps script but I can not find any clear video. Could you give me some link <i>basic expression</i><code>Logger.log('Do not take into account the log');</code></p>
<p>Thanks</p>
| 0debug |
creating brick wall with turtle : So I have an idea on how to make the wall, but I have to implement spaces between the bricks and it has to fill up the window. Would anyone have any suggestions on how best to implement this? | 0debug |
python program slows over time - feedparser : <p>I have a python program which is running in a loop and downloading 20k RSS feeds using feedparser and inserting feed data into RDBMS.</p>
<p>I have observed that it starts from 20-30 feeds a min and gradually slows down. After couple of hours it comes down to 4-5 feeds an hour. If I kill the program and restart from where it left, again the throughput is 20-30 feeds a min.</p>
<p>It certainly is not mySQL which is slowing down.</p>
<p>Can you please suggest some potential issues with the program?</p>
<p>Thanks</p>
| 0debug |
Matlab incorrect computation result : <p>I got a few Matlab code to play. But the answer is not correct:</p>
<pre><code>x = linspace(-pi, pi, 10)
sinc = @(x) sin(x) ./ x
sinc(x) // wrong result occurs at here.
</code></pre>
<p>The expected result as below:</p>
<pre><code>ans =
Columns 1 through 6:
3.8982e-17 2.6306e-01 5.6425e-01 8.2699e-01 9.7982e-01 9.7982e-01
Columns 7 through 10:
8.2699e-01 5.6425e-01 2.6306e-01 3.8982e-17
</code></pre>
<p>real result:</p>
<pre><code>ans =
Columns 1 through 3
0.000000000000000 0.263064408273866 0.564253278793615
Columns 4 through 6
0.826993343132688 0.979815536051016 0.979815536051016
Columns 7 through 9
0.826993343132688 0.564253278793615 0.263064408273866
Column 10
0.000000000000000
</code></pre>
<p>details: My OS is arch linux,
Matlab is downloaded through official website.</p>
<p>matlab version is 2015b</p>
| 0debug |
How to access estimate values in lm? : <p>I have linear model I would like to run weekly with updated data, and then extract and print the Estimate coefficients along with the titles. For example:</p>
<pre><code>data <- mtcars
fit <- lm(mpg ~ cyl + disp + hp, data = data)
summary(fit)
Call:
lm(formula = mpg ~ cyl + disp + hp, data = data)
Residuals:
Min 1Q Median 3Q Max
-4.0888899 -2.0845357 -0.7744705 1.3971991 6.9183052
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 34.18491917 2.59077758 13.19485 0.00000000000015372 ***
cyl -1.22741994 0.79727631 -1.53952 0.134904
disp -0.01883809 0.01040369 -1.81071 0.080929 .
hp -0.01467933 0.01465087 -1.00194 0.324952
Signif. codes: 0 β***β 0.001 β**β 0.01 β*β 0.05 β.β 0.1 β β 1
Residual standard error: 3.055261 on 28 degrees of freedom
Multiple R-squared: 0.7678877, Adjusted R-squared: 0.7430186
F-statistic: 30.8771 on 3 and 28 DF, p-value: 0.000000005053802
</code></pre>
<p>My ultimate goal would be to output something like below to a csv (or similar) file.</p>
<pre><code>(Intercept) 34.18491917
cyl -1.22741994
disp -0.01883809
hp -0.01467933
</code></pre>
<p>Is there any easy way to access the data in the fit, or would it have to be done manually?</p>
| 0debug |
How to get weights in tf.layers.dense? : <p>I wanna draw the weights of tf.layers.dense in tensorboard histogram, but it not show in the parameter, how could I do that?</p>
| 0debug |
Node js app.configure is not a function : <p>Can anyone tell what is wrong within this code .I have installed all necessary modules .When i run this script then it tells app.configure is not a function . If i am missing any thing , please suggest me .</p>
<pre><code>var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require("socket.io").listen(server)
, npid = require("npid")
, uuid = require('node-uuid')
, Room = require('./room.js')
, _ = require('underscore')._;
app.configure(function() {
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 3000);
app.set('ipaddr', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
app.use('/components', express.static(__dirname + '/components'));
app.use('/js', express.static(__dirname + '/js'));
app.use('/icons', express.static(__dirname + '/icons'));
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
/* Store process-id (as priviledged user) */
try {
npid.create('/var/run/advanced-chat.pid', true);
} catch (err) {
console.log(err);
//process.exit(1);
}
});
</code></pre>
| 0debug |
How to include Glyphicons without using Bootstrap CSS : <p>My Client project using some basic HTML and CSS. But they like the Glyphicons on the Website menus. So i just tried to include Glyphicons with the Bootstrap CSS, it does, but the other css got affected after including the Bootstrap CSS. </p>
<p>So the question may be silly, I just want to include Glyphicons in client website menu links without bootstrap css. </p>
<p>Is that possible first? I know Glyphicons free will be available with Bootstrap Package. </p>
<p>And other things is that my client do not want me to include Bootstrap CSS since it is affecting page structure. </p>
<p>So is it possible to include Glyphicons without Bootstrap css or my own custom css?</p>
<p>Any help would be appreciated!</p>
| 0debug |
static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
if ((uint64_t)atom.size > (1<<30))
return AVERROR_INVALIDDATA;
av_free(st->codec->extradata);
st->codec->extradata = av_mallocz(atom.size + 0x5a + FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
st->codec->extradata_size = 0x5a + atom.size;
memcpy(st->codec->extradata, "SVQ3", 4);
avio_read(pb, st->codec->extradata + 0x5a, atom.size);
av_log(c->fc, AV_LOG_TRACE, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a);
return 0;
}
| 1threat |
How to remove hyphen from compound words? : <p>If i have a string:</p>
<pre><code>txt = "Good-bye my friend"
</code></pre>
<p>I want it to be like this:</p>
<pre><code>txt = "Good bye my friend"
</code></pre>
<p>What should i do?</p>
| 0debug |
Get values from URL in Java : <p>I want to get "BusinessId" from this URL in Java: <a href="https://example.com/?link=https://play.google.com/store/apps/details?id=com.example.cp&hl=es&apn=com.picker.cp&st=Share+this+app&utm_source=AndroidApp?businessId=5d8648b561abf51ff7a6c189" rel="nofollow noreferrer">https://example.com/?link=https://play.google.com/store/apps/details?id=com.example.cp&hl=es&apn=com.picker.cp&st=Share+this+app&utm_source=AndroidApp?businessId=5d8648b561abf51ff7a6c189</a></p>
<p>What can i do?
I need some help, please :C</p>
| 0debug |
Client wants following css button : <p>I need help in creating following css style for button, Don't know how to add the different backgrounds with spacing between them.</p>
<p><a href="http://i64.tinypic.com/df9936.jpg" rel="nofollow noreferrer">http://i64.tinypic.com/df9936.jpg</a></p>
| 0debug |
How to run Eclipse memory analyzer on Mac os? : <p>I have some issues with running Eclipse memory analyzer on my laptop.</p>
<p>This happen when i have just downloaded(from <a href="http://www.eclipse.org/mat/downloads.php" rel="noreferrer">the place</a>) and executed application:</p>
<p><a href="https://i.stack.imgur.com/mcCbK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mcCbK.png" alt="enter image description here"></a></p>
<p><a href="https://i.stack.imgur.com/0nWam.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/0nWam.jpg" alt="enter image description here"></a></p>
<p>And i can't figure out what is the cause of problem. Can someone help me???</p>
| 0debug |
static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq)
{
CPUState *env = opaque;
ppc_tb_t *tb_env = env->tb_env;
tb_env->tb_freq = freq;
tb_env->decr_freq = freq;
_cpu_ppc_store_decr(env, 0xFFFFFFFF, 0xFFFFFFFF, 0);
#if defined(TARGET_PPC64H)
_cpu_ppc_store_hdecr(env, 0xFFFFFFFF, 0xFFFFFFFF, 0);
cpu_ppc_store_purr(env, 0x0000000000000000ULL);
#endif
}
| 1threat |
static void test_tco_defaults(void)
{
TestData d;
d.args = NULL;
d.noreboot = true;
test_init(&d);
g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_RLD), ==,
TCO_RLD_DEFAULT);
g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_DAT_IN), ==,
(TCO_DAT_OUT_DEFAULT << 8) | TCO_DAT_IN_DEFAULT);
g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_bar, TCO1_STS), ==,
(TCO2_STS_DEFAULT << 16) | TCO1_STS_DEFAULT);
g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_bar, TCO1_CNT), ==,
(TCO2_CNT_DEFAULT << 16) | TCO1_CNT_DEFAULT);
g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_MESSAGE1), ==,
(TCO_MESSAGE2_DEFAULT << 8) | TCO_MESSAGE1_DEFAULT);
g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_bar, TCO_WDCNT), ==,
TCO_WDCNT_DEFAULT);
g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_bar, SW_IRQ_GEN), ==,
SW_IRQ_GEN_DEFAULT);
g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_TMR), ==,
TCO_TMR_DEFAULT);
qtest_end();
}
| 1threat |
def min_length_list(input_list):
min_length = min(len(x) for x in input_list )
min_list = min(input_list, key = lambda i: len(i))
return(min_length, min_list) | 0debug |
How to close a form that opened another form using ShowDialog() : <p>so i have this <code>frmUser</code> but to close this i have to call <code>frmPass</code> (which i called using <code>ShowDialog()</code>instead of <code>Show()</code>) that will confirm first if the user is an admin but the problem is when i execute the codes below</p>
<pre><code>frmUser us = new frmUser(lblEID.Text, lblAdmin.Text, lblType.Text);
us.Hide();
this.Hide();
</code></pre>
<p><code>frmPass</code> only hides itself and not along with <code>frmUser</code>. Also here's my code calling <code>frmPass</code> from <code>frmUser</code></p>
<pre><code>frmPass pass = new frmPass(lblAID.Text, lblName.Text, lblType.Text, "User Module");
pass.ShowDialog();
</code></pre>
| 0debug |
scala - how to find Minimum in a tuple : A = tuples of Medication(patientid,date,medicine)
B = A.groupby(x => x.patientid)
example B would look like below - now I need to find the minimum date, how to do that in scala??
(478009505-01,CompactBuffer(Some(Medication(478009505-01,Fri Jun 12 10:30:00 EDT 2009,glimepiride)), Some(Medication(478009505-01,Fri Jun 12 10:30:00 EDT 2009,glimepiride)), Some(Medication(478009505-01,Fri Jun 12 10:30:00 EDT 2009,glimepiride))) | 0debug |
[JAVA]how to get a value from another java file : first java file
public class Swordsman extends Beginner {
public String attFunc;
public String attSkill;
private String nickname;
private int power;
private int result;
public void setnickname(String nickname){
this.nickname=nickname;
}
public void setpower(int power){
this.power=power;
}
public Swordsman(int p,String nm){
setnickname(nm);
setpower(p);
/*nickname=nm;
*power=p;
*/
}
public String nickname(){
return nickname;
}
public int power(){
return power;
}
public int result(){
if(power>=bpower){
result=1;
}else if(power<bpower){
result=0;
}
}
}
secong java file
public class Boss {
public int bpower(){
return bpower;
}
}
compile error
.\Swordsman.java:32: error: cannot find symbol
}else if(power<bpower){
As you see,the bpower in first java file,and how can i get the bpower from secong java file ?
As you see,the bpower in first java file,and how can i get the bpower from secong java file
?As you see,the bpower in first java file,and how can i get the bpower from secong java file
As you see,the bpower in first java file,and how can i get the bpower from secong java file ?
| 0debug |
static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
{
MpegEncContext *const s = w->s;
uint8_t *scantable;
int final, run, level;
int ac_mode, dc_mode, est_run, dc_level;
int pos, n;
int zeros_only;
int use_quant_matrix;
int sign;
assert(w->orient < 12);
s->bdsp.clear_block(s->block[0]);
if (chroma)
dc_mode = 2;
else
dc_mode = !!w->est_run;
if (x8_get_dc_rlf(w, dc_mode, &dc_level, &final))
return -1;
n = 0;
zeros_only = 0;
if (!final) {
use_quant_matrix = w->use_quant_matrix;
if (chroma) {
ac_mode = 1;
est_run = 64;
} else {
if (w->raw_orient < 3)
use_quant_matrix = 0;
if (w->raw_orient > 4) {
ac_mode = 0;
est_run = 64;
} else {
if (w->est_run > 1) {
ac_mode = 2;
est_run = w->est_run;
} else {
ac_mode = 3;
est_run = 64;
}
}
}
x8_select_ac_table(w, ac_mode);
scantable = w->scantable[(0x928548 >> (2 * w->orient)) & 3].permutated;
pos = 0;
do {
n++;
if (n >= est_run) {
ac_mode = 3;
x8_select_ac_table(w, 3);
}
x8_get_ac_rlf(w, ac_mode, &run, &level, &final);
pos += run + 1;
if (pos > 63) {
return -1;
}
level = (level + 1) * w->dquant;
level += w->qsum;
sign = -get_bits1(&s->gb);
level = (level ^ sign) - sign;
if (use_quant_matrix)
level = (level * quant_table[pos]) >> 8;
s->block[0][scantable[pos]] = level;
} while (!final);
s->block_last_index[0] = pos;
} else {
s->block_last_index[0] = 0;
if (w->flat_dc && ((unsigned) (dc_level + 1)) < 3) {
int32_t divide_quant = !chroma ? w->divide_quant_dc_luma
: w->divide_quant_dc_chroma;
int32_t dc_quant = !chroma ? w->quant
: w->quant_dc_chroma;
dc_level += (w->predicted_dc * divide_quant + (1 << 12)) >> 13;
dsp_x8_put_solidcolor(av_clip_uint8((dc_level * dc_quant + 4) >> 3),
w->dest[chroma],
s->current_picture.f->linesize[!!chroma]);
goto block_placed;
}
zeros_only = (dc_level == 0);
}
if (!chroma)
s->block[0][0] = dc_level * w->quant;
else
s->block[0][0] = dc_level * w->quant_dc_chroma;
if ((unsigned int) (dc_level + 1) >= 3 && (w->edges & 3) != 3) {
int direction;
direction = (0x6A017C >> (w->orient * 2)) & 3;
if (direction != 3) {
x8_ac_compensation(w, direction, s->block[0][0]);
}
}
if (w->flat_dc) {
dsp_x8_put_solidcolor(w->predicted_dc, w->dest[chroma],
s->current_picture.f->linesize[!!chroma]);
} else {
w->dsp.spatial_compensation[w->orient](s->sc.edge_emu_buffer,
w->dest[chroma],
s->current_picture.f->linesize[!!chroma]);
}
if (!zeros_only)
w->idsp.idct_add(w->dest[chroma],
s->current_picture.f->linesize[!!chroma],
s->block[0]);
block_placed:
if (!chroma)
x8_update_predictions(w, w->orient, n);
if (s->loop_filter) {
uint8_t *ptr = w->dest[chroma];
int linesize = s->current_picture.f->linesize[!!chroma];
if (!((w->edges & 2) || (zeros_only && (w->orient | 4) == 4)))
w->dsp.h_loop_filter(ptr, linesize, w->quant);
if (!((w->edges & 1) || (zeros_only && (w->orient | 8) == 8)))
w->dsp.v_loop_filter(ptr, linesize, w->quant);
}
return 0;
}
| 1threat |
db.execute('SELECT * FROM employees WHERE id = ' + user_input) | 1threat |
creating a .bat file using python : I am trying to make a program that creates .bat files using python script and runs them in the same program, I have figured out how to run .bat files but I am stuck on how to change the file type of created files (using python). Currently python creates .txt files but i wish to create a .bat file. Please help. | 0debug |
How can I use z3 in SMT-LIB format in java/eclipse? : <p>Well, I can run z3 solver in eclipse with Java binding, and the using language is Java, but I need to use the SMT-LIB format to run z3 solver in eclipse, how can I make it ?</p>
<p>I have research for something such as jSMTLIB Project, I don't know if it works.
And this web <a href="https://stackoverflow.com/questions/30568447/how-to-run-z3-in-java-from-smt-lib-standard">How to run Z3 in Java from SMT-Lib standard?</a>, it seems similar but not the point.</p>
| 0debug |
static void cpu_notify_map_clients_locked(void)
{
MapClient *client;
while (!QLIST_EMPTY(&map_client_list)) {
client = QLIST_FIRST(&map_client_list);
client->callback(client->opaque);
cpu_unregister_map_client(client);
}
}
| 1threat |
Read a file of unknown size/length, strip non-alphabetic chars, and change uppercase to lower : <p>then it has to be printed to the screen 80 chars per line.</p>
<p>this is done in c.</p>
<p>My coding is super weak and don't know where to begin.</p>
<p>Any help is appreciated</p>
| 0debug |
Why is a type registered twice when lifetime manager is specified? : <p>I'm using Unity's <em>Register by convention</em> mechanism in the following scenario:</p>
<pre><code>public interface IInterface { }
public class Implementation : IInterface { }
</code></pre>
<p>Given <code>Implementation</code> class and its interface I'm running <code>RegisterTypes</code> in the following way:</p>
<pre><code>unityContainer.RegisterTypes(
new[] { typeof(Implementation) },
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled);
</code></pre>
<p>After this call, <code>unitContainer</code> contains three registrations:</p>
<ul>
<li><code>IUnityContainer</code> -> <code>IUnityContainer</code> (ok)</li>
<li><code>IInterface</code> -> <code>Implementation</code> (ok)</li>
<li><code>Implementation</code> -> <code>Implementation</code> (???)</li>
</ul>
<p>When I change the call as follows:</p>
<pre><code>unityContainer.RegisterTypes(
new[] { typeof(Implementation) },
WithMappings.FromAllInterfaces,
WithName.Default);
</code></pre>
<p>The container contains only two registrations:</p>
<ul>
<li><code>IUnityContainer</code> -> <code>IUnityContainer</code> (ok)</li>
<li><code>IInterface</code> -> <code>Implementation</code> (ok)</li>
</ul>
<p>(this is the desired behaviour).</p>
<p>After peeking into <a href="https://github.com/unitycontainer/unity/blob/master/source/Unity/Src/RegistrationByConvention/UnityContainerRegistrationByConventionExtensions.cs">Unity's source code</a>, I've noticed that there is some misunderstanding about how <code>IUnityContainer.RegisterType</code> should work.</p>
<p>The <code>RegisterTypes</code> method works as follows (the comments indicate what are the values in the scenarios presented above):</p>
<pre><code>foreach (var type in types)
{
var fromTypes = getFromTypes(type); // { IInterface }
var name = getName(type); // null
var lifetimeManager = getLifetimeManager(type); // null or ContainerControlled
var injectionMembers = getInjectionMembers(type).ToArray(); // null
RegisterTypeMappings(container, overwriteExistingMappings, type, name, fromTypes, mappings);
if (lifetimeManager != null || injectionMembers.Length > 0)
{
container.RegisterType(type, name, lifetimeManager, injectionMembers); // !
}
}
</code></pre>
<p>Because <code>fromTypes</code> is not empty, the <code>RegisterTypeMappings</code> adds one type mapping: <code>IInterface</code> -> <code>Implementation</code> (correct).</p>
<p>Then, in case when <code>lifetimeManager</code> is not null, the code attempts to change the lifetime manager with the following call:</p>
<pre><code>container.RegisterType(type, name, lifetimeManager, injectionMembers);
</code></pre>
<p>This function's name is completely misleading, because <a href="https://msdn.microsoft.com/en-us/library/ee650597.aspx">the documentation</a> clearly states that:</p>
<blockquote>
<p>RegisterType a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.</p>
</blockquote>
<p>Unfortunately, not only the name is misleading but the documentation is wrong. When debugging this code, I've noticed, that when there is no mapping from <code>type</code> (<code>Implementation</code> in the scenarios presented above), it is added (as <code>type</code> -> <code>type</code>) and that's why we end up with three registrations in the first scenario.</p>
<p>I've downloaded Unity's sources to fix the problem, but I've found the following unit test:</p>
<pre><code>[TestMethod]
public void RegistersMappingAndImplementationTypeWithLifetimeAndMixedInjectionMembers()
{
var container = new UnityContainer();
container.RegisterTypes(new[] { typeof(MockLogger) }, getName: t => "name", getFromTypes: t => t.GetTypeInfo().ImplementedInterfaces, getLifetimeManager: t => new ContainerControlledLifetimeManager());
var registrations = container.Registrations.Where(r => r.MappedToType == typeof(MockLogger)).ToArray();
Assert.AreEqual(2, registrations.Length);
// ...
</code></pre>
<p>- which is almost exactly my case, and leads to my question:</p>
<p>Why is this expected? Is it a conceptual mistake, a unit test created to match existing behaviour but not necessarily correct, or am I missing something important?</p>
<p>I'm using Unity v4.0.30319.</p>
| 0debug |
VS2017: No suitable conversion from "vector<string>" to "vector<string>"* exists? : I am writing a program that will receive a text file, read in a list of names from that file, sort those names in alphabetical order, and then print the sorted list back out.
This originally was a project for my Intro to Programming class that was to use arrays, but I'm trying to retool it to work with vectors instead, allowing me to use a file of any length instead of a rigid array length.
But Intellisense is giving me the error "No suitable conversion function from "std::vector<std::string, std::allocator<std::string>>" to "std::vector<std::string, std::allocator<std::string>>*" exists" above any time that I try to pass the filename to a function (lines 27, 30, and 33). I'm having a hard time Googling how to pass a vector to a function, so I think that's where my problem is. The full code is pasted below:
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int readFromFile(string[], string);
void displayArray(vector<string>[], int);
void alphaSort(vector<string>[], int);
void swap(string&, string&);
int main() {
//Declare variables
string fileName;
vector<string>names(1);
int nameQty;
//Prompt for file name
cout << "Please enter the name of the file to read names from: " << endl;
cin >> fileName;
//Call function to open file and read names into a vector array. Function will return the number of names in file
nameQty = readFromFile(names, fileName);
//Display unsorted names
cout << "Unsorted names:" << endl;
displayArray(names, nameQty);
//Sort names into alphabetical order
alphaSort(names, nameQty);
//Display sorted names
cout << "Sorted names:" << endl;
displayArray(names, nameQty);
//More to come after this; program isn't done yet!
}
/*
* Function to read a list from a text file into an array.
* The array starts at size 1, then increments by 1 for each subsequent iteration
* The array then deletes the final element when there is nothing more to read
* (since the last element will be uninitialized)
*/
int readFromFile(vector<string> array, string fileName) {
ifstream inputFile;
inputFile.open(fileName);
if (!inputFile) {
cout << "Invalid file name. Please restart program and try again."
<< endl;
system("pause");
exit(EXIT_FAILURE);
}
else {
int index = 0;
while (inputFile) {
cin >> array[index];
array.push_back;
index++;
}
array.pop_back;
inputFile.close();
return (index + 1);
}
}
//Function to display list of items in array
void displayArray(vector<string> array[], int quantity) {
for (int i = 0; i < quantity; i++)
cout << array[i] << endl;
}
//Selection sort function puts array elements in alphabetical order
void alphaSort(vector<string> names[], int qty) {
for (int j = 0; j < qty - 1; j++) {
for (int i = j + 1; i < qty; i++) {
if (names[j] > names[i]) {
swap(names[j], names[i]);
}
}
}
}
//Function to swap elements a and b in array
void swap(string &a, string &b) {
string temp = a;
a = b;
b = temp;
}
Please don't worry about my using system("pause") and using namespace std. I'm aware that's poor practice, but it's what we've been asked to do in class. Thanks! | 0debug |
Recommended strategy to sync vuex state with server : <p>Immagine this simple case. You have a Vue JS application in which users can create lists of tasks and sort them. These lists should be stored in a database by the server. Let's assume we have a <code>ListComponent</code> which does the bulk of the UX.</p>
<p>My question is, which pattern should I use to handle front-end and back-end data synchronization?</p>
<p>A) <strong>Go through vuex</strong>: Store the active lists (those being shown, edited or created) in the vuex <code>store</code>. The <code>ListComponent</code> will change the <code>store</code> and <em>then</em>, the changes made to a list will be sent to the backend through an API.</p>
<p>B) <strong>Go directly to the server</strong>: Read and write directly from the <code>ListComponent</code> to the server every time a list is shown, edited or created.</p>
<p>If following A, which architecture should the store have? how and when should I kick a synchronization? How can I keep track of what has changed and what has not?</p>
| 0debug |
def tuple_int_str(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result | 0debug |
static int get_mmu_address(CPUState * env, target_ulong * physical,
int *prot, target_ulong address,
int rw, int access_type)
{
int use_asid, is_code, n;
tlb_t *matching = NULL;
use_asid = (env->mmucr & MMUCR_SV) == 0 && (env->sr & SR_MD) == 0;
is_code = env->pc == address;
if (env->pc == address && !(rw & PAGE_WRITE)) {
n = find_itlb_entry(env, address, use_asid, 1);
if (n >= 0) {
matching = &env->itlb[n];
if ((env->sr & SR_MD) & !(matching->pr & 2))
n = MMU_ITLB_VIOLATION;
else
*prot = PAGE_READ;
}
} else {
n = find_utlb_entry(env, address, use_asid);
if (n >= 0) {
matching = &env->utlb[n];
switch ((matching->pr << 1) | ((env->sr & SR_MD) ? 1 : 0)) {
case 0:
case 2:
n = (rw & PAGE_WRITE) ? MMU_DTLB_VIOLATION_WRITE :
MMU_DTLB_VIOLATION_READ;
break;
case 1:
case 4:
case 5:
if (rw & PAGE_WRITE)
n = MMU_DTLB_VIOLATION_WRITE;
else
*prot = PAGE_READ;
break;
case 3:
case 6:
case 7:
*prot = rw & (PAGE_READ | PAGE_WRITE);
break;
}
} else if (n == MMU_DTLB_MISS) {
n = (rw & PAGE_WRITE) ? MMU_DTLB_MISS_WRITE :
MMU_DTLB_MISS_READ;
}
}
if (n >= 0) {
*physical = ((matching->ppn << 10) & ~(matching->size - 1)) |
(address & (matching->size - 1));
if ((rw & PAGE_WRITE) & !matching->d)
n = MMU_DTLB_INITIAL_WRITE;
else
n = MMU_OK;
}
return n;
}
| 1threat |
int floatx80_le(floatx80 a, floatx80 b, float_status *status)
{
flag aSign, bSign;
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
&& (uint64_t) ( extractFloatx80Frac( a )<<1 ) )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
&& (uint64_t) ( extractFloatx80Frac( b )<<1 ) )
) {
float_raise(float_flag_invalid, status);
return 0;
}
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
if ( aSign != bSign ) {
return
aSign
|| ( ( ( (uint16_t) ( ( a.high | b.high )<<1 ) ) | a.low | b.low )
== 0 );
}
return
aSign ? le128( b.high, b.low, a.high, a.low )
: le128( a.high, a.low, b.high, b.low );
}
| 1threat |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.