problem
stringlengths 26
131k
| labels
class label 2
classes |
|---|---|
Sample code to connect to MS Access(accdb) database : Can anyone provide a sample code to connect to an MS Access database (.accdb file) from a C# application. Details are given below:
I need to connect using the OdbcConnection class
I am using Access 2007
| 0debug
|
static bool bdrv_start_throttled_reqs(BlockDriverState *bs)
{
bool drained = false;
bool enabled = bs->io_limits_enabled;
int i;
bs->io_limits_enabled = false;
for (i = 0; i < 2; i++) {
while (qemu_co_enter_next(&bs->throttled_reqs[i])) {
drained = true;
}
}
bs->io_limits_enabled = enabled;
return drained;
}
| 1threat
|
static void *qpa_thread_in (void *arg)
{
PAVoiceIn *pa = arg;
HWVoiceIn *hw = &pa->hw;
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
return NULL;
}
for (;;) {
int incr, to_grab, wpos;
for (;;) {
if (pa->done) {
goto exit;
}
if (pa->dead > 0) {
break;
}
if (audio_pt_wait (&pa->pt, AUDIO_FUNC)) {
goto exit;
}
}
incr = to_grab = audio_MIN (pa->dead, conf.samples >> 2);
wpos = pa->wpos;
if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) {
return NULL;
}
while (to_grab) {
int error;
int chunk = audio_MIN (to_grab, hw->samples - wpos);
void *buf = advance (pa->pcm_buf, wpos);
if (pa_simple_read (pa->s, buf,
chunk << hw->info.shift, &error) < 0) {
qpa_logerr (error, "pa_simple_read failed\n");
return NULL;
}
hw->conv (hw->conv_buf + wpos, buf, chunk);
wpos = (wpos + chunk) % hw->samples;
to_grab -= chunk;
}
if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) {
return NULL;
}
pa->wpos = wpos;
pa->dead -= incr;
pa->incr += incr;
}
exit:
audio_pt_unlock (&pa->pt, AUDIO_FUNC);
return NULL;
}
| 1threat
|
static PCIReqIDCache pci_req_id_cache_get(PCIDevice *dev)
{
PCIDevice *parent;
PCIReqIDCache cache = {
.dev = dev,
.type = PCI_REQ_ID_BDF,
};
while (!pci_bus_is_root(dev->bus)) {
parent = dev->bus->parent_dev;
if (pci_is_express(parent)) {
if (pcie_cap_get_type(parent) == PCI_EXP_TYPE_PCI_BRIDGE) {
cache.type = PCI_REQ_ID_SECONDARY_BUS;
cache.dev = dev;
}
} else {
cache.type = PCI_REQ_ID_BDF;
cache.dev = parent;
}
dev = parent;
}
return cache;
}
| 1threat
|
int ff_listen_connect(int fd, const struct sockaddr *addr,
socklen_t addrlen, int timeout, URLContext *h)
{
struct pollfd p = {fd, POLLOUT, 0};
int ret;
socklen_t optlen;
ff_socket_nonblock(fd, 1);
while ((ret = connect(fd, addr, addrlen))) {
ret = ff_neterrno();
switch (ret) {
case AVERROR(EINTR):
if (ff_check_interrupt(&h->interrupt_callback))
return AVERROR_EXIT;
continue;
case AVERROR(EINPROGRESS):
case AVERROR(EAGAIN):
while (timeout--) {
if (ff_check_interrupt(&h->interrupt_callback))
return AVERROR_EXIT;
ret = poll(&p, 1, 100);
if (ret > 0)
break;
}
if (ret <= 0)
return AVERROR(ETIMEDOUT);
optlen = sizeof(ret);
if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
ret = AVUNERROR(ff_neterrno());
if (ret != 0) {
char errbuf[100];
ret = AVERROR(ret);
av_strerror(ret, errbuf, sizeof(errbuf));
av_log(h, AV_LOG_ERROR,
"Connection to %s failed: %s\n",
h->filename, errbuf);
}
default:
return ret;
}
}
return ret;
}
| 1threat
|
What is modifier for the variables inside the public static void main(String args[]) method : I have read at many places that static method can access static variables only but when I write code, I am mentioning my variables as static and my code still works.
Is anyone out there to help me understand this concept clearly?
public class LearnMain {
public static void main(String args[])
{
int a = 1;
System.out.println(""+a);
}
}
| 0debug
|
CharDriverState *uart_hci_init(qemu_irq wakeup)
{
struct csrhci_s *s = (struct csrhci_s *)
g_malloc0(sizeof(struct csrhci_s));
s->chr.opaque = s;
s->chr.chr_write = csrhci_write;
s->chr.chr_ioctl = csrhci_ioctl;
s->hci = qemu_next_hci();
s->hci->opaque = s;
s->hci->evt_recv = csrhci_out_hci_packet_event;
s->hci->acl_recv = csrhci_out_hci_packet_acl;
s->out_tm = qemu_new_timer_ns(vm_clock, csrhci_out_tick, s);
s->pins = qemu_allocate_irqs(csrhci_pins, s, __csrhci_pins);
csrhci_reset(s);
return &s->chr;
}
| 1threat
|
static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
QEMUIOVector *qiov, int flags)
{
BlockDriver *drv = bs->drv;
int ret;
int64_t sector_num = offset >> BDRV_SECTOR_BITS;
unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS;
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
if (bs->copy_on_read_in_flight) {
wait_for_overlapping_requests(bs, req, offset, bytes);
}
ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req);
if (ret < 0) {
} else if (flags & BDRV_REQ_ZERO_WRITE) {
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, flags);
} else {
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
}
if (ret == 0 && !bs->enable_write_cache) {
ret = bdrv_co_flush(bs);
}
bdrv_set_dirty(bs, sector_num, nb_sectors);
if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
bs->wr_highest_sector = sector_num + nb_sectors - 1;
}
if (bs->growable && ret >= 0) {
bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
}
return ret;
}
| 1threat
|
Transfer files from dropbox/drive to Google cloud storage : <p>We are planning to implement a feature to let customers browse their images in their own google drive or dropbox accounts (within our app), and select ones they wanna use in our app. Then, we will save these images into our Google cloud storage (GCS) place.</p>
<p>A simple approach is to use OAuth to download the customers' images from dropbox/drive to our local disk, then upload them to our GCS.</p>
<p>I am wondering if it is possible to make a direct transfer between dropbox/drive and GCS? GCS does provide <a href="https://cloud.google.com/storage/transfer/" rel="noreferrer">transfer service</a> for S3. You can also create a list of URL list, but each URL needs to be publicly accessible, which in our case does not seem possible.</p>
<p>Is there any better suggestion on how to implement this feature? Thanks</p>
| 0debug
|
static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
unsigned size)
{
SerialState *s = opaque;
addr &= 7;
DPRINTF("write addr=0x%" HWADDR_PRIx " val=0x%" PRIx64 "\n", addr, val);
switch(addr) {
default:
case 0:
if (s->lcr & UART_LCR_DLAB) {
s->divider = (s->divider & 0xff00) | val;
serial_update_parameters(s);
} else {
s->thr = (uint8_t) val;
if(s->fcr & UART_FCR_FE) {
if (fifo8_is_full(&s->xmit_fifo)) {
fifo8_pop(&s->xmit_fifo);
}
fifo8_push(&s->xmit_fifo, s->thr);
s->lsr &= ~UART_LSR_TEMT;
}
s->thr_ipending = 0;
s->lsr &= ~UART_LSR_THRE;
serial_update_irq(s);
serial_xmit(NULL, G_IO_OUT, s);
}
break;
case 1:
if (s->lcr & UART_LCR_DLAB) {
s->divider = (s->divider & 0x00ff) | (val << 8);
serial_update_parameters(s);
} else {
s->ier = val & 0x0f;
if (s->poll_msl >= 0) {
if (s->ier & UART_IER_MSI) {
s->poll_msl = 1;
serial_update_msl(s);
} else {
timer_del(s->modem_status_poll);
s->poll_msl = 0;
}
}
if (s->lsr & UART_LSR_THRE) {
s->thr_ipending = 1;
serial_update_irq(s);
}
}
break;
case 2:
val = val & 0xFF;
if (s->fcr == val)
break;
if ((val ^ s->fcr) & UART_FCR_FE)
val |= UART_FCR_XFR | UART_FCR_RFR;
if (val & UART_FCR_RFR) {
timer_del(s->fifo_timeout_timer);
s->timeout_ipending=0;
fifo8_reset(&s->recv_fifo);
}
if (val & UART_FCR_XFR) {
fifo8_reset(&s->xmit_fifo);
}
if (val & UART_FCR_FE) {
s->iir |= UART_IIR_FE;
switch (val & 0xC0) {
case UART_FCR_ITL_1:
s->recv_fifo_itl = 1;
break;
case UART_FCR_ITL_2:
s->recv_fifo_itl = 4;
break;
case UART_FCR_ITL_3:
s->recv_fifo_itl = 8;
break;
case UART_FCR_ITL_4:
s->recv_fifo_itl = 14;
break;
}
} else
s->iir &= ~UART_IIR_FE;
s->fcr = val & 0xC9;
serial_update_irq(s);
break;
case 3:
{
int break_enable;
s->lcr = val;
serial_update_parameters(s);
break_enable = (val >> 6) & 1;
if (break_enable != s->last_break_enable) {
s->last_break_enable = break_enable;
qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
&break_enable);
}
}
break;
case 4:
{
int flags;
int old_mcr = s->mcr;
s->mcr = val & 0x1f;
if (val & UART_MCR_LOOP)
break;
if (s->poll_msl >= 0 && old_mcr != s->mcr) {
qemu_chr_fe_ioctl(s->chr,CHR_IOCTL_SERIAL_GET_TIOCM, &flags);
flags &= ~(CHR_TIOCM_RTS | CHR_TIOCM_DTR);
if (val & UART_MCR_RTS)
flags |= CHR_TIOCM_RTS;
if (val & UART_MCR_DTR)
flags |= CHR_TIOCM_DTR;
qemu_chr_fe_ioctl(s->chr,CHR_IOCTL_SERIAL_SET_TIOCM, &flags);
timer_mod(s->modem_status_poll, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->char_transmit_time);
}
}
break;
case 5:
break;
case 6:
break;
case 7:
s->scr = val;
break;
}
}
| 1threat
|
static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
sPAPRMachineState *spapr,
target_ulong opcode, target_ulong *args)
{
int i;
target_ulong liobn = args[0];
target_ulong ioba = args[1];
target_ulong ioba1 = ioba;
target_ulong tce_list = args[2];
target_ulong npages = args[3];
target_ulong ret = H_PARAMETER, tce = 0;
sPAPRTCETable *tcet = spapr_tce_find_by_liobn(liobn);
CPUState *cs = CPU(cpu);
hwaddr page_mask, page_size;
if (!tcet) {
return H_PARAMETER;
}
if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) {
return H_PARAMETER;
}
page_mask = IOMMU_PAGE_MASK(tcet->page_shift);
page_size = IOMMU_PAGE_SIZE(tcet->page_shift);
ioba &= page_mask;
for (i = 0; i < npages; ++i, ioba += page_size) {
target_ulong off = (tce_list & ~SPAPR_TCE_RW) +
i * sizeof(target_ulong);
tce = ldq_be_phys(cs->as, off);
ret = put_tce_emu(tcet, ioba, tce);
if (ret) {
break;
}
}
i = i ? (i - 1) : 0;
if (SPAPR_IS_PCI_LIOBN(liobn)) {
trace_spapr_iommu_pci_indirect(liobn, ioba1, tce_list, i, tce, ret);
} else {
trace_spapr_iommu_indirect(liobn, ioba1, tce_list, i, tce, ret);
}
return ret;
}
| 1threat
|
static int zipl_load_segment(struct component_entry *entry)
{
const int max_entries = (SECTOR_SIZE / sizeof(struct scsi_blockptr));
struct scsi_blockptr *bprs = (void*)sec;
const int bprs_size = sizeof(sec);
uint64_t blockno;
long address;
int i;
blockno = entry->data.blockno;
address = entry->load_address;
debug_print_int("loading segment at block", blockno);
debug_print_int("addr", address);
do {
memset(bprs, FREE_SPACE_FILLER, bprs_size);
if (virtio_read(blockno, (uint8_t *)bprs)) {
debug_print_int("failed reading bprs at", blockno);
goto fail;
}
for (i = 0;; i++) {
u64 *cur_desc = (void*)&bprs[i];
blockno = bprs[i].blockno;
if (!blockno)
break;
if (i == (max_entries - 1))
break;
if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
sizeof(struct scsi_blockptr))) {
break;
}
address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
(void*)address);
if (address == -1)
goto fail;
}
} while (blockno);
return 0;
fail:
sclp_print("failed loading segment\n");
return -1;
}
| 1threat
|
void do_info_vnc(Monitor *mon, QObject **ret_data)
{
if (vnc_display == NULL || vnc_display->display == NULL) {
*ret_data = qobject_from_jsonf("{ 'enabled': false }");
} else {
QDict *qdict;
QList *clist;
clist = qlist_new();
if (vnc_display->clients) {
VncState *client = vnc_display->clients;
while (client) {
qdict = do_info_vnc_client(mon, client);
if (qdict)
qlist_append(clist, qdict);
client = client->next;
}
}
*ret_data = qobject_from_jsonf("{ 'enabled': true, 'clients': %p }",
QOBJECT(clist));
assert(*ret_data != NULL);
if (vnc_server_info_put(qobject_to_qdict(*ret_data)) < 0) {
qobject_decref(*ret_data);
*ret_data = NULL;
}
}
}
| 1threat
|
how to transpose every multiple rows that start with a specific string into columns using python? : i would like to ask how to transpose every multiple rows into columns and save into text file using python? I have attached input and expected output at the following part. According to the input, i would like to select every rows that starting with 'number' and then transpose into columns.
if my input and output is not clear, i had upload the images into google drive:
input image:
https://drive.google.com/open?id=1jm5ZxtmY0xbc1wgUpnY0S88J70-UpulZ
expected output image:
https://drive.google.com/open?id=11xH5yzeHgQa3m6HB_JFrSq2c6l9H_lYL
and finally i would like to save expected output into text file, sorry for my poor english and thanks for anyone that able to solve it, thanks!
input:
number
12
apple
13
banana
14
number
1
carrot
2
cucumber
3
number
11
pen
10
expected output:
number 12 apple 13 banana 14
number 1 carrot 2 cucumber 3
number 11 pen 10
| 0debug
|
long vnc_client_read_ws(VncState *vs)
{
int ret, err;
uint8_t *payload;
size_t payload_size, frame_size;
VNC_DEBUG("Read websocket %p size %zd offset %zd\n", vs->ws_input.buffer,
vs->ws_input.capacity, vs->ws_input.offset);
buffer_reserve(&vs->ws_input, 4096);
ret = vnc_client_read_buf(vs, buffer_end(&vs->ws_input), 4096);
if (!ret) {
return 0;
}
vs->ws_input.offset += ret;
do {
err = vncws_decode_frame(&vs->ws_input, &payload,
&payload_size, &frame_size);
if (err <= 0) {
return err;
}
buffer_reserve(&vs->input, payload_size);
buffer_append(&vs->input, payload, payload_size);
buffer_advance(&vs->ws_input, frame_size);
} while (vs->ws_input.offset > 0);
return ret;
}
| 1threat
|
How to display Math equations in React Native View : <p>How to render Math equations in React Native Views? For web applications, we can use LaTex or MathJax solutions. But React Native renders native components. Using WebView will be bad as MathJax loading will take time for each WebView component.
How do we render Math equations on React Native Views (non-WebView)?</p>
| 0debug
|
Why does my code not return the requested number but always the requested number -1? : The Task is to create a Function.
The function takes two arguments:
current father's age (years)
current age of his son (years)
Сalculate how many years ago the father was twice as old as his son (or in how many years he will be twice as old).
```java
public static int TwiceAsOld(int dadYears, int sonYears){
int dadYearsTemp = dadYears;
int years = 0;
int yearsAgo = 0;
for (int i = 0; i <= dadYears; i++){
if(dadYearsTemp / 2 == sonYears){
years = dadYearsTemp;
yearsAgo = dadYears - years;
System.out.println(yearsAgo);
return yearsAgo;
}
else if (sonYears * 2 > dadYears) {
years = (sonYears * 2) - dadYears;
System.out.println(years);
return years;
}
dadYearsTemp = dadYearsTemp -1;
}
return 42; // The meaning of life
}
```
So for example with an input of (30, 7) i would expect my function to return 16, because 16 Years ago the father was 14 which means he was twice as old as his son now (7). But my function returns 15.
I guess its not a big mistake but i honestly cant find out why it doesnt work, so i would apreciate some help. Thank you.
| 0debug
|
Unrecognized Selector swift : <p>I've perused the previous posts on SO regarding this topic and I've ensured my code doesn't contain the same bugs, but I keep getting the error "Unrecognized selector sent to instance" when I try tap my UIButton. Can anyone figure out what the issue is? I've made sure that both my action name and signature are identical to the function I'm connecting to my button. I've tried restarting XCode and it still doesn't work. Any input is appreciated. </p>
<pre><code>import UIKit
import MapKit
class MapViewController: UIViewController {
var mapView: MKMapView!
override func loadView() {
//create an instance of the MkMapView class and set it as the view controllers view
mapView = MKMapView ()
view = mapView
//create a set of segmented controls to the map interface to give the user some options regarding their map
let segmentedControls = UISegmentedControl(items: ["Satellite", "Standard", "Hybrid"])
//set the color of the segemented controls and set which index they default to on launch
segmentedControls.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
segmentedControls.selectedSegmentIndex = 0
//how auto-layout used to work was each view would have an auto-resizing mask that iOS would look at and add constraints onto the view based on its mask. The problem is now that we can manually add constraints ourselves, we run into conflicts in the layout between the constraints we set out and those iOS sets up itself through the mask. The best way to avoid this is to simply set the translatesAutoreszing... property to "false" so that iOS doesn't create its own constraints and only ours get set in the project
segmentedControls.translatesAutoresizingMaskIntoConstraints = false
//add the segmentedControl to the main view
view.addSubview(segmentedControls)
//use the view margins to set the insets of the segmented controls- that way they'll adapt to the margins of whatever screen the ap loads on
let margins = view.layoutMarginsGuide
//create a set of constraints for the segmented controls
let topConstraint = segmentedControls.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor, constant: 8)
let leadConstraint = segmentedControls.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor)
let traiConstraint = segmentedControls.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor)
//activate the constraints
topConstraint.active = true
leadConstraint.active = true
trailConstraint.active = true
//create a UIButton, set its label, and add it to the view hierarchy
let button = UIButton(type: .System)
button.setTitle("Show Location", forState: .Normal)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
//create constraints and set them to active
let buttonBottomConstraint = button.bottomAnchor.constraintEqualToAnchor(bottomLayoutGuide.topAnchor)
let buttonLeadConstraint = button.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor)
let buttonTrailConstraint = button.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor);
buttonBottomConstraint.active = true
buttonLeadConstraint.active = true
buttonTrailConstraint.active = true
//set the action-target connection
button.addTarget(self, action: "zoomToUser:", forControlEvents: UIControlEvents.TouchUpInside)
func zoomToUser(sender: UIButton!) {
mapView.showsUserLocation = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
print("Loaded map view")
}
}
</code></pre>
| 0debug
|
import math
def calculate_polygons(startx, starty, endx, endy, radius):
sl = (2 * radius) * math.tan(math.pi / 6)
p = sl * 0.5
b = sl * math.cos(math.radians(30))
w = b * 2
h = 2 * sl
startx = startx - w
starty = starty - h
endx = endx + w
endy = endy + h
origx = startx
origy = starty
xoffset = b
yoffset = 3 * p
polygons = []
row = 1
counter = 0
while starty < endy:
if row % 2 == 0:
startx = origx + xoffset
else:
startx = origx
while startx < endx:
p1x = startx
p1y = starty + p
p2x = startx
p2y = starty + (3 * p)
p3x = startx + b
p3y = starty + h
p4x = startx + w
p4y = starty + (3 * p)
p5x = startx + w
p5y = starty + p
p6x = startx + b
p6y = starty
poly = [
(p1x, p1y),
(p2x, p2y),
(p3x, p3y),
(p4x, p4y),
(p5x, p5y),
(p6x, p6y),
(p1x, p1y)]
polygons.append(poly)
counter += 1
startx += w
starty += yoffset
row += 1
return polygons
| 0debug
|
Where has gone getItem() method? : <p>Making <code>RecyclerView</code> <code>Adapter class</code> and dont know why <code>getItem()</code> method is missing.</p>
<p>My adapter class:</p>
<pre><code>package com.example.pc.example;
import android.content.Context;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter .MyHolder> {
private Context mContext;
private Cursor mCursor;
public MyRecyclerAdapter (Cursor mCursor) {
this.mCursor = mCursor;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
mContext = parent.getContext();
View itemView = LayoutInflater.from(mContext).inflate(R.layout.row, parent, false);
return new MyHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull MyHolder holder, int position) {
//here all my life i ussed the getItem() method, but now it is missing
}
@Override
public int getItemCount() {
return mCursor.getCount();
}
public class MyHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView tv1, tv2;
public MyHolder (View itemView) {
super(itemView);
tv1= (TextView) itemView.findViewById(R.id.tv1);
tv2= (TextView) itemView.findViewById(R.id.tv2);
}
@Override
public void onClick(View v) {
}
}
}
</code></pre>
<p>In ScreenShot you can see that there are <code>getItemCount()</code>, <code>getItemId(position);</code>, and <code>getItemViewType(position);</code>, but no <code>getItem(position)</code> .</p>
<p><a href="https://i.stack.imgur.com/BUlAn.png" rel="nofollow noreferrer">CLICK FOR SCREENSHOT</a></p>
<p>Can someone explane me what is happening?
Many thanks in advance!</p>
| 0debug
|
Extract Last Name only from Lastname,Firstname : <p>I just started working with Oracle recently so please bear with me.</p>
<p>I have a column of names as LASTNAME,FIRSTNAME and I need to extract JUST the last name. I know how to do this in excel, where I want to so search for the "," find the length of characters before the comma and return those characters. </p>
<p>I know to use SUBSTR as my LEFT() function, but I'm stuck from there.</p>
| 0debug
|
Remove rows from listview as well as from my hostinger server database using remove button which is set by Adapter : i want to remove a particular row from database as well as from list view when i click the remove button,i tried but i am not getting the error
> UserAdapter cannot be cast to android.content.Context
here is my Adapter
public class UserAdapter extends BaseAdapter implements OnTaskCompleted{
Context context;
UserAdapter userAdapter;
Bundle b=new Bundle();
HashMap<Integer, UserSetter> userSettersClassHashMap;
int layoutResId;
String email_id="";
private HashMap<String, String> postDataParams = null;
TextView fname,lname,uname,empid,emailid,contact,role;
Button edit,remove;
public UserAdapter(Context context, HashMap<Integer, UserSetter> userSettersClassHashMap, int layoutResId) {
this.context = context;
this.userSettersClassHashMap = userSettersClassHashMap;
this.layoutResId = layoutResId;
}
@Override
public int getCount() {
return userSettersClassHashMap.size();
}
@Override
public Object getItem(int position) {
return userSettersClassHashMap.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
LayoutInflater lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = lf.inflate(layoutResId, parent, false);
view = convertView;
} else {
view = convertView;
}
fname = (TextView) view.findViewById(R.id.fname);
// lname = (TextView) view.findViewById(R.id.lname);
//uname = (TextView) view.findViewById(R.id.uname);
// empid= (TextView) view.findViewById(R.id.empid);
emailid= (TextView) view.findViewById(R.id.emailid);
//contact= (TextView) view.findViewById(R.id.contact);
role= (TextView) view.findViewById(R.id.role);
remove=(Button) view.findViewById(R.id.remove);
fname.setText(Html.fromHtml(userSettersClassHashMap.get(position).getFirstname()));
// lname.setText(Html.fromHtml(userSettersClassHashMap.get(position).getLastname()));
// uname.setText(Html.fromHtml(userSettersClassHashMap.get(position).getUsername()));
// empid.setText(Html.fromHtml(userSettersClassHashMap.get(position).getEmployee_id()));
emailid.setText(Html.fromHtml(userSettersClassHashMap.get(position).getEmail_id()));
// contact.setText(Html.fromHtml(userSettersClassHashMap.get(position).getContact_no()));
role.setText(Html.fromHtml(userSettersClassHashMap.get(position).getRoleName()));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
email_id = String.valueOf(emailid.getText());
Log.v("email adapter", String.valueOf(email_id));
callRemove();
notifyDataSetChanged();
}
public void callRemove() {
postDataParams = new HashMap<>();
postDataParams.put("email_id", email_id);
Log.d("postdataparams","->"+postDataParams);
new WebService(UserAdapter.this, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
}
});
return view;
}
@Override
public void onTaskCompleted(JSONObject jsonObject, String result, String TAG) throws Exception {
if (jsonObject != null) {
if (jsonObject.has("success"))
{
if (jsonObject.optString("success").equalsIgnoreCase("1"))
{
Toast.makeText(context.getApplicationContext(), "User Deleted", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(context.getApplicationContext(),User.class);
context.startActivity(intent);
}
}
else if (jsonObject.optString("success").equalsIgnoreCase("0"))
{
Toast.makeText(context.getApplicationContext(), "failed", Toast.LENGTH_SHORT).show();
}
}
}
}
| 0debug
|
React prevent event bubbling in nested components on click : <p>Here's a basic component. Both the <code><ul></code> and <code><li></code> have onClick functions. I want only the onClick on the <code><li></code> to fire, not the <code><ul></code>. How can I achieve this?</p>
<p>I've played around with e.preventDefault(), e.stopPropagation(), to no avail. </p>
<pre><code>class List extends React.Component {
constructor(props) {
super(props);
}
handleClick() {
// do something
}
render() {
return (
<ul
onClick={(e) => {
console.log('parent');
this.handleClick();
}}
>
<li
onClick={(e) => {
console.log('child');
// prevent default? prevent propagation?
this.handleClick();
}}
>
</li>
</ul>
)
}
}
// => parent
// => child
</code></pre>
| 0debug
|
How to select the first <li> in an unordered list? : <p>I,m a beginner in programming. I'm trying to build a portfolio from scratch. In my navbar I want to select the first link to color it differently. Can anyone tell me the best possible way to select the first link from the unordered list?</p>
<pre><code><ul id="main-nav">
<li>
<a href="#" class="nav-links">
<i class="fas fa-home"></i>Home</a>
</li>
<li>
<a href="#about" class="nav-links"><i class="fas fa-info-circle"></i>About Me</a>
</li>
<li>
<a href="#portfolio" class="nav-links"><i class="fas fa-image"></i>Portfolio</a>
</li>
<li>
<a href="#contact" class="nav-links"><i class="fas fa-envelope"></i>Contact</a>
</li>
</ul>
</code></pre>
| 0debug
|
static void spapr_dt_ov5_platform_support(void *fdt, int chosen)
{
PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu);
char val[2 * 4] = {
23, 0x00,
24, 0x00,
25, 0x00,
26, 0x40,
};
if (kvm_enabled()) {
if (kvmppc_has_cap_mmu_radix() && kvmppc_has_cap_mmu_hash_v3()) {
val[3] = 0x80;
} else if (kvmppc_has_cap_mmu_radix()) {
val[3] = 0x40;
} else {
val[3] = 0x00;
}
} else {
if (first_ppc_cpu->env.mmu_model & POWERPC_MMU_V3) {
val[3] = 0xC0;
} else {
val[3] = 0x00;
}
}
_FDT(fdt_setprop(fdt, chosen, "ibm,arch-vec-5-platform-support",
val, sizeof(val)));
}
| 1threat
|
In App Purchase with fingerprint or Face ID in Objective c : I have an Objective C Project which i am working using Xcode 11 and i am trying to implement In App Purchase.
I used some tutorials and implemented successfully but i am not able to use Fingerprint or Face ID.
Please find the Image Url below in which it shows old subscription interface asking for password.
https://i.stack.imgur.com/Ux78D.jpg
Can someone help me ?
| 0debug
|
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
int i, k, channel;
DCAContext *c = avctx->priv_data;
const int16_t *samples;
int ret, real_channel = 0;
if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE)))
return ret;
samples = (const int16_t *)frame->data[0];
for (i = 0; i < PCM_SAMPLES; i ++) {
for (channel = 0; channel < c->prim_channels + 1; channel++) {
real_channel = c->channel_order_tab[channel];
if (real_channel >= 0) {
for (k = 0; k < 32; k++) {
c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16;
}
qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel);
}
}
}
if (c->lfe_channel) {
for (i = 0; i < PCM_SAMPLES / 2; i++) {
for (k = 0; k < LFE_INTERPOLATION; k++)
c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16;
c->lfe_data[i] = lfe_downsample(c, c->pcm);
}
}
put_frame(c, c->subband, avpkt->data);
avpkt->size = c->frame_size;
*got_packet_ptr = 1;
return 0;
}
| 1threat
|
How to sort variables in my particular case : I would like to sort "years" in var yearObject so the menu starts with 2016 instead of 2013. Please help. [Example](http:jsfiddle.net/bond1126/r1nvsta9/)
| 0debug
|
How to create a simple Binding for previews : <p>With the new <code>@Binding</code> delegate and previews, I find it kinda awkward to always have to create a <code>@State static var</code> to create the neccesarry binding:</p>
<pre class="lang-swift prettyprint-override"><code>struct TestView: View {
@Binding var someProperty: Double
var body: some View {
//...
}
}
#if DEBUG
struct TestView_Previews : PreviewProvider {
@State static var someProperty = 0.7
static var previews: some View {
TestView(someProperty: $someProperty)
}
}
#endif
</code></pre>
<p>Is there a simpler way to create a binding, that proxies a simple values for testing and previewing? </p>
| 0debug
|
Angular 4 renderer2 setStyle not working : <p>in a component, im attempting to target a dom node and change it's style but this does not work, can anyone tell me what i am doing wrong here?</p>
<pre><code>@Input() progress:number = 0;
...
ngOnChanges() {
this.progressInnerEl = this.elRef.nativeElement.querySelector('.progress-inner');
this.renderer.setStyle(this.progressInnerEl, 'width', this.progress+'%');
}
</code></pre>
| 0debug
|
Why can't I edit the style property with javascript? : So, I was just trying to make a <div> appear on an onkeyup event with javascript and for some reason, it didn't let me do it and I got the error: **Uncaught TypeError: Cannot read property 'style' of null**
This is my code:
HTML:
```
<div class="content" id="content" style="display: none">
```
Javascript:
```
function showContent() {
document.getElementById('content').style.display = 'block';
}
```
Can you please help? Thanks.
| 0debug
|
static int qio_channel_command_close(QIOChannel *ioc,
Error **errp)
{
QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc);
int rv = 0;
if (close(cioc->writefd) < 0) {
rv = -1;
}
if (close(cioc->readfd) < 0) {
rv = -1;
}
#ifndef WIN32
if (qio_channel_command_abort(cioc, errp) < 0) {
return -1;
}
#endif
if (rv < 0) {
error_setg_errno(errp, errno, "%s",
"Unable to close command");
}
return rv;
}
| 1threat
|
How to create method to count occurrences of type char within an array and return int of occurrences : I need to create a method that searches a String array whether a char exists in the array and returns an integer of the number of occurrences, I have looked on other posts to try and work it out myself but they are all arrays of ints not
public Object countFirstNameOccurrences(char c) {
}
| 0debug
|
void *grow_array(void *array, int elem_size, int *size, int new_size)
{
if (new_size >= INT_MAX / elem_size) {
av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
exit(1);
}
if (*size < new_size) {
uint8_t *tmp = av_realloc(array, new_size*elem_size);
if (!tmp) {
av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
exit(1);
}
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size;
return tmp;
}
return array;
}
| 1threat
|
static void decode_hrd(HEVCContext *s, int common_inf_present,
int max_sublayers)
{
GetBitContext *gb = &s->HEVClc->gb;
int nal_params_present = 0, vcl_params_present = 0;
int subpic_params_present = 0;
int i;
if (common_inf_present) {
nal_params_present = get_bits1(gb);
vcl_params_present = get_bits1(gb);
if (nal_params_present || vcl_params_present) {
subpic_params_present = get_bits1(gb);
if (subpic_params_present) {
skip_bits(gb, 8);
skip_bits(gb, 5);
skip_bits(gb, 1);
skip_bits(gb, 5);
}
skip_bits(gb, 4);
skip_bits(gb, 4);
if (subpic_params_present)
skip_bits(gb, 4);
skip_bits(gb, 5);
skip_bits(gb, 5);
skip_bits(gb, 5);
}
}
for (i = 0; i < max_sublayers; i++) {
int low_delay = 0;
unsigned int nb_cpb = 1;
int fixed_rate = get_bits1(gb);
if (!fixed_rate)
fixed_rate = get_bits1(gb);
if (fixed_rate)
get_ue_golomb_long(gb);
else
low_delay = get_bits1(gb);
if (!low_delay)
nb_cpb = get_ue_golomb_long(gb) + 1;
if (nal_params_present)
decode_sublayer_hrd(s, nb_cpb, subpic_params_present);
if (vcl_params_present)
decode_sublayer_hrd(s, nb_cpb, subpic_params_present);
}
}
| 1threat
|
Why is IEnumerable(of T) not accepted as extension method receiver : <p>Complete <strong>question</strong> before code:</p>
<p>Why is <code>IEnumerable<T></code> <code>where T : ITest</code> not accepted as receiver of an extension method that expects <code>this IEnumerable<ITest></code>?</p>
<p>And now the <strong>code</strong>:</p>
<p>I have three types:</p>
<pre><code>public interface ITest { }
public class Element : ITest { }
public class ElementInfo : ITest { }
</code></pre>
<p>And two extension methods:</p>
<pre><code>public static class Extensions
{
public static IEnumerable<ElementInfo> Method<T>(
this IEnumerable<T> collection)
where T : ITest
{
→ return collection.ToInfoObjects();
}
public static IEnumerable<ElementInfo> ToInfoObjects(
this IEnumerable<ITest> collection)
{
return collection.Select(item => new ElementInfo());
}
}
</code></pre>
<p>The compiler error I get (on the marked line):</p>
<blockquote>
<p><code>CS1929</code> : <code>'IEnumerable<T>'</code> does not contain a definition for <code>'ToInfoObjects'</code> and the best extension method overload <code>'Extensions.ToInfoObjects(IEnumerable<ITest>)'</code> requires a receiver of type <code>'IEnumerable<ITest>'</code></p>
</blockquote>
<p>Why is this so? The receiver of the <code>ToInfoObjects</code> extension method is an <code>IEnumerable<T></code> and by the generic type constraint, <code>T</code> must implement <code>ITest</code>. </p>
<p><strong>Why is then the receiver not accepted</strong>? My guess is the covariance of the <code>IEnumerable<T></code> but I am not sure.</p>
<p>If I change <code>ToInfoObjects</code> to receive <code>IEnumerable<T> where T : ITest</code>, then everything is ok.</p>
| 0debug
|
Q: How do I delete a specific nickname and password in a text file in python? : I have difficulties on **deleting an account** in a **text file**, although it is a school work.
Here is my code (long and complicated):
create = ""
import time
import sys
while True:
print("Type create to create, delete to delete")
acc = input("an account or quit to exit Python: ")
while acc.lower() == "create":
found = False
MinName = 5
MinPass = 8
print("Please enter your name.")
create = input(">").lower()
if len(create) < MinName:
print("The name is too short.")
print("Please enter your name.")
create = input(">").lower()
# Open a file
fi = open("E:/New folder/NO/How about no/accounts.txt", "r")
#get the data
data = fi.readlines()
# Close opened file
fi.close()
#check each line in the text file
for li in data:
#if the name is already in a file
if(li.split(":")[0].lower() == create):
#print an error of similar username
print("Found a similar name, try a different one!")
#the name has been found
found = True
#if the name wasn't found anywhere in the file
while found == False:
#ask the user for the password
passk = input("Your name is OK, enter pasword:\n>")
if len(passk) < MinPass:
print("Password must be a minimum of 8 letters.")
passk = input(">")
# Open a file to append to
fi = open("E:/New folder/NO/How about no/accounts.txt", "a")
#add the new name/password to the file
fi.write("\n" + create + ":" + passk)
# Close opened file
fi.close()
print("Created an account. You may now login.")
sys.exit()
#Deleting an account##########
while acc.lower() == 'delete':
MinName = 5
MinPass = 8
print("Please enter your name.")
delete = input(">").lower()
if len(delete) < MinName:
print("The name is too short.")
print("Please enter your name.")
delete = input(">").lower()
fi = open("E:/New folder/NO/How about no/accounts.txt", "r")
data = fi.readlines()
fi.close()
#check each line in the text file
for li in data:
#if the name is in a file
if(li.split(":")[0].lower() == delete):
#print an text
print("Found the name.")
#the name has been found
found = True
#Password
while True:
#Set foundpass to false
foundpass = False
print("Enter your password:")
del2 = input(">").lower()
if len(del2) < MinPass:
print("The password is too short.")
print("Please enter your name.")
delete = input(">").lower()
fi = open("E:/New folder/NO/How about no/accounts.txt", "r")
data = fi.readlines()
fi.close()
for li in data:
if(li.split(":")[1].lower() == del2):
print("Are you sure you want to delete this account?")
delok = input("You may lose all your status (for a long time)! Y/N\n>")
if delok.lower() == 'y':
file = open("E:/New folder/NO/How about no/accounts.txt", "r")
lines = f.readlines()
f.close()
file = open("E:/New folder/NO/How about no/accounts.txt", "w")
for line in lines:
if line !=
sys.exit()
elif delok.lower() == 'n':
print("Your account is not deleted.")
sys.exit()
if foundpass == False:
print("Incorrect password!")
#If the name is not in the file
if found == False:
print("Incorrect name!")
delete = input(">").lower()
if acc.lower() == 'quit':
break
else:
print("This is not an option.")
time.sleep(1)
The part I need help is:
for li in data:
if(li.split(":")[1].lower() == del2):
print("Are you sure you want to delete this account?")
delok = input("You may lose all your status (for a long time)! Y/N\n>")
**
if delok.lower() == 'y':
file = open("E:/New folder/NO/How about no/accounts.txt", "r")
lines = f.readlines()
f.close()
file = open("E:/New folder/NO/How about no/accounts.txt", "w")
for line in lines:
if line !=
print("Deleted the account.")
sys.exit()
**
https://stackoverflow.com/questions/4710067/deleting-a-specific-line-in-a-file-python
This is the website I went on (Deleting a specific line in a file (python)) but it would only do the nickname I realised. The text file is below:
Name:Password
aswitneto:llllllll
madda:mmmmmmmm
I want to **remove the account in the text file**.
Any ideas?
| 0debug
|
static av_noinline void emulated_edge_mc_sse(uint8_t * buf,const uint8_t *src,
ptrdiff_t buf_stride,
ptrdiff_t src_stride,
int block_w, int block_h,
int src_x, int src_y, int w, int h)
{
emulated_edge_mc(buf, src, buf_stride, src_stride, block_w, block_h,
src_x, src_y, w, h, vfixtbl_sse, &ff_emu_edge_vvar_sse,
hfixtbl_sse, &ff_emu_edge_hvar_sse);
}
| 1threat
|
React - TypeError: Cannot read property 'props' of undefined : <p>I'm trying to create a click event be able to delete an item on my list, but when I click it I get "TypeError: Cannot read property 'props' of undefined".</p>
<p>I'm trying to stick to ES6 as much as possible, and I'm pretty sure its something to do binding 'this' somewhere, but I've tried many places and been unsuccessful.</p>
<pre><code>import React, { Component } from 'react';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<StreetFighter />
</div>
);
}
}
class StreetFighter extends Component {
constructor(props) {
super(props);
this.state = {
characters: [
'Chun-Li',
'Guile',
'Ryu',
'Ken',
'E.Honda',
'Dhalsim',
],
};
}
render() {
let characters = this.state.characters;
characters = characters.map((char, index) => {
return (
<Character char={char} key={index} onDelete={this.onDelete} />
);
});
return (
<div>
<p>Street Fighter Characters</p>
<ul>{characters}</ul>
</div>
);
}
onDelete(chosenCharacter) {
let updatedCharactersList = this.state.characters.filter(
(char, index) => {
return chosenCharacter !== char;
}
);
this.setState({
characters: updatedCharactersList,
});
}
}
class Character extends Component {
render() {
return (
<li>
<div className="character">
<span className="character-name">{this.props.char}</span>
<span
className="character-delete"
onClick={this.handleDelete}
> x </span>
</div>
</li>
)
};
handleDelete() {
this.props.onDelete(this.props.char);
}
}
export default App;
</code></pre>
| 0debug
|
How can i create object from a file in c++? : Im learning c++.
I have my class complex:
#include "Complejo.h"
#include <sstream>
Complejo::Complejo() {
// TODO Auto-generated constructor stub
real = 0;
imaginary = 0;
}
Complejo::Complejo(int a, int b){
real = a;
imaginary = b;
}
Complejo::~Complejo() {
// TODO Auto-generated destructor stub
}
std::string Complejo::mostrar()const{
std::stringstream s;
s << real << "+" << imaginary <<"i";
return s.str();
}
and in my main i need to read a file(every line has a complex) like this:
3 + 5i
4 + 2i
3 + 3i
and create objects. How i can do it?
| 0debug
|
accessing name of an index in a list : <p>With a list like below</p>
<pre><code>mapping <- c( "All A"= list(c('a1', 'a2')), "All B" = list(c('b1', 'b2')))
</code></pre>
<p>I can access the vector in index 1 as below</p>
<pre><code>> mapping[[1]]
[1] "a1" "a2"
</code></pre>
<p>How do I get the name of list at index 1 - i.e <code>All A</code> </p>
| 0debug
|
Split String into smaller words by length variable in c# : <p>Hi I have a string paragraph containing 25 words and 300 characters, I want to set it in set of labels which can be contain 40 characters. I am trying it as below code with character lengths.</p>
<pre><code>public static List<string> _mSplitByLength(this string str, int maxLength)
{
List<string> _a = new List<string>();
for (int index = 0; index < str.Length; index += maxLength)
{
_a.Add(str.Substring(index, Math.Min(maxLength, str.Length - index)));
}
return _a;
}
</code></pre>
<p>with above code i can split string into 40 character but problem is that it split words also.</p>
<p>suppose my string is <code>"My school Name is stack over flow High school."</code> which is 46 characters so with my code its getting like this</p>
<pre><code>list 1 = "My school Name is stack over flow High s"
list 2 = "chool."
</code></pre>
<p>My question is how to split string on basis of words. if last word not comming so it should be transfer to next list.</p>
<p>my Aim is </p>
<pre><code>list 1 = "My school Name is stack over flow High "
list 2 = "school."
</code></pre>
| 0debug
|
What is the best The IMDB REST API? Wher e can I get it from? : <p>I want access to IMDB REST API. How can I get it?</p>
| 0debug
|
void helper_rsm(CPUX86State *env)
{
X86CPU *cpu = x86_env_get_cpu(env);
CPUState *cs = CPU(cpu);
target_ulong sm_state;
int i, offset;
uint32_t val;
sm_state = env->smbase + 0x8000;
#ifdef TARGET_X86_64
cpu_load_efer(env, x86_ldq_phys(cs, sm_state + 0x7ed0));
env->gdt.base = x86_ldq_phys(cs, sm_state + 0x7e68);
env->gdt.limit = x86_ldl_phys(cs, sm_state + 0x7e64);
env->ldt.selector = x86_lduw_phys(cs, sm_state + 0x7e70);
env->ldt.base = x86_ldq_phys(cs, sm_state + 0x7e78);
env->ldt.limit = x86_ldl_phys(cs, sm_state + 0x7e74);
env->ldt.flags = (x86_lduw_phys(cs, sm_state + 0x7e72) & 0xf0ff) << 8;
env->idt.base = x86_ldq_phys(cs, sm_state + 0x7e88);
env->idt.limit = x86_ldl_phys(cs, sm_state + 0x7e84);
env->tr.selector = x86_lduw_phys(cs, sm_state + 0x7e90);
env->tr.base = x86_ldq_phys(cs, sm_state + 0x7e98);
env->tr.limit = x86_ldl_phys(cs, sm_state + 0x7e94);
env->tr.flags = (x86_lduw_phys(cs, sm_state + 0x7e92) & 0xf0ff) << 8;
env->regs[R_EAX] = x86_ldq_phys(cs, sm_state + 0x7ff8);
env->regs[R_ECX] = x86_ldq_phys(cs, sm_state + 0x7ff0);
env->regs[R_EDX] = x86_ldq_phys(cs, sm_state + 0x7fe8);
env->regs[R_EBX] = x86_ldq_phys(cs, sm_state + 0x7fe0);
env->regs[R_ESP] = x86_ldq_phys(cs, sm_state + 0x7fd8);
env->regs[R_EBP] = x86_ldq_phys(cs, sm_state + 0x7fd0);
env->regs[R_ESI] = x86_ldq_phys(cs, sm_state + 0x7fc8);
env->regs[R_EDI] = x86_ldq_phys(cs, sm_state + 0x7fc0);
for (i = 8; i < 16; i++) {
env->regs[i] = x86_ldq_phys(cs, sm_state + 0x7ff8 - i * 8);
}
env->eip = x86_ldq_phys(cs, sm_state + 0x7f78);
cpu_load_eflags(env, x86_ldl_phys(cs, sm_state + 0x7f70),
~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
env->dr[6] = x86_ldl_phys(cs, sm_state + 0x7f68);
env->dr[7] = x86_ldl_phys(cs, sm_state + 0x7f60);
cpu_x86_update_cr4(env, x86_ldl_phys(cs, sm_state + 0x7f48));
cpu_x86_update_cr3(env, x86_ldq_phys(cs, sm_state + 0x7f50));
cpu_x86_update_cr0(env, x86_ldl_phys(cs, sm_state + 0x7f58));
for (i = 0; i < 6; i++) {
offset = 0x7e00 + i * 16;
cpu_x86_load_seg_cache(env, i,
x86_lduw_phys(cs, sm_state + offset),
x86_ldq_phys(cs, sm_state + offset + 8),
x86_ldl_phys(cs, sm_state + offset + 4),
(x86_lduw_phys(cs, sm_state + offset + 2) &
0xf0ff) << 8);
}
val = x86_ldl_phys(cs, sm_state + 0x7efc);
if (val & 0x20000) {
env->smbase = x86_ldl_phys(cs, sm_state + 0x7f00);
}
#else
cpu_x86_update_cr0(env, x86_ldl_phys(cs, sm_state + 0x7ffc));
cpu_x86_update_cr3(env, x86_ldl_phys(cs, sm_state + 0x7ff8));
cpu_load_eflags(env, x86_ldl_phys(cs, sm_state + 0x7ff4),
~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
env->eip = x86_ldl_phys(cs, sm_state + 0x7ff0);
env->regs[R_EDI] = x86_ldl_phys(cs, sm_state + 0x7fec);
env->regs[R_ESI] = x86_ldl_phys(cs, sm_state + 0x7fe8);
env->regs[R_EBP] = x86_ldl_phys(cs, sm_state + 0x7fe4);
env->regs[R_ESP] = x86_ldl_phys(cs, sm_state + 0x7fe0);
env->regs[R_EBX] = x86_ldl_phys(cs, sm_state + 0x7fdc);
env->regs[R_EDX] = x86_ldl_phys(cs, sm_state + 0x7fd8);
env->regs[R_ECX] = x86_ldl_phys(cs, sm_state + 0x7fd4);
env->regs[R_EAX] = x86_ldl_phys(cs, sm_state + 0x7fd0);
env->dr[6] = x86_ldl_phys(cs, sm_state + 0x7fcc);
env->dr[7] = x86_ldl_phys(cs, sm_state + 0x7fc8);
env->tr.selector = x86_ldl_phys(cs, sm_state + 0x7fc4) & 0xffff;
env->tr.base = x86_ldl_phys(cs, sm_state + 0x7f64);
env->tr.limit = x86_ldl_phys(cs, sm_state + 0x7f60);
env->tr.flags = (x86_ldl_phys(cs, sm_state + 0x7f5c) & 0xf0ff) << 8;
env->ldt.selector = x86_ldl_phys(cs, sm_state + 0x7fc0) & 0xffff;
env->ldt.base = x86_ldl_phys(cs, sm_state + 0x7f80);
env->ldt.limit = x86_ldl_phys(cs, sm_state + 0x7f7c);
env->ldt.flags = (x86_ldl_phys(cs, sm_state + 0x7f78) & 0xf0ff) << 8;
env->gdt.base = x86_ldl_phys(cs, sm_state + 0x7f74);
env->gdt.limit = x86_ldl_phys(cs, sm_state + 0x7f70);
env->idt.base = x86_ldl_phys(cs, sm_state + 0x7f58);
env->idt.limit = x86_ldl_phys(cs, sm_state + 0x7f54);
for (i = 0; i < 6; i++) {
if (i < 3) {
offset = 0x7f84 + i * 12;
} else {
offset = 0x7f2c + (i - 3) * 12;
}
cpu_x86_load_seg_cache(env, i,
x86_ldl_phys(cs,
sm_state + 0x7fa8 + i * 4) & 0xffff,
x86_ldl_phys(cs, sm_state + offset + 8),
x86_ldl_phys(cs, sm_state + offset + 4),
(x86_ldl_phys(cs,
sm_state + offset) & 0xf0ff) << 8);
}
cpu_x86_update_cr4(env, x86_ldl_phys(cs, sm_state + 0x7f14));
val = x86_ldl_phys(cs, sm_state + 0x7efc);
if (val & 0x20000) {
env->smbase = x86_ldl_phys(cs, sm_state + 0x7ef8);
}
#endif
if ((env->hflags2 & HF2_SMM_INSIDE_NMI_MASK) == 0) {
env->hflags2 &= ~HF2_NMI_MASK;
}
env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK;
env->hflags &= ~HF_SMM_MASK;
cpu_smm_update(cpu);
qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n");
log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
}
| 1threat
|
static void nbd_request_put(NBDRequest *req)
{
NBDClient *client = req->client;
if (req->data) {
qemu_vfree(req->data);
}
g_slice_free(NBDRequest, req);
if (client->nb_requests-- == MAX_NBD_REQUESTS) {
qemu_notify_event();
}
nbd_client_put(client);
}
| 1threat
|
go over all multiples of 3 between 0 and 100 (inclusive), and print the ones that are divisible by 2 : what I have so far...
>num = range(0,101,3)
>list = []
>if num % 3 == 0:
>>>list.append
>print(list)
| 0debug
|
static int seq_fill_buffer(SeqDemuxContext *seq, ByteIOContext *pb, int buffer_num, unsigned int data_offs, int data_size)
{
TiertexSeqFrameBuffer *seq_buffer;
if (buffer_num >= SEQ_NUM_FRAME_BUFFERS)
return AVERROR_INVALIDDATA;
seq_buffer = &seq->frame_buffers[buffer_num];
if (seq_buffer->fill_size + data_size > seq_buffer->data_size)
return AVERROR_INVALIDDATA;
url_fseek(pb, seq->current_frame_offs + data_offs, SEEK_SET);
if (get_buffer(pb, seq_buffer->data + seq_buffer->fill_size, data_size) != data_size)
return AVERROR(EIO);
seq_buffer->fill_size += data_size;
return 0;
}
| 1threat
|
Remove jquery from JavaScript : I am new in the field of development, I develop an API with angularjs 2 using the janus media server, I have a problem with the start button, once I run my janus it starts the button automatically not manually , This is the function I used:
// Use a button to start the demo
$('#start').click(function() {
if(started)
return;
started = true;
$(this).attr('disabled',
'true').unbind('click');
// Make sure the browser supports WebRTC
// if(!Janus.isWebrtcSupported()) {
// Janus.log("No WebRTC support... ");
return;
// }
});
| 0debug
|
static int old_codec37(SANMVideoContext *ctx, int top,
int left, int width, int height)
{
int stride = ctx->pitch;
int i, j, k, t;
int skip_run = 0;
int compr, mvoff, seq, flags;
uint32_t decoded_size;
uint8_t *dst, *prev;
compr = bytestream2_get_byte(&ctx->gb);
mvoff = bytestream2_get_byte(&ctx->gb);
seq = bytestream2_get_le16(&ctx->gb);
decoded_size = bytestream2_get_le32(&ctx->gb);
bytestream2_skip(&ctx->gb, 4);
flags = bytestream2_get_byte(&ctx->gb);
bytestream2_skip(&ctx->gb, 3);
if (decoded_size > height * stride - left - top * stride) {
decoded_size = height * stride - left - top * stride;
av_log(ctx->avctx, AV_LOG_WARNING, "decoded size is too large\n");
}
ctx->rotate_code = 0;
if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
rotate_bufs(ctx, 1);
dst = ((uint8_t*)ctx->frm0) + left + top * stride;
prev = ((uint8_t*)ctx->frm2) + left + top * stride;
if (mvoff > 2) {
av_log(ctx->avctx, AV_LOG_ERROR, "invalid motion base value %d\n", mvoff);
return AVERROR_INVALIDDATA;
}
av_dlog(ctx->avctx, "compression %d\n", compr);
switch (compr) {
case 0:
for (i = 0; i < height; i++) {
bytestream2_get_buffer(&ctx->gb, dst, width);
dst += stride;
}
memset(ctx->frm1, 0, ctx->height * stride);
memset(ctx->frm2, 0, ctx->height * stride);
break;
case 2:
if (rle_decode(ctx, dst, decoded_size))
return AVERROR_INVALIDDATA;
memset(ctx->frm1, 0, ctx->frm1_size);
memset(ctx->frm2, 0, ctx->frm2_size);
break;
case 3:
case 4:
if (flags & 4) {
for (j = 0; j < height; j += 4) {
for (i = 0; i < width; i += 4) {
int code;
if (skip_run) {
skip_run--;
copy_block4(dst + i, prev + i, stride, stride, 4);
continue;
}
if (bytestream2_get_bytes_left(&ctx->gb) < 1)
return AVERROR_INVALIDDATA;
code = bytestream2_get_byteu(&ctx->gb);
switch (code) {
case 0xFF:
if (bytestream2_get_bytes_left(&ctx->gb) < 16)
return AVERROR_INVALIDDATA;
for (k = 0; k < 4; k++)
bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4);
break;
case 0xFE:
if (bytestream2_get_bytes_left(&ctx->gb) < 4)
return AVERROR_INVALIDDATA;
for (k = 0; k < 4; k++)
memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->gb), 4);
break;
case 0xFD:
if (bytestream2_get_bytes_left(&ctx->gb) < 1)
return AVERROR_INVALIDDATA;
t = bytestream2_get_byteu(&ctx->gb);
for (k = 0; k < 4; k++)
memset(dst + i + k * stride, t, 4);
break;
default:
if (compr == 4 && !code) {
if (bytestream2_get_bytes_left(&ctx->gb) < 1)
return AVERROR_INVALIDDATA;
skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
i -= 4;
} else {
int mx, my;
mx = c37_mv[(mvoff * 255 + code) * 2 ];
my = c37_mv[(mvoff * 255 + code) * 2 + 1];
codec37_mv(dst + i, prev + i + mx + my * stride,
ctx->height, stride, i + mx, j + my);
}
}
}
dst += stride * 4;
prev += stride * 4;
}
} else {
for (j = 0; j < height; j += 4) {
for (i = 0; i < width; i += 4) {
int code;
if (skip_run) {
skip_run--;
copy_block4(dst + i, prev + i, stride, stride, 4);
continue;
}
code = bytestream2_get_byte(&ctx->gb);
if (code == 0xFF) {
if (bytestream2_get_bytes_left(&ctx->gb) < 16)
return AVERROR_INVALIDDATA;
for (k = 0; k < 4; k++)
bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4);
} else if (compr == 4 && !code) {
if (bytestream2_get_bytes_left(&ctx->gb) < 1)
return AVERROR_INVALIDDATA;
skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
i -= 4;
} else {
int mx, my;
mx = c37_mv[(mvoff * 255 + code) * 2];
my = c37_mv[(mvoff * 255 + code) * 2 + 1];
codec37_mv(dst + i, prev + i + mx + my * stride,
ctx->height, stride, i + mx, j + my);
}
}
dst += stride * 4;
prev += stride * 4;
}
}
break;
default:
av_log(ctx->avctx, AV_LOG_ERROR,
"subcodec 37 compression %d not implemented\n", compr);
return AVERROR_PATCHWELCOME;
}
return 0;
}
| 1threat
|
Angular 2: how to create radio buttons from enum and add two-way binding? : <p>I'm trying to use Angular2 syntax to create radio buttons from an enum definition, and bind the value to a property that has the type of that enum.</p>
<p>My html contains:</p>
<pre><code><div class="from_elem">
<label>Motif</label><br>
<div *ngFor="let choice of motifChoices">
<input type="radio" name="motif" [(ngModel)]="choice.value"/>{{choice.motif}}<br>
</div>
</div>
</code></pre>
<p>In my @Component, I declared the set of choices and values:</p>
<pre><code>private motifChoices: any[] = [];
</code></pre>
<p>And in the constructor of my @Component, I filled the choices the following way:</p>
<pre><code>constructor( private interService: InterventionService )
{
this.motifChoices =
Object.keys(MotifIntervention).filter( key => isNaN( Number( key )))
.map( key => { return { motif: key, value: false } });
}
</code></pre>
<p>The radio buttons are displayed correctly, now I seek to bind the value selected to a property. But when I click one of the buttons the value choice.value is set to undefined.</p>
| 0debug
|
@EnableResourceServer @EnableAuthorizationServer are deprecated? : <p>I am writing a simple application to test Oauth. But i see that both the annotations @EnableResourceServer @EnableAuthorizationServer were deprecated!</p>
<p>I don't find an alternative way to deal with it and I don't find any info anywhere.</p>
<p>What is the latest way to configure resource server and Auth server?</p>
<p>Thanks!</p>
| 0debug
|
static void do_info(int argc, const char **argv)
{
term_cmd_t *cmd;
const char *item;
if (argc < 2)
goto help;
item = argv[1];
for(cmd = info_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(argv[1], cmd->name))
goto found;
}
help:
help_cmd(argv[0]);
return;
found:
cmd->handler(argc, argv);
}
| 1threat
|
static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
const uint8_t **buf, int buf_size)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
AVCodecContext *avctx= s->avctx;
const int field_pic= s->picture_structure != PICT_FRAME;
const int lowres= s->avctx->lowres;
s->resync_mb_x=
s->resync_mb_y= -1;
if (mb_y >= s->mb_height){
av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height);
return -1;
}
init_get_bits(&s->gb, *buf, buf_size*8);
ff_mpeg1_clean_buffers(s);
s->interlaced_dct = 0;
s->qscale = get_qscale(s);
if(s->qscale == 0){
av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
return -1;
}
while (get_bits1(&s->gb) != 0) {
skip_bits(&s->gb, 8);
}
s->mb_x=0;
for(;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
return -1;
}
if (code >= 33) {
if (code == 33) {
s->mb_x += 33;
}
} else {
s->mb_x += code;
break;
}
}
if(s->mb_x >= (unsigned)s->mb_width){
av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
return -1;
}
if (avctx->hwaccel) {
const uint8_t *buf_end, *buf_start = *buf - 4;
int start_code = -1;
buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
if (buf_end < *buf + buf_size)
buf_end -= 4;
s->mb_y = mb_y;
if (avctx->hwaccel->decode_slice(avctx, buf_start, buf_end - buf_start) < 0)
return DECODE_SLICE_ERROR;
*buf = buf_end;
return DECODE_SLICE_OK;
}
s->resync_mb_x= s->mb_x;
s->resync_mb_y= s->mb_y= mb_y;
s->mb_skip_run= 0;
ff_init_block_index(s);
if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")),
s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
}
}
for(;;) {
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1)
ff_xvmc_init_block(s);
if(mpeg_decode_mb(s, s->block) < 0)
return -1;
if(s->current_picture.motion_val[0] && !s->encoding){
const int wrap = s->b8_stride;
int xy = s->mb_x*2 + s->mb_y*2*wrap;
int motion_x, motion_y, dir, i;
for(i=0; i<2; i++){
for(dir=0; dir<2; dir++){
if (s->mb_intra || (dir==1 && s->pict_type != FF_B_TYPE)) {
motion_x = motion_y = 0;
}else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
motion_x = s->mv[dir][0][0];
motion_y = s->mv[dir][0][1];
} else {
motion_x = s->mv[dir][i][0];
motion_y = s->mv[dir][i][1];
}
s->current_picture.motion_val[dir][xy ][0] = motion_x;
s->current_picture.motion_val[dir][xy ][1] = motion_y;
s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
s->current_picture.ref_index [dir][xy ]=
s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i];
assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
}
xy += wrap;
}
}
s->dest[0] += 16 >> lowres;
s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
MPV_decode_mb(s, s->block);
if (++s->mb_x >= s->mb_width) {
const int mb_size= 16>>s->avctx->lowres;
ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size);
s->mb_x = 0;
s->mb_y += 1<<field_pic;
if(s->mb_y >= s->mb_height){
int left= get_bits_left(&s->gb);
int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && avctx->profile==0 && avctx->level==5
&& s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0
&& s->progressive_frame == 0 ;
if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
|| (avctx->error_recognition >= FF_ER_AGGRESSIVE && left>8)){
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
return -1;
}else
goto eos;
}
ff_init_block_index(s);
}
if (s->mb_skip_run == -1) {
s->mb_skip_run = 0;
for(;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
return -1;
}
if (code >= 33) {
if (code == 33) {
s->mb_skip_run += 33;
}else if(code == 35){
if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
return -1;
}
goto eos;
}
} else {
s->mb_skip_run += code;
break;
}
}
if(s->mb_skip_run){
int i;
if(s->pict_type == FF_I_TYPE){
av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
s->mb_intra = 0;
for(i=0;i<12;i++)
s->block_last_index[i] = -1;
if(s->picture_structure == PICT_FRAME)
s->mv_type = MV_TYPE_16X16;
else
s->mv_type = MV_TYPE_FIELD;
if (s->pict_type == FF_P_TYPE) {
s->mv_dir = MV_DIR_FORWARD;
s->mv[0][0][0] = s->mv[0][0][1] = 0;
s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
s->field_select[0][0]= (s->picture_structure - 1) & 1;
} else {
s->mv[0][0][0] = s->last_mv[0][0][0];
s->mv[0][0][1] = s->last_mv[0][0][1];
s->mv[1][0][0] = s->last_mv[1][0][0];
s->mv[1][0][1] = s->last_mv[1][0][1];
}
}
}
}
eos:
*buf += (get_bits_count(&s->gb)-1)/8;
return 0;
}
| 1threat
|
static void bufp_free(USBRedirDevice *dev, struct buf_packet *bufp,
uint8_t ep)
{
QTAILQ_REMOVE(&dev->endpoint[EP2I(ep)].bufpq, bufp, next);
dev->endpoint[EP2I(ep)].bufpq_size--;
free(bufp->data);
g_free(bufp);
}
| 1threat
|
MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index)
{
PhysPageEntry lp = d->phys_map;
PhysPageEntry *p;
int i;
for (i = P_L2_LEVELS - 1; i >= 0 && !lp.is_leaf; i--) {
if (lp.ptr == PHYS_MAP_NODE_NIL) {
return &phys_sections[phys_section_unassigned];
}
p = phys_map_nodes[lp.ptr];
lp = p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)];
}
return &phys_sections[lp.ptr];
}
| 1threat
|
Cordova / Ionic creates <allow-navigation> garbage in config.xml on each run : <p>When running an app with Ionic and live reload enabled it automatically adds a new <code>allow-navigation</code> entry to config.xml with my local IP address and port in there.</p>
<p>After some time this results in a lot of garbage in config.xml, especially if there are multiple developers that each may use multiple development machines to run the app. Since the file is included in Git (or other VCS) and nobody cares to remove this stuff before committing it often creates merge conflicts, which is easy to fix but is quite annoying.</p>
<p>Can Ionic store these settings somewhere else to avoid polluting config.xml every time somebody runs the app? Like a local (user-specific) config?</p>
| 0debug
|
How to define a mathematical function in SymPy? : <p>I've been trying this now for hours. I think I don't understand a basic concept, that's why I couldn't answer this question to myself so far.</p>
<p>What I'm trying is to implement a simple mathematical function, like this:</p>
<pre><code>f(x) = x**2 + 1
</code></pre>
<p>After that I want to derive that function.</p>
<p>I've defined the symbol and function with:</p>
<pre><code>x = sympy.Symbol('x')
f = sympy.Function('f')(x)
</code></pre>
<p>Now I'm struggling with defining the equation to this function <code>f(x)</code>. Something like <code>f.exp("x**2 + 1")</code> is not working.</p>
<p>I also wonder how I could get a print out to the console of this function after it's finally defined. </p>
| 0debug
|
complex JavaScript object : <p>I have 3 Javascript arrays:</p>
<pre><code>array1 = ["data", "data1", "data2"]
array2 = ["data", "data1", "data2"]
array3 = ["data", "data1", "data2"]
</code></pre>
<p>How can I combine them all, so that I can simply run a single loop and retrieve values from them.</p>
<pre><code>for (let index = 0; index < mainArray.length; index++) {
value1 = mainArray.array1[index];
value2 = mainArray.array2[index];
value3 = mainArray.array3[index];
}
</code></pre>
<p>How can I create a the <code>mainArray</code> to accommodate all three javascript arrays, can a complex object or json object be created?</p>
| 0debug
|
How to implement map instead of for loop in javascript :
> I have two json arrays(req[],res[]) which need to be compared and the differences should display in log,for this I am using for loop,But i want to use map for solving this problem.
Note: Need to sort both the arrays first
for(var i=0;i<req.length;i++)
{
if(req[i]!==res[i])
{
console.log('unmatched element : '+req[i]+' and '+res[i]);
}
else
{
continue;
}
}
So how can i use map to sort both the arrays using some attribute like(id or name) and then compare both the arrays and print error with values when match fails .
| 0debug
|
static void decode_v1_vector(CinepakEncContext *s, AVPicture *sub_pict, mb_info *mb, strip_info *info)
{
int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;
sub_pict->data[0][0] =
sub_pict->data[0][1] =
sub_pict->data[0][ sub_pict->linesize[0]] =
sub_pict->data[0][1+ sub_pict->linesize[0]] = info->v1_codebook[mb->v1_vector*entry_size];
sub_pict->data[0][2] =
sub_pict->data[0][3] =
sub_pict->data[0][2+ sub_pict->linesize[0]] =
sub_pict->data[0][3+ sub_pict->linesize[0]] = info->v1_codebook[mb->v1_vector*entry_size+1];
sub_pict->data[0][2*sub_pict->linesize[0]] =
sub_pict->data[0][1+2*sub_pict->linesize[0]] =
sub_pict->data[0][ 3*sub_pict->linesize[0]] =
sub_pict->data[0][1+3*sub_pict->linesize[0]] = info->v1_codebook[mb->v1_vector*entry_size+2];
sub_pict->data[0][2+2*sub_pict->linesize[0]] =
sub_pict->data[0][3+2*sub_pict->linesize[0]] =
sub_pict->data[0][2+3*sub_pict->linesize[0]] =
sub_pict->data[0][3+3*sub_pict->linesize[0]] = info->v1_codebook[mb->v1_vector*entry_size+3];
if(s->pix_fmt == AV_PIX_FMT_YUV420P) {
sub_pict->data[1][0] =
sub_pict->data[1][1] =
sub_pict->data[1][ sub_pict->linesize[1]] =
sub_pict->data[1][1+ sub_pict->linesize[1]] = info->v1_codebook[mb->v1_vector*entry_size+4];
sub_pict->data[2][0] =
sub_pict->data[2][1] =
sub_pict->data[2][ sub_pict->linesize[2]] =
sub_pict->data[2][1+ sub_pict->linesize[2]] = info->v1_codebook[mb->v1_vector*entry_size+5];
}
}
| 1threat
|
static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
int ret;
gsm_signal *samples = (gsm_signal *)frame->data[0];
struct gsm_state *state = avctx->priv_data;
if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align)))
return ret;
switch(avctx->codec_id) {
case AV_CODEC_ID_GSM:
gsm_encode(state, samples, avpkt->data);
break;
case AV_CODEC_ID_GSM_MS:
gsm_encode(state, samples, avpkt->data);
gsm_encode(state, samples + GSM_FRAME_SIZE, avpkt->data + 32);
}
*got_packet_ptr = 1;
return 0;
}
| 1threat
|
static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
Error **errp)
{
uint32_t flags;
bool fixedNewstyle = false;
bool no_zeroes = false;
if (nbd_read(client->ioc, &flags, sizeof(flags), errp) < 0) {
error_prepend(errp, "read failed: ");
return -EIO;
}
be32_to_cpus(&flags);
trace_nbd_negotiate_options_flags(flags);
if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) {
fixedNewstyle = true;
flags &= ~NBD_FLAG_C_FIXED_NEWSTYLE;
}
if (flags & NBD_FLAG_C_NO_ZEROES) {
no_zeroes = true;
flags &= ~NBD_FLAG_C_NO_ZEROES;
}
if (flags != 0) {
error_setg(errp, "Unknown client flags 0x%" PRIx32 " received", flags);
return -EINVAL;
}
while (1) {
int ret;
uint32_t option, length;
uint64_t magic;
if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) {
error_prepend(errp, "read failed: ");
return -EINVAL;
}
magic = be64_to_cpu(magic);
trace_nbd_negotiate_options_check_magic(magic);
if (magic != NBD_OPTS_MAGIC) {
error_setg(errp, "Bad magic received");
return -EINVAL;
}
if (nbd_read(client->ioc, &option,
sizeof(option), errp) < 0) {
error_prepend(errp, "read failed: ");
return -EINVAL;
}
option = be32_to_cpu(option);
client->opt = option;
if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) {
error_prepend(errp, "read failed: ");
return -EINVAL;
}
length = be32_to_cpu(length);
client->optlen = length;
if (length > NBD_MAX_BUFFER_SIZE) {
error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u)",
length, NBD_MAX_BUFFER_SIZE);
return -EINVAL;
}
trace_nbd_negotiate_options_check_option(option,
nbd_opt_lookup(option));
if (client->tlscreds &&
client->ioc == (QIOChannel *)client->sioc) {
QIOChannel *tioc;
if (!fixedNewstyle) {
error_setg(errp, "Unsupported option 0x%" PRIx32, option);
return -EINVAL;
}
switch (option) {
case NBD_OPT_STARTTLS:
if (length) {
return nbd_reject_length(client, true, errp);
}
tioc = nbd_negotiate_handle_starttls(client, errp);
if (!tioc) {
return -EIO;
}
ret = 0;
object_unref(OBJECT(client->ioc));
client->ioc = QIO_CHANNEL(tioc);
break;
case NBD_OPT_EXPORT_NAME:
error_setg(errp, "Option 0x%x not permitted before TLS",
option);
return -EINVAL;
default:
if (nbd_drop(client->ioc, length, errp) < 0) {
return -EIO;
}
ret = nbd_negotiate_send_rep_err(client,
NBD_REP_ERR_TLS_REQD, errp,
"Option 0x%" PRIx32
"not permitted before TLS",
option);
if (option == NBD_OPT_ABORT) {
return 1;
}
break;
}
} else if (fixedNewstyle) {
switch (option) {
case NBD_OPT_LIST:
if (length) {
ret = nbd_reject_length(client, false, errp);
} else {
ret = nbd_negotiate_handle_list(client, errp);
}
break;
case NBD_OPT_ABORT:
nbd_negotiate_send_rep(client, NBD_REP_ACK, NULL);
return 1;
case NBD_OPT_EXPORT_NAME:
return nbd_negotiate_handle_export_name(client,
myflags, no_zeroes,
errp);
case NBD_OPT_INFO:
case NBD_OPT_GO:
ret = nbd_negotiate_handle_info(client, myflags, errp);
if (ret == 1) {
assert(option == NBD_OPT_GO);
return 0;
}
break;
case NBD_OPT_STARTTLS:
if (length) {
ret = nbd_reject_length(client, false, errp);
} else if (client->tlscreds) {
ret = nbd_negotiate_send_rep_err(client,
NBD_REP_ERR_INVALID, errp,
"TLS already enabled");
} else {
ret = nbd_negotiate_send_rep_err(client,
NBD_REP_ERR_POLICY, errp,
"TLS not configured");
}
break;
case NBD_OPT_STRUCTURED_REPLY:
if (length) {
ret = nbd_reject_length(client, false, errp);
} else if (client->structured_reply) {
ret = nbd_negotiate_send_rep_err(
client, NBD_REP_ERR_INVALID, errp,
"structured reply already negotiated");
} else {
ret = nbd_negotiate_send_rep(client, NBD_REP_ACK, errp);
client->structured_reply = true;
myflags |= NBD_FLAG_SEND_DF;
}
break;
default:
if (nbd_drop(client->ioc, length, errp) < 0) {
return -EIO;
}
ret = nbd_negotiate_send_rep_err(client,
NBD_REP_ERR_UNSUP, errp,
"Unsupported option 0x%"
PRIx32 " (%s)", option,
nbd_opt_lookup(option));
break;
}
} else {
switch (option) {
case NBD_OPT_EXPORT_NAME:
return nbd_negotiate_handle_export_name(client,
myflags, no_zeroes,
errp);
default:
error_setg(errp, "Unsupported option 0x%" PRIx32 " (%s)",
option, nbd_opt_lookup(option));
return -EINVAL;
}
}
if (ret < 0) {
return ret;
}
}
}
| 1threat
|
static int mp_decode_frame(MPADecodeContext *s,
short *samples)
{
int i, nb_frames, ch;
short *samples_ptr;
init_get_bits(&s->gb, s->inbuf + HEADER_SIZE,
s->inbuf_ptr - s->inbuf - HEADER_SIZE);
if (s->error_protection)
get_bits(&s->gb, 16);
dprintf("frame %d:\n", s->frame_count);
switch(s->layer) {
case 1:
nb_frames = mp_decode_layer1(s);
break;
case 2:
nb_frames = mp_decode_layer2(s);
break;
case 3:
default:
nb_frames = mp_decode_layer3(s);
break;
}
#if defined(DEBUG)
for(i=0;i<nb_frames;i++) {
for(ch=0;ch<s->nb_channels;ch++) {
int j;
printf("%d-%d:", i, ch);
for(j=0;j<SBLIMIT;j++)
printf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
printf("\n");
}
}
#endif
for(ch=0;ch<s->nb_channels;ch++) {
samples_ptr = samples + ch;
for(i=0;i<nb_frames;i++) {
synth_filter(s, ch, samples_ptr, s->nb_channels,
s->sb_samples[ch][i]);
samples_ptr += 32 * s->nb_channels;
}
}
#ifdef DEBUG
s->frame_count++;
#endif
return nb_frames * 32 * sizeof(short) * s->nb_channels;
}
| 1threat
|
C: non-NULL terminated unsigned char * : I saw [here][1] that it isn't possible to find out an unsigned char * length using strlen if it isn't NULL terminated, since the strlen function will go over the string but won't find any '\0', hence a run-time error. I figure that it is exactly the same for signed char *.
I saw a code snippet that was doing something like `int len = sizeof(unsigned char *);` but, as I understand, it only gives the size of a pointer - word size. Is it possible to use sizeof in another way to get the result or do I have to get the length somewhere else?
[1]: http://stackoverflow.com/questions/261431/how-to-find-the-length-of-unsigned-char-in-c
| 0debug
|
static int usb_host_update_interfaces(USBHostDevice *dev, int configuration)
{
int dev_descr_len, config_descr_len;
int interface, nb_interfaces, nb_configurations;
int ret, i;
if (configuration == 0)
return 1;
i = 0;
dev_descr_len = dev->descr[0];
if (dev_descr_len > dev->descr_len)
goto fail;
nb_configurations = dev->descr[17];
i += dev_descr_len;
while (i < dev->descr_len) {
#ifdef DEBUG
printf("i is %d, descr_len is %d, dl %d, dt %d\n", i, dev->descr_len,
dev->descr[i], dev->descr[i+1]);
#endif
if (dev->descr[i+1] != USB_DT_CONFIG) {
i += dev->descr[i];
continue;
}
config_descr_len = dev->descr[i];
if (configuration == dev->descr[i + 5])
break;
i += config_descr_len;
}
if (i >= dev->descr_len) {
printf("usb_host: error - device has no matching configuration\n");
goto fail;
}
nb_interfaces = dev->descr[i + 4];
#ifdef USBDEVFS_DISCONNECT
{
struct usbdevfs_ioctl ctrl;
for (interface = 0; interface < nb_interfaces; interface++) {
ctrl.ioctl_code = USBDEVFS_DISCONNECT;
ctrl.ifno = interface;
ret = ioctl(dev->fd, USBDEVFS_IOCTL, &ctrl);
if (ret < 0 && errno != ENODATA) {
perror("USBDEVFS_DISCONNECT");
goto fail;
}
}
}
#endif
for (interface = 0; interface < nb_interfaces; interface++) {
ret = ioctl(dev->fd, USBDEVFS_CLAIMINTERFACE, &interface);
if (ret < 0) {
if (errno == EBUSY) {
fprintf(stderr,
"usb_host: warning - device already grabbed\n");
} else {
perror("USBDEVFS_CLAIMINTERFACE");
}
fail:
return 0;
}
}
#ifdef DEBUG
printf("usb_host: %d interfaces claimed for configuration %d\n",
nb_interfaces, configuration);
#endif
return 1;
}
| 1threat
|
static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt)
{
MOVMuxContext *mov = s->priv_data;
MOVTrack *trk = &mov->tracks[pkt->stream_index];
AVCodecParameters *par = trk->par;
int64_t frag_duration = 0;
int size = pkt->size;
if (mov->flags & FF_MOV_FLAG_FRAG_DISCONT) {
int i;
for (i = 0; i < s->nb_streams; i++)
mov->tracks[i].frag_discont = 1;
mov->flags &= ~FF_MOV_FLAG_FRAG_DISCONT;
}
if (!pkt->size) {
if (trk->start_dts == AV_NOPTS_VALUE && trk->frag_discont) {
trk->start_dts = pkt->dts;
if (pkt->pts != AV_NOPTS_VALUE)
trk->start_cts = pkt->pts - pkt->dts;
else
trk->start_cts = 0;
}
if (trk->par->codec_id == AV_CODEC_ID_MP4ALS) {
int side_size = 0;
uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
if (side && side_size > 0 && (side_size != par->extradata_size || memcmp(side, par->extradata, side_size))) {
void *newextra = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!newextra)
return AVERROR(ENOMEM);
av_free(par->extradata);
par->extradata = newextra;
memcpy(par->extradata, side, side_size);
par->extradata_size = side_size;
mov->need_rewrite_extradata = 1;
}
}
return 0;
}
if (trk->entry && pkt->stream_index < s->nb_streams)
frag_duration = av_rescale_q(pkt->dts - trk->cluster[0].dts,
s->streams[pkt->stream_index]->time_base,
AV_TIME_BASE_Q);
if ((mov->max_fragment_duration &&
frag_duration >= mov->max_fragment_duration) ||
(mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) ||
(mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME &&
par->codec_type == AVMEDIA_TYPE_VIDEO &&
trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) {
if (frag_duration >= mov->min_fragment_duration) {
trk->track_duration = pkt->dts - trk->start_dts;
if (pkt->pts != AV_NOPTS_VALUE)
trk->end_pts = pkt->pts;
else
trk->end_pts = pkt->dts;
trk->end_reliable = 1;
mov_auto_flush_fragment(s, 0);
}
}
return ff_mov_write_packet(s, pkt);
}
| 1threat
|
RegExp to search words starts with numbers and special characters only using C# : <p>I want to perform a search to C# list object to find all products starts with any number or special characters only. I am looking for a Regular expressions for this scenario.</p>
<p>Please help </p>
| 0debug
|
What are docValues in Solr? When should I use them? : <p>So, I have read multiple sources that try to explain what 'docValues' are in Solr, but I don't seem to understand when I should use them, especially in relation to indexed vs stored fields. Can anyone please throw some light on it?</p>
| 0debug
|
Androis studio not openning in my laptop : [after installed i open that android studio but it is not opening. Please provide some help.thank you][1]
[1]: https://i.stack.imgur.com/SwlvD.jpg
| 0debug
|
static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
int nb_sectors)
{
if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
return -EIO;
}
return bdrv_check_byte_request(bs, sector_num * BDRV_SECTOR_SIZE,
nb_sectors * BDRV_SECTOR_SIZE);
}
| 1threat
|
static QObject *parse_value(JSONParserContext *ctxt, va_list *ap)
{
QObject *token;
token = parser_context_peek_token(ctxt);
if (token == NULL) {
parse_error(ctxt, NULL, "premature EOI");
return NULL;
}
switch (token_get_type(token)) {
case JSON_LCURLY:
return parse_object(ctxt, ap);
case JSON_LSQUARE:
return parse_array(ctxt, ap);
case JSON_ESCAPE:
return parse_escape(ctxt, ap);
case JSON_INTEGER:
case JSON_FLOAT:
case JSON_STRING:
return parse_literal(ctxt);
case JSON_KEYWORD:
return parse_keyword(ctxt);
default:
parse_error(ctxt, token, "expecting value");
return NULL;
}
}
| 1threat
|
Helper function to return size of a custom object in java : <p>This is an interview question:
There is a custom PERSON object which have some properties like name, age, gender, etc. Write a generic function which can return the size of this object. It should not use any direct API of Java to get the size of Object. This object can have int, float, char or any custom type also like address.</p>
| 0debug
|
How to tell if a "ZipArchiveEntry" is directory? : <p>I am handling some 3rd party ZIP files with .Net 4.5.2 System.IO.Compression.ZipArchive class and all works nicely.<br>
However, I need to tell apart <strong>file entries</strong> from <strong>directory entries</strong>, preferably without extracting them first.</p>
<p><strong>Is there a way to tell if a ZipArchive entry is a directory without extracting it?</strong></p>
<p>As far as could find out there is no property of ZipArchiveEntry that tells if it is a file or directory.</p>
| 0debug
|
static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
float *out, float X[2][38][64],
float mdct_buf[2][64],
float *v0, int *v_off, const unsigned int div)
{
int i, n;
const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;
const int step = 128 >> div;
float *v;
for (i = 0; i < 32; i++) {
if (*v_off < step) {
int saved_samples = (1280 - 128) >> div;
memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float));
*v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step;
} else {
*v_off -= step;
}
v = v0 + *v_off;
if (div) {
for (n = 0; n < 32; n++) {
X[0][i][ n] = -X[0][i][n];
X[0][i][32+n] = X[1][i][31-n];
}
mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
for (n = 0; n < 32; n++) {
v[ n] = mdct_buf[0][63 - 2*n];
v[63 - n] = -mdct_buf[0][62 - 2*n];
}
} else {
for (n = 1; n < 64; n+=2) {
X[1][i][n] = -X[1][i][n];
}
mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
mdct->imdct_half(mdct, mdct_buf[1], X[1][i]);
for (n = 0; n < 64; n++) {
v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ];
v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ];
}
}
dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div);
dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);
out += 64 >> div;
}
}
| 1threat
|
Error handling when calling .bat within .bat : I am trying call a .bat file from within a .bat file. This is how the call is invoked :
call %FWK_DIR%\run_sqlldr_process.bat !ldr!.ctl !log!.log !bad!.bad !data!.dat %BATCHUSER% %BATCHPWD% %ORACLE_SID%
echo %ERRORLEVEL%
echo %RC%
There is a failure inside run_sqlldr_process.bat after which run_sqlldr_process.bat fails with return code 1 and exits with RC = 1. However, the parent .bat file does not capture the failed return code from run_sqlldr_process.bat. Both the echo statements return 0 and the parent script completes successfully. Please provide any pointers.
| 0debug
|
static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
MOVStreamContext *sc;
int64_t ret;
uint8_t uuid[16];
static const uint8_t uuid_isml_manifest[] = {
0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
};
static const uint8_t uuid_xmp[] = {
0xbe, 0x7a, 0xcf, 0xcb, 0x97, 0xa9, 0x42, 0xe8,
0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac
};
static const uint8_t uuid_spherical[] = {
0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93,
0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd,
};
if (atom.size < sizeof(uuid) || atom.size == INT64_MAX)
return AVERROR_INVALIDDATA;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams - 1];
sc = st->priv_data;
ret = avio_read(pb, uuid, sizeof(uuid));
if (ret < 0) {
return ret;
} else if (ret != sizeof(uuid)) {
return AVERROR_INVALIDDATA;
}
if (!memcmp(uuid, uuid_isml_manifest, sizeof(uuid))) {
uint8_t *buffer, *ptr;
char *endptr;
size_t len = atom.size - sizeof(uuid);
if (len < 4) {
return AVERROR_INVALIDDATA;
}
ret = avio_skip(pb, 4);
len -= 4;
buffer = av_mallocz(len + 1);
if (!buffer) {
return AVERROR(ENOMEM);
}
ret = avio_read(pb, buffer, len);
if (ret < 0) {
av_free(buffer);
return ret;
} else if (ret != len) {
av_free(buffer);
return AVERROR_INVALIDDATA;
}
ptr = buffer;
while ((ptr = av_stristr(ptr, "systemBitrate=\""))) {
ptr += sizeof("systemBitrate=\"") - 1;
c->bitrates_count++;
c->bitrates = av_realloc_f(c->bitrates, c->bitrates_count, sizeof(*c->bitrates));
if (!c->bitrates) {
c->bitrates_count = 0;
av_free(buffer);
return AVERROR(ENOMEM);
}
errno = 0;
ret = strtol(ptr, &endptr, 10);
if (ret < 0 || errno || *endptr != '"') {
c->bitrates[c->bitrates_count - 1] = 0;
} else {
c->bitrates[c->bitrates_count - 1] = ret;
}
}
av_free(buffer);
} else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
uint8_t *buffer;
size_t len = atom.size - sizeof(uuid);
if (c->export_xmp) {
buffer = av_mallocz(len + 1);
if (!buffer) {
return AVERROR(ENOMEM);
}
ret = avio_read(pb, buffer, len);
if (ret < 0) {
av_free(buffer);
return ret;
} else if (ret != len) {
av_free(buffer);
return AVERROR_INVALIDDATA;
}
buffer[len] = '\0';
av_dict_set(&c->fc->metadata, "xmp", buffer, 0);
av_free(buffer);
} else {
ret = avio_skip(pb, len);
if (ret < 0)
return ret;
}
} else if (!memcmp(uuid, uuid_spherical, sizeof(uuid))) {
size_t len = atom.size - sizeof(uuid);
ret = mov_parse_uuid_spherical(sc, pb, len);
if (ret < 0)
return ret;
if (!sc->spherical)
av_log(c->fc, AV_LOG_WARNING, "Invalid spherical metadata found\n"); }
return 0;
}
| 1threat
|
Why using the symbol "$" in Angular : <p><a href="https://i.stack.imgur.com/p7705.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p7705.png" alt="enter image description here"></a></p>
<p>Based on the picture with the white selection.</p>
<p>I don't understand why you need to use the symbol "$". (<a href="https://www.twilio.com/blog/prevent-memory-leaks-angular-observable-ngondestroy" rel="nofollow noreferrer">https://www.twilio.com/blog/prevent-memory-leaks-angular-observable-ngondestroy</a>)</p>
<p>What is the purpose to use a symbol "$"?
What benefit is it to use it?</p>
<p>Thank you!</p>
| 0debug
|
Image processing using matlab : I have a question for you
I have 10 gray images and I would like for each image the mean gray value and standard deviation but not for the whole picture ... but for each pixel in the image the mean gray value and the standard deviation
thank you in advance
| 0debug
|
int event_notifier_get_fd(EventNotifier *e)
{
return e->fd;
}
| 1threat
|
static int rscc_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
RsccContext *ctx = avctx->priv_data;
GetByteContext *gbc = &ctx->gbc;
GetByteContext tiles_gbc;
AVFrame *frame = data;
const uint8_t *pixels, *raw;
uint8_t *inflated_tiles = NULL;
int tiles_nb, packed_size, pixel_size = 0;
int i, ret = 0;
bytestream2_init(gbc, avpkt->data, avpkt->size);
if (bytestream2_get_bytes_left(gbc) < 12) {
av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
return AVERROR_INVALIDDATA;
}
tiles_nb = bytestream2_get_le16(gbc);
av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
tiles_nb * sizeof(*ctx->tiles));
if (!ctx->tiles) {
ret = AVERROR(ENOMEM);
goto end;
}
av_log(avctx, AV_LOG_DEBUG, "Frame with %d tiles.\n", tiles_nb);
if (tiles_nb > 5) {
uLongf packed_tiles_size;
if (tiles_nb < 32)
packed_tiles_size = bytestream2_get_byte(gbc);
else
packed_tiles_size = bytestream2_get_le16(gbc);
ff_dlog(avctx, "packed tiles of size %lu.\n", packed_tiles_size);
if (packed_tiles_size != tiles_nb * TILE_SIZE) {
uLongf length = tiles_nb * TILE_SIZE;
inflated_tiles = av_malloc(length);
if (!inflated_tiles) {
ret = AVERROR(ENOMEM);
goto end;
}
ret = uncompress(inflated_tiles, &length,
gbc->buffer, packed_tiles_size);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Tile deflate error %d.\n", ret);
ret = AVERROR_UNKNOWN;
goto end;
}
bytestream2_skip(gbc, packed_tiles_size);
bytestream2_init(&tiles_gbc, inflated_tiles, length);
gbc = &tiles_gbc;
}
}
for (i = 0; i < tiles_nb; i++) {
ctx->tiles[i].x = bytestream2_get_le16(gbc);
ctx->tiles[i].w = bytestream2_get_le16(gbc);
ctx->tiles[i].y = bytestream2_get_le16(gbc);
ctx->tiles[i].h = bytestream2_get_le16(gbc);
pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * ctx->component_size;
ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
if (ctx->tiles[i].w == 0 || ctx->tiles[i].h == 0) {
av_log(avctx, AV_LOG_ERROR,
"invalid tile %d at (%d.%d) with size %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
ret = AVERROR_INVALIDDATA;
goto end;
} else if (ctx->tiles[i].x + ctx->tiles[i].w > avctx->width ||
ctx->tiles[i].y + ctx->tiles[i].h > avctx->height) {
av_log(avctx, AV_LOG_ERROR,
"out of bounds tile %d at (%d.%d) with size %dx%d.\n", i,
ctx->tiles[i].x, ctx->tiles[i].y,
ctx->tiles[i].w, ctx->tiles[i].h);
ret = AVERROR_INVALIDDATA;
goto end;
}
}
gbc = &ctx->gbc;
if (pixel_size < 0x100)
packed_size = bytestream2_get_byte(gbc);
else if (pixel_size < 0x10000)
packed_size = bytestream2_get_le16(gbc);
else if (pixel_size < 0x1000000)
packed_size = bytestream2_get_le24(gbc);
else
packed_size = bytestream2_get_le32(gbc);
ff_dlog(avctx, "pixel_size %d packed_size %d.\n", pixel_size, packed_size);
if (packed_size < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid tile size %d\n", packed_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
if (pixel_size == packed_size) {
if (bytestream2_get_bytes_left(gbc) < pixel_size) {
av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", pixel_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
pixels = gbc->buffer;
} else {
uLongf len = ctx->inflated_size;
if (bytestream2_get_bytes_left(gbc) < packed_size) {
av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", packed_size);
ret = AVERROR_INVALIDDATA;
goto end;
}
ret = uncompress(ctx->inflated_buf, &len, gbc->buffer, packed_size);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Pixel deflate error %d.\n", ret);
ret = AVERROR_UNKNOWN;
goto end;
}
pixels = ctx->inflated_buf;
}
ret = ff_reget_buffer(avctx, ctx->reference);
if (ret < 0)
goto end;
raw = pixels;
for (i = 0; i < tiles_nb; i++) {
uint8_t *dst = ctx->reference->data[0] + ctx->reference->linesize[0] *
(avctx->height - ctx->tiles[i].y - 1) +
ctx->tiles[i].x * ctx->component_size;
av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
raw, ctx->tiles[i].w * ctx->component_size,
ctx->tiles[i].w * ctx->component_size,
ctx->tiles[i].h);
raw += ctx->tiles[i].w * ctx->component_size * ctx->tiles[i].h;
}
ret = av_frame_ref(frame, ctx->reference);
if (ret < 0)
goto end;
if (pixel_size == ctx->inflated_size) {
frame->pict_type = AV_PICTURE_TYPE_I;
frame->key_frame = 1;
} else {
frame->pict_type = AV_PICTURE_TYPE_P;
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
const uint8_t *pal = av_packet_get_side_data(avpkt,
AV_PKT_DATA_PALETTE,
NULL);
if (pal) {
frame->palette_has_changed = 1;
memcpy(ctx->pal, pal, AVPALETTE_SIZE);
}
memcpy (frame->data[1], ctx->pal, AVPALETTE_SIZE);
}
*got_frame = 1;
end:
av_free(inflated_tiles);
return ret;
}
| 1threat
|
How to delete 1 random row at a time in Oracle database : I am working on a project where I need to delete a random row in Oracle database,which query should be fired for that.?
| 0debug
|
Create Integer List of Lists in C : <p>I would like to create an integer list in C containing integer arrays of variable size. The length of the main list will not need to change.</p>
<p>How would I declare it - my implementation - particularly my access is not working:</p>
<pre><code>int dataArray[length];
int dataArray[0] = [1,2,3];
int dataArray[1] = [5,6];
.
.
.
populate
for(int a = 0; a<sizeof(dataArray); a++) {
tempArr = dataArray[a];
for(into = 0; b>sizeof(tempArr); b++) {
print(dataArray[a][b])
}
}
</code></pre>
| 0debug
|
Splitting datime in PHP : I am doing project to school and need something like this in PHP.
I have 2 datetime value:
$begin = new DateTime( "2015-07-03 12:00:00" );
$end = new DateTime( "2015-07-04 14:00:00" );
and I need to split it to this result:
val11 = 2015-07-03 12:00:00;
val12 = 2015-07-03 23:59:59;
val21 = 2015-07-04 00:00:00;
val22 = 2015-07-04 14:00:00;
Can anybody help me, please?
| 0debug
|
static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
{
uint32_t dw10 = le32_to_cpu(cmd->cdw10);
uint32_t result;
switch (dw10) {
case NVME_VOLATILE_WRITE_CACHE:
result = blk_enable_write_cache(n->conf.blk);
break;
case NVME_NUMBER_OF_QUEUES:
result = cpu_to_le32((n->num_queues - 1) | ((n->num_queues - 1) << 16));
break;
default:
return NVME_INVALID_FIELD | NVME_DNR;
}
req->cqe.result = result;
return NVME_SUCCESS;
}
| 1threat
|
saparate object to array of object : <p>i dont know how to make for loop to create new array of object with javascript coding</p>
<p>here i have some object like this</p>
<pre><code>item :[
{
res_name: 'a',
id: 1,
name: name1
},
{
res_name: 'b',
id: 2,
name: name2
},
{
res_name: 'b',
id: 3,
name: name3
}
]
</code></pre>
<p>i want to change to array of object like this</p>
<pre><code>product:[
{
res_name: 'a',
product:[
{
id: 1,
name: name1
}
]
},
{
res_name: 'b',
product:[
{
id: 2,
name: name2
},
{
id: 3,
name: name3
}
]
}
]
</code></pre>
<p>can someone help me</p>
| 0debug
|
static void disable_device(PIIX4PMState *s, int slot)
{
s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
s->pci0_status.down |= (1 << slot);
}
| 1threat
|
void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
uint8_t *segment, uint8_t *ref, int layout, int is_vp7)
{
VP56RangeCoder *c = &s->c;
static const char *vp7_feature_name[] = { "q-index",
"lf-delta",
"partial-golden-update",
"blit-pitch" };
if (is_vp7) {
int i;
*segment = 0;
for (i = 0; i < 4; i++) {
if (s->feature_enabled[i]) {
if (vp56_rac_get_prob_branchy(c, s->feature_present_prob[i])) {
int index = vp8_rac_get_tree(c, vp7_feature_index_tree,
s->feature_index_prob[i]);
av_log(s->avctx, AV_LOG_WARNING,
"Feature %s present in macroblock (value 0x%x)\n",
vp7_feature_name[i], s->feature_value[i][index]);
}
}
}
} else if (s->segmentation.update_map) {
int bit = vp56_rac_get_prob(c, s->prob->segmentid[0]);
*segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
} else if (s->segmentation.enabled)
*segment = ref ? *ref : *segment;
mb->segment = *segment;
mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
if (s->keyframe) {
mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra,
vp8_pred16x16_prob_intra);
if (mb->mode == MODE_I4x4) {
decode_intra4x4_modes(s, c, mb, mb_x, 1, layout);
} else {
const uint32_t modes = (is_vp7 ? vp7_pred4x4_mode
: vp8_pred4x4_mode)[mb->mode] * 0x01010101u;
if (s->mb_layout)
AV_WN32A(mb->intra4x4_pred_mode_top, modes);
else
AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
AV_WN32A(s->intra4x4_pred_mode_left, modes);
}
mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,
vp8_pred8x8c_prob_intra);
mb->ref_frame = VP56_FRAME_CURRENT;
} else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {
if (vp56_rac_get_prob_branchy(c, s->prob->last))
mb->ref_frame =
(!is_vp7 && vp56_rac_get_prob(c, s->prob->golden)) ? VP56_FRAME_GOLDEN2
: VP56_FRAME_GOLDEN;
else
mb->ref_frame = VP56_FRAME_PREVIOUS;
s->ref_count[mb->ref_frame - 1]++;
if (is_vp7)
vp7_decode_mvs(s, mb, mb_x, mb_y, layout);
else
vp8_decode_mvs(s, mb, mb_x, mb_y, layout);
} else {
mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
if (mb->mode == MODE_I4x4)
decode_intra4x4_modes(s, c, mb, mb_x, 0, layout);
mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,
s->prob->pred8x8c);
mb->ref_frame = VP56_FRAME_CURRENT;
mb->partitioning = VP8_SPLITMVMODE_NONE;
AV_ZERO32(&mb->bmv[0]);
}
}
| 1threat
|
Method that returns Task<string> : <p>I need a method that returns a <code>Task<string></code> with empty string like</p>
<pre><code>public static Task<string> AsyncTest()
{
return new Task<string>(() => string.Empty); //problem here
// this method would work:
// return new WebClient().DownloadStringTaskAsync(@"http://www.google.de");
}
public static void Workdl(string input)
{
Console.Write("OUT: " + input.Substring(0, 100));
}
</code></pre>
<p>This snippet compiles but when I call it like</p>
<pre><code>Task<string> dlTask = AsyncTest();
Workdl(await dlTask);
await Task.WhenAll(dlTask); //Task never completes
</code></pre>
<p>it never determines.</p>
| 0debug
|
void scsi_req_unref(SCSIRequest *req)
{
assert(req->refcount > 0);
if (--req->refcount == 0) {
BusState *qbus = req->dev->qdev.parent_bus;
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qbus);
if (bus->info->free_request && req->hba_private) {
bus->info->free_request(bus, req->hba_private);
}
if (req->ops->free_req) {
req->ops->free_req(req);
}
object_unref(OBJECT(req->dev));
object_unref(OBJECT(qbus->parent));
g_free(req);
}
}
| 1threat
|
Primitive Data Types - BYTE in Java : <p>Can you help me explain more detail about this sentence:</p>
<p>"BYTE: They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation."
Source:<a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html</a></p>
<p>Thank you!</p>
| 0debug
|
static int crc_write_packet(struct AVFormatContext *s,
int stream_index,
const uint8_t *buf, int size, int64_t pts)
{
CRCState *crc = s->priv_data;
crc->crcval = adler32(crc->crcval, buf, size);
return 0;
}
| 1threat
|
static int hdcd_scan(HDCDContext *ctx, hdcd_state_t *state, const int32_t *samples, int max, int stride)
{
int cdt_active = 0;
int result;
if (state->sustain > 0) {
cdt_active = 1;
if (state->sustain <= max) {
state->control = 0;
max = state->sustain;
}
state->sustain -= max;
}
result = 0;
while (result < max) {
int flag;
int consumed = hdcd_integrate(ctx, state, &flag, samples, max - result, stride);
result += consumed;
if (flag > 0) {
hdcd_sustain_reset(state);
break;
}
samples += consumed * stride;
}
if (cdt_active && state->sustain == 0)
state->count_sustain_expired++;
return result;
}
| 1threat
|
SWIFT BEGINNER: How to assign values to deck of cards images and then compare them : How can I assign values to a deck of cards? Like A is high and 2 is low with images named c-2 to c-53?
This is my code so far, so I need to assign values to the numbers and also colours of the specific cards images(4 colours), and then compare the two to a correct or false statement.
*For example, 2 is the lowest, A is the highest, A and 2 mean choose a colour, 7 means play the same pile and if the same card comes up it is discarded.*
Thanks!
@IBOutlet weak var leftPile: UIImageView!
@IBOutlet weak var rightPile: UIImageView!
@IBOutlet weak var player1Cards: UIImageView!
@IBOutlet weak var player2Cards: UIImageView!
@IBOutlet weak var cardsAmount: UILabel!
@IBOutlet weak var cardsAmount2: UILabel!
@IBAction func deal(_ sender: Any) {
let shuffled = (2...53).shuffled()
let leftNumber = shuffled[0]
let rightNumber = shuffled[1]
let player1Deck = shuffled[2]
let player2Deck = shuffled[3]
cardsNumber -= 1
cardsNumber2 -= 1
leftPile.image = UIImage(named: "c\(leftNumber)")
rightPile.image = UIImage(named: "c\(rightNumber)")
player1Cards.image = UIImage(named: "c\(player1Deck)")
player2Cards.image = UIImage(named: "c\(player2Deck)"
}
| 0debug
|
How does Python assign variables simultaneously? : There I was, all this time, under the impression that `a, b, c = c, a, b` is the same as `a, c, b = c, b, a`... I thought this was a way to assign variables at the same time so you don't have to create a bunch of temp vars. But apparently they're different because one breaks my code.
So how does it work exactly?
| 0debug
|
static void slirp_receive(void *opaque, const uint8_t *buf, size_t size)
{
#ifdef DEBUG_SLIRP
printf("slirp input:\n");
hex_dump(stdout, buf, size);
#endif
slirp_input(buf, size);
}
| 1threat
|
DIsplaying a php variable inside js : I must start by saying I'm a complete js noob but I've spent a big portion of today solving this with all the answers I found here + google, couldn't get it done, so I decided to ask for a direct help.
Basically, I want to embed an Youtube video in a php page. The videoid variable is defined into the php page but I cannot make the js display that variable.
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '460',
width: '760',
videoId: '<? echo $var;>'
});
}
</script>
The $var variable is present globally within the php file but it doesn't work. I also declared a variable within the js, with no success. What am I doing wrong?
| 0debug
|
Is there a way to generate an empty Html node in Elm-Html? : <p>I'm writing a function that displays error messages, so in my view, I have something like </p>
<pre><code>div [] [ displayErrors model ]
</code></pre>
<p>in the event that there are no errors, how can I make displayErrors return something that is interpreted as an empty Html node?</p>
| 0debug
|
QBool *qobject_to_qbool(const QObject *obj)
{
if (qobject_type(obj) != QTYPE_QBOOL)
return NULL;
return container_of(obj, QBool, base);
}
| 1threat
|
void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info)
{
host_to_target_siginfo_noswap(tinfo, info);
tswap_siginfo(tinfo, tinfo);
}
| 1threat
|
static void close_connection(HTTPContext *c)
{
HTTPContext **cp, *c1;
int i, nb_streams;
AVFormatContext *ctx;
URLContext *h;
AVStream *st;
cp = &first_http_ctx;
while ((*cp) != NULL) {
c1 = *cp;
if (c1 == c) {
*cp = c->next;
} else {
cp = &c1->next;
}
}
for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {
if (c1->rtsp_c == c)
c1->rtsp_c = NULL;
}
if (c->fd >= 0)
close(c->fd);
if (c->fmt_in) {
for(i=0;i<c->fmt_in->nb_streams;i++) {
st = c->fmt_in->streams[i];
if (st->codec->codec) {
avcodec_close(st->codec);
}
}
av_close_input_file(c->fmt_in);
}
nb_streams = 0;
if (c->stream)
nb_streams = c->stream->nb_streams;
for(i=0;i<nb_streams;i++) {
ctx = c->rtp_ctx[i];
if (ctx) {
av_write_trailer(ctx);
av_free(ctx);
}
h = c->rtp_handles[i];
if (h) {
url_close(h);
}
}
ctx = &c->fmt_ctx;
if (!c->last_packet_sent) {
if (ctx->oformat) {
if (url_open_dyn_buf(&ctx->pb) >= 0) {
av_write_trailer(ctx);
url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
}
}
}
for(i=0; i<ctx->nb_streams; i++)
av_free(ctx->streams[i]) ;
if (c->stream)
current_bandwidth -= c->stream->bandwidth;
av_freep(&c->pb_buffer);
av_freep(&c->packet_buffer);
av_free(c->buffer);
av_free(c);
nb_connections--;
}
| 1threat
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.