problem
stringlengths 26
131k
| labels
class label 2
classes |
|---|---|
Can two terminal windows running on the same OS at the same time, communicate with one another? : <p>I was wondering if it's possible to send a young message such as "hello world" from one terminal/cmd window to another terminal/cmd window - both running at the same time on the same operating system?</p>
<p>I'm using mac OSX and have access to a linux OS. </p>
| 0debug
|
void spapr_events_init(sPAPRMachineState *spapr)
{
QTAILQ_INIT(&spapr->pending_events);
spapr->check_exception_irq = xics_spapr_alloc(spapr->xics, 0, false,
&error_fatal);
spapr->epow_notifier.notify = spapr_powerdown_req;
qemu_register_powerdown_notifier(&spapr->epow_notifier);
spapr_rtas_register(RTAS_CHECK_EXCEPTION, "check-exception",
check_exception);
spapr_rtas_register(RTAS_EVENT_SCAN, "event-scan", event_scan);
}
| 1threat
|
target_ulong spapr_hypercall(CPUState *env, target_ulong opcode,
target_ulong *args)
{
if (msr_pr) {
hcall_dprintf("Hypercall made with MSR[PR]=1\n");
return H_PRIVILEGE;
}
if ((opcode <= MAX_HCALL_OPCODE)
&& ((opcode & 0x3) == 0)) {
spapr_hcall_fn fn = hypercall_table[opcode / 4];
if (fn) {
return fn(env, spapr, opcode, args);
}
}
hcall_dprintf("Unimplemented hcall 0x" TARGET_FMT_lx "\n", opcode);
return H_FUNCTION;
}
| 1threat
|
static void gen_tlbsx_440(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
#else
TCGv t0;
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
return;
}
t0 = tcg_temp_new();
gen_addr_reg_index(ctx, t0);
gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
tcg_temp_free(t0);
if (Rc(ctx->opcode)) {
TCGLabel *l1 = gen_new_label();
tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
gen_set_label(l1);
}
#endif
}
| 1threat
|
iOS 11 UIBarButtonItem images not sizing : <p>The answer to my question was hinted at in <a href="https://stackoverflow.com/questions/45759482/how-to-set-uibarbutton-size-in-ios-11-to-match-size-in-ios-10">this question</a>, so I think the answer is to disable autolayout for my UIToolbar view. </p>
<p>The code that is said to work for views is</p>
<pre><code>cButton.translatesAutoresizingMaskIntoConstraints = YES;
</code></pre>
<p>But I’m not sure if it applies to my code since UIToolbar doesn’t inherit from UIView.</p>
<p>I have lots of small images that I use in my games that are different sizes depending on the device and orientation. Rather than having lots of different images, and adding new ones when Apple introduces new devices, I decided to make one 160x160 image fore each and then resize it when it is used. This worked fine from iOS 4 - iOS 10 but fails in iOS 11.</p>
<p>The code is pretty straightforward:</p>
<pre><code>// Get the image
NSString *pictFile = [[NSBundle mainBundle] pathForResource:@"Correct" ofType:@"png"];
UIImage *imageToDisplay = [UIImage imageWithContentsOfFile:pictFile];
UIImage *cImage = [UIImage imageWithCGImage:imageToDisplay.CGImage scale:[UIScreen mainScreen].scale orientation:imageToDisplay.imageOrientation];
UIButton *cButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cButton setImage:cImage forState:UIControlStateNormal];
[cButton setTitle:@"c" forState:UIControlStateNormal];
//set the frame of the button to the size of the image
cButton.frame = CGRectMake(0, 0, standardButtonSize.width, standardButtonSize.height);
//create a UIBarButtonItem with the button as a custom view
c = [[UIBarButtonItem alloc] initWithCustomView:cButton];
</code></pre>
<p>This is what it looks like pre11. The bar button items have been resized and fit nicely in the bottom bar. Note I reduced the size of the checkmark by 50% just to make sure I was looking at the correct code and that it behaves like I expect.</p>
<p><a href="https://i.stack.imgur.com/phDsI.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/phDsI.jpg" alt="correct version"></a></p>
<p>Here’s what they look like in the simulator for Xcode 9.0 GM and iOS 11. Note that the top row of buttons resize correctly but the bottom row expand to fill the space allocated for the tab bar. The same behaviour happens on iPads as well and various devices. </p>
<p><a href="https://i.stack.imgur.com/SpiY4.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/SpiY4.jpg" alt="iOS 11"></a></p>
<p>Any ideas about how to disable Autolayout or add constraints?</p>
| 0debug
|
static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
const AVSubtitle *h)
{
uint8_t *q, *qq;
int object_id;
int offset1[20], offset2[20];
int i, imax, color, alpha, rects = h->num_rects;
unsigned long hmax;
unsigned long hist[256];
int cmap[256];
if (rects == 0 || h->rects == NULL)
return -1;
if (rects > 20)
rects = 20;
for (i=0; i<256; ++i) {
hist[i] = 0;
cmap[i] = 0;
}
for (object_id = 0; object_id < rects; object_id++)
for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) {
color = h->rects[object_id]->pict.data[0][i];
alpha = ((uint32_t*)h->rects[object_id]->pict.data[1])[color] >> 24;
hist[color] += alpha;
}
for (color=3;; --color) {
hmax = 0;
imax = 0;
for (i=0; i<256; ++i)
if (hist[i] > hmax) {
imax = i;
hmax = hist[i];
}
if (hmax == 0)
break;
if (color == 0)
color = 3;
av_log(NULL, AV_LOG_DEBUG, "dvd_subtitle hist[%d]=%ld -> col %d\n",
imax, hist[imax], color);
cmap[imax] = color;
hist[imax] = 0;
}
q = outbuf + 4;
for (object_id = 0; object_id < rects; object_id++) {
offset1[object_id] = q - outbuf;
if ((q - outbuf) + h->rects[object_id]->w*h->rects[object_id]->h/2
+ 17*rects + 21 > outbuf_size) {
av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
return -1;
}
dvd_encode_rle(&q, h->rects[object_id]->pict.data[0],
h->rects[object_id]->w*2,
h->rects[object_id]->w, h->rects[object_id]->h >> 1,
cmap);
offset2[object_id] = q - outbuf;
dvd_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
h->rects[object_id]->w*2,
h->rects[object_id]->w, h->rects[object_id]->h >> 1,
cmap);
}
qq = outbuf + 2;
bytestream_put_be16(&qq, q - outbuf);
bytestream_put_be16(&q, (h->start_display_time*90) >> 10);
bytestream_put_be16(&q, (q - outbuf) + 8 + 12*rects + 2);
*q++ = 0x03;
*q++ = 0x03; *q++ = 0x7f;
*q++ = 0x04;
*q++ = 0xf0; *q++ = 0x00;
for (object_id = 0; object_id < rects; object_id++) {
int x2 = h->rects[object_id]->x + h->rects[object_id]->w - 1;
int y2 = h->rects[object_id]->y + h->rects[object_id]->h - 1;
*q++ = 0x05;
*q++ = h->rects[object_id]->x >> 4;
*q++ = (h->rects[object_id]->x << 4) | ((x2 >> 8) & 0xf);
*q++ = x2;
*q++ = h->rects[object_id]->y >> 4;
*q++ = (h->rects[object_id]->y << 4) | ((y2 >> 8) & 0xf);
*q++ = y2;
*q++ = 0x06;
bytestream_put_be16(&q, offset1[object_id]);
bytestream_put_be16(&q, offset2[object_id]);
}
*q++ = 0x01;
*q++ = 0xff;
bytestream_put_be16(&q, (h->end_display_time*90) >> 10);
bytestream_put_be16(&q, (q - outbuf) - 2 );
*q++ = 0x02;
*q++ = 0xff;
qq = outbuf;
bytestream_put_be16(&qq, q - outbuf);
av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf);
return q - outbuf;
}
| 1threat
|
Date Value Code For Conversion To Date in PHP or RUBY : <p>How do I convert a date value to a date in a csv file using PHP or Ruby?</p>
<p>Here is a sample of my column 'created_at' :
created_at
1309380645
1237178109
1303585711
1231175716
That is the current date and I need mm/dd/yyyy format.
Thank you.</p>
| 0debug
|
Java 10 migration from Java 8. Running services in production : <p>We want to migrate all our production services to Java 10 from Java 8. As I understood, we might face issues with builds (gradle etc.), dependencies etc. for development. But when it comes just to the JVM itself, i.e. running services, will we face any issues if we just install JVM 10 in production to run our jar services?</p>
| 0debug
|
can a unique constraint column have 2 or more null values? (oracle) : <p>Is it possible to have 2 or more null values in unique constraint column?</p>
| 0debug
|
i am trying to add new elementes to my arraylist but it shows er*or : I am trying to add a new element into my arraylist but it shows er*or and I do not know why.
I have tried to change it but the error does not go away. I cannot think of saomething else.Plese help me if you want to fix it.
this is my code:
//main class
import java.util.ArrayList;
public class Ticket {
static ArrayList<T> arrayticket = new ArrayList <T>(); //T for Ticket( Generic Type)
public static void main(String[] args) {
BuyTicket ticket1 = new BuyTicket();
ticket1.BuyaTicket();
}
class T {
// instance variables
private String type;
private int RoutesOrDays;
private String kind;
private String name;
private String email;
private int TicketCode;
private String ExpirationDate;
//constructor
public T(String type, int RoutesOrDays, String kind, String name, String email, int TicketCode, String ExpirationDate) {
this.type = type;
this.RoutesOrDays = RoutesOrDays;
this.kind = kind;
name = " ";
email = " ";
TicketCode = 0;
ExpirationDate = " ";
}
//++setters aand getters
}
public class BuyTicket extends MyInterface {
//METHOD
int BuyaTicket() {
Save save_dataA = new Save();
save_dataA.Person3(type, hostOfRoutes, kind);
}
}
public class SaveData extends T {
private String name;
private String email;
private int code;
static AtomicInteger codeSequence = new AtomicInteger(); //Creates a new AtomicInteger with initial value 0
//contructor
public SaveData(String name, String email, int code ) {
name =" ";
email =" ";
this.code = codeSequence.incrementAndGet(); //Atomically increments by one the current value.
}
//contructor of super
public SaveData(String type, int RoutesOrDays, String kind, String name, String email, int TicketCode, String ExpirationDate) {
super(type, RoutesOrDays, kind, name, email, TicketCode, ExpirationDate);
}
void Person3(String type, int RoutesOrDays, String kind){
System.out.println("Type your full name.");
String name = input.nextLine();
System.out.println("Please type your email. ");
String email = input.nextLine();
code = codeSequence.incrementAndGet();
arrayticket.add(new T(type, RoutesOrDays, kind, code,email, name));
//here is the er*or
}
I am very new to java so what can I change in order to fix it???
| 0debug
|
static ssize_t handle_aiocb_rw_linear(RawPosixAIOData *aiocb, char *buf)
{
ssize_t offset = 0;
ssize_t len;
while (offset < aiocb->aio_nbytes) {
if (aiocb->aio_type & QEMU_AIO_WRITE) {
len = pwrite(aiocb->aio_fildes,
(const char *)buf + offset,
aiocb->aio_nbytes - offset,
aiocb->aio_offset + offset);
} else {
len = pread(aiocb->aio_fildes,
buf + offset,
aiocb->aio_nbytes - offset,
aiocb->aio_offset + offset);
}
if (len == -1 && errno == EINTR) {
continue;
} else if (len == -1) {
offset = -errno;
} else if (len == 0) {
}
offset += len;
}
return offset;
}
| 1threat
|
static int vc1t_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
ByteIOContext *pb = s->pb;
AVStream *st;
int fps, frames;
frames = get_le24(pb);
if(get_byte(pb) != 0xC5 || get_le32(pb) != 4)
return -1;
st = av_new_stream(s, 0);
if (!st)
return -1;
st->codec->codec_type = CODEC_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_WMV3;
st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
st->codec->extradata_size = VC1_EXTRADATA_SIZE;
get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
st->codec->height = get_le32(pb);
st->codec->width = get_le32(pb);
if(get_le32(pb) != 0xC)
return -1;
url_fskip(pb, 8);
fps = get_le32(pb);
if(fps == -1)
av_set_pts_info(st, 32, 1, 1000);
else{
av_set_pts_info(st, 24, 1, fps);
st->duration = frames;
}
return 0;
}
| 1threat
|
static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
const uint8_t *buf, int len, uint16_t seq,
int flags)
{
uint8_t type, q, width, height;
const uint8_t *qtables = NULL;
uint16_t qtable_len;
uint32_t off;
int ret;
if (len < 8) {
av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
return AVERROR_INVALIDDATA;
}
off = AV_RB24(buf + 1);
type = AV_RB8(buf + 4);
q = AV_RB8(buf + 5);
width = AV_RB8(buf + 6);
height = AV_RB8(buf + 7);
buf += 8;
len -= 8;
if (type > 63) {
av_log(ctx, AV_LOG_ERROR,
"Unimplemented RTP/JPEG restart marker header.\n");
return AVERROR_PATCHWELCOME;
}
if (type > 1) {
av_log(ctx, AV_LOG_ERROR, "Unimplemented RTP/JPEG type %d\n", type);
return AVERROR_PATCHWELCOME;
}
if (off == 0) {
uint8_t new_qtables[128];
uint8_t hdr[1024];
if (q > 127) {
uint8_t precision;
if (len < 4) {
av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
return AVERROR_INVALIDDATA;
}
precision = AV_RB8(buf + 1);
qtable_len = AV_RB16(buf + 2);
buf += 4;
len -= 4;
if (precision)
av_log(ctx, AV_LOG_WARNING, "Only 8-bit precision is supported.\n");
if (qtable_len > 0) {
if (len < qtable_len) {
av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
return AVERROR_INVALIDDATA;
}
qtables = buf;
buf += qtable_len;
len -= qtable_len;
if (q < 255) {
if (jpeg->qtables_len[q - 128] &&
(jpeg->qtables_len[q - 128] != qtable_len ||
memcmp(qtables, &jpeg->qtables[q - 128][0], qtable_len))) {
av_log(ctx, AV_LOG_WARNING,
"Quantization tables for q=%d changed\n", q);
} else if (!jpeg->qtables_len[q - 128] && qtable_len <= 128) {
memcpy(&jpeg->qtables[q - 128][0], qtables,
qtable_len);
jpeg->qtables_len[q - 128] = qtable_len;
}
}
} else {
if (q == 255) {
av_log(ctx, AV_LOG_ERROR,
"Invalid RTP/JPEG packet. Quantization tables not found.\n");
return AVERROR_INVALIDDATA;
}
if (!jpeg->qtables_len[q - 128]) {
av_log(ctx, AV_LOG_ERROR,
"No quantization tables known for q=%d yet.\n", q);
return AVERROR_INVALIDDATA;
}
qtables = &jpeg->qtables[q - 128][0];
qtable_len = jpeg->qtables_len[q - 128];
}
} else {
if (q == 0 || q > 99) {
av_log(ctx, AV_LOG_ERROR, "Reserved q value %d\n", q);
return AVERROR_INVALIDDATA;
}
create_default_qtables(new_qtables, q);
qtables = new_qtables;
qtable_len = sizeof(new_qtables);
}
ffio_free_dyn_buf(&jpeg->frame);
if ((ret = avio_open_dyn_buf(&jpeg->frame)) < 0)
return ret;
jpeg->timestamp = *timestamp;
jpeg->hdr_size = jpeg_create_header(hdr, sizeof(hdr), type, width,
height, qtables,
qtable_len / 64);
avio_write(jpeg->frame, hdr, jpeg->hdr_size);
}
if (!jpeg->frame) {
av_log(ctx, AV_LOG_ERROR,
"Received packet without a start chunk; dropping frame.\n");
return AVERROR(EAGAIN);
}
if (jpeg->timestamp != *timestamp) {
ffio_free_dyn_buf(&jpeg->frame);
av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match.\n");
return AVERROR_INVALIDDATA;
}
if (off != avio_tell(jpeg->frame) - jpeg->hdr_size) {
av_log(ctx, AV_LOG_ERROR,
"Missing packets; dropping frame.\n");
return AVERROR(EAGAIN);
}
avio_write(jpeg->frame, buf, len);
if (flags & RTP_FLAG_MARKER) {
uint8_t buf[2] = { 0xff, EOI };
avio_write(jpeg->frame, buf, sizeof(buf));
if ((ret = ff_rtp_finalize_packet(pkt, &jpeg->frame, st->index)) < 0) {
av_log(ctx, AV_LOG_ERROR,
"Error occurred when getting frame buffer.\n");
return ret;
}
return 0;
}
return AVERROR(EAGAIN);
}
| 1threat
|
New Ruby on Rails Setup : "Expected string default value for '--rc'; got false (boolean)" : <p>I'm setting up a Ruby on Rails web development environment on a new machine (macOS Sierra v. 10.12.1). I'm following the setup instructions here: <a href="https://gorails.com/setup/osx/10.12-sierra">Setup Ruby On Rails on macOS 10.12 Sierra</a>. When I check the newly installed rails version, I get the following:</p>
<pre><code>$ rails --version
Expected string default value for '--rc'; got false (boolean)
Rails 4.2.6
</code></pre>
<p>I haven't seen that second line before, and googling hasn't yielded any helpful results. Background information: clean install of macOS 10.12.1; installed xcode via the App Store; installed Homebrew via the instructions on <a href="http://brew.sh/">its homepage</a>; installing Ruby, Rails, etc. via the first link I mentioned.</p>
<p>Anyone have any idea what might be going on?</p>
| 0debug
|
Pyton pyodbc insert in for loop : heya I'm trying to get urls and using extruct json and rdfa data by using libraies. but some how there is mistake in code and getting sql error.
Codeis below
import pyodbc
import requests
from pprint import pprint
import extruct
cnxn = pyodbc.connect('DRIVER={SQL
Server};SERVER=localhost\SQLEXPRESS;DATABASE=WebCrawler;
Trusted_Connection=yes')
cursor = cnxn.cursor()
cursor.execute("select Id, url from WebCrawlerEFs")
rows = cursor.fetchall()
for row in rows:
print (row.Id,",", row.url)
r = requests.get(row.url)
data = extruct.extract(r.text, r.url)
cursor.execute("INSERT INTO RdfaEFs(rdfa) VALUES ('"data"')")
cnxn.commit()
| 0debug
|
Java application start point : <p>I downloaded a simple java app and I want to know which file I need to run to start. There are several classes in the project and I do not know which one is the main one. Thank you.</p>
| 0debug
|
static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
{
BDRVSheepdogState *s = acb->common.bs->opaque;
struct iovec iov;
AIOReq *aio_req;
uint32_t offset, data_len, mn, mx;
mn = s->min_dirty_data_idx;
mx = s->max_dirty_data_idx;
if (mn <= mx) {
offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) +
mn * sizeof(s->inode.data_vdi_id[0]);
data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]);
s->min_dirty_data_idx = UINT32_MAX;
s->max_dirty_data_idx = 0;
iov.iov_base = &s->inode;
iov.iov_len = sizeof(s->inode);
aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id),
data_len, offset, 0, false, 0, offset);
QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA);
acb->aio_done_func = sd_finish_aiocb;
acb->aiocb_type = AIOCB_WRITE_UDATA;
return;
}
sd_finish_aiocb(acb);
}
| 1threat
|
void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)
{
int fd, rc;
int i;
fd = kvmppc_get_htab_fd(false, ptex, &error_abort);
i = 0;
while (i < n) {
struct kvm_get_htab_header *hdr;
int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;
char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];
rc = read(fd, buf, sizeof(buf));
if (rc < 0) {
hw_error("kvmppc_read_hptes: Unable to read HPTEs");
}
hdr = (struct kvm_get_htab_header *)buf;
while ((i < n) && ((char *)hdr < (buf + rc))) {
int invalid = hdr->n_invalid;
if (hdr->index != (ptex + i)) {
hw_error("kvmppc_read_hptes: Unexpected HPTE index %"PRIu32
" != (%"HWADDR_PRIu" + %d", hdr->index, ptex, i);
}
memcpy(hptes + i, hdr + 1, HASH_PTE_SIZE_64 * hdr->n_valid);
i += hdr->n_valid;
if ((n - i) < invalid) {
invalid = n - i;
}
memset(hptes + i, 0, invalid * HASH_PTE_SIZE_64);
i += hdr->n_invalid;
hdr = (struct kvm_get_htab_header *)
((char *)(hdr + 1) + HASH_PTE_SIZE_64 * hdr->n_valid);
}
}
close(fd);
}
| 1threat
|
static int flv_write_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
FLVContext *flv = s->priv_data;
AVCodecContext *audio_enc = NULL, *video_enc = NULL, *data_enc = NULL;
int i, metadata_count = 0;
double framerate = 0.0;
int64_t metadata_size_pos, data_size, metadata_count_pos;
AVDictionaryEntry *tag = NULL;
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
FLVStreamContext *sc;
switch (enc->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (s->streams[i]->r_frame_rate.den &&
s->streams[i]->r_frame_rate.num) {
framerate = av_q2d(s->streams[i]->r_frame_rate);
} else {
framerate = 1 / av_q2d(s->streams[i]->codec->time_base);
}
video_enc = enc;
if (enc->codec_tag == 0) {
av_log(s, AV_LOG_ERROR, "video codec not compatible with flv\n");
return -1;
}
break;
case AVMEDIA_TYPE_AUDIO:
audio_enc = enc;
if (get_audio_flags(s, enc) < 0)
return AVERROR_INVALIDDATA;
break;
case AVMEDIA_TYPE_DATA:
if (enc->codec_id != CODEC_ID_TEXT) {
av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
return AVERROR_INVALIDDATA;
}
data_enc = enc;
break;
default:
av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
return -1;
}
avpriv_set_pts_info(s->streams[i], 32, 1, 1000);
sc = av_mallocz(sizeof(FLVStreamContext));
if (!sc)
return AVERROR(ENOMEM);
s->streams[i]->priv_data = sc;
sc->last_ts = -1;
}
flv->delay = AV_NOPTS_VALUE;
avio_write(pb, "FLV", 3);
avio_w8(pb, 1);
avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc +
FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
avio_wb32(pb, 9);
avio_wb32(pb, 0);
for (i = 0; i < s->nb_streams; i++)
if (s->streams[i]->codec->codec_tag == 5) {
avio_w8(pb, 8);
avio_wb24(pb, 0);
avio_wb24(pb, 0);
avio_wb32(pb, 0);
avio_wb32(pb, 11);
flv->reserved = 5;
}
avio_w8(pb, 18);
metadata_size_pos = avio_tell(pb);
avio_wb24(pb, 0); of data part (sum of all parts below)
avio_wb24(pb, 0);
avio_wb32(pb, 0);
avio_w8(pb, AMF_DATA_TYPE_STRING);
put_amf_string(pb, "onMetaData");
avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
metadata_count_pos = avio_tell(pb);
metadata_count = 5 * !!video_enc +
5 * !!audio_enc +
1 * !!data_enc +
2;
avio_wb32(pb, metadata_count);
put_amf_string(pb, "duration");
flv->duration_offset= avio_tell(pb);
put_amf_double(pb, s->duration / AV_TIME_BASE);
if (video_enc) {
put_amf_string(pb, "width");
put_amf_double(pb, video_enc->width);
put_amf_string(pb, "height");
put_amf_double(pb, video_enc->height);
put_amf_string(pb, "videodatarate");
put_amf_double(pb, video_enc->bit_rate / 1024.0);
put_amf_string(pb, "framerate");
put_amf_double(pb, framerate);
put_amf_string(pb, "videocodecid");
put_amf_double(pb, video_enc->codec_tag);
}
if (audio_enc) {
put_amf_string(pb, "audiodatarate");
put_amf_double(pb, audio_enc->bit_rate / 1024.0);
put_amf_string(pb, "audiosamplerate");
put_amf_double(pb, audio_enc->sample_rate);
put_amf_string(pb, "audiosamplesize");
put_amf_double(pb, audio_enc->codec_id == CODEC_ID_PCM_U8 ? 8 : 16);
put_amf_string(pb, "stereo");
put_amf_bool(pb, audio_enc->channels == 2);
put_amf_string(pb, "audiocodecid");
put_amf_double(pb, audio_enc->codec_tag);
}
if (data_enc) {
put_amf_string(pb, "datastream");
put_amf_double(pb, 0.0);
}
while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
put_amf_string(pb, tag->key);
avio_w8(pb, AMF_DATA_TYPE_STRING);
put_amf_string(pb, tag->value);
metadata_count++;
}
put_amf_string(pb, "filesize");
flv->filesize_offset = avio_tell(pb);
put_amf_double(pb, 0);
put_amf_string(pb, "");
avio_w8(pb, AMF_END_OF_OBJECT);
data_size = avio_tell(pb) - metadata_size_pos - 10;
avio_seek(pb, metadata_count_pos, SEEK_SET);
avio_wb32(pb, metadata_count);
avio_seek(pb, metadata_size_pos, SEEK_SET);
avio_wb24(pb, data_size);
avio_skip(pb, data_size + 10 - 3);
avio_wb32(pb, data_size + 11);
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) {
int64_t pos;
avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
avio_wb24(pb, 0); patched later
avio_wb24(pb, 0);
avio_w8(pb, 0); ext
avio_wb24(pb, 0);
pos = avio_tell(pb);
if (enc->codec_id == CODEC_ID_AAC) {
avio_w8(pb, get_audio_flags(s, enc));
avio_w8(pb, 0);
avio_write(pb, enc->extradata, enc->extradata_size);
} else {
avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY);
avio_w8(pb, 0);
avio_wb24(pb, 0);
ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
}
data_size = avio_tell(pb) - pos;
avio_seek(pb, -data_size - 10, SEEK_CUR);
avio_wb24(pb, data_size);
avio_skip(pb, data_size + 10 - 3);
avio_wb32(pb, data_size + 11);
}
}
return 0;
}
| 1threat
|
What flavor of Regex does Visual Studio Code use? : <p>Trying to search-replace in Visual Studio Code, I find that its Regex flavor is different from full Visual Studio. Specifically, I try to declare a named group with <code>string (?<p>[\w]+)</code> which works in Visual Studio but not in Visual Studio Code. It'll complain with the error <code>Invalid group</code>.</p>
<p>Apart from solving this specific issue, I'm looking for information about the flavor of Regexes in Visual Studio Code and where to find documentation about it, so I can help myself with any other questions I might stumble upon.</p>
<p>Full Visual Studio uses .NET Regular Expressions as documented <a href="https://msdn.microsoft.com/en-us/library/2k3te2cs.aspx" rel="noreferrer">here</a>. This link is mentioned as the documentation for VS Code elsewhere on Stackoverflow, but it's not.</p>
| 0debug
|
Adding a Cell Reference to a file name using VBA : I am trying to save a file using VBA but the file name needs to reference a cell within the Workbook. Below is my code, can anyone tell me what I am doing wrong please?
ActiveWorkbook.SaveAs fileName:= _
"C:\Desktop\CashBook_\" & Range("E3") & ".txt", FileFormat:=xlCSV, _
CreateBackup:=False
Kind Regards,
John
| 0debug
|
How to show image view before activity will open on button click : <p>i am new to android.
i want to show full screen image on Activity like a layer,
When i click on button i want to call new activity but before activity i want to show an image(full screen)on that activity for 5 seconds.like ads. how can i do ? please help me. thank you in advance.</p>
<p>here is my xml</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/black_ng2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageViewForAd"
android:adjustViewBounds="true"
android:src="@drawable/splash_screen"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_15sdp"
android:layout_marginRight="@dimen/_15sdp"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_15sdp"
android:padding="@dimen/_10sdp"
android:id="@+id/cardLayout"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:layout_alignParentRight="true">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_15sdp"
android:id="@+id/textInputLayoutPooja"
android:textColorHint="@color/colorwhite">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="Date Of Mandal Pooja"
android:id="@+id/txtDateOfPooja"
android:drawableLeft="@drawable/calender"
android:textSize="@dimen/_15sdp"
android:textColor="@color/colorwhite"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_15sdp"
android:id="@+id/textInputLayoutYaatra"
android:layout_below="@+id/textInputLayoutPooja"
android:textColorHint="@color/colorwhite">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date Of Yaatra"
android:id="@+id/txtDateOfYaatra"
android:textSize="@dimen/_15sdp"
android:drawableLeft="@drawable/calender"
android:textColor="@color/colorwhite"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_15sdp"
android:id="@+id/textInputLayoutDarshan"
android:layout_below="@+id/textInputLayoutYaatra"
android:textColorHint="@color/colorwhite">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date Of Darshan"
android:id="@+id/txtDateOfDarshan"
android:textSize="@dimen/_15sdp"
android:drawableLeft="@drawable/calender"
android:textColor="@color/colorwhite"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="@dimen/_80sdp"
android:layout_height="@dimen/_40sdp"
android:text="Add Yaatra"
android:id="@+id/btnAddYaatra"
android:textSize="@dimen/_15sdp"
android:layout_below="@+id/textInputLayoutDarshan"
android:background="@color/btncolor"
android:textColor="@color/colorwhite"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</code></pre>
<p></p>
| 0debug
|
How to share conda environments across platforms : <p>The conda docs at <a href="http://conda.pydata.org/docs/using/envs.html" rel="noreferrer">http://conda.pydata.org/docs/using/envs.html</a> explain how to share environments with other people.</p>
<p>However, the docs tell us this is not cross platform:</p>
<pre><code>NOTE: These explicit spec files are not usually cross platform, and
therefore have a comment at the top such as # platform: osx-64 showing the
platform where they were created. This platform is the one where this spec
file is known to work. On other platforms, the packages specified might not
be available or dependencies might be missing for some of the key packages
already in the spec.
NOTE: Conda does not check architecture or dependencies when installing
from an explicit specification file. To ensure the packages work correctly,
be sure that the file was created from a working environment and that it is
used on the same architecture, operating system and platform, such as linux-
64 or osx-64.
</code></pre>
<p>Is there a good method to share and recreate a conda environment in one platform (e.g. CentOS) in another platform (e.g. Windows)?</p>
| 0debug
|
FORTRAN ERROR 6837 : Hello I am trying to write a FORTRAN subroutine for ABAQUS that would modify the seepage coefficient and thus the flow depending on whether there is contact on the surface. In order to do so I need 2 subroutines URDFIL to retrieve the node data and FLOW to modify the seepage coefficient.
However, when I compile my subroutine I get the following errors:
flow_us.for(81): error #6837: The leftmost part-ref in a data-ref can not be a function reference. [K_ELE_DETAILS]
IF(K_ELE_DETAILS(E_INDX)%IS_CONT(N_INDX).EQ.0)THEN
----------^
flow_us.for(81): error #6158: The structure-name is invalid or is missing. [K_ELE_DETAILS]
IF(K_ELE_DETAILS(E_INDX)%IS_CONT(N_INDX).EQ.0)THEN
Obviously it is repeated for the 3 lines (if's) that contain such structure (81,8, and 89).
Please find the code below and hopefully someone will be able to help
`****************************************************************************************
***SUBROUTINE FOR ADAPTIVE FLUID FLOW
****************************************************************************************
****************************************************************************************
**
**
**
*USER SUBROUTINE
SUBROUTINE URDFIL(LSTOP,LOVRWRT, KSTEP, KINC, DTIME, TIME)
INCLUDE 'ABA_PARAM.INC'
C
DIMENSION ARRAY(513),JRRAY(NPRECD,513),TIME(2)
EQUIVALENCE (ARRAY(1),JRRAY(1,1))
C DECLARATIONS
TYPE ELE_DATA
SEQUENCE
DOUBLE PRECISION :: NODE_COORD(9)
DOUBLE PRECISION :: OPP_NODE_COORD(9)
DOUBLE PRECISION :: IPT_COORD(9)
DOUBLE PRECISION :: POR(3)
DOUBLE PRECISION :: OPP_POR(3)
INTEGER :: ELE_NUM
INTEGER :: OPP_ELE_NUM
INTEGER :: NODE_NUM(3)
INTEGER :: OPP_NODE_NUM(3)
INTEGER :: IPT_NUM(3)
INTEGER :: OPP_IS_CONT(3)
END TYPE ELE_DATA
TYPE(ELE_DATA)::K_ELE_DETAILS(500)
COMMON K_ELE_DETAILS
PARAMETER (THRESHOLD_CSTRESS=1.0E-6)
*******************************************************
INTEGER :: NO_OF_NODES
INTEGER :: NO_OF_ELEMENTS
INTEGER :: NO_OF_DIM
COMMON NO_OF_DIM, NO_OF_NODES, NO_OF_ELEMENTS
********************************************************
C INITIALIZE
LSTOP=0
LOVRWRT=1
LOP=0
NO_OF_NODES=10000
NO_OF_ELEMENTS=10000
NO_OF_DIM=2
DO K1=1,999999
CALL DBFILE(0, ARRAY,JRCD)
IF (JCRD.NE.0) GO TO 110
KEY=JRRAY(1,2)
*******************************************************
C THE KEYS USED IN THE FOLLOWING LINES REFER
C TO INFORMATION ON THE SURFACE, NODES, CONTACT ETC
IF (KEY.EQ.1501) THEN
ELSE IF (KEY.EQ.1502)THEN
ELSE IF(KEY.EQ.1911) THEN
ELSE IF(KEY.EQ.108.AND.SURFACE_N_SET.EQ.'N_TOP') THEN
ELSE IF(KEY.EQ.107.AND.SURFACE_N_SET.EQ.'N_TOP') THEN
ELSE IF(KEY.EQ.1503)THEN
ELSE IF(KEY.EQ.1504.AND.K_NODE_SET.EQ.'N_TOP')THEN
ELSE IF(KEY.EQ.1511.AND.K_NODE_SET.EQ.'N_TOP')THEN
C IS THE NODE IN CONTACT?
120 CONTINUE
END IF
END DO
110 CONTINUE
RETURN
END
**********************************************************
**********************************************************
*USER SUBROUTINE
SUBROUTINE FLOW(H, SINK, KSTEP, KINC, TIME, NOEL, NPT, COORDS,
1 JLTYP,SNAME)
INCLUDE 'ABA_PARAM.INC'
C
DIMENSION TIME(2), COORDS(3)
CHARACTER*80 SNAME
MIN_DIST=10E-20
DO K25=1,NO_OF_ELEMENTS
DO K26=1,NO_OF_NODES
C FINDS THE CLOSEST NODE TO THE INTEGRATION POINT NPT
END DO
END DO
C NOT IN CONTACT
IF(K_ELE_DETAILS(E_INDX)%IS_CONT(N_INDX).EQ.0)THEN
IF(K_ELE_DETAILS(E_INDX)%POR(N_INDX).GE.0) THEN
SINK=0
H=0.001
ELSE
SINK=0
H=1
END IF
ELSE IF(K_ELE_DETAILS(E_INDX)%IS_CONT(N_INDX).EQ.1)THEN
C IF THERE IS CONTACT
SINK=0
H=0
END IF
RETURN
END
`
| 0debug
|
static int protocol_client_auth_sasl_step_len(VncState *vs, uint8_t *data, size_t len)
{
uint32_t steplen = read_u32(data, 0);
VNC_DEBUG("Got client step len %d\n", steplen);
if (steplen > SASL_DATA_MAX_LEN) {
VNC_DEBUG("Too much SASL data %d\n", steplen);
vnc_client_error(vs);
return -1;
}
if (steplen == 0)
return protocol_client_auth_sasl_step(vs, NULL, 0);
else
vnc_read_when(vs, protocol_client_auth_sasl_step, steplen);
return 0;
}
| 1threat
|
How to set a window icon with PyQt5? : <pre><code>from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Application(QMainWindow):
def __init__(self):
super(Application, self).__init__()
self.setWindowIcon(QtGui.QIcon('icon.png'))
</code></pre>
<p>I am trying to set a window icon (top left of the window) but the normal icon disappeared instead.</p>
<p>I tried with many icon resolutions (8x8, 16x16, 32x32, 64x64) and extensions (.png and .ico). </p>
<p>What am I doing wrong?</p>
| 0debug
|
Javascript - Why is it doing this? : I am trying to get this script to autofill another filled while the original field is being filled in. But the second filed is missing the last character. Any ideas why? Thanks...
Here is the code...
<input type="text" class="first" placeholder="type here">
<input type="text" class="second" placeholder="here it is the reuslt">
$(".first").on('keydown',function(){
$(".second").val($(this).val());
});
http://jsfiddle.net/fmdwv/1/
| 0debug
|
Insert whitespace after every 3 character in a string Javascript : <p>I need to display a price in a format like</p>
<pre><code>7
70
700
700 000
70 000
700 000
7 000 000 etc
</code></pre>
<p>The problem is that I receive the price from json file, so it's always a string. </p>
<p>What I want is to convert that price string into the desired format by RegEx.</p>
<ol>
<li>We invert the price <code>7000000 = 0000007</code></li>
<li>We put a whitespace after 3rd character in the inverted string <code>000 000 7</code></li>
<li>Then we invert the string again and get a normal price format <code>7 000 000</code></li>
</ol>
<p>Is it possible for json data and perhaps there is a more correct way to go? Didn't find any working examples.</p>
| 0debug
|
this program for pythagorean triplet gives complex numbers for some cases. Can somebody help me with this? : x=int(input("enter side 1")) #inputs sides 1
y=int(input("enter side 2")) #and 2
z=((x**2)+(y**2))**(1/2) #applying pythagoras' theorem[when sides are 4 and 5][1]
if z%1==0:
print(z,"is the missing side")
elif z%1!=0:
k=((x**2)-(y**2))
import math
math.fabs(k)
a=k**(1/2)
print(a,"is the missing side")
[1]: https://i.stack.imgur.com/wIlwY.jpg
| 0debug
|
ng-template - typed variable : <p>How can parent component recognise type of <code>let-content</code> which comes from <code>ngTemplateOutletContext</code>? Now <code>{{content.type}}</code> works correctly, but IDE says:</p>
<blockquote>
<p>unresolved variable type</p>
</blockquote>
<p>How can I type it as <code>Video</code>?</p>
<p><strong>parent.component.ts:</strong></p>
<pre><code>export interface Video {
id: number;
duration: number;
type: string;
}
public videos: Video = [{id: 1, duration: 30, type: 'documentary'}];
</code></pre>
<p><strong>parent.component.html:</strong></p>
<pre><code><ul>
<li *ngFor="let video of videos">
<tile [bodyTemplate]="tileTemplate" [content]="video"></app-card>
</li>
</ul>
<ng-template #tileTemplate let-content>
<h5 class="tile__type">{{content.type}}</h5>
</ng-template>
</code></pre>
<p><strong>tile.component.ts:</strong></p>
<pre><code>@Component({
selector: 'tile',
templateUrl: './tile.component.html',
styleUrls: ['./tile.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CardComponent {
@Input() tileTemplate: TemplateRef<any>;
@Input() content: Video;
}
</code></pre>
<p><strong>tile.component.html:</strong></p>
<pre><code><div
...
<ng-container
[ngTemplateOutlet]="tileTemplate"
[ngTemplateOutletContext]="{ $implicit: content }">
</ng-container>
...
</div>
</code></pre>
| 0debug
|
How to use multiple remotes with GitKraken : <p>I'm using GitKraken quite frequently, but I cannot manage how to set to which remote I want to push. In the context menu I cannot find any entry like "use this remote for push/pull". </p>
<p>I have to set it via the command line, then it works as expected. </p>
<p><code>git push -u origin2 dev/mybranch</code></p>
<p>is this really a missing feature?</p>
| 0debug
|
static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
ByteIOContext *pb = &s->pb;
int nbits, len, frame_rate, tag, v;
AVStream *st;
if ((get_be32(pb) & 0xffffff00) != MKBETAG('F', 'W', 'S', 0))
return -EIO;
get_le32(pb);
nbits = get_byte(pb) >> 3;
len = (4 * nbits - 3 + 7) / 8;
url_fskip(pb, len);
frame_rate = get_le16(pb);
get_le16(pb);
for(;;) {
tag = get_swf_tag(pb, &len);
if (tag < 0) {
fprintf(stderr, "No streaming found in SWF\n");
return -EIO;
}
if (tag == TAG_STREAMHEAD) {
get_byte(pb);
v = get_byte(pb);
get_le16(pb);
if (len!=4)
url_fskip(pb,len-4);
if ((v & 0x20) != 0) {
st = av_new_stream(s, 0);
if (!st)
return -ENOMEM;
if (v & 0x01)
st->codec.channels = 2;
else
st->codec.channels = 1;
switch((v>> 2) & 0x03) {
case 1:
st->codec.sample_rate = 11025;
break;
case 2:
st->codec.sample_rate = 22050;
break;
case 3:
st->codec.sample_rate = 44100;
break;
default:
av_free(st);
return -EIO;
}
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_MP2;
break;
}
} else {
url_fskip(pb, len);
}
}
return 0;
}
| 1threat
|
Get the mean of numerical columns in a multi-index datafram : I want to calculate the mean of numerical columns in a multi-index datafram, and append the datafram with the new results as a new row.
```python
subject 1 subject 2 subject 3…
Country 2017 2018 Frq 2017 Score 2018 Score 2017 2018 Frq 2017 Score 2018 Score
Argentina 12 22 100 50. 51. 12 22 100 50. 51.
Australia 68 13 150 66. 67. 68 13 150 66. 67.
```
I'v tried using this line, But I get a new row full with nan
```python
G20.loc['mean'] = G20.mean(axis=0, numeric_only=True)
```
Thanks
| 0debug
|
matplotlib not showing first label on x axis for the Bar Plot : <p>Here is the code I am working on to create a logarithmic bar plot</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize = (12,6))
ax = fig.add_subplot(111)
x = ['Blue Whale', 'Killer Whale', 'Bluefin tuna', \
'Bottlenose dolphin', "Maui's dolphin", 'Flounder',\
'Starfish', 'Spongebob Squarepants']
y = [190000, 5987, 684, 650, 40, 6.8, 5, 0.02]
ax.bar(np.arange(len(x)),y, log=1)
ax.set_xticklabels(x, rotation = 45)
fig.savefig(filename = "f:/plot.png")
</code></pre>
<p>Now this is creating the bar plot where its not showing the first label, which is <code>Blue Whale</code>. Here is the plot I am getting<a href="https://i.stack.imgur.com/0uzoz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0uzoz.png" alt="enter image description here"></a> So how can this be rectified ? Matplotlib version is <code>2.0.0</code> and Numpy version is <code>1.12.1</code></p>
<p>Thanks</p>
| 0debug
|
multi-stage build in docker compose? : <p>How can I specify multi-stage build with in a <code>docker-compose.yml</code>?</p>
<p>For each variant (e.g. dev, prod...) I have a multi-stage build with 2 docker files:</p>
<ul>
<li>dev: <code>Dockerfile.base</code> + <code>Dockerfile.dev</code></li>
<li>or prod: <code>Dockerfile.base</code> + <code>Dockerfile.prod</code></li>
</ul>
<p>File <code>Dockerfile.base</code> (common for all variants):</p>
<pre><code>FROM python:3.6
RUN apt-get update && apt-get upgrade -y
RUN pip install pipenv pip
COPY Pipfile ./
# some more common configuration...
</code></pre>
<p>File <code>Dockerfile.dev</code>:</p>
<pre><code>FROM flaskapp:base
RUN pipenv install --system --skip-lock --dev
ENV FLASK_ENV development
ENV FLASK_DEBUG 1
</code></pre>
<p>File <code>Dockerfile.prod</code>:</p>
<pre><code>FROM flaskapp:base
RUN pipenv install --system --skip-lock
ENV FLASK_ENV production
</code></pre>
<p>Without docker-compose, I can build as:</p>
<pre><code># Building dev
docker build --tag flaskapp:base -f Dockerfile.base .
docker build --tag flaskapp:dev -f Dockerfile.dev .
# or building prod
docker build --tag flaskapp:base -f Dockerfile.base .
docker build --tag flaskapp:dev -f Dockerfile.dev .
</code></pre>
<p>According to the <a href="https://docs.docker.com/compose/compose-file/#build" rel="noreferrer">compose-file doc</a>, I can specify a Dockerfile to build.</p>
<pre><code># docker-compose.yml
version: '3'
services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
</code></pre>
<p>But how can I specify 2 Dockerfiles in <code>docker-compose.yml</code> (for multi-stage build)?</p>
| 0debug
|
static int mpeg_decode_slice(AVCodecContext *avctx,
AVPicture *pict,
int start_code,
UINT8 *buf, int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
int ret;
start_code = (start_code - 1) & 0xff;
if (start_code >= s->mb_height)
return -1;
s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
s->last_dc[1] = s->last_dc[0];
s->last_dc[2] = s->last_dc[0];
memset(s->last_mv, 0, sizeof(s->last_mv));
s->mb_x = -1;
s->mb_y = start_code;
s->mb_incr = 0;
if (s->first_slice) {
s->first_slice = 0;
MPV_frame_start(s);
}
init_get_bits(&s->gb, buf, buf_size);
s->qscale = get_qscale(s);
while (get_bits1(&s->gb) != 0) {
skip_bits(&s->gb, 8);
}
for(;;) {
clear_blocks(s->block[0]);
emms_c();
ret = mpeg_decode_mb(s, s->block);
dprintf("ret=%d\n", ret);
if (ret < 0)
return -1;
if (ret == 1)
break;
MPV_decode_mb(s, s->block);
}
emms_c();
if (s->mb_x == (s->mb_width - 1) &&
s->mb_y == (s->mb_height - 1)) {
UINT8 **picture;
MPV_frame_end(s);
if (s->pict_type == B_TYPE) {
picture = s->current_picture;
avctx->quality = s->qscale;
} else {
if (s->picture_number == 0) {
picture = NULL;
} else {
picture = s->last_picture;
avctx->quality = s->last_qscale;
}
s->last_qscale = s->qscale;
s->picture_number++;
}
if (picture) {
pict->data[0] = picture[0];
pict->data[1] = picture[1];
pict->data[2] = picture[2];
pict->linesize[0] = s->linesize;
pict->linesize[1] = s->linesize / 2;
pict->linesize[2] = s->linesize / 2;
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
| 1threat
|
Using Thread.Sleep in Xamarin.Forms : <p>I want to execute the following</p>
<pre><code>MainPage = new ContentPage
{
Content = new StackLayout
{
Children =
{
new Button
{
Text = "Thread.Sleep",
Command = new Command(() =>
{
Thread.Sleep(1000);
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
}),
},
new Button
{
Text = "Task.Run + Thread.Sleep",
Command = new Command(async () =>
{
await Task.Run(() => Thread.Sleep(1000));
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
})
},
new Button
{
Text = "Device.StartTimer",
Command = new Command(() => Device.StartTimer(
TimeSpan.FromSeconds(1),
() =>
{
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
return false;
})),
},
}
}
};
</code></pre>
<p>I included <code>System.Threading</code> and <code>System.Threading.Tasks</code>, but I still get</p>
<blockquote>
<p>The name 'Thread' does not exist in the current context.</p>
</blockquote>
<p><a href="http://www.xforms-kickstarter.com/#timer-never-miss-an-action" rel="noreferrer">This site</a> suggests that <code>Thread.Sleep</code> can be used in <code>Xamarin.Forms</code>. I have this in a shared project, not a PCL.</p>
| 0debug
|
int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(head) != 0)
return -1;
if (avpriv_mpegaudio_decode_header(s, head) != 0) {
return -1;
}
switch(s->layer) {
case 1:
avctx->codec_id = AV_CODEC_ID_MP1;
*frame_size = 384;
break;
case 2:
avctx->codec_id = AV_CODEC_ID_MP2;
*frame_size = 1152;
break;
default:
case 3:
if (avctx->codec_id != AV_CODEC_ID_MP3ADU)
avctx->codec_id = AV_CODEC_ID_MP3;
if (s->lsf)
*frame_size = 576;
else
*frame_size = 1152;
break;
}
*sample_rate = s->sample_rate;
*channels = s->nb_channels;
*bit_rate = s->bit_rate;
return s->frame_size;
}
| 1threat
|
Sending JSON to AJAX from Python Flask : <p>I'm trying to send data from a server made with Flask in Python, to the client and collect this data with AJAX. Many of the examples I have seen does this with jQuery, but I'd like to do it without jQuery. Is it possible to do this with just ordinary Javascript without jQuery, and how would I build this functionality?</p>
| 0debug
|
i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
{
i2c_bus *bus;
bus = FROM_QBUS(i2c_bus, qbus_create(BUS_TYPE_I2C, sizeof(i2c_bus),
parent, name));
register_savevm("i2c_bus", -1, 1, i2c_bus_save, i2c_bus_load, bus);
return bus;
}
| 1threat
|
I want to avoid id duplication and add values using push : angular.module("app", [])
.controller('TabsDemoCtrl',function($scope,$http){
$scope.items = [
{ id: 10, name: 'foo', price: '1000' },
{ id: 10, name: 'bar', price: '2000' },
{ id: 33, name: 'blah', price: '3000' }
];
});
output:<br>
id: 10<br>
name: foo<br>
price:1000<p>
id: 10<br>
name: bar<br>
price:2000<p>
id: 33<br>
name: blah<br>
price:3000<p>
Output as follows
id 10<br>
name: foo<br>
price: 1000<p>
name: bar<br>
price: 2000<p>
id 33<br>
name: blah<br>
price: 3000<br>
Please help me.
| 0debug
|
static void conv411(uint8_t *dst, int dst_wrap,
uint8_t *src, int src_wrap,
int width, int height)
{
int w, c;
uint8_t *s1, *s2, *d;
for(;height > 0; height--) {
s1 = src;
s2 = src + src_wrap;
d = dst;
for(w = width;w > 0; w--) {
c = (s1[0] + s2[0]) >> 1;
d[0] = c;
d[1] = c;
s1++;
s2++;
d += 2;
}
src += src_wrap * 2;
dst += dst_wrap;
}
}
| 1threat
|
select posts from the last month : <p>In a table <code>posts</code> I have a column named <code>date</code> format - <code>datetime</code> - <code>current timestamp</code> and need to select posts from the last month only. </p>
<p>All dates in the column are from december 2016. for example - <code>2016-12-09 04:25:00</code></p>
<pre><code><?php
$start = strtotime("-1 month"); // 1488285716
$stmt = $db->query("SELECT * FROM posts where date > " . $start . " order by...");
?>
</code></pre>
<p>But all posts are selected! Resulut should be zero.<br>
Any help?</p>
| 0debug
|
ElasticSearch updates are not immediate, how do you wait for ElasticSearch to finish updating it's index? : <p>I'm attempting to improve performance on a suite that tests against ElasticSearch. </p>
<p>The tests take a long time because Elasticsearch does not update it's indexes immediately after updating. For instance, the following code runs without raising an assertion error.</p>
<pre><code>from elasticsearch import Elasticsearch
elasticsearch = Elasticsearch('es.test')
# Asumming that this is a clean and empty elasticsearch instance
elasticsearch.update(
index='blog',
doc_type=,'blog'
id=1,
body={
....
}
)
results = elasticsearch.search()
assert not results
# results are not populated
</code></pre>
<p>Currently out hacked together solution to this issue is dropping a <code>time.sleep</code> call into the code, to give ElasticSearch some time to update it's indexes.</p>
<pre><code>from time import sleep
from elasticsearch import Elasticsearch
elasticsearch = Elasticsearch('es.test')
# Asumming that this is a clean and empty elasticsearch instance
elasticsearch.update(
index='blog',
doc_type=,'blog'
id=1,
body={
....
}
)
# Don't want to use sleep functions
sleep(1)
results = elasticsearch.search()
assert len(results) == 1
# results are now populated
</code></pre>
<p>Obviously this isn't great, as it's rather failure prone, hypothetically if ElasticSearch takes longer than a second to update it's indexes, despite how unlikely that is, the test will fail. Also it's extremely slow when you're running 100s of tests like this.</p>
<p>My attempt to solve the issue has been to query the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html" rel="noreferrer">pending cluster jobs</a> to see if there are any tasks left to be done. However this doesn't work, and this code will run without an assertion error.</p>
<pre><code>from elasticsearch import Elasticsearch
elasticsearch = Elasticsearch('es.test')
# Asumming that this is a clean and empty elasticsearch instance
elasticsearch.update(
index='blog',
doc_type=,'blog'
id=1,
body={
....
}
)
# Query if there are any pending tasks
while elasticsearch.cluster.pending_tasks()['tasks']:
pass
results = elasticsearch.search()
assert not results
# results are not populated
</code></pre>
<p>So basically, back to my original question, ElasticSearch updates are not
immediate, how do you wait for ElasticSearch to finish updating it's index?</p>
| 0debug
|
How do I return in a function two different lists? (Phyton) : How do I return two different lists in a function I made?
def eolist(num1):
li_1 = []
li_2 = []
for i in range(1, num1+1):
if i % 2 != 0:
li_2.append(i)
else:
li_1.append(i)
return li_1, li_2
| 0debug
|
What does the var[x] do? : I have a pretty simple question regarding c variables
All I wanna know is what the x does in
int var[x]
I know its a pretty simple question but I cannot find the answer directly on Google.
Thank you!
| 0debug
|
How to detect if 64 bit MSVC with cmake? : <p>I have a project which uses cmake, one target is set to only build with MSVC:</p>
<pre><code> if (MSVC)
add_library(test SHARED source.cpp)
endif()
</code></pre>
<p>Now the other issue is that this target is only designed for MSVC 32bit. So how can I detect that the generator is MSVC64 and skip this target?</p>
| 0debug
|
Bash Split a String with a Path in it : <p>I have the follow Problem, my file '2018_08_18__Lysto BackUp.plist' looks like this:</p>
<pre><code>/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/exit_codes/
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/exit_codes/code_FUNC
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/exit_codes/code_SCRI
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/login/
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/login/check_appprivilege.php
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/login/check_login.php
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/login/privilege.php
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/scripte/
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/scripte/Lysto BackUp/
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/scripte/Lysto BackUp/sys
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/scripte/Lysto BackUp/sys_func
/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/SSH_ERROR
</code></pre>
<p>i read the file with an for loop so i get every single lines in:</p>
<pre><code>mainDirectory
</code></pre>
<p>i need the output like this...
Count --> '6'</p>
<p>so i need an idea to count every single /*/</p>
<pre><code>1 --> /volume1/
2 --> 02_public/
3 --> 3rd_Party_Apps/
4 --> SPK_SCRIPTS/
5 --> SynoDSApps/
6 --> webapp/
</code></pre>
<p>in this case:</p>
<pre><code>/volume1/02_public/3rd_Party_Apps/SPK_SCRIPTS/SynoDSApps/webapp/scripte/Lysto BackUp/sys_func
</code></pre>
<p>i need only this count --> '8'</p>
<pre><code>1 --> /volume1/
2 --> 02_public/
3 --> 3rd_Party_Apps/
4 --> SPK_SCRIPTS/
5 --> SynoDSApps/
6 --> webapp/
7 --> scripte/
8 --> Lysto BackUp/
not in the count result --> sys_func
</code></pre>
<p>I hope you Guys can Help me to fix my Problems....
i look for a result since one Week :(</p>
| 0debug
|
static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)
{
RTL8139State *s = opaque;
addr &= 0xfc;
switch (addr)
{
case RxMissed:
DPRINTF("RxMissed clearing on write\n");
s->RxMissed = 0;
break;
case TxConfig:
rtl8139_TxConfig_write(s, val);
break;
case RxConfig:
rtl8139_RxConfig_write(s, val);
break;
case TxStatus0 ... TxStatus0+4*4-1:
rtl8139_TxStatus_write(s, addr-TxStatus0, val);
break;
case TxAddr0 ... TxAddr0+4*4-1:
rtl8139_TxAddr_write(s, addr-TxAddr0, val);
break;
case RxBuf:
rtl8139_RxBuf_write(s, val);
break;
case RxRingAddrLO:
DPRINTF("C+ RxRing low bits write val=0x%08x\n", val);
s->RxRingAddrLO = val;
break;
case RxRingAddrHI:
DPRINTF("C+ RxRing high bits write val=0x%08x\n", val);
s->RxRingAddrHI = val;
break;
case Timer:
DPRINTF("TCTR Timer reset on write\n");
s->TCTR_base = qemu_get_clock_ns(vm_clock);
rtl8139_set_next_tctr_time(s, s->TCTR_base);
break;
case FlashReg:
DPRINTF("FlashReg TimerInt write val=0x%08x\n", val);
if (s->TimerInt != val) {
s->TimerInt = val;
rtl8139_set_next_tctr_time(s, qemu_get_clock_ns(vm_clock));
}
break;
default:
DPRINTF("ioport write(l) addr=0x%x val=0x%08x via write(b)\n",
addr, val);
rtl8139_io_writeb(opaque, addr, val & 0xff);
rtl8139_io_writeb(opaque, addr + 1, (val >> 8) & 0xff);
rtl8139_io_writeb(opaque, addr + 2, (val >> 16) & 0xff);
rtl8139_io_writeb(opaque, addr + 3, (val >> 24) & 0xff);
break;
}
}
| 1threat
|
static int ftp_passive_mode(FTPContext *s)
{
char *res = NULL, *start, *end;
int i;
const char *command = "PASV\r\n";
const int pasv_codes[] = {227, 0};
if (!ftp_send_command(s, command, pasv_codes, &res))
goto fail;
start = NULL;
for (i = 0; i < strlen(res); ++i) {
if (res[i] == '(') {
start = res + i + 1;
} else if (res[i] == ')') {
end = res + i;
break;
}
}
if (!start || !end)
goto fail;
*end = '\0';
if (!av_strtok(start, ",", &end)) goto fail;
if (!av_strtok(end, ",", &end)) goto fail;
if (!av_strtok(end, ",", &end)) goto fail;
if (!av_strtok(end, ",", &end)) goto fail;
start = av_strtok(end, ",", &end);
if (!start) goto fail;
s->server_data_port = atoi(start) * 256;
start = av_strtok(end, ",", &end);
if (!start) goto fail;
s->server_data_port += atoi(start);
av_dlog(s, "Server data port: %d\n", s->server_data_port);
av_free(res);
return 0;
fail:
av_free(res);
s->server_data_port = -1;
return AVERROR(EIO);
}
| 1threat
|
static inline void *host_from_stream_offset(QEMUFile *f,
ram_addr_t offset,
int flags)
{
static RAMBlock *block = NULL;
char id[256];
uint8_t len;
if (flags & RAM_SAVE_FLAG_CONTINUE) {
if (!block || block->max_length <= offset) {
error_report("Ack, bad migration stream!");
return NULL;
}
return block->host + offset;
}
len = qemu_get_byte(f);
qemu_get_buffer(f, (uint8_t *)id, len);
id[len] = 0;
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
if (!strncmp(id, block->idstr, sizeof(id)) &&
block->max_length > offset) {
return block->host + offset;
}
}
error_report("Can't find block %s!", id);
return NULL;
}
| 1threat
|
static bool cmd_set_features(IDEState *s, uint8_t cmd)
{
uint16_t *identify_data;
if (!s->bs) {
ide_abort_command(s);
return true;
}
switch (s->feature) {
case 0x02:
bdrv_set_enable_write_cache(s->bs, true);
identify_data = (uint16_t *)s->identify_data;
put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
return true;
case 0x82:
bdrv_set_enable_write_cache(s->bs, false);
identify_data = (uint16_t *)s->identify_data;
put_le16(identify_data + 85, (1 << 14) | 1);
ide_flush_cache(s);
return false;
case 0xcc:
case 0x66:
case 0xaa:
case 0x55:
case 0x05:
case 0x85:
case 0x69:
case 0x67:
case 0x96:
case 0x9a:
case 0x42:
case 0xc2:
return true;
case 0x03:
{
uint8_t val = s->nsector & 0x07;
identify_data = (uint16_t *)s->identify_data;
switch (s->nsector >> 3) {
case 0x00:
case 0x01:
put_le16(identify_data + 62, 0x07);
put_le16(identify_data + 63, 0x07);
put_le16(identify_data + 88, 0x3f);
break;
case 0x02:
put_le16(identify_data + 62, 0x07 | (1 << (val + 8)));
put_le16(identify_data + 63, 0x07);
put_le16(identify_data + 88, 0x3f);
break;
case 0x04:
put_le16(identify_data + 62, 0x07);
put_le16(identify_data + 63, 0x07 | (1 << (val + 8)));
put_le16(identify_data + 88, 0x3f);
break;
case 0x08:
put_le16(identify_data + 62, 0x07);
put_le16(identify_data + 63, 0x07);
put_le16(identify_data + 88, 0x3f | (1 << (val + 8)));
break;
default:
goto abort_cmd;
}
return true;
}
}
abort_cmd:
ide_abort_command(s);
return true;
}
| 1threat
|
delete a string but the string is not terminated : I need to delete around four thousand lines that contain SEU/C0 among around 25,000 lines
Find SEU in following line:
inpin "SEUC0/example_controller/U0/wrapper_wrappe/genx7.wrapper_controller/pid_reg<3>" A6 ,
But the solution; I tried :
I got this code from this forum suppose to do what I want but no luck
f = open("test.xdl","r+")
d = f.readlines()
f.seek(0)
for i in d:
if i != "SEU": # want to remove the SEU string
f.write(i)
f.truncate()
f.close()
When If if try
i!="inpin SEUC0/
it didn't work because it's a long string, and if I write
"inpin "SEUC0/"" Python gives error.
Is there anyway that I can remove all these lines which contain SEUC0.
| 0debug
|
how to upload large file(image,pdf,documents) like chunk? give some methods : Need to upload minimum 20 mb files in client side only. Need different type of methods to upload large file without any interruption?
| 0debug
|
npm ERR! code Z_BUF_ERROR when install : <p>In my server(CentOS 7.2) I install the dependencies:</p>
<pre><code>npm install
</code></pre>
<p>But I get bellow error:</p>
<pre><code>npm ERR! code Z_BUF_ERROR
npm ERR! errno -5
npm ERR! unexpected end of file
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-02-11T21_03_20_261Z-debug.log
</code></pre>
<p>in the <code>/root/.npm/_logs/2018-02-11T21_03_20_261Z-debug.log</code>, the info is bellow:</p>
<pre><code>10234 verbose bundle EBUNDLEOVERRIDE: Replacing npm@1.4.29's bundled version of readable-stream with readable-stream@1.0.34.
10235 verbose unlock done using /root/.npm/_locks/staging-ace74a3b0cf47932.lock for /home/ubuntu/source_code_web/vue_admin_site/node_modules/.staging
10236 warn The package iview is included as both a dev and production dependency.
10237 warn npm@1.4.29 had bundled packages that do not match the required version(s). They have been replaced with non-bundled versions.
10238 verbose type OperationalError
10239 verbose stack Error: unexpected end of file
10239 verbose stack at Gunzip.zlibOnError (zlib.js:152:15)
10240 verbose cwd /home/ubuntu/source_code_web/vue_admin_site
10241 verbose Linux 3.10.0-327.el7.x86_64
10242 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
10243 verbose node v8.4.0
10244 verbose npm v5.3.0
10245 error code Z_BUF_ERROR
10246 error errno -5
10247 error unexpected end of file
10248 verbose exit [ -5, true ]
</code></pre>
<p>I tried use:</p>
<pre><code>npm cache clean
</code></pre>
<p>to clean the npm, but fails:</p>
<pre><code>npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
npm ERR!
npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-02-11T21_13_51_943Z-debug.log
</code></pre>
| 0debug
|
What are the exact semantics of Rust's shift operators? : <p>I tried to find exact information about how the <code><<</code> and <code>>></code> operators work on integers, but I couldn't find a clear answer (<a href="https://doc.rust-lang.org/stable/std/ops/trait.Shr.html" rel="noreferrer">the documentation</a> is not that great in that regard). </p>
<p>There are two parts of the semantics that are not clear to me. First, what bits are "shifted in"?</p>
<ul>
<li>Zeroes are shifted in from one side (i.e. <code>0b1110_1010u8 << 4 == 0b1010_0000u8</code>), or </li>
<li>the bits rotate (i.e. <code>0b1110_1010u8 << 4 == 0b1010_1110u8</code>), or</li>
<li>it's unspecified (like overflowing behavior of integers is unspecified), or</li>
<li>something else.</li>
</ul>
<p>Additionally, how does shifts work with signed integers? Is the sign bit also involved in the shift or not? Or is this unspecified?</p>
| 0debug
|
static inline void json_print_item_str(WriterContext *wctx,
const char *key, const char *value,
const char *indent)
{
char *key_esc = json_escape_str(key);
char *value_esc = json_escape_str(value);
printf("%s\"%s\": \"%s\"", indent,
key_esc ? key_esc : "",
value_esc ? value_esc : "");
av_free(key_esc);
av_free(value_esc);
}
| 1threat
|
static void dump_qobject(fprintf_function func_fprintf, void *f,
int comp_indent, QObject *obj)
{
switch (qobject_type(obj)) {
case QTYPE_QINT: {
QInt *value = qobject_to_qint(obj);
func_fprintf(f, "%" PRId64, qint_get_int(value));
break;
}
case QTYPE_QSTRING: {
QString *value = qobject_to_qstring(obj);
func_fprintf(f, "%s", qstring_get_str(value));
break;
}
case QTYPE_QDICT: {
QDict *value = qobject_to_qdict(obj);
dump_qdict(func_fprintf, f, comp_indent, value);
break;
}
case QTYPE_QLIST: {
QList *value = qobject_to_qlist(obj);
dump_qlist(func_fprintf, f, comp_indent, value);
break;
}
case QTYPE_QFLOAT: {
QFloat *value = qobject_to_qfloat(obj);
func_fprintf(f, "%g", qfloat_get_double(value));
break;
}
case QTYPE_QBOOL: {
QBool *value = qobject_to_qbool(obj);
func_fprintf(f, "%s", qbool_get_int(value) ? "true" : "false");
break;
}
case QTYPE_QERROR: {
QString *value = qerror_human((QError *)obj);
func_fprintf(f, "%s", qstring_get_str(value));
break;
}
case QTYPE_NONE:
break;
case QTYPE_MAX:
default:
abort();
}
}
| 1threat
|
How to get text input and past it in front of a link (php) : I'm currently busy with (re)making the dutch Wikipedia site.
And i want to make the search bar.
My idea was to get text input and when you click on search the text will go to the front of a link like this https://ibb.co/XbndsKP
this is currently the search bar:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<div align='center'>
<form method="submit" action='php/zoeken.php'>
<input placeholder="zoeken"id="zoeken"class='zoeken'type="text">
<button class='button'type="submit">zoeken</button>
</div>
<!-- end snippet -->
[1]: https://i.stack.imgur.com/cNf7B.png
| 0debug
|
How to convert java to kotlin : <p>We are trying to convert java code to Kotlin and are having a hard time figuring out how to do it. Any help or recommendations are welcome. Thanks!</p>
<pre><code> private void runTextRecognition() {
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(mSelectedImage);
FirebaseVisionTextRecognizer recognizer = FirebaseVision.getInstance()
.getOnDeviceTextRecognizer();
mTextButton.setEnabled(false);
recognizer.processImage(image)
.addOnSuccessListener(
new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText texts) {
mTextButton.setEnabled(true);
processTextRecognitionResult(texts);
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
mTextButton.setEnabled(true);
e.printStackTrace();
}
});
}
</code></pre>
<p>The above code is what we are trying to convert to Kotlin.</p>
| 0debug
|
App unfortunately stopped when click button/functions : I created App with mp3 / mp4 buttons.
When I click Buttons It unfortunately stopped.
Don`t Mark as Duplicate or anything.
I searched Well.
I'm not found any solution.
Also I Used Button onclick listener and its not work.
Here is my main java code:
https://vivekp.co/main.java
| 0debug
|
babel-node vs babel-register in development : <p>Is there any difference between using babel-register or babel-node <strong>when running my code in development</strong>? The two options are:</p>
<ol>
<li><p><code>require('babel-register')({
"presets": ["es2015"]
});</code> at entry-point.js and npm start script <code>node entry-point.js</code></p></li>
<li><p>simply have npm start script <code>babel-node entry-point.js --preset=es2015</code></p></li>
</ol>
<p>Do they do the exact same thing? And is one way recommended over the other?</p>
| 0debug
|
3 Dimensional Dynamic Tkinter Widgets : [Tkinter Requirements][1]
[1]: https://i.stack.imgur.com/WsY2X.png
So I am relatively new to using Tkinter and I am struggling with a very specific doubt here. I tried finding solutions to this but as much as I find it obvious, the solution to this doesn't seem to be easy to understand. So if you can see the image I have linked, I am trying to create a GUI for a particular project which requires multi-layer (I am calling it 3D array based) widgets.
Let's say the variables used for this pointer system are **i, j and k**.
I am creating individual layer widgets using for-loop:
for n in range(i):
frame_x[i] = Frame(root).grid(row = 1, column = i)
entry_x[i] = Entry(frame_x[i]).grid(row = 2, column = i)
button_x[i] = Button(frame_x[i]).grid(row=3, column = i)
**Please note this is not a functional code, I have tried to keep it to the point just to give an idea of the method I am using(Let me know if you want a more detailed code block.**
Now coming to the problem. I am able to do the basic part of this. But the problem is that I want it to work dynamically.
**Lets say if the user enters j = 4 first. 4 blocks will be created.
Later if he changes the value to j = 2 and the presses the button, ideally it should make the widgets at block j= 3 and 4 disappear. But I guess Tkinter works on overlapping basis and doesn't change a grid element until something is specifically overlapped over it. How do I do that. I tried destroying the entire frame just after entering the for-loop but that doesn't work as for the first time no widget is created before destroying and python throws NameError saying I cant use a variable before assignment.**
Anyways, please let me know how do I do this efficiently.
And also in general, if there is a better way to go about the whole thing. Please refer the image linked and let me know if it doesn't make sense.
I am not very comfortable with classes in general. I prefer the inefficient way by only using functions to do everything I have to. So it would be great if you can share me a framework without using classes. But its okay if you use them. I know I should start working with classes at some point.
| 0debug
|
static void ebml_free(EbmlSyntax *syntax, void *data)
{
int i, j;
for (i = 0; syntax[i].id; i++) {
void *data_off = (char *) data + syntax[i].data_offset;
switch (syntax[i].type) {
case EBML_STR:
case EBML_UTF8:
av_freep(data_off);
break;
case EBML_BIN:
av_freep(&((EbmlBin *) data_off)->data);
break;
case EBML_LEVEL1:
case EBML_NEST:
if (syntax[i].list_elem_size) {
EbmlList *list = data_off;
char *ptr = list->elem;
for (j = 0; j < list->nb_elem;
j++, ptr += syntax[i].list_elem_size)
ebml_free(syntax[i].def.n, ptr);
av_freep(&list->elem);
} else
ebml_free(syntax[i].def.n, data_off);
default:
break;
}
}
}
| 1threat
|
int ff_hevc_decode_nal_vps(HEVCContext *s)
{
int i,j;
GetBitContext *gb = &s->HEVClc.gb;
int vps_id = 0;
HEVCVPS *vps;
AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps));
if (!vps_buf)
return AVERROR(ENOMEM);
vps = (HEVCVPS*)vps_buf->data;
av_log(s->avctx, AV_LOG_DEBUG, "Decoding VPS\n");
vps_id = get_bits(gb, 4);
if (vps_id >= MAX_VPS_COUNT) {
av_log(s->avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id);
goto err;
}
if (get_bits(gb, 2) != 3) {
av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
goto err;
}
vps->vps_max_layers = get_bits(gb, 6) + 1;
vps->vps_max_sub_layers = get_bits(gb, 3) + 1;
vps->vps_temporal_id_nesting_flag = get_bits1(gb);
if (get_bits(gb, 16) != 0xffff) {
av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n");
goto err;
}
if (vps->vps_max_sub_layers > MAX_SUB_LAYERS) {
av_log(s->avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n",
vps->vps_max_sub_layers);
goto err;
}
if (decode_profile_tier_level(&s->HEVClc, &vps->ptl, vps->vps_max_sub_layers) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Error decoding profile tier level.\n");
goto err;
}
vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb);
i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1;
for (; i < vps->vps_max_sub_layers; i++) {
vps->vps_max_dec_pic_buffering[i] = get_ue_golomb_long(gb) + 1;
vps->vps_num_reorder_pics[i] = get_ue_golomb_long(gb);
vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1;
if (vps->vps_max_dec_pic_buffering[i] > MAX_DPB_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n",
vps->vps_max_dec_pic_buffering[i] - 1);
goto err;
}
if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) {
av_log(s->avctx, AV_LOG_ERROR, "vps_max_num_reorder_pics out of range: %d\n",
vps->vps_num_reorder_pics[i]);
goto err;
}
}
vps->vps_max_layer_id = get_bits(gb, 6);
vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1;
for (i = 1; i < vps->vps_num_layer_sets; i++)
for (j = 0; j <= vps->vps_max_layer_id; j++)
skip_bits(gb, 1);
vps->vps_timing_info_present_flag = get_bits1(gb);
if (vps->vps_timing_info_present_flag) {
vps->vps_num_units_in_tick = get_bits_long(gb, 32);
vps->vps_time_scale = get_bits_long(gb, 32);
vps->vps_poc_proportional_to_timing_flag = get_bits1(gb);
if (vps->vps_poc_proportional_to_timing_flag)
vps->vps_num_ticks_poc_diff_one = get_ue_golomb_long(gb) + 1;
vps->vps_num_hrd_parameters = get_ue_golomb_long(gb);
for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
int common_inf_present = 1;
get_ue_golomb_long(gb);
if (i)
common_inf_present = get_bits1(gb);
decode_hrd(s, common_inf_present, vps->vps_max_sub_layers);
}
}
get_bits1(gb);
av_buffer_unref(&s->vps_list[vps_id]);
s->vps_list[vps_id] = vps_buf;
return 0;
err:
av_buffer_unref(&vps_buf);
return AVERROR_INVALIDDATA;
}
| 1threat
|
What's wrogf with this code here? I cannot use array Tage in my lists :
I m posting few code here for you to see, the error is on names[]
var names = new Lists<string>();
while(true)
{
Console.Write("type a name (or hit ENTER to quit)");
var input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input))
break;
names.Add(input);
}
if (names.count >2)
Console.WriteLine("{0} {1} and {2} others like your posts", names[0], names[1], names.count - 2);}
}
}
i am having an error on names[0], names[1], saying cannot apply indexing with[] to an expression of list<string>
| 0debug
|
Is there a way to get existing window insets after dispatch? : <p>Is there a way to fetch an activity's <code>WindowInsets</code> at will, long past the activity's creation, without holding on to it or otherwise caching it?</p>
<p>eg.</p>
<pre><code>WindowInsets insets = getWindow().getWindowInsets();
myUseCaseView.setPaddingTop(insets.getSystemWindowInsetTop);
</code></pre>
| 0debug
|
What's the difference between ArrayList<Integer> a[]; and ArrayList<Integer> a;? : <p>What is the difference in adding the [] to an ArrayList <code>a</code>, as opposed to initializing like ArrayList <code>b</code>? Is there any purpose for one way or the other?</p>
<pre><code>ArrayList<Integer> a[];
ArrayList<Integer> b;
</code></pre>
| 0debug
|
Is it possible to use the instance defined in managed C++ class in C#? : In the C++/CLI, I have defined some instance in the class as follow.
public ref class A
{
public:
int test(){return 0;}
};
public ref Class B
{
public:
static A^ a_Instance = gcnew A();
};
And in the C# side, I have create a B instance in order try to use the function in a_Instance as follow.
private B b_instance = new B();
The question is, if it is possible for me to get the instance create in the managed C++ class and use the function in it?
Thanks all.
| 0debug
|
static int crypto_close(URLContext *h)
{
CryptoContext *c = h->priv_data;
if (c->hd)
ffurl_close(c->hd);
av_freep(&c->aes);
av_freep(&c->key);
av_freep(&c->iv);
return 0;
}
| 1threat
|
why I got UnicodeDecodeError when i use python3 readlines to read a file which contains Chinese characters? : ```
>>> path = 'name.txt'
>>> content = None
>>> with open(path, 'r') as file:
... content = file.readlines()
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/mnt/lustre/share/miniconda3/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 163: ordinal not in range(128)
```
When I run this code to read a file which contains Chinese characters, I got an error. The file is saved by using UTF-8. My python version is 3.6.5. But it runs ok in python2.7.
| 0debug
|
Installing modules : <p>I'm new to programming in Python. I can't figure out how to install a library called Requests. I followed a youtube instructional video, and it seems to be able to import the module in command prompt, but not from the IDLE, which I would prefer to use.</p>
| 0debug
|
void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm, int min_mtu,
int (*new_channel)(struct bt_l2cap_device_s *dev,
struct bt_l2cap_conn_params_s *params))
{
struct bt_l2cap_psm_s *new_psm = l2cap_psm(dev, psm);
if (new_psm) {
fprintf(stderr, "%s: PSM %04x already registered for device `%s'.\n",
__FUNCTION__, psm, dev->device.lmp_name);
exit(-1);
}
new_psm = g_malloc0(sizeof(*new_psm));
new_psm->psm = psm;
new_psm->min_mtu = min_mtu;
new_psm->new_channel = new_channel;
new_psm->next = dev->first_psm;
dev->first_psm = new_psm;
}
| 1threat
|
Java Threads producer-consumer shared buffer : <p>Implement producer consumer problem using threads in Java. Producers and consumers share a buffer, producers put elements in buffer and consumers consume elements from the shared buffer. If the buffer is full producers should wait till consumers take out elements, similarly consumers should wait till producers put elements if the buffer is empty.
Your program should accept the following inputs:</p>
<pre><code>m: the number of producer threads
n: the number of consumer threads
k: the size of the bounded buffer
</code></pre>
<p>Your code should prompt for the above inputs in that order. You can assume that a valid integer is provided by the user for each of these. You will need to spawn m Producer threads and n Consumer threads. Each producer generates 20 integers ranging between 0 and 9 and puts them in the buffer. After putting a number in the buffer, it prints its id along with the generated number. The producer sleeps for a random amount of time before repeating the number generating cycle again. Each consumer takes a number from the buffer then prints its id along with the value it got. Then, it sleeps for a random amount of time before reading from the buffer again.
A sample output of the program is:</p>
<pre><code>Producer #2 put: 1
Producer #1 put: 4
Consumer #3 got: 1
Producer #1 put: 3
Consumer #3 got: 4
Consumer #3 got: 3
...
</code></pre>
<p>i have this problem. it is clear that the <strong>array of buffer</strong> is a global variable for two method because of that array is shared with Producer & Consumer. so? Unfortunately i have no idea how to do this project. anybody have an idea?</p>
| 0debug
|
static int scsi_disk_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
int is_cd;
DriveInfo *dinfo;
if (!s->qdev.conf.bs) {
error_report("scsi-disk: drive property not set");
s->bs = s->qdev.conf.bs;
is_cd = bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM;
if (bdrv_get_on_error(s->bs, 1) != BLOCK_ERR_REPORT) {
error_report("Device doesn't support drive option rerror");
if (!s->serial) {
dinfo = drive_get_by_blockdev(s->bs);
s->serial = qemu_strdup(*dinfo->serial ? dinfo->serial : "0");
if (!s->version) {
s->version = qemu_strdup(QEMU_VERSION);
if (bdrv_is_sg(s->bs)) {
error_report("scsi-disk: unwanted /dev/sg*");
if (is_cd) {
s->qdev.blocksize = 2048;
} else {
s->qdev.blocksize = s->qdev.conf.logical_block_size;
s->cluster_size = s->qdev.blocksize / 512;
s->qdev.type = TYPE_DISK;
qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
bdrv_set_removable(s->bs, is_cd);
return 0;
| 1threat
|
Database for .net web api : <p>I'm looking for a tip on what database I should use for my api.</p>
<p>The api will be querying one table with maximum of 10 million rows. I'm looking for a free and easy DB which can interact well with c# .net.</p>
<p>Any suggestions?</p>
| 0debug
|
Python can't find module NLTK to download punkt : I am using PyCharm and Anaconda. I have installed NTLK with sudo `pip install -U nltk` and even to make sure since I'm on Mac OS and I saw [this previous SO post][1] to also try `pip3 install nltk`.
However, no matter where I try (PyCharm's terminal, Pycharm's Python, or my own terminal), I cannot get import ntlk to work and always get `ModuleNotFoundError: No module named 'ntlk'`.
The weird thing is that I actually manage to run some code with a simple "Python test.py" that contains: `from nltk.tag import StanfordPOSTagger` but whenever I try to `import ntlk` to be able to then `nltk.download('punkt')` I get the `No module named 'ntlk'` error.
Would you know where that is coming from?
[1]: https://stackoverflow.com/questions/27947414/python-cant-find-module-nltk
| 0debug
|
"0" From nowhere after cout : <p>When i compile and run the program i am getting:The year you were born: 0
Where is the "0" coming from??
Here is the code:</p>
<pre><code>//! Program written by Samer!//
#include <iostream>
using namespace std;
int main()
{
double Year, Age;
cout <<"The year you were born: "<< Year; //!Here the error appears!//
cin >>Year;
while (Year > 2017) //!That't a While loop!//
{
cout <<"Please enter a valid Year:" << Year << endl;
cin >>Year;
}
Age=2017-Year;
cout <<"Your age is:" <<Age;
std::cin.get();
return 0;
}
</code></pre>
| 0debug
|
static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_ctrl_hdr ctrl;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
VirtQueueElement elem;
size_t s;
struct iovec *iov, *iov2;
unsigned int iov_cnt;
while (virtqueue_pop(vq, &elem)) {
if (iov_size(elem.in_sg, elem.in_num) < sizeof(status) ||
iov_size(elem.out_sg, elem.out_num) < sizeof(ctrl)) {
error_report("virtio-net ctrl missing headers");
exit(1);
}
iov_cnt = elem.out_num;
iov2 = iov = g_memdup(elem.out_sg, sizeof(struct iovec) * elem.out_num);
s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
if (s != sizeof(ctrl)) {
status = VIRTIO_NET_ERR;
} else if (ctrl.class == VIRTIO_NET_CTRL_RX) {
status = virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MAC) {
status = virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) {
status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_ANNOUNCE) {
status = virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MQ) {
status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt);
}
s = iov_from_buf(elem.in_sg, elem.in_num, 0, &status, sizeof(status));
assert(s == sizeof(status));
virtqueue_push(vq, &elem, sizeof(status));
virtio_notify(vdev, vq);
g_free(iov2);
}
}
| 1threat
|
How to create new string in C++ by two other ones? : <p>I want to create <code>string</code> <code>"hello1world</code> by this two strings:</p>
<pre><code>string s1 = "hello"
string s2 = "world"
</code></pre>
<p>I do this:</p>
<pre><code>string my_str;
sprintf(my_str, "%s1%s", s1, s2);
</code></pre>
<p>But I have an error:</p>
<pre><code>error: cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ to ‘char*’ for argument ‘1’ to ‘int sprintf(char*, const char*, ...)’
sprintf(my_str, "%s1%s", s1, s2);
</code></pre>
<p>How to do it properly?</p>
| 0debug
|
static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
int32_t *buffer_out,
int32_t *wasted_bits_buffer[MAX_CHANNELS],
int wasted_bits,
int numchannels, int numsamples,
uint8_t interlacing_shift,
uint8_t interlacing_leftweight)
{
int i;
if (numsamples <= 0)
return;
if (interlacing_leftweight) {
for (i = 0; i < numsamples; i++) {
int32_t a, b;
a = buffer[0][i];
b = buffer[1][i];
a -= (b * interlacing_leftweight) >> interlacing_shift;
b += a;
if (wasted_bits) {
b = (b << wasted_bits) | wasted_bits_buffer[0][i];
a = (a << wasted_bits) | wasted_bits_buffer[1][i];
}
buffer_out[i * numchannels] = b << 8;
buffer_out[i * numchannels + 1] = a << 8;
}
} else {
for (i = 0; i < numsamples; i++) {
int32_t left, right;
left = buffer[0][i];
right = buffer[1][i];
if (wasted_bits) {
left = (left << wasted_bits) | wasted_bits_buffer[0][i];
right = (right << wasted_bits) | wasted_bits_buffer[1][i];
}
buffer_out[i * numchannels] = left << 8;
buffer_out[i * numchannels + 1] = right << 8;
}
}
}
| 1threat
|
Kindly help me regarding the code i have given below : i am writing this code for lexical analyzer to detect tokens , identifiers and operater's from a file. But the problem is that when ever i pass the file path and run the code it does't reads the file instead it keeps on giving the output that "UNABLE TO OPEN FILE". Kindly help me
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
using namespace std;
int isKeyword(char buffer[]){
char keywords[32][10] = {"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto",
"if","int","long","register","return","short","signed",
"sizeof","static","struct","switch","typedef","union",
"unsigned","void","volatile","while"};
int i, flag = 0;
for(i = 0; i < 32; ++i){
if(strcmp(keywords[i], buffer) == 0){
flag = 1;
break;
}
}
return flag;
}
int main(){
char ch, buffer[15], operators[] = "+-*/%=";
fstream inFile;
int i , j =0;
inFile.open("C:\Users\Muhammad Shaeel\Desktop\CC\Lexical Analyser Code\Lexical Analyser Code\program.txt.txt");
if (!inFile) {
cout << "Unable to open file";
exit(0);
}
while(!inFile.eof()){
ch = inFile.get();
for(i = 0; i < 6; ++i){
if(ch == operators[i])
cout<<ch<<" is operator\n";
}
if(isalnum(ch)){
buffer[j++] = ch;
}
else if((ch == ' ' || ch == '\n') && (j != 0)){
buffer[j] = '\0';
j = 0;
if(isKeyword(buffer) == 1)
cout<<buffer<<" is keyword\n";
else
cout<<buffer<<" is indentifier\n";
}
}
inFile.close();
return 0;
system("pause");
}
| 0debug
|
static int qcow2_write(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
{
Coroutine *co;
AioContext *aio_context = bdrv_get_aio_context(bs);
Qcow2WriteCo data = {
.bs = bs,
.sector_num = sector_num,
.buf = buf,
.nb_sectors = nb_sectors,
.ret = -EINPROGRESS,
};
co = qemu_coroutine_create(qcow2_write_co_entry);
qemu_coroutine_enter(co, &data);
while (data.ret == -EINPROGRESS) {
aio_poll(aio_context, true);
}
return data.ret;
}
| 1threat
|
which jquery plug-in for bootstrap data grid : <p>Any jquery plug-in that can give me an editable data-grid with drop-downs and popups on specific columns? Where I can also have some fixed rows etc.</p>
<p>I have a bootstrap table which i just want to look better and let the user do in-line editing (like excel), sorting, paging, and binding drop-downs, custom popups etc.</p>
| 0debug
|
index: true vs foreign_key: true (Rails) : <p>Following a guide, I ran the following command:</p>
<pre><code>rails g migration CreateSnippetsUsers snippet:belongs_to user:belongs_to
</code></pre>
<p>This created the following migration:</p>
<pre><code>class CreateSnippetsUsers < ActiveRecord::Migration[5.0]
def change
create_table :snippets_users do |t|
t.belongs_to :snippet, foreign_key: true
t.belongs_to :user, foreign_key: true
end
end
end
</code></pre>
<p>In the past I've seen the same thing, but with <code>index: true</code> instead of <code>foreign_key: true</code>. What's the difference between the two?</p>
| 0debug
|
static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
QDict *options, int flags, BlockDriver *drv)
{
int ret, open_flags;
const char *filename;
assert(drv != NULL);
assert(bs->file == NULL);
assert(options != NULL && bs->options != options);
trace_bdrv_open_common(bs, filename, flags, drv->format_name);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
return -ENOTSUP;
}
if (file != NULL && drv->bdrv_file_open) {
bdrv_swap(file, bs);
return 0;
}
bs->open_flags = flags;
bs->buffer_alignment = 512;
assert(bs->copy_on_read == 0);
if ((flags & BDRV_O_RDWR) && (flags & BDRV_O_COPY_ON_READ)) {
bdrv_enable_copy_on_read(bs);
}
if (file != NULL) {
filename = file->filename;
} else {
filename = qdict_get_try_str(options, "filename");
}
if (filename != NULL) {
pstrcpy(bs->filename, sizeof(bs->filename), filename);
} else {
bs->filename[0] = '\0';
}
bs->drv = drv;
bs->opaque = g_malloc0(drv->instance_size);
bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
open_flags = bdrv_open_flags(bs, flags);
bs->read_only = !(open_flags & BDRV_O_RDWR);
if (drv->bdrv_file_open) {
assert(file == NULL);
assert(drv->bdrv_parse_filename || filename != NULL);
ret = drv->bdrv_file_open(bs, options, open_flags);
} else {
if (file == NULL) {
qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a "
"block driver for the protocol level",
drv->format_name);
ret = -EINVAL;
goto free_and_fail;
}
assert(file != NULL);
bs->file = file;
ret = drv->bdrv_open(bs, options, open_flags);
}
if (ret < 0) {
goto free_and_fail;
}
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
goto free_and_fail;
}
#ifndef _WIN32
if (bs->is_temporary) {
assert(filename != NULL);
unlink(filename);
}
#endif
return 0;
free_and_fail:
bs->file = NULL;
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret;
}
| 1threat
|
av_cold void ff_vc1dsp_init_x86(VC1DSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (INLINE_MMX(cpu_flags))
ff_vc1dsp_init_mmx(dsp);
if (INLINE_MMXEXT(cpu_flags))
ff_vc1dsp_init_mmxext(dsp);
#define ASSIGN_LF(EXT) \
dsp->vc1_v_loop_filter4 = ff_vc1_v_loop_filter4_ ## EXT; \
dsp->vc1_h_loop_filter4 = ff_vc1_h_loop_filter4_ ## EXT; \
dsp->vc1_v_loop_filter8 = ff_vc1_v_loop_filter8_ ## EXT; \
dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_ ## EXT; \
dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_ ## EXT; \
dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_ ## EXT
#if HAVE_YASM
if (cpu_flags & AV_CPU_FLAG_MMX) {
dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = ff_put_vc1_chroma_mc8_nornd_mmx;
}
if (cpu_flags & AV_CPU_FLAG_MMXEXT) {
ASSIGN_LF(mmxext);
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_mmxext;
dsp->avg_vc1_mspel_pixels_tab[0] = avg_vc1_mspel_mc00_mmxext;
} else if (cpu_flags & AV_CPU_FLAG_3DNOW) {
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_3dnow;
}
if (cpu_flags & AV_CPU_FLAG_SSE2) {
dsp->vc1_v_loop_filter8 = ff_vc1_v_loop_filter8_sse2;
dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse2;
dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_sse2;
dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_sse2;
}
if (cpu_flags & AV_CPU_FLAG_SSSE3) {
ASSIGN_LF(ssse3);
dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = ff_put_vc1_chroma_mc8_nornd_ssse3;
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_ssse3;
}
if (cpu_flags & AV_CPU_FLAG_SSE4) {
dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse4;
dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_sse4;
}
#endif
}
| 1threat
|
static QObject *get_stats_qobject(VirtIOBalloon *dev)
{
QDict *dict = qdict_new();
uint32_t actual = ram_size - (dev->actual << VIRTIO_BALLOON_PFN_SHIFT);
stat_put(dict, "actual", actual);
stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
return QOBJECT(dict);
}
| 1threat
|
int css_register_io_adapter(CssIoAdapterType type, uint8_t isc, bool swap,
bool maskable, uint32_t *id)
{
IoAdapter *adapter;
bool found = false;
int ret;
S390FLICState *fs = s390_get_flic();
S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
*id = 0;
QTAILQ_FOREACH(adapter, &channel_subsys.io_adapters, sibling) {
if ((adapter->type == type) && (adapter->isc == isc)) {
*id = adapter->id;
found = true;
ret = 0;
break;
}
if (adapter->id >= *id) {
*id = adapter->id + 1;
}
}
if (found) {
goto out;
}
adapter = g_new0(IoAdapter, 1);
ret = fsc->register_io_adapter(fs, *id, isc, swap, maskable);
if (ret == 0) {
adapter->id = *id;
adapter->isc = isc;
adapter->type = type;
QTAILQ_INSERT_TAIL(&channel_subsys.io_adapters, adapter, sibling);
} else {
g_free(adapter);
fprintf(stderr, "Unexpected error %d when registering adapter %d\n",
ret, *id);
}
out:
return ret;
}
| 1threat
|
My loop cannot stop : I have got this code, but loop cannot stop.
I using break in scope, but lopp cannot stop.
http://wklej.org/id/3236950/txt/
| 0debug
|
static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
{
if (acb->flags & QED_AIOCB_ZERO) {
struct iovec *iov = acb->qiov->iov;
if (!iov->iov_base) {
iov->iov_base = qemu_blockalign(acb->common.bs, iov->iov_len);
memset(iov->iov_base, 0, iov->iov_len);
}
}
acb->cur_cluster = offset;
qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len);
qed_aio_write_main(acb, 0);
}
| 1threat
|
How to convert String to Date with a specific format in java : <p>I have a requirement to convert String to Date (in dd-MM-yyyy format). But dateformat.parse gives the format with seconds. I need to convert the String date to Date in the same format as mentioned above.</p>
| 0debug
|
Security with laravel : <p>I have been building a site with Laravel 5.2 and now i'm trying to make my forms more secure, i have used laravel's built in validation to only allow so many characters and required certain field.
Should i be using trim or other forms of validation to make my forms more secure i been looking at the below or does laravel have a lot more security built into it to help.</p>
<pre><code>$data = trim($id); //security
$data1 = stripslashes($id); //security
$data1 = htmlspecialchars($id);
</code></pre>
| 0debug
|
C++ Copy constructor gets called instead of initializer_list<> : <p>Based on this code</p>
<pre><code>struct Foo
{
Foo()
{
cout << "default ctor" << endl;
}
Foo(std::initializer_list<Foo> ilist)
{
cout << "initializer list" << endl;
}
Foo(const Foo& copy)
{
cout << "copy ctor" << endl;
}
};
int main()
{
Foo a;
Foo b(a);
// This calls the copy constructor again!
//Shouldn't this call the initializer_list constructor?
Foo c{b};
_getch();
return 0;
}
</code></pre>
<p>The output is:</p>
<p><strong>default ctor</strong></p>
<p><strong>copy ctor</strong></p>
<p><strong>copy ctor</strong></p>
<p>In the third case, I'm putting b into the brace-initialization which should call the initializer_list<> constructor.</p>
<p>Instead, the copy constructor takes the lead.</p>
<p>Will someone of you tell me how this works and why?</p>
| 0debug
|
static void put_uint16(QEMUFile *f, void *pv, size_t size)
{
uint16_t *v = pv;
qemu_put_be16s(f, v);
}
| 1threat
|
Why do const references extend the lifetime of rvalues? : <p>Why did the C++ committee decide that const references should extend the lifetime of temporaries?</p>
<p>This fact has already been discussed extensively online, including here on stackoverflow. The definitive resource explaining that this is the case is probably this GoTW:</p>
<p><a href="https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" rel="noreferrer">GotW #88: A Candidate For the “Most Important const”</a></p>
<p>What was the rationale for this language feature? Is it known?</p>
<p>(The alternative would be that the lifetime of temporaries is not extended by any references.)</p>
<hr>
<p>My own pet theory for the rationale is that this behavior allows objects to hide implementation details. With this rule, a member function can switch between returning a value or a const reference to an already internally existent value without any change to client code. For example, a matrix class might be able to return row vectors and column vectors. To minimize copies, either one or the other could be returned as a reference depending on the implementation (row major vs column major). Whichever one cannot be returned by reference must be returned by making a copy and returning that value (if the returned vectors are contiguous). The library writer might want leeway to change the implementation in the future (row major vs column major) and prevent clients from writing code that strongly depends on if the implementation is row major or column major. By asking clients to accept return values as const ref, the matrix class can return either const refs or values without any change to client code. Regardless, if the original rationale is known, I would like to know it.</p>
| 0debug
|
error while launching app : Error message:
$ adb shell am start -n "test.beta1/test.beta1.MainActivity" -a
android.intent.action.MAIN -c android.intent.category.LAUNCHER
Unexpected error while executing: am start -n
"test.beta1/test.beta1.MainActivity" -a android.intent.action.MAIN -c
android.intent.category.LAUNCHER
Error while Launching activity
MainActivity.java code :
package test.beta1;
import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener{
private static final int RESULT_LOAD_IMAGE = 1;
ImageView imageToUpload, DownloadImage;
Button bUploadImage, bDownloadImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
DownloadImage = (ImageView) findViewById(R.id.DownloadImage);
bUploadImage = (Button) findViewById(R.id.etUploadName);
bDownloadImage = (Button) findViewById(R.id.etDownloadName);
imageToUpload.setOnClickListener(this);
bUploadImage.setOnClickListener(this);
bDownloadImage.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.imageToUpload:
Intent galleryIntent = new
Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent,RESULT_LOAD_IMAGE);
break;
case R.id.bUploadImage:
break;
case R.id.bDownloadImage:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK &&
data != null){
Uri selectedImage = data.getData();
imageToUpload.setImageURI(selectedImage);
}
}
}
| 0debug
|
void ff_h264_direct_dist_scale_factor(H264Context *const h)
{
const int poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD];
const int poc1 = h->ref_list[1][0].poc;
int i, field;
if (FRAME_MBAFF(h))
for (field = 0; field < 2; field++) {
const int poc = h->cur_pic_ptr->field_poc[field];
const int poc1 = h->ref_list[1][0].field_poc[field];
for (i = 0; i < 2 * h->ref_count[0]; i++)
h->dist_scale_factor_field[field][i ^ field] =
get_scale_factor(h, poc, poc1, i + 16);
}
for (i = 0; i < h->ref_count[0]; i++)
h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
}
| 1threat
|
Authentication (Passport) enough for security with Node js backend server? : <p>Is PassportJS using Facebook Authentication enough for an iOS backend with Node JS?</p>
<p>I have the toobusy package as well to decline requests when things get to busy (I'm guessing it would be good for DDOSes).</p>
<p>I'm thinking of using nginx as a reverse proxy to my Node.JS server as well.</p>
<p>What are some more security measures that can scale? Some advice and tips? Anything security related that I should be concerned about that PassportJS's authenticated session can't handle?</p>
| 0debug
|
static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, int size,
int c, int a, int d,
int width, ptrdiff_t stride)
{
PixletContext *ctx = avctx->priv_data;
GetBitContext *b = &ctx->gbit;
unsigned cnt1, shbits, rlen, nbits, length, i = 0, j = 0, k;
int ret, escape, pfx, value, yflag, xflag, flag = 0;
int64_t state = 3, tmp;
if ((ret = init_get_bits8(b, src, bytestream2_get_bytes_left(&ctx->gb))) < 0)
return ret;
if ((a >= 0) + (a ^ (a >> 31)) - (a >> 31) != 1) {
nbits = 33 - ff_clz((a >= 0) + (a ^ (a >> 31)) - (a >> 31) - 1);
if (nbits > 16)
return AVERROR_INVALIDDATA;
} else {
nbits = 1;
}
length = 25 - nbits;
while (i < size) {
if (state >> 8 != -3) {
value = ff_clz((state >> 8) + 3) ^ 0x1F;
} else {
value = -1;
}
cnt1 = get_unary(b, 0, length);
if (cnt1 >= length) {
cnt1 = get_bits(b, nbits);
} else {
pfx = 14 + ((((uint64_t)(value - 14)) >> 32) & (value - 14));
cnt1 *= (1 << pfx) - 1;
shbits = show_bits(b, pfx);
if (shbits <= 1) {
skip_bits(b, pfx - 1);
} else {
skip_bits(b, pfx);
cnt1 += shbits - 1;
}
}
xflag = flag + cnt1;
yflag = xflag;
if (flag + cnt1 == 0) {
value = 0;
} else {
xflag &= 1u;
tmp = c * ((yflag + 1) >> 1) + (c >> 1);
value = xflag + (tmp ^ -xflag);
}
i++;
dst[j++] = value;
if (j == width) {
j = 0;
dst += stride;
}
state += d * yflag - (d * state >> 8);
flag = 0;
if (state * 4 > 0xFF || i >= size)
continue;
pfx = ((state + 8) >> 5) + (state ? ff_clz(state): 32) - 24;
escape = av_mod_uintp2(16383, pfx);
cnt1 = get_unary(b, 0, 8);
if (cnt1 < 8) {
if (pfx < 1 || pfx > 25)
return AVERROR_INVALIDDATA;
value = show_bits(b, pfx);
if (value > 1) {
skip_bits(b, pfx);
rlen = value + escape * cnt1 - 1;
} else {
skip_bits(b, pfx - 1);
rlen = escape * cnt1;
}
} else {
if (get_bits1(b))
value = get_bits(b, 16);
else
value = get_bits(b, 8);
rlen = value + 8 * escape;
}
if (rlen > 0xFFFF || i + rlen > size)
return AVERROR_INVALIDDATA;
i += rlen;
for (k = 0; k < rlen; k++) {
dst[j++] = 0;
if (j == width) {
j = 0;
dst += stride;
}
}
state = 0;
flag = rlen < 0xFFFF ? 1 : 0;
}
align_get_bits(b);
return get_bits_count(b) >> 3;
}
| 1threat
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.