problem
stringlengths 26
131k
| labels
class label 2
classes |
|---|---|
static void setup_sigframe_v2(struct target_ucontext_v2 *uc,
target_sigset_t *set, CPUState *env)
{
struct target_sigaltstack stack;
int i;
memset(uc, 0, offsetof(struct target_ucontext_v2, tuc_mcontext));
memset(&stack, 0, sizeof(stack));
__put_user(target_sigaltstack_used.ss_sp, &stack.ss_sp);
__put_user(target_sigaltstack_used.ss_size, &stack.ss_size);
__put_user(sas_ss_flags(get_sp_from_cpustate(env)), &stack.ss_flags);
memcpy(&uc->tuc_stack, &stack, sizeof(stack));
setup_sigcontext(&uc->tuc_mcontext, env, set->sig[0]);
for(i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &uc->tuc_sigmask.sig[i]);
}
}
| 1threat
|
The c ++ stl library containers have dynamic memory allocations? : <p>I would like to know for example if to allocate memory dynamically I use new [] or malloc in std :: vector, or do not need, if I do not need, where should I use new [], malloc and smartpointers?</p>
| 0debug
|
Convert whole dataframe from lower case to upper case with Pandas : <p>I have a dataframe like the one displayed below: </p>
<pre><code># Create an example dataframe about a fictional army
raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks'],
'company': ['1st', '1st', '2nd', '2nd'],
'deaths': ['kkk', 52, '25', 616],
'battles': [5, '42', 2, 2],
'size': ['l', 'll', 'l', 'm']}
df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'deaths', 'battles', 'size'])
</code></pre>
<p><a href="https://i.stack.imgur.com/fiOEt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fiOEt.png" alt="enter image description here"></a></p>
<p>My goal is to transform every single string inside of the dataframe to upper case so that it looks like this:</p>
<p><a href="https://i.stack.imgur.com/gprF6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gprF6.png" alt="enter image description here"></a></p>
<p>Notice: all data types are objects and must not be changed; the output must contain all objects. I want to avoid to convert every single column one by one... I would like to do it generally over the whole dataframe possibly.</p>
<p>What I tried so far is to do this but without success</p>
<pre><code>df.str.upper()
</code></pre>
| 0debug
|
What's difference between tf.sub and just minus operation in tensorflow? : <p>I am trying to use Tensorflow. Here is an very simple code.</p>
<pre><code>train = tf.placeholder(tf.float32, [1], name="train")
W1 = tf.Variable(tf.truncated_normal([1], stddev=0.1), name="W1")
loss = tf.pow(tf.sub(train, W1), 2)
step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
</code></pre>
<p>Just ignore the optimization part (4th line). It will take a floating number and train W1 so as to increase squared difference.</p>
<p>My question is simple. If I use just minus sign instead of
tf.sub" as below, what is different? Will it cause a wrong result? </p>
<pre><code>loss = tf.pow(train-W1, 2)
</code></pre>
<p>When I replace it, the result looks the same. If they are the same, why do we need to use the "tf.add/tf.sub" things?</p>
<p>Built-in back propagation calculation can be done only by the "tf.*" things? </p>
| 0debug
|
How does the Shouldly assertion library know the expression the assertion was applied to? : <p>The <a href="http://shouldly.readthedocs.io/en/latest/">Shouldly assertion library for .NET</a> somehow knows what expression the assertion method was called on so it is able to display it into the message. I tried to find out how it works but got lost in the source code. I suspect it looks into the compiled code but I would really like to see how this happens. From the documentation</p>
<pre><code>map.IndexOfValue("boo").ShouldBe(2); // -> map.IndexOfValue("boo") should be 2 but was 1
</code></pre>
<p>Somehow Shouldly knows the expression map.IndexOfValue("boo") and was able to display it in the test failure message. Does anyone know how this happens?</p>
| 0debug
|
bash [[ [a] == [a] ]] not true? square bracket affect compare result : <p>Anyone know why this happens? Is this a bug of bash?</p>
<pre><code>x='mnt:[4026532411]'
[[ $x == $x ]] && echo OK
</code></pre>
<p>I am expecting result <code>OK</code>, but it did not.</p>
<p>Of course, this works</p>
<pre><code>[[ "$x" == "$x" ]] && echo OK
</code></pre>
<p>But as I know, bash [[ ]] have a merit that no need to quote var when compare.</p>
<pre><code>x='a b'
[[ $x == $x ]] && echo OK
</code></pre>
<p>works.</p>
<p>Ironical things is</p>
<pre><code>x='mnt:[4026532411]'
[[ $x != $x ]] && echo Oh my god
</code></pre>
<p>result is Oh my god</p>
| 0debug
|
How to print the contents of enzyme's shallow wrapper : <p>I have the following :</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import {shallow} from "enzyme"
const wrapper = shallow(<SampleComponent/>);</code></pre>
</div>
</div>
</p>
<p>how do I see the contents of wrapper?</p>
| 0debug
|
undefined reference to `startswith' : I am writing some C in which the program is going to convert the first command line argument into a int and check to see if it is an int. If it isnt a integer value it will then attempt to check to see whether the string begins with a '.' character or not. For some reason I am getting an undefined reference. How is this an undefined reference when it seems to be defined?
Here is the following code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
int startswith(char,char);
int main(int argc, char *argv[])
{
int forst;
srand(time(NULL));
int speed_delay = rand()%20;
printf("The speed delay is:%i\n",speed_delay);
int first = atoi(argv[1]);
printf("First:%i\n",first );
if(first == 0)
{
//this means text was inserted instead of a number
if(startswith(first,'.'))
{
printf("string starts with a period !");
}
}
else
{
}
int startswith( const char *one, const char *two)
{
if(strncmp(one,two,strlen(two)) == 0)
{
return 1;
}
return 0;
}
}
| 0debug
|
Slicing HTML based on delimiter : <p>I am converting Word docs on the fly to HTML and needing to parse said HTML based on a delimiter. For example:</p>
<pre><code><div id="div1">
<p>
<font>
<b>[[delimiter]]Start of content section 1.</b>
</font>
</p>
<p>
<span>More content in section 1</span>
</p>
</div>
<div id="div2">
<p>
<b>
<font>[[delimiter]]Start of section 2</font>
</b>
<p>
<span>More content in section 2</span>
<p><font>[[delimiter]]Start of section 3</font></p>
<div>
<div id="div3">
<span><font>More content in section 3</font></span>
</div>
<!-- This continues on... -->
</code></pre>
<p>Should be parsed as:</p>
<p>Section 1:</p>
<pre><code><div id="div1">
<p>
<font>
<b>[[delimiter]]Start of content section 1.</b>
</font>
</p>
<p>
<span>More content in section 1</span>
</p>
</div>
</code></pre>
<p>Section 2:</p>
<pre><code><div id="div2">
<p>
<b>
<font>[[delimiter]]Start of section 2</font>
</b>
<p>
<span>More content in section 2</span>
<p></p>
<div>
</code></pre>
<p>Section 3:</p>
<pre><code><div id="div2">
<p>
<b>
</b>
<p>
<p><font>[[delimiter]]Start of section 3</font></p>
<div>
<div id="div3">
<span><font>More content in section 3</font></span>
</div>
</code></pre>
<ol>
<li><p>I can't simply "explode"/slice based on the delimiter, because that would break the HTML. Every bit of text content has many parent elements.</p></li>
<li><p>I have no control over the HTML structure and it sometimes changes based on the structure of the Word doc. An end user will import their Word doc to be parsed in the application, so the resulting HTML will not be altered before being parsed.</p></li>
<li><p>Often the content is at different depths in the HTML.</p></li>
<li><p>I cannot rely on element classes or IDs because they are not consistent from doc to doc. #div1, #div2, and #div3 are just for illustration in my example.</p></li>
<li><p>My goal is to parse out the content, so if there's empty elements left over that's OK, I can simply run over the markup again and remove empty tags (p, font, b, etc).</p></li>
</ol>
<p>My attempts:</p>
<p>I am using the PHP DOM extension to parse the HTML and loop through the nodes. But I cannot come up with a good algorithm to figure this out.</p>
<pre><code>$doc = new \DOMDocument();
$doc->loadHTML($html);
$body = $doc->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child) {
if ($child->hasChildNodes()) {
// Do recursive call...
} else {
// Contains slide identifier?
}
}
</code></pre>
| 0debug
|
static void omap_lpg_tick(void *opaque)
{
struct omap_lpg_s *s = opaque;
if (s->cycle)
timer_mod(s->tm, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + s->period - s->on);
else
timer_mod(s->tm, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + s->on);
s->cycle = !s->cycle;
printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
}
| 1threat
|
static void ehci_frame_timer(void *opaque)
{
EHCIState *ehci = opaque;
int need_timer = 0;
int64_t expire_time, t_now;
uint64_t ns_elapsed;
uint64_t uframes, skipped_uframes;
int i;
t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ns_elapsed = t_now - ehci->last_run_ns;
uframes = ns_elapsed / UFRAME_TIMER_NS;
if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) {
need_timer++;
if (uframes > (ehci->maxframes * 8)) {
skipped_uframes = uframes - (ehci->maxframes * 8);
ehci_update_frindex(ehci, skipped_uframes);
ehci->last_run_ns += UFRAME_TIMER_NS * skipped_uframes;
uframes -= skipped_uframes;
DPRINTF("WARNING - EHCI skipped %d uframes\n", skipped_uframes);
}
for (i = 0; i < uframes; i++) {
if (i >= MIN_UFR_PER_TICK) {
ehci_commit_irq(ehci);
if ((ehci->usbsts & USBINTR_MASK) & ehci->usbintr) {
break;
}
}
if (ehci->periodic_sched_active) {
ehci->periodic_sched_active--;
}
ehci_update_frindex(ehci, 1);
if ((ehci->frindex & 7) == 0) {
ehci_advance_periodic_state(ehci);
}
ehci->last_run_ns += UFRAME_TIMER_NS;
}
} else {
ehci->periodic_sched_active = 0;
ehci_update_frindex(ehci, uframes);
ehci->last_run_ns += UFRAME_TIMER_NS * uframes;
}
if (ehci->periodic_sched_active) {
ehci->async_stepdown = 0;
} else if (ehci->async_stepdown < ehci->maxframes / 2) {
ehci->async_stepdown++;
}
if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) {
need_timer++;
ehci_advance_async_state(ehci);
}
ehci_commit_irq(ehci);
if (ehci->usbsts_pending) {
need_timer++;
ehci->async_stepdown = 0;
}
if (ehci_enabled(ehci) && (ehci->usbintr & USBSTS_FLR)) {
need_timer++;
}
if (need_timer) {
if (ehci->int_req_by_async && (ehci->usbsts & USBSTS_INT)) {
expire_time = t_now +
NANOSECONDS_PER_SECOND / (FRAME_TIMER_FREQ * 4);
ehci->int_req_by_async = false;
} else {
expire_time = t_now + (NANOSECONDS_PER_SECOND
* (ehci->async_stepdown+1) / FRAME_TIMER_FREQ);
}
timer_mod(ehci->frame_timer, expire_time);
}
}
| 1threat
|
sql make time in datetime 12 pm : I have datetime field as
<pre>
03/04/2016 08:00:00 AM
03/15/2016 04:00:00 AM
</pre>
I want to keep it as date time but make all the time to 12 am.So the result should be
<pre>
03/04/2016 12:00:00 AM
03/15/2016 12:00:00 AM
</pre>
No t-sql or declaring variables. Please advice.
| 0debug
|
Retrieve next Id from table using specific id from same table : <p>I am working on Blog, If user chooses to read Full Post from home page, it redirects to Details page where only one post gets displayed with all details, where all data being displayed from database table.</p>
<p>What I want to implement is, user can redirect to next post from Details page only, using NEXT button placed at bottom of Details page.
I have Post ID in in Querystring. Now I want NEXT post's ID so I can redirect user to Next post.</p>
<p>Please help me to retrieve Next ID from table using specific ID.</p>
<p>Thanks in Advance.</p>
| 0debug
|
Android app licensing - any current tutorials on this? : I am hoping somebody can point me in the right direction on this one. I have been reading for a few days now on the developer site, various posts on stackoverflow, etc., and am really struggling to piece all of this together. The Google documentation seems to have some gaps, or I'm simply missing the boat. I have attempted to follow the Google docs on this a few times and keep running in to issues.
The most recent is that after going through the steps of downloading the market libraries via the SDK manager and then creating the new library module, I feel I'm missing the piece that will allow my app to see the modules. Specifically, I am guessing there is a dependency that needs to be added to gradle, but I have found no such reference in any of the documentation. If that's not the case, then I have no idea why my imports are not being found.
Certainly this feature must work and work well, so I am hoping somebody can point me to a current/decent tutorial or functional sample application that I can view the code on. I did review the sample application that is part of the sdk and as far as the code within the MainActivity goes, that is all fine and good. My main issue is that I can't seem to get my application to be aware of these libraries to move forward with the implementation of the methods to perform the validation how I need.
Any direction would be greatly appreciated.
Thank you!
| 0debug
|
Prevent Foreach Array Give Same Value : <p>I have this array code</p>
<pre><code>$data = array();
foreach($getAllUserTicketHistoryJson as $value){
$data[$value['user_id']] = number_format((float)($value['total_ticket'] / $getAllTicketRound * 100), 2, '.', '');
}
$array=$data;
</code></pre>
<p>which will give output</p>
<pre><code>array(4) { [4]=> string(5) "16.28" [3]=> string(4) "5.81" [2]=> string(5) "11.63" [5]=> string(5) "66.28" }
</code></pre>
<p>the array is user_id and chance to win from 100%.</p>
<p>and I want to show 3 random winner without repeat the first winner. Means that if user already win they cannot win again.</p>
<p>I created this code</p>
<pre><code> $number=rand(0,array_sum($array));
$starter=0;
foreach($array as $key => $val)
{
$starter+=$val;
if($number<=$starter)
{
$ret=$key;
break;
}
}
for($i=0;$i<3;$i++)
{
echo 'Winner is '.$ret.'<br/>';
}
</code></pre>
<p>The code will give output</p>
<pre><code>Winner is 5
Winner is 5
Winner is 5
</code></pre>
<p>The problem is, how to show 3 winner based on their chance without repeating the first winner. The result should be like this</p>
<pre><code>Winner is 4
Winner is 5
Winner is 2
</code></pre>
<p>thanks for helping me</p>
| 0debug
|
JavaScript in Echo php : <p>hey guys can anyone help me to make this javascript code work in echo php area :/ .. please help cuz i really need this :) </p>
<pre><code><script type="text/javascript">
function countDown(secs,elem){
var element = document.getElementById(elem);
element.innerHTML = "Please wait for "+secs+" seconds";
if(secs<1){
clearTimeout(timer);
element.innerHTML = '<h2>Countdown Complete!</h2>';
element.innerHTML += '<a href="'.$url.'">Click here now</a>';
}
secs--;
var timer = setTimeout ('countDown('+secs+',"'+elem+'")',1000)
}
</script>
<div id="status"></div>
<script type="text/javascript">countDown(10,"status"); </script>
</code></pre>
| 0debug
|
static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
uint32_t addr, uint32_t size,
target_ulong rets)
{
PCIDevice *pci_dev;
uint32_t val;
if ((size != 1) && (size != 2) && (size != 4)) {
rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
return;
}
pci_dev = find_dev(spapr, buid, addr);
addr = rtas_pci_cfgaddr(addr);
if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
return;
}
val = pci_host_config_read_common(pci_dev, addr,
pci_config_size(pci_dev), size);
rtas_st(rets, 0, RTAS_OUT_SUCCESS);
rtas_st(rets, 1, val);
}
| 1threat
|
Batch file, how to remove the first world in a text file and only in the first line? : I have a .txt file that may contain various words on various lines and I just want to remove the first word in the first line. (ex: I have 2 lines in my text file containing 2 words each (abc, bcd on the first line and cde, def on the second) annd I want the output to be bcd on the first line and cde and def on the second). I researched this and I only came across to how to remove the first word in all the lines but I only need in the first line. Thanks in advance.
| 0debug
|
should be really straight forward but my background for website wont show : [My Code]<https://codepen.io/Crudge/pen/MWgBwZW>
body {background: url('images\Copy_of_mona-eendra-208388-unsplash.jpg') width 100% height 100% margin:0;}
I've got a pen with the whole code on. i'm using ATOM so i've just pulling the objects path and pasting it in the url.
My first website so don't be to harsh please but any critique is welcome.
For some reason i can't set a background image on the body no matter what i try.
cheers
sam
| 0debug
|
Python equivalent of golang's defer statement : <p>How would one implement something that works like the <code>defer</code> statement from go in python? </p>
<p>Defer pushes a function call to a stack. When the function containing the defer statement returns, the defered function calls are popped and executed one by one, in the scope that the defer statement was inside in the first place. Defer statements look like function calls, but are not executed until they are popped.</p>
<p>Go example of how it works:</p>
<pre><code>func main() {
fmt.Println("counting")
var a *int
for i := 0; i < 10; i++ {
a = &i
defer fmt.Println(*a, i)
}
x := 42
a = &x
fmt.Println("done")
}
</code></pre>
<p>Outputs: </p>
<pre><code>counting
done
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
</code></pre>
<p>Go example of a usecase:</p>
<pre><code>var m sync.Mutex
func someFunction() {
m.Lock()
defer m.Unlock()
// Whatever you want, with as many return statements as you want, wherever.
// Simply forget that you ever locked a mutex, or that you have to remember to release it again.
}
</code></pre>
| 0debug
|
static void avc_luma_hv_qrt_8w_msa(const uint8_t *src_x, const uint8_t *src_y,
int32_t src_stride, uint8_t *dst,
int32_t dst_stride, int32_t height)
{
uint32_t loop_cnt;
v16i8 src_hz0, src_hz1, src_hz2, src_hz3;
v16i8 src_vt0, src_vt1, src_vt2, src_vt3, src_vt4;
v16i8 src_vt5, src_vt6, src_vt7, src_vt8;
v16i8 mask0, mask1, mask2;
v8i16 hz_out0, hz_out1, hz_out2, hz_out3;
v8i16 vert_out0, vert_out1, vert_out2, vert_out3;
v8i16 out0, out1, out2, out3;
v16u8 tmp0, tmp1;
LD_SB3(&luma_mask_arr[0], 16, mask0, mask1, mask2);
LD_SB5(src_y, src_stride, src_vt0, src_vt1, src_vt2, src_vt3, src_vt4);
src_y += (5 * src_stride);
src_vt0 = (v16i8) __msa_insve_d((v2i64) src_vt0, 1, (v2i64) src_vt1);
src_vt1 = (v16i8) __msa_insve_d((v2i64) src_vt1, 1, (v2i64) src_vt2);
src_vt2 = (v16i8) __msa_insve_d((v2i64) src_vt2, 1, (v2i64) src_vt3);
src_vt3 = (v16i8) __msa_insve_d((v2i64) src_vt3, 1, (v2i64) src_vt4);
XORI_B4_128_SB(src_vt0, src_vt1, src_vt2, src_vt3);
for (loop_cnt = (height >> 2); loop_cnt--;) {
LD_SB4(src_x, src_stride, src_hz0, src_hz1, src_hz2, src_hz3);
XORI_B4_128_SB(src_hz0, src_hz1, src_hz2, src_hz3);
src_x += (4 * src_stride);
hz_out0 = AVC_HORZ_FILTER_SH(src_hz0, src_hz0, mask0, mask1, mask2);
hz_out1 = AVC_HORZ_FILTER_SH(src_hz1, src_hz1, mask0, mask1, mask2);
hz_out2 = AVC_HORZ_FILTER_SH(src_hz2, src_hz2, mask0, mask1, mask2);
hz_out3 = AVC_HORZ_FILTER_SH(src_hz3, src_hz3, mask0, mask1, mask2);
SRARI_H4_SH(hz_out0, hz_out1, hz_out2, hz_out3, 5);
SAT_SH4_SH(hz_out0, hz_out1, hz_out2, hz_out3, 7);
LD_SB4(src_y, src_stride, src_vt5, src_vt6, src_vt7, src_vt8);
src_y += (4 * src_stride);
src_vt4 = (v16i8) __msa_insve_d((v2i64) src_vt4, 1, (v2i64) src_vt5);
src_vt5 = (v16i8) __msa_insve_d((v2i64) src_vt5, 1, (v2i64) src_vt6);
src_vt6 = (v16i8) __msa_insve_d((v2i64) src_vt6, 1, (v2i64) src_vt7);
src_vt7 = (v16i8) __msa_insve_d((v2i64) src_vt7, 1, (v2i64) src_vt8);
XORI_B4_128_SB(src_vt4, src_vt5, src_vt6, src_vt7);
AVC_CALC_DPADD_B_6PIX_2COEFF_SH(src_vt0, src_vt1, src_vt2, src_vt3,
src_vt4, src_vt5, vert_out0, vert_out1);
AVC_CALC_DPADD_B_6PIX_2COEFF_SH(src_vt2, src_vt3, src_vt4, src_vt5,
src_vt6, src_vt7, vert_out2, vert_out3);
SRARI_H4_SH(vert_out0, vert_out1, vert_out2, vert_out3, 5);
SAT_SH4_SH(vert_out0, vert_out1, vert_out2, vert_out3, 7);
out0 = __msa_srari_h((hz_out0 + vert_out0), 1);
out1 = __msa_srari_h((hz_out1 + vert_out1), 1);
out2 = __msa_srari_h((hz_out2 + vert_out2), 1);
out3 = __msa_srari_h((hz_out3 + vert_out3), 1);
SAT_SH4_SH(out0, out1, out2, out3, 7);
tmp0 = PCKEV_XORI128_UB(out0, out1);
tmp1 = PCKEV_XORI128_UB(out2, out3);
ST8x4_UB(tmp0, tmp1, dst, dst_stride);
dst += (4 * dst_stride);
src_vt3 = src_vt7;
src_vt1 = src_vt5;
src_vt5 = src_vt4;
src_vt4 = src_vt8;
src_vt2 = src_vt6;
src_vt0 = src_vt5;
}
}
| 1threat
|
void virtio_reset(void *opaque)
{
VirtIODevice *vdev = opaque;
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
int i;
virtio_set_status(vdev, 0);
if (current_cpu) {
vdev->device_endian = virtio_current_cpu_endian();
} else {
vdev->device_endian = virtio_default_endian();
}
if (k->reset) {
k->reset(vdev);
}
vdev->guest_features = 0;
vdev->queue_sel = 0;
vdev->status = 0;
vdev->isr = 0;
vdev->config_vector = VIRTIO_NO_VECTOR;
virtio_notify_vector(vdev, vdev->config_vector);
for(i = 0; i < VIRTIO_QUEUE_MAX; i++) {
vdev->vq[i].vring.desc = 0;
vdev->vq[i].vring.avail = 0;
vdev->vq[i].vring.used = 0;
vdev->vq[i].last_avail_idx = 0;
vdev->vq[i].shadow_avail_idx = 0;
vdev->vq[i].used_idx = 0;
virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
vdev->vq[i].signalled_used = 0;
vdev->vq[i].signalled_used_valid = false;
vdev->vq[i].notification = true;
vdev->vq[i].vring.num = vdev->vq[i].vring.num_default;
vdev->vq[i].inuse = 0;
}
}
| 1threat
|
static void fill_block(uint16_t *pdest, uint16_t color, int block_size, int pitch)
{
int x, y;
pitch -= block_size;
for (y = 0; y != block_size; y++, pdest += pitch)
for (x = 0; x != block_size; x++)
*pdest++ = color;
}
| 1threat
|
static void ipvideo_decode_format_10_opcodes(IpvideoContext *s, AVFrame *frame)
{
int pass, x, y, changed_block;
int16_t opcode, skip;
GetByteContext decoding_map_ptr;
GetByteContext skip_map_ptr;
bytestream2_skip(&s->stream_ptr, 14);
memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
s->stride = frame->linesize[0];
s->line_inc = s->stride - 8;
s->upper_motion_limit_offset = (s->avctx->height - 8) * frame->linesize[0]
+ (s->avctx->width - 8) * (1 + s->is_16bpp);
bytestream2_init(&decoding_map_ptr, s->decoding_map, s->decoding_map_size);
bytestream2_init(&skip_map_ptr, s->skip_map, s->skip_map_size);
for (pass = 0; pass < 2; ++pass) {
bytestream2_seek(&decoding_map_ptr, 0, SEEK_SET);
bytestream2_seek(&skip_map_ptr, 0, SEEK_SET);
skip = bytestream2_get_le16(&skip_map_ptr);
for (y = 0; y < s->avctx->height; y += 8) {
for (x = 0; x < s->avctx->width; x += 8) {
s->pixel_ptr = s->cur_decode_frame->data[0] + x + y * s->cur_decode_frame->linesize[0];
while (skip <= 0 && bytestream2_get_bytes_left(&decoding_map_ptr) > 1) {
if (skip != -0x8000 && skip) {
opcode = bytestream2_get_le16(&decoding_map_ptr);
ipvideo_format_10_passes[pass](s, frame, opcode);
break;
}
skip = bytestream2_get_le16(&skip_map_ptr);
}
skip *= 2;
}
}
}
bytestream2_seek(&skip_map_ptr, 0, SEEK_SET);
skip = bytestream2_get_le16(&skip_map_ptr);
for (y = 0; y < s->avctx->height; y += 8) {
for (x = 0; x < s->avctx->width; x += 8) {
changed_block = 0;
s->pixel_ptr = frame->data[0] + x + y*frame->linesize[0];
while (skip <= 0) {
if (skip != -0x8000 && skip) {
changed_block = 1;
break;
}
if (bytestream2_get_bytes_left(&skip_map_ptr) < 2)
return;
skip = bytestream2_get_le16(&skip_map_ptr);
}
if (changed_block) {
copy_from(s, s->cur_decode_frame, frame, 0, 0);
} else {
if (s->avctx->frame_number)
copy_from(s, s->last_frame, frame, 0, 0);
}
skip *= 2;
}
}
FFSWAP(AVFrame*, s->prev_decode_frame, s->cur_decode_frame);
if (bytestream2_get_bytes_left(&s->stream_ptr) > 1) {
av_log(s->avctx, AV_LOG_DEBUG,
"decode finished with %d bytes left over\n",
bytestream2_get_bytes_left(&s->stream_ptr));
}
}
| 1threat
|
Android Country codes : <p>How i use Country codes String in my android code using edittext startswith number
here my code m using.</p>
<p>String</p>
<pre><code>private static final String[] mCodes = {
"+93", "+355", "+213", "+376", "+244", "+672", "+54", "+374",
"+297", "+61", "+43", "+994", "+973", "+880", "+375", "+32",
"+501", "+229", "+975", "+591", "+387", "+267", "+55", "+673",
"+359", "+226", "+95", "+257", "+855", "+237", "+1", "+238",
"+236", "+235", "+56", "+86", "+61", "+61", "+57", "+269",
"+242", "+243", "+682", "+506", "+385", "+53", "+357", "+420",
"+45", "+253", "+670", "+593", "+20", "+503", "+240", "+291",
"+372", "+251", "+500", "+298", "+679", "+358", "+33", "+689",
"+241", "+220", "+995", "+49", "+233", "+350", "+30", "+299",
"+502", "+224", "+245", "+592", "+509", "+504", "+852", "+36",
"+91", "+62", "+98", "+964", "+353", "+44", "+972", "+39",
"+225", "+81", "+962", "+254", "+686", "+965", "+996", "+856",
"+371", "+961", "+266", "+231", "+218", "+423", "+370", "+352",
"+853", "+389", "+261", "+265", "+60", "+960", "+223", "+356",
"+692", "+222", "+230", "+262", "+52", "+691", "+373", "+377",
"+976", "+382", "+212", "+258", "+264", "+674", "+977", "+31",
"+599", "+687", "+64", "+505", "+227", "+234", "+683", "+850",
"+47", "+968", "+92", "+680", "+507", "+675", "+595", "+51",
"+63", "+870", "+48", "+351", "+974", "+40", "+7", "+250",
"+590", "+685", "+378", "+239", "+966", "+221", "+381", "+248",
"+232", "+65", "+421", "+386", "+677", "+252", "+27", "+82",
"+34", "+94", "+290", "+508", "+249", "+597", "+268", "+46",
"+41", "+963", "+886", "+992", "+255", "+66", "+228", "+690",
"+676", "+216", "+90", "+993", "+688", "+971", "+256", "+380",
"+598", "+998", "+678", "+58", "+84", "+681", "+967", "+260",
"+263"
};
</code></pre>
<p>Edittext</p>
<pre><code>etAddNumber = (EditText) findViewById(R.id.etAddNumber);
String addnumber = etAddNumber.getText().toString();
</code></pre>
<p>And also use edittext code, if user enter number without country code show Toast</p>
<pre><code> if (!addnumber.startsWith(mCodes.toString())) {
Toast.makeText(getApplicationContext(), "You did not enter country code", Toast.LENGTH_SHORT).show();
}
</code></pre>
<p>Thanks Advance</p>
| 0debug
|
Difference between Firefox and Firefox developer nowdays - 2017 : <p>When Firefox developer edition introduced, I was so happy, that I can use WebIde, responsive design tool, eyedroper, etc... Today I had enough.</p>
<p>There are a lot of bugs in it, I wont start to enumarate how many bugs sended and approved by me and my colleague... </p>
<p>I've searched for this topic in google, and everywhere I saw, that regular firefox has no WebIde, responsive design view, eyedropper, etc...</p>
<p>I've downloaded the regular firefox, and see no difference. All of these tools are in it, so it seems to me that with aurora channel I get an unstable something what is just impede in my work instead it helps me.</p>
<p>So, my question is: is there any significant difference between the two versions what I did not spot?</p>
| 0debug
|
static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
{
int i, j, k, l;
int sf_max, sf, len, non_zero_found;
INTFLOAT (*is_tab)[16], *tab0, *tab1, tmp0, tmp1, v1, v2;
int non_zero_found_short[3];
if (s->mode_ext & MODE_EXT_I_STEREO) {
if (!s->lsf) {
is_tab = is_table;
sf_max = 7;
} else {
is_tab = is_table_lsf[g1->scalefac_compress & 1];
sf_max = 16;
}
tab0 = g0->sb_hybrid + 576;
tab1 = g1->sb_hybrid + 576;
non_zero_found_short[0] = 0;
non_zero_found_short[1] = 0;
non_zero_found_short[2] = 0;
k = (13 - g1->short_start) * 3 + g1->long_end - 3;
for (i = 12; i >= g1->short_start; i--) {
if (i != 11)
k -= 3;
len = band_size_short[s->sample_rate_index][i];
for (l = 2; l >= 0; l--) {
tab0 -= len;
tab1 -= len;
if (!non_zero_found_short[l]) {
for (j = 0; j < len; j++) {
if (tab1[j] != 0) {
non_zero_found_short[l] = 1;
goto found1;
}
}
sf = g1->scale_factors[k + l];
if (sf >= sf_max)
goto found1;
v1 = is_tab[0][sf];
v2 = is_tab[1][sf];
for (j = 0; j < len; j++) {
tmp0 = tab0[j];
tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
}
} else {
found1:
if (s->mode_ext & MODE_EXT_MS_STEREO) {
for (j = 0; j < len; j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
}
}
non_zero_found = non_zero_found_short[0] |
non_zero_found_short[1] |
non_zero_found_short[2];
for (i = g1->long_end - 1;i >= 0;i--) {
len = band_size_long[s->sample_rate_index][i];
tab0 -= len;
tab1 -= len;
if (!non_zero_found) {
for (j = 0; j < len; j++) {
if (tab1[j] != 0) {
non_zero_found = 1;
goto found2;
}
}
k = (i == 21) ? 20 : i;
sf = g1->scale_factors[k];
if (sf >= sf_max)
goto found2;
v1 = is_tab[0][sf];
v2 = is_tab[1][sf];
for (j = 0; j < len; j++) {
tmp0 = tab0[j];
tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
}
} else {
found2:
if (s->mode_ext & MODE_EXT_MS_STEREO) {
for (j = 0; j < len; j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
}
} else if (s->mode_ext & MODE_EXT_MS_STEREO) {
#if USE_FLOATS
s->fdsp->butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
#else
tab0 = g0->sb_hybrid;
tab1 = g1->sb_hybrid;
for (i = 0; i < 576; i++) {
tmp0 = tab0[i];
tmp1 = tab1[i];
tab0[i] = tmp0 + tmp1;
tab1[i] = tmp0 - tmp1;
}
#endif
}
}
| 1threat
|
Why does std::find_if(first, last, p) not take predicate by reference? : <p>I was looking at the various signatures for <a href="http://en.cppreference.com/w/cpp/algorithm/find" rel="noreferrer"><code>std::find_if</code> on cppreference.com,</a> and I noticed that the flavors that take a predicate function appear to accept it by value:</p>
<pre><code>template< class InputIt, class UnaryPredicate >
InputIt find_if( InputIt first, InputIt last,
UnaryPredicate p );
</code></pre>
<p>If I understand them correctly, lambdas with captured variables allocate storage for either references or copies of their data, and so presumably a "pass-by-value" would imply that the copies of captured data are copied for the call.</p>
<p>On the other hand, for function pointers and other directly addressable things, the performance should be better if the function pointer is passed directly, rather than by reference-to-pointer (pointer-to-pointer). </p>
<p>First, is this correct? Is the <code>UnaryPredicate</code> above going to be a by-value parameter?</p>
<p>Second, is my understanding of passing lambdas correct?</p>
<p>Third, is there a reason for passing by value instead of by reference in this situation? And more to the point, is there not some sufficiently ambiguous syntax (hello, universal reference) that would let the compiler do whatever it wants to get the most performance out?</p>
| 0debug
|
Is it possible to set custom CPU throttling in Chrome DevTools? : <p>I am using Google Chrome 63.</p>
<p>In DevTools in <strong>Performance</strong> tab there are three CPU throttling settings: "No throttling", "4x slowdown" and "6x slowdown".</p>
<p>Is it possible to set custom throttling, for example "20x slowdown"? It could be via setting some flag in <strong>chrome.exe</strong> file or programmatically via NodeJS library.</p>
<p>I found that Lighthouse library has kind of <a href="https://npmdoc.github.io/node-npmdoc-lighthouse/build/apidoc.html#apidoc.element.lighthouse.emulation.enableCPUThrottling" rel="noreferrer">helpful function</a> but if I change the default value inside it (<strong>CPU_THROTTLE_METRICS</strong> seems to be equal to 4) from 4 to (for example) 20 and run it, how can I be sure it really is 20x slowed down?</p>
<p>Also, I would like to know, if it is possible to do such simulated "slow down" to the GPU in similar way?</p>
<p>Thanks for any advice.</p>
| 0debug
|
How do I make make/ninja limit parallelism based on memory pressure? : <p>If I use <code>make -j2</code>, it builds fine, but under-utilizes CPU:</p>
<p><a href="https://i.stack.imgur.com/gYhxt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gYhxt.png" alt="j2"></a></p>
<p>If I use <code>make -j4</code>, it builds fast, but for some particular template-heavy files it consumes a lot of memory, slowing down entire system and build process as well due to swapping out to HDD:</p>
<p><a href="https://i.stack.imgur.com/qKxol.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qKxol.png" alt="j4"></a></p>
<p>How do I make it automatically limit number of parallel tasks based on memory, like this:</p>
<p><a href="https://i.stack.imgur.com/KN4jW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KN4jW.png" alt="enter image description here"></a></p>
<p>, so that it builds the project at maximum rate, but slows down in some places to avoid hitting memory wall?</p>
<p>Ideas:</p>
<ul>
<li>Use <code>-l</code> and artificially adjust load average if memory is busy (load average grows naturally when system is already in trouble).</li>
<li>Makes memory allocation syscalls (like sbrk(2) or mmap(2)) or page faults keep process hanged until memory gets reclaimed by finished jobs instead of swapping out other processes. Deadlock-prone unfortunately...</li>
</ul>
| 0debug
|
Passing props as parameter to the onClick event : I am working on a React project. I am having a div in my component. I give a key to this div using uuid.v4() function (generates random number). Now when I click this div, I want to send this key as a parameter to click event. I am not able to solve how to sent the key to the click event when they are of same component. I am trying to do it like this
<div className="img-scroll">
{this.state.imageSearchResults.items.map((item, ind) => {
return <div className="person-image"
key={uuid.v4()}
onClick={()=>{this.onGoogleImageSelect()}}
style={{backgroundImage:`url(${item.link})`}}>
</div>
})}
</div>
click event function
onGoogleImageSelect(e){
console.log(e.target.key)
}
This gives me error
Uncaught TypeError: Cannot read property 'target' of undefined
How can I send that key to the click event?
| 0debug
|
void axisdev88_init (ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
{
CPUState *env;
DeviceState *dev;
SysBusDevice *s;
qemu_irq irq[30], nmi[2], *cpu_irq;
void *etraxfs_dmac;
struct etraxfs_dma_client *eth[2] = {NULL, NULL};
int kernel_size;
int i;
int nand_regs;
int gpio_regs;
ram_addr_t phys_ram;
ram_addr_t phys_intmem;
if (cpu_model == NULL) {
cpu_model = "crisv32";
}
env = cpu_init(cpu_model);
qemu_register_reset(main_cpu_reset, env);
phys_ram = qemu_ram_alloc(ram_size);
cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
phys_intmem = qemu_ram_alloc(INTMEM_SIZE);
cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
phys_intmem | IO_MEM_RAM);
nand_state.nand = nand_init(NAND_MFR_STMICRO, 0x39);
nand_regs = cpu_register_io_memory(nand_read, nand_write, &nand_state);
cpu_register_physical_memory(0x10000000, 0x05000000, nand_regs);
gpio_state.nand = &nand_state;
gpio_regs = cpu_register_io_memory(gpio_read, gpio_write, &gpio_state);
cpu_register_physical_memory(0x3001a000, 0x5c, gpio_regs);
cpu_irq = cris_pic_init_cpu(env);
dev = qdev_create(NULL, "etraxfs,pic");
qdev_prop_set_ptr(dev, "interrupt_vector", &env->interrupt_vector);
qdev_init(dev);
s = sysbus_from_qdev(dev);
sysbus_mmio_map(s, 0, 0x3001c000);
sysbus_connect_irq(s, 0, cpu_irq[0]);
sysbus_connect_irq(s, 1, cpu_irq[1]);
for (i = 0; i < 30; i++) {
irq[i] = qdev_get_gpio_in(dev, i);
}
nmi[0] = qdev_get_gpio_in(dev, 30);
nmi[1] = qdev_get_gpio_in(dev, 31);
etraxfs_dmac = etraxfs_dmac_init(0x30000000, 10);
for (i = 0; i < 10; i++) {
etraxfs_dmac_connect(etraxfs_dmac, i, irq + 7 + i, i & 1);
}
eth[0] = etraxfs_eth_init(&nd_table[0], 0x30034000, 1);
if (nb_nics > 1)
eth[1] = etraxfs_eth_init(&nd_table[1], 0x30036000, 2);
etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
etraxfs_dmac_connect_client(etraxfs_dmac, 1, eth[0] + 1);
if (eth[1]) {
etraxfs_dmac_connect_client(etraxfs_dmac, 6, eth[1]);
etraxfs_dmac_connect_client(etraxfs_dmac, 7, eth[1] + 1);
}
sysbus_create_varargs("etraxfs,timer", 0x3001e000, irq[0x1b], nmi[1], NULL);
sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
for (i = 0; i < 4; i++) {
sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000,
irq[0x14 + i]);
}
if (kernel_filename) {
uint64_t entry, high;
int kcmdline_len;
kernel_size = load_elf(kernel_filename, -0x80000000LL,
&entry, NULL, &high, 0, ELF_MACHINE, 0);
bootstrap_pc = entry;
if (kernel_size < 0) {
kernel_size = load_image_targphys(kernel_filename, 0x40004000,
ram_size);
bootstrap_pc = 0x40004000;
env->regs[9] = 0x40004000 + kernel_size;
}
env->regs[8] = 0x56902387;
if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
if (kcmdline_len > 256) {
fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
exit(1);
}
env->regs[10] = 0x87109563;
env->regs[11] = 0x40000000;
pstrcpy_targphys(env->regs[11], 256, kernel_cmdline);
}
}
env->pc = bootstrap_pc;
printf ("pc =%x\n", env->pc);
printf ("ram size =%ld\n", ram_size);
}
| 1threat
|
static void sd_reset(SDState *sd)
{
uint64_t size;
uint64_t sect;
if (sd->blk) {
blk_get_geometry(sd->blk, §);
} else {
sect = 0;
}
size = sect << 9;
sect = sd_addr_to_wpnum(size) + 1;
sd->state = sd_idle_state;
sd->rca = 0x0000;
sd_set_ocr(sd);
sd_set_scr(sd);
sd_set_cid(sd);
sd_set_csd(sd, size);
sd_set_cardstatus(sd);
sd_set_sdstatus(sd);
if (sd->wp_groups)
g_free(sd->wp_groups);
sd->wp_switch = sd->blk ? blk_is_read_only(sd->blk) : false;
sd->wpgrps_size = sect;
sd->wp_groups = bitmap_new(sd->wpgrps_size);
memset(sd->function_group, 0, sizeof(sd->function_group));
sd->erase_start = 0;
sd->erase_end = 0;
sd->size = size;
sd->blk_len = 0x200;
sd->pwd_len = 0;
sd->expecting_acmd = false;
}
| 1threat
|
Animation Proble m CSS : Hover doesnt work. https://jsfiddle.net/j52qz6v4/ .When mouse hover the div , animation must stop and never start again.I dont want to use jquery
.box:hover { -webkit-animation-play-state: paused;}
| 0debug
|
bool st_set_trace_file(const char *file)
{
st_set_trace_file_enabled(false);
free(trace_file_name);
if (!file) {
if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) {
trace_file_name = NULL;
return false;
}
} else {
if (asprintf(&trace_file_name, "%s", file) < 0) {
trace_file_name = NULL;
return false;
}
}
st_set_trace_file_enabled(true);
return true;
}
| 1threat
|
How to get text between data and comma in a string? Python 3 : I am parsing text from a website, where I got string: "Some Event 21.08.2019—31.08.2019 Standart (1+1) , Some text" or something same. I need to get text beetween last data and comma, here is "Standart (1+1)" slice. How to do that? I use Python 3
str1 = "Some Event 21.08.2019—31.08.2019 Standart (1+1) , Some text"
Answer: str2 = "Standart (1+1)"
| 0debug
|
static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
{
AVStream *st = c->fc->streams[c->fc->nb_streams-1];
MOVStreamContext *sc = st->priv_data;
unsigned int i, entries;
int64_t duration=0;
int64_t total_sample_count=0;
get_byte(pb);
get_be24(pb);
entries = get_be32(pb);
dprintf(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
if(entries >= UINT_MAX / sizeof(*sc->stts_data))
return -1;
sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data));
if (!sc->stts_data)
return AVERROR(ENOMEM);
sc->stts_count = entries;
for(i=0; i<entries; i++) {
int sample_duration;
int sample_count;
sample_count=get_be32(pb);
sample_duration = get_be32(pb);
sc->stts_data[i].count= sample_count;
sc->stts_data[i].duration= sample_duration;
dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
duration+=(int64_t)sample_duration*sample_count;
total_sample_count+=sample_count;
}
st->nb_frames= total_sample_count;
if(duration)
st->duration= duration;
return 0;
}
| 1threat
|
Spring boot - number of backup log files restricted to 7 : <p>In our <strong>spring-boot</strong> project we are using <strong>slf4j</strong> for logging purpose. Below are configuration which we have added in <strong>application.properties</strong> file</p>
<pre><code>logging.file=/opt/logs/my_log.log
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.level.nl.yestelecom.boss=DEBUG
logging.level.com.github.isrsal.logging.LoggingFilter=DEBUG
</code></pre>
<p>It <strong>generates only 7 backup files</strong> (my_log.log.1, my_log.log.2 ..., my_log.log.7) with each file of size <strong>10.5MB</strong> and after that logging is not happening at all. </p>
<p>Is there any way to change this behavior? </p>
<p>We looked into available properties of spring-boot but, didn't find anything. Any suggestion is appreciated.</p>
| 0debug
|
connection.query('SELECT * FROM users WHERE username = ' + input_string)
| 1threat
|
Batch - How to create a command with set/p and if : <p>i need help for extracting variable from set/p
i explain : </p>
<pre><code>set/p command=
:: THE %COMMAND% IS : setname mirtex
if "%command%"=="setname %name%" goto test
:test
echo your name is %name%
</code></pre>
<p>so i would like to extract my name "mirtex" like the echo mirtex
Thanks</p>
| 0debug
|
is there any way to run this applet code and why is my code wrong please help me guys :
import java.applet.*;
import java.awt.Graphics;
public class App extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Hello World", 20, 20);
}
}
| 0debug
|
basic SQL: selecting AVG() values depending two columns : I want to get AVG values depending two columns value.
Here is my table example [example][1];
And this is what i need to [get][2];
I'm using that code to get required data but it gives me average for issue not isssue and owner
and here is my code;
select issue, owner, AVG(time) from myTable group by issue, owner
Any suggestion about that?
[1]: http://i.stack.imgur.com/ptSqg.png
[2]: http://i.stack.imgur.com/ZZK28.png
| 0debug
|
object twitterBootstrap is not a member of package views.html.helper : <p>Read from stdout: D:\PROJECTS\test\SimpleRequest5\app\views\products\editProduct.scala.html:11: object twitterBootstrap is not a member of package views.html.helper
D:\PROJECTS\test\SimpleRequest5\app\views\products\editProduct.scala.html:11: object twitterBootstrap is not a member of package views.html.helper
Read from stdout: <h2>@Messages("products.form")</h2>
<h2>@Messages("products.form")</h2>
Read from stdout: ^
^</p>
| 0debug
|
C++: Binary Heap : <p>I'm working on a C++ implementation of a Binary Heap, but I'm having some issues getting started. Here's a snippet of my code:</p>
<pre><code>class binaryHeap {
public:
// Constructor
binaryHeap(int _capacity)
{
// initializes the binary heap with a capacity, size, and space in memory
_size = 0;
_n = ceil(pow(2, log10(_capacity)/log10(2)));
_heap = new int[_n];
}
~binaryHeap(void)
{
delete[] _heap;
}
/* Omitted: insert, remove, size, capacity functions
Not necessary to the issue I'm having */
private:
int _size;
int _capacity;
int _n;
int *_heap;
};
</code></pre>
<p>In the main.cpp file, when I write the following line:</p>
<pre><code>struct BinaryHeap heap(10);
</code></pre>
<p>I get the error: <em>Variable has incomplete type 'struct BinaryHeap'</em>. Any ideas what is causing this?</p>
| 0debug
|
Why I cannot receive the content of arraylist : <p>I am currently struggling to fix the outcome of my code.</p>
<p>I am supposed to add a list from menu and then display the list. However, I cannot retrieve its content, rather I receive its memory value (I guess?).</p>
<p>Studentclass </p>
<pre><code> private int number;
private String author;
private String title;
public Student() {
}
public Student(int number, String title, String author) {
this.number = number;
this.title = title;
this.author = author;
}
public int getNumber() {
return number;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public void setNumber(int number) {
this.number = number;
}
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public String ToString() {
return "Number: " + number + "\tTitle: " + title + "\tAuthor: " + author;
}
</code></pre>
<p>Mainclass</p>
<pre><code>import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Student> newStudents = new ArrayList<Student>();
System.out.println("Please select a number from the options below \n");
while (true) {
// Give the user a list of their options
System.out.println("1: Add a student to the list.");
System.out.println("2: Remove a student from the list.");
System.out.println("3: Display all students in the list.");
// Get the user input
int userChoice = input.nextInt();
switch (userChoice) {
case 1:
addStudents(newStudents);
break;
case 2:
//removeStudent(newStudents);
break;
case 3:
displayStudent(newStudents);
break;
}
}
}
public static void addStudents(ArrayList<Student> newStudents) {
Scanner input = new Scanner(System.in);
Student newStudent = new Student();
System.out.print("Please enter number: ");
newStudent.setNumber(input.nextInt());
System.out.print("Please enter title: ");
newStudent.setTitle(input.next());
System.out.print("Please enter author: ");
newStudent.setAuthor(input.next());
if (newStudents.size() <= 100) {
newStudents.add(newStudent);
System.out.println("Student added\n");
} else {
System.out.println("\n Student interface is full!");
}
}
}
private static void displayStudent(ArrayList<Student> newStudents) {
for (Student e : newStudents) {
System.out.println(e);
}
}
}
</code></pre>
<p>Output:</p>
<blockquote>
<p>1: Add a student to the list.</p>
<p>2: Remove a student from the list.</p>
<p>3: Display all students in the list.</p>
<p>3</p>
<p><strong>Student@6b2acb7a</strong></p>
</blockquote>
<p>Why @6b2babc7a?</p>
<p>Thank you for your kind help and attention. I'm roughly new to programming, and Java is my first language. So, I'd highly appreciate the help and clarification.</p>
| 0debug
|
What if I use 1 million IPv6 addresses per second then how long would it take to exhaust all the addresses? : <p>if I use 1 million IPv6 addresses per second then how long would it take to exhaust all the addresses. Explain </p>
| 0debug
|
Encrypt / Decrypt in C# using Certificate : <p>I'm having trouble finding a good example in encrypting / decrypting strings in C# <em>using a certificate</em>. I was able to find and implement an example of <strong>signing</strong> and validating a signature, as shown below. Could someone point me to an easy, similar example for encryption?</p>
<pre><code>private static string Sign(RSACryptoServiceProvider privateKey, string content)
{
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding ();
byte[] data = encoding.GetBytes(content);
byte[] hash = sha1.ComputeHash(data);
// Sign the hash
var signature = privateKey.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
return Convert.ToBase64String(signature);
}
public static bool Verify(RSACryptoServiceProvider publicKey, string content, string hashString)
{
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding ();
byte[] data = encoding.GetBytes(content);
byte[] hash = sha1.ComputeHash(data);
return publicKey.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), Convert.FromBase64String(hashString));
}
</code></pre>
| 0debug
|
calculating occurances of values in an input stream : I am a college student who is currently learning programming. one of the problem statements given to us was:
user inputs an integer n followed by n different integers. Without using arrays or strings, find the number which occurs the most number of times in the input stream.
we are required to use the simplecpp package which is basically easier commands than standard c++. for example we write repeat(n) to get a for loop with n iterations.
What can i do to solve the problem?.
I thought of creating a number like 10101010[number]10101010[number2]... to store the input and then splitting but this fails to solve the problem.
we are not allowed to use anything like while loops or string manipulation to solve the problem.the only solutions i could think of were using the string method and then manipulating the string but apparently that is not allowed.
Any method to do this and such other problems where input cannot be stored in an array?
| 0debug
|
Hey everyone, how do i sum up all the fractions in a loop in python : Id like to calculate the sum of the following numbers using a loop
1/3 + 3/5 + 5/7 + . . . + 95/97 + 97/99
Print the sum
So far this is what I wrote but I could only get it to print the fractions
s = ''
for j in range(30, 0, -1):
s += "{}/{} + ".format(31-j, j)
sum = +=j
print sum
| 0debug
|
Javascript ES6 - Enums inside classes used outside like a static enum : <p>I'd like to ask if it's possible to add an enum similar to:</p>
<pre><code>STATES = {
WIP: "Work in progress",
ONLINE: "Online",
ONLINE_MODIFIED: "Online, modified",
HIDDEN: "Hidden"
}
</code></pre>
<p>inside a Class, and be able to use it in some other file with something similar to: <code>object.updateState(Class.STATES.HIDDEN)</code> without having to construct a new object like <code>boxObject.updateState(new Box().STATES.HIDDEN)</code></p>
<p>Thank you.</p>
| 0debug
|
how to delete file you don't know it's location with batch file : how to delete a file with batch/command line you don't know it's location "text.txt" for example
| 0debug
|
static int mpegts_resync(ByteIOContext *pb)
{
int c, i;
for(i = 0;i < MAX_RESYNC_SIZE; i++) {
c = url_fgetc(pb);
if (c < 0)
return -1;
if (c == 0x47) {
url_fseek(pb, -1, SEEK_CUR);
return 0;
}
}
return -1;
}
| 1threat
|
leaflet multi geojson nested overlays control : i have 3 separated geojson files ,each one contains a featurecollection of polygons
first one for regions the second for provinces and last for communes.
so the scenario is
for each region on click or zoom
show provinces in the clicked region then same thing with procinces,
im using leaflet for interactive map
im stuck on how to link every region with their provinces ....
is there any way to detect nested polygons ...
do i need a database or server side analysis
thanks
| 0debug
|
Ubuntu 18.04 add gpg key failed with gpg-agent not found error : <p>trying to migrate our base image to the stable Ubuntu 18.04, when we try to add our gpg key, getting this error:</p>
<pre><code>root@77ff14f29cab:/# apt-key add apt-key.gpg
gpg: failed to start agent '/usr/bin/gpg-agent': No such file or directory
gpg: can't connect to the agent: No such file or directory
gpg: failed to start agent '/usr/bin/gpg-agent': No such file or directory
gpg: can't connect to the agent: No such file or directory
</code></pre>
| 0debug
|
How to calculate how many time passed from the date with timezone? : I get from the server date with this format:
2016-05-27 17:33:43+0400
Now, I want to detect, how many time passed since that date? For example `1 day 5 hours 10 minutes 20 seconds`.
How can I do it? I know how to calculate this from the timestamp, but do not know how to convert this to timestamp.
Can anyone help me with it?
| 0debug
|
static ssize_t nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply,
int len)
{
NBDClient *client = req->client;
int csock = client->sock;
ssize_t rc, ret;
qemu_co_mutex_lock(&client->send_lock);
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read,
nbd_restart_write, client);
client->send_coroutine = qemu_coroutine_self();
if (!len) {
rc = nbd_send_reply(csock, reply);
} else {
socket_set_cork(csock, 1);
rc = nbd_send_reply(csock, reply);
if (rc >= 0) {
ret = qemu_co_send(csock, req->data, len);
if (ret != len) {
rc = -EIO;
}
}
socket_set_cork(csock, 0);
}
client->send_coroutine = NULL;
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
qemu_co_mutex_unlock(&client->send_lock);
return rc;
}
| 1threat
|
How to convert numbers written in words to digits in Java? : <p>Does anyone know how to convert something like <code>quatre-vingt mille quatre cent quatre-vingt-dix-sept</code> to <code>80497</code> in Java?</p>
| 0debug
|
static void monitor_start_input(void)
{
readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
}
| 1threat
|
How can i sort it : <pre><code>[{TIME21=0, TIME22=2, TIME23=0, TIME12=0, TIME13=1, LOAN_AMT=500, TIME10=0, TIME20=0, TIME11=1, TIME17=0, TIME9=2, TIME16=0, TIME15=0, TIME14=1, TIME5=0, REG_DT=20170517, TIME6=0, TIME19=0, TIME7=0, TIME18=1, TIME8=4, TIME1=0, TIME2=0, TIME3=0, TIME4=0, TIME0=0}, {TIME21=3, TIME22=2, TIME23=3, TIME12=6, TIME13=7, LOAN_AMT=1000, TIME10=8, TIME20=2, TIME11=6, TIME17=6, TIME9=7, TIME16=2, TIME15=7, TIME14=5, TIME5=0, REG_DT=20170517, TIME6=1, TIME19=1, TIME7=3, TIME18=1, TIME8=5, TIME1=0, TIME2=1, TIME3=0, TIME4=0, TIME0=3}]
</code></pre>
<p>This is a list,the form is List>, i want to sort it let it show like TIME1,TIME2......,how i should to do it, and the TIME1 like this that it type is BigDecimal, this is my code,but it dose not worked</p>
<pre><code>for (Map<String, Object> dataMap : chartData) {
List<Object> objs = new ArrayList<Object>();
for (final Map.Entry<String, Object> entry : dataMap.entrySet()) {
Collections.sort(chartData,new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
BigDecimal s1 = (BigDecimal) o1.get(entry.getKey());
BigDecimal s2 = (BigDecimal) o2.get(entry.getKey());
int result = s1.compareTo(s2);
if (result < 0) {
System.out.println("a < b");
return 1;
}else {
System.out.println("a>b");
return -1;
}
}
});
}
}
</code></pre>
| 0debug
|
static void store_slice16_c(uint16_t *dst, const uint16_t *src,
int dst_linesize, int src_linesize,
int width, int height, int log2_scale,
const uint8_t dither[8][8])
{
int y, x;
#define STORE16(pos) do { \
temp = ((src[x + y*src_linesize + pos] << log2_scale) + (d[pos]>>1)) >> 5; \
if (temp & 0x400) \
temp = ~(temp >> 31); \
dst[x + y*dst_linesize + pos] = temp; \
} while (0)
for (y = 0; y < height; y++) {
const uint8_t *d = dither[y];
for (x = 0; x < width; x += 8) {
int temp;
STORE16(0);
STORE16(1);
STORE16(2);
STORE16(3);
STORE16(4);
STORE16(5);
STORE16(6);
STORE16(7);
}
}
}
| 1threat
|
C# How to send currect date format from dateTimePicker to MySQL : This is the format used in my MySql database: 2018-04-22.
In my C# form, I pick the value form dataTimePicker:
String data1 = dataTimePicker1.Text;
Then send it with parameter:
cmd.Parameters.Add("@data1", MySqlDbType.Date).Value = data1;
I changed dataTimePicker1 custom format to: `yyyy-MM-dd` but it seems it still sends the wrong format: `An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll`
| 0debug
|
R Data-Frame: Get Maximum of Variable B condititional on Variable A : <p>I am searching for an efficient and fast way to do the following:
I have a data frame with, say, 2 variables, A and B, where the values for A can occur several times:</p>
<pre><code>mat<-data.frame('VarA'=rep(seq(1,10),2),'VarB'=rnorm(20))
VarA VarB
1 0.95848233
2 -0.07477916
3 2.08189370
4 0.46523827
5 0.53500190
6 0.52605101
7 -0.69587974
8 -0.21772252
9 0.29429577
10 3.30514605
1 0.84938361
2 1.13650996
3 1.25143046
</code></pre>
<p>Now I want to get a vector giving me for every unique value of VarA</p>
<pre><code>unique(mat$VarA)
</code></pre>
<p>the maximum of VarB conditional on VarA.
In the example here that would be</p>
<pre><code>1 0.95848233
2 1.13650996
3 2.08189370
etc...
</code></pre>
<p>My data-frame is very big so I want to avoid the use of loops. </p>
| 0debug
|
Convert int to BigDecimal with decimal - Java : <p>I'm having a hard time figuring out how to convert this. Here is what I want:</p>
<pre><code>int i = 5900;
BigDecimal bD = new BigDecimal(i);
</code></pre>
<p>I need bD to be 59.00 but I can't figure out how to get this result. All I've been able to get is 5900 as type BigDecimal. Any suggestion would help, thanks.</p>
| 0debug
|
Xcode 8 return height= 1000 and Width =1000 for UIview (actual size is (328,40)) : <p>Since i installed Xcode 8, i am in trouble.
I didnt get the correct value for each or any UIView.</p>
<p>I also got the constraint alert for UIView. So i update it.
But view returns 1000 as width or height.
I tried or search a lot. But didnt got any proper solution.
pls help me.</p>
| 0debug
|
static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
unsigned size)
{
IMXEPITState *s = IMX_EPIT(opaque);
uint32_t reg = offset >> 2;
uint64_t oldcr;
DPRINTF("(%s, value = 0x%08x)\n", imx_epit_reg_name(reg), (uint32_t)value);
switch (reg) {
case 0:
oldcr = s->cr;
s->cr = value & 0x03ffffff;
if (s->cr & CR_SWR) {
imx_epit_reset(DEVICE(s));
} else {
imx_epit_set_freq(s);
}
if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
if (s->cr & CR_ENMOD) {
if (s->cr & CR_RLD) {
ptimer_set_limit(s->timer_reload, s->lr, 1);
ptimer_set_limit(s->timer_cmp, s->lr, 1);
} else {
ptimer_set_limit(s->timer_reload, TIMER_MAX, 1);
ptimer_set_limit(s->timer_cmp, TIMER_MAX, 1);
}
}
imx_epit_reload_compare_timer(s);
ptimer_run(s->timer_reload, 0);
if (s->cr & CR_OCIEN) {
ptimer_run(s->timer_cmp, 0);
} else {
ptimer_stop(s->timer_cmp);
}
} else if (!(s->cr & CR_EN)) {
ptimer_stop(s->timer_reload);
ptimer_stop(s->timer_cmp);
} else if (s->cr & CR_OCIEN) {
if (!(oldcr & CR_OCIEN)) {
imx_epit_reload_compare_timer(s);
ptimer_run(s->timer_cmp, 0);
}
} else {
ptimer_stop(s->timer_cmp);
}
break;
case 1:
if (value & 0x01) {
s->sr = 0;
imx_epit_update_int(s);
}
break;
case 2:
s->lr = value;
if (s->cr & CR_RLD) {
ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW);
ptimer_set_limit(s->timer_cmp, s->lr, 0);
} else if (s->cr & CR_IOVW) {
ptimer_set_count(s->timer_reload, s->lr);
}
imx_epit_reload_compare_timer(s);
break;
case 3:
s->cmp = value;
imx_epit_reload_compare_timer(s);
break;
default:
IPRINTF("Bad offset %x\n", reg);
break;
}
}
| 1threat
|
Set password on Zip file using DotNetZip : <p>I'm using <a href="https://www.nuget.org/packages/DotNetZip/" rel="noreferrer">DotNetZip</a> to zip my files, but I need to set a password in zip.</p>
<p>I tryed:</p>
<pre><code>public void Zip(string path, string outputPath)
{
using (ZipFile zip = new ZipFile())
{
zip.AddDirectory(path);
zip.Password = "password";
zip.Save(outputPath);
}
}
</code></pre>
<p>But the output zip not have password.</p>
<p>The parameter <code>path</code>has a subfolder for exemple:
<code>path = c:\path\</code>
and inside path I have <code>subfolder</code></p>
<p>What is wrong?</p>
| 0debug
|
BlockAIOCB *ide_issue_trim(BlockDriverState *bs,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockCompletionFunc *cb, void *opaque)
{
TrimAIOCB *iocb;
iocb = qemu_aio_get(&trim_aiocb_info, bs, cb, opaque);
iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb);
iocb->ret = 0;
iocb->qiov = qiov;
iocb->i = -1;
iocb->j = 0;
ide_issue_trim_cb(iocb, 0);
return &iocb->common;
}
| 1threat
|
Call java method from other class (servlet) : I want to call a method from my Servlet but I think I messed something up with the declaration.
It says
> " The method println(boolean) in the type Printwriter is not
> applicable for the arguments (void)"
.
Here is a part of my servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String Name = request.getParamter("name");
Printwriter = p=response.getWriter();
Names n = new Names();
n.setName(Name);
p.println(Names.theName());
And here is my other class
... (getter and setter for Name) ...
public void theName(){ if(Name.equals("Josh"){ System.out.println("Hi Josh, what's up?")}
if(Name.equals("Peter"){System.out.printlkn("Hi Peter, how are you?")}
}
| 0debug
|
Putting a new value into a Map if not present, or adding it if it is : <p>I have a <code>java.util.Map<Foo, Double></code> for a key-type class <code>Foo</code>. Let's call the instance of the map <code>map</code>.</p>
<p>I want to add {<code>foo</code>, <code>f</code>} (<code>foo</code> is an instance of <code>Foo</code>, and <code>f</code> a <code>Double</code>) to that map. But if the key <code>foo</code> is already present I want to sum <code>f</code> to the current value in that map.</p>
<p>Currently I use</p>
<pre><code>Double current = map.get(foo);
f += current == null ? 0.0 : current;
map.put(foo, f);
</code></pre>
<p>But is there a funky way of doing this in Java 8, such as using <code>Map#merge</code>, and <code>Double::sum</code>?</p>
<p>Regrettably I can't figure it out.</p>
<p>Thank you.</p>
| 0debug
|
Programmatically Call on a mobile number without user interaction and without user confirmation prompt in Swift / Objective C : How to call on a mobile number without user interaction and without user confirmation prompt in Swift / Objective C.
| 0debug
|
Is there a proper way of resetting a component's initial data in vuejs? : <p>I have a component with a specific set of starting data:</p>
<pre><code>data: function (){
return {
modalBodyDisplay: 'getUserInput', // possible values: 'getUserInput', 'confirmGeocodedValue'
submitButtonText: 'Lookup', // possible values 'Lookup', 'Yes'
addressToConfirm: null,
bestViewedByTheseBounds: null,
location:{
name: null,
address: null,
position: null
}
}
</code></pre>
<p>This is data for a modal window, so when it shows I want it to start with this data. If the user cancels from the window I want to reset all of the data to this. </p>
<p>I know I can create a method to reset the data and just manually set all of the data properties back to their original:</p>
<pre><code>reset: function (){
this.modalBodyDisplay = 'getUserInput';
this.submitButtonText = 'Lookup';
this.addressToConfirm = null;
this.bestViewedByTheseBounds = null;
this.location = {
name: null,
address: null,
position: null
};
}
</code></pre>
<p>But this seems really sloppy. It means that if I ever make a change to the component's data properties I'll need to make sure I remember to update the reset method's structure. That's not absolutely horrible since it's a small modular component, but it makes the optimization portion of my brain scream. </p>
<p>The solution that I thought would work would be to grab the initial data properties in a <code>ready</code> method and then use that saved data to reset the components:</p>
<pre><code>data: function (){
return {
modalBodyDisplay: 'getUserInput',
submitButtonText: 'Lookup',
addressToConfirm: null,
bestViewedByTheseBounds: null,
location:{
name: null,
address: null,
position: null
},
// new property for holding the initial component configuration
initialDataConfiguration: null
}
},
ready: function (){
// grabbing this here so that we can reset the data when we close the window.
this.initialDataConfiguration = this.$data;
},
methods:{
resetWindow: function (){
// set the data for the component back to the original configuration
this.$data = this.initialDataConfiguration;
}
}
</code></pre>
<p>But the <code>initialDataConfiguration</code> object is changing along with the data (which makes sense because in the read method our <code>initialDataConfiguration</code> is getting the scope of the data function. </p>
<p>Is there a way of grabbing the initial configuration data without inheriting the scope? </p>
<p>Am I overthinking this and there's a better/easier way of doing this? </p>
<p>Is hardcoding the initial data the only option?</p>
| 0debug
|
simple poker program (Draw same cards) : First, i must say you sorry for my english.
I'm learning Java for my own and i have this problem:
I created a poker program, and always AI and me draws Ace of Spades (5 each) all the rounds. I let you the code and thanks so much!
import java.io.IOException;
import java.util.Scanner;
public class poker {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int score1 = 0,score2 = 0;
for(int i=0; i<10; i++){
int[][] previous_cards = new int[0][2];
int[][] hand1 = generate_hand(previous_cards);
int[][] sorted1 = sort_hand(hand1);
System.out.println("Round "+(i+1)+": ");
System.out.print(" Your hand: ");
print_hand(sorted1);
int identify_hand1 = identify_hand(sorted1);
System.out.print(" ");
print_identify_hand(identify_hand1);
System.out.println();
int[][] hand2 = generate_hand(hand1);
int[][] sorted2 = sort_hand(hand2);
System.out.print(" Computer hand: ");
print_hand(sorted2);
int identify_hand2 = identify_hand(sorted2);
System.out.print(" ");
print_identify_hand(identify_hand2);
System.out.println();
int compared = compare_hands(sorted1,sorted2);
if(compared==-1)
System.out.println(" You win this round!");
else if(compared==1)
System.out.println(" The computer wins this round!");
else System.out.println("Draw!");
score1 += (compared<0)?1:0;
score2 += (compared>0)?1:0;
System.out.println(" Score: You:"+score1+" - Computer:"+score2);
input.nextLine();
}
if(score1<score2)
System.out.println("The computer won with: "+score2+"-"+score1+".");
else if(score1==score2)
System.out.println("Draw: "+score1+"-"+score2+".");
else System.out.println("You won with: "+score1+"-"+score2+".");
}
public static int[][] generate_hand(int[][] previous_cards){
int[][] hand = new int[5][2];
return hand;
}
public static int[] generate_card(){
int[] card = new int[2];
card[0] = (int) (Math.random()*13 + 2);
card[1] = (int) (Math.random()*4 + 1);
return card;
}
public static int compare_2_cards(int[] card1, int[] card2){
return 0;
}
public static void print_hand(int[][] hand){
System.out.print(card_to_String(hand[0])+", ");
System.out.print(card_to_String(hand[1])+", ");
System.out.print(card_to_String(hand[2])+", ");
System.out.print(card_to_String(hand[3])+", ");
System.out.print(card_to_String(hand[4]));
}
public static String card_to_String(int[] c){
String card = "";
if(2<=c[0] && c[0]<=10)
card += c[0];
else if(c[0]==11) card += "Jack";
else if(c[0]==12) card += "Queen";
else if(c[0]==13) card += "king";
else card += "Ace";
card += " of ";
if(c[1]==1) card += "hearts";
else if(c[1]==2) card += "diamonds";
else if(c[1]==2) card += "clubs";
else card += "spades";
return card;
}
public static int[][] sort_hand(int[][] hand){
int[][] sorted = new int[5][2];
return sorted;
}
public static void print_identify_hand(int identify_hand){
if(identify_hand==1)
System.out.print("(straight flush)");
else if(identify_hand==2)
System.out.print("(four of a kind)");
else if(identify_hand==3)
System.out.print("(full house)");
else if(identify_hand==3)
System.out.print("(four of a kind)");
else if(identify_hand==4)
System.out.print("(flush)");
else if(identify_hand==5)
System.out.print("(straight)");
else if(identify_hand==6)
System.out.print("(three of a kind)");
else if(identify_hand==7)
System.out.print("(two pairs)");
else if(identify_hand==8)
System.out.print("(one pair)");
else
System.out.print("(nothing - high hand comparison)");
}
public static int compare_hands(int[][] hand1,int[][] hand2){
// IMPLEMENT: compare 2 cards
return 1;
}
public static int identify_hand(int[][] hand){
if(hand[0][1]==hand[1][1] && hand[1][1]==hand[2][1] && hand[2][1]==hand[3][1] && hand[3][1]==hand[4][1] && // compare that they have the same suit
hand[0][0]+1==hand[1][0] && hand[1][0]+1==hand[2][0] && hand[2][0]+1==hand[3][0] && hand[3][0]+1==hand[4][0]) // compare card numbers
return 1;
if(hand[0][0]==hand[1][0] && hand[1][0]==hand[2][0] && hand[2][0]==hand[3][0]) // compare card numbers
return 2;
if(hand[1][0]==hand[2][0] && hand[2][0]==hand[3][0] && hand[3][0]==hand[4][0]) // compare card numbers
return 2;
return 9;
}
}
| 0debug
|
static int get_uint32_equal(QEMUFile *f, void *pv, size_t size,
VMStateField *field)
{
uint32_t *v = pv;
uint32_t v2;
qemu_get_be32s(f, &v2);
if (*v == v2) {
return 0;
error_report("%" PRIx32 " != %" PRIx32, *v, v2);
return -EINVAL;
| 1threat
|
How to import moment.js in ES6 using npm? : <p>I am using angular js and nodejs along with ES6. I want to import the moment.js in the angular js code. I did <code>'npm install moment --save'</code></p>
<p>Now I am able to see moment.js file in moment folder which is inside node modules. </p>
<p>and in my app.js file I have wriiten like this</p>
<pre><code>'import moment from 'moment';
</code></pre>
<p>But if search something with date range It is showing error in console. Can anybody help me how to do this..?</p>
| 0debug
|
Sorting through list and storing different variables : So I'm using pandas to read from a row of data that looks like this:
0 overcast
1 overcast
2 overcast
3 overcast
4 rainy
5 rainy
6 rainy
7 rainy
8 rainy
9 sunny
10 sunny
11 sunny
12 sunny
13 sunny
And I wish to store overcast (first entry) as a variable, and then iterate through the list until there is a contrasting variable, and store that one also. This should assign any other contrasting variables along the way until until the end of the list.
So in this case, I should end up with 3 variables. 0 = overcast, 1 = rainy, 2 = sunny but I want this to work just as well if there are five different conditions in a classifier, not just two or three.
I'm having a hard time figuring out the best way to do this or maybe there is something in pandas that does this for me that I'm missing?
| 0debug
|
RxJS5 finalize operator not called : <p>I'm trying to trigger a callback when all my observables are executed. In my other, older project i used <code>finally</code> like so and that worked like a charm: </p>
<pre><code>this.myService.callDummy()
.finally(() => console.log('Works!'))
.subscribe(result => ...)
</code></pre>
<p>But now I'm using a newer version of RxJS with <strong>Pipeable operators</strong>, but the <code>finally</code> call (now renamed to <code>finalize</code>) never gets executed. There is little information to be found and I'm not sure what I'm doing wrong.</p>
<pre><code>combineLatest(
this.route.queryParams,
this.myService.callDummy1(),
this.myService.callDummy2()
)
.pipe(finalize(() => console.log('Does not work!')))
.subscribe(results => ...);
</code></pre>
<p>Any help is appreciated.</p>
| 0debug
|
START_TEST(unterminated_sq_string)
{
QObject *obj = qobject_from_json("'abc");
fail_unless(obj == NULL);
}
| 1threat
|
Wait for state to update when using hooks : <p>How do I wait for state to update using Hooks. When I submit my form I need to check if <code>termsValidation</code> is false before running some additional code. If the state has just changed it doesn't pick up on this. </p>
<pre><code>import React, { useState } from 'react';
export default function Signup() {
const [terms, setTerms] = useState('');
const [termsValidation, setTermsValidation] = useState(false);
function handleSubmit(e) {
e.preventDefault();
if (!terms) {
setTermsValidation(true);
} else {
setTermsValidation(false);
}
if (!termsValidation) {
console.log('run something here');
}
}
return (
<div>
<form>
<input type="checkbox" id="terms" name="terms" checked={terms} />
<button type="submit" onClick={handleSubmit}>
Sign up
</button>
</form>
</div>
);
}
</code></pre>
| 0debug
|
Ruby implementation array#flatten : I need to implement ruby Array#Flatten. This implementation remove all the nested arrays
a = [ 1, 2, [3, [4, 5] ] ]
def my_flatten(arr)
arr.reduce([]) do |result, item|
item.is_a?(Array) ? result + my_flatten(item) : result << item
end
end
my_flatten(a) #=> [1, 2, 3, 4, 5]
Prompt how to implement such behavior
a.flatten(1) #=> [1, 2, 3, [4, 5]]
| 0debug
|
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 error on my calendar program : My program compiles correctly but I get the same message when I try and run it.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package displaycalendars;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DisplayCalendars {
public static void main(String[] args){
Calendar calendar = new GregorianCalendar
(Integer.valueOf(args[1]),
Integer.valueOf(args[0])-1,1);
printHeader(calendar);
printData(calendar);
}
public static void printHeader(Calendar calendar){
int month = calendar.get(Calendar.MONTH)+1;
String monthName = "";
switch(month){
case 1: monthName="January";
break;
case 2: monthName="February";
break;
case 3: monthName="March";
break;
case 4: monthName="April";
break;
case 5: monthName="May";
break;
case 6: monthName="June";
break;
case 7: monthName="July";
break;
case 8: monthName="August";
break;
case 9: monthName="September";
break;
case 10: monthName="October";
break;
case 11: monthName="November";
break;
case 12: monthName="December";
break;
}
System.out.println(" "+monthName+ ", " +calendar.get(Calendar.YEAR));
System.out.println("--------------------");
System.out.println("Sun Mon Tue Wed Thu Fri Sat");
}
public static void printData(Calendar calendar){
int dayinWeek=calendar.get(Calendar.DAY_OF_WEEK);
for (int i = 1; i< (dayinWeek); i++)
{
System.out.print(" ");
}
for (int i = 1; i <
(Calendar.DATE); i++){
System.out.print("\n");
calendar.add(Calendar.DATE,1);
}
System.out.printf("%4d",calendar.get(Calendar.DATE));
}
}
| 0debug
|
Issue with comma in jquery : I've this Function that retrive a xml for a listview content :
function xmlParser(data) {
xml = data;
$('#load').fadeOut();
$(xml).find("item").each(function () {
var title = $(this).find("title").text();
var description = $(this).find("description").text();
$("#list").append('<li><h2>' + title + '</h2><font style="white-space:normal; font-size: x-small;">' + description + '</font><br/><button onclick="window.plugins.socialsharing.share('+"'description'"+')">share!</button></li>');
});
$('#list').listview('refresh');
}
after the content, the button share is display but when I click on, it displays 'description' and not the content of the variable (a text).
I think my commas ' and " are misplaced but I can't fix it.
Some help will apreciated.
| 0debug
|
int ff_init_me(MpegEncContext *s){
MotionEstContext * const c= &s->me;
int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
if(FFMIN(s->avctx->dia_size, s->avctx->pre_dia_size) < -ME_MAP_SIZE){
av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n");
return -1;
}
if(s->me_method!=ME_ZERO && s->me_method!=ME_EPZS && s->me_method!=ME_X1 && s->avctx->codec_id != AV_CODEC_ID_SNOW){
av_log(s->avctx, AV_LOG_ERROR, "me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n");
return -1;
}
c->avctx= s->avctx;
if(cache_size < 2*dia_size && !c->stride){
av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
}
ff_set_cmp(&s->dsp, s->dsp.me_pre_cmp, c->avctx->me_pre_cmp);
ff_set_cmp(&s->dsp, s->dsp.me_cmp, c->avctx->me_cmp);
ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, c->avctx->me_sub_cmp);
ff_set_cmp(&s->dsp, s->dsp.mb_cmp, c->avctx->mb_cmp);
c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA);
if(s->flags&CODEC_FLAG_QPEL){
c->sub_motion_search= qpel_motion_search;
c->qpel_avg= s->dsp.avg_qpel_pixels_tab;
if(s->no_rounding) c->qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
else c->qpel_put= s->dsp.put_qpel_pixels_tab;
}else{
if(c->avctx->me_sub_cmp&FF_CMP_CHROMA)
c->sub_motion_search= hpel_motion_search;
else if( c->avctx->me_sub_cmp == FF_CMP_SAD
&& c->avctx-> me_cmp == FF_CMP_SAD
&& c->avctx-> mb_cmp == FF_CMP_SAD)
c->sub_motion_search= sad_hpel_motion_search;
else
c->sub_motion_search= hpel_motion_search;
}
c->hpel_avg= s->dsp.avg_pixels_tab;
if(s->no_rounding) c->hpel_put= s->dsp.put_no_rnd_pixels_tab;
else c->hpel_put= s->dsp.put_pixels_tab;
if(s->linesize){
c->stride = s->linesize;
c->uvstride= s->uvlinesize;
}else{
c->stride = 16*s->mb_width + 32;
c->uvstride= 8*s->mb_width + 16;
}
if(s->codec_id != AV_CODEC_ID_SNOW){
if((c->avctx->me_cmp&FF_CMP_CHROMA)){
s->dsp.me_cmp[2]= zero_cmp;
}
if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){
s->dsp.me_sub_cmp[2]= zero_cmp;
}
c->hpel_put[2][0]= c->hpel_put[2][1]=
c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
}
if(s->codec_id == AV_CODEC_ID_H261){
c->sub_motion_search= no_sub_motion_search;
}
return 0;
}
| 1threat
|
static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MP3Context *mp3 = s->priv_data;
if (pkt->stream_index == mp3->audio_stream_idx) {
if (mp3->pics_to_write) {
AVPacketList *pktl = av_mallocz(sizeof(*pktl));
if (!pktl)
return AVERROR(ENOMEM);
pktl->pkt = *pkt;
pktl->pkt.buf = av_buffer_ref(pkt->buf);
if (!pktl->pkt.buf) {
av_freep(&pktl);
return AVERROR(ENOMEM);
}
if (mp3->queue_end)
mp3->queue_end->next = pktl;
else
mp3->queue = pktl;
mp3->queue_end = pktl;
} else
return mp3_write_audio_packet(s, pkt);
} else {
int ret;
if (s->streams[pkt->stream_index]->nb_frames == 1) {
av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d,"
" ignoring.\n", pkt->stream_index);
}
if (!mp3->pics_to_write || s->streams[pkt->stream_index]->nb_frames >= 1)
return 0;
if ((ret = ff_id3v2_write_apic(s, &mp3->id3, pkt)) < 0)
return ret;
mp3->pics_to_write--;
if (!mp3->pics_to_write &&
(ret = mp3_queue_flush(s)) < 0)
return ret;
}
return 0;
}
| 1threat
|
How can i get the male count and female count seperately : here is my code `public function getmaletofemaleCountById()
{
$select=$this->select();
$select->from($this->_name, array('count(*) AS candidateSum','count(candidate_gender='.MALE.') AS male','count(candidate_gender='.FEMALE.') AS female'));
$select->joinLeft(array('batch'=>DBPREFIX.'batch'), 'batch.batch_training_center=tc_id AND batch.deleted=0', array());
$select->joinLeft(array('candidate'=>DBPREFIX.'candidate'), 'candidate.candidate_batch_id=batch.batch_id AND candidate.deleted=0', array());
$select->where( 'tc_id = ?',$this->tc_id);
$select->where( 'candidate_gender != ?',3);
//$select->group('candidate_gender');
die($select);
return $this->fetchRow($select);
}`
| 0debug
|
import heapq
def k_smallest_pairs(nums1, nums2, k):
queue = []
def push(i, j):
if i < len(nums1) and j < len(nums2):
heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
push(0, 0)
pairs = []
while queue and len(pairs) < k:
_, i, j = heapq.heappop(queue)
pairs.append([nums1[i], nums2[j]])
push(i, j + 1)
if j == 0:
push(i + 1, 0)
return pairs
| 0debug
|
Square button with rounded shape on hover : <p>I designed a call to action box. The idea is to add on hover a rounded shape. This shape need to slide in smoothly. Does anyone an idea or an example how to program this?</p>
<p><a href="https://i.stack.imgur.com/hp4Gi.png" rel="nofollow noreferrer">Normal state on the left. On the right the hover state. </a></p>
<p>Thanks for now.</p>
<p>Arjan</p>
| 0debug
|
static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LibSpeexContext *s = avctx->priv_data;
int16_t *output;
int ret, consumed = 0;
s->frame.nb_samples = s->frame_size;
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
output = (int16_t *)s->frame.data[0];
if (speex_bits_remaining(&s->bits) < 5 ||
speex_bits_peek_unsigned(&s->bits, 5) == 0x1F) {
if (!buf || !buf_size) {
*got_frame_ptr = 0;
return buf_size;
}
speex_bits_read_from(&s->bits, buf, buf_size);
consumed = buf_size;
}
ret = speex_decode_int(s->dec_state, &s->bits, output);
if (ret <= -2) {
av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
return AVERROR_INVALIDDATA;
}
if (avctx->channels == 2)
speex_decode_stereo_int(output, s->frame_size, &s->stereo);
*got_frame_ptr = 1;
*(AVFrame *)data = s->frame;
return consumed;
}
| 1threat
|
No debuggable processes in android studio when connected with phone which runs android 6.0 : <p>everyone!</p>
<p>I got so confused by android studio.
when I plug in my phone to debug apps,logcat can detect my phone,but i can not choose process. It said "no debuggable processes",not common "no debuggable applications".</p>
<p>My phone is samsung s5 (android 6.0),rooted.</p>
<p>Any ideas?</p>
<p>Thanks!</p>
| 0debug
|
import math
def surfacearea_cone(r,h):
l = math.sqrt(r * r + h * h)
SA = math.pi * r * (r + l)
return SA
| 0debug
|
void qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
void *opaque)
{
aio_set_fd_handler(qemu_aio_context, fd, io_read, io_write, io_flush,
opaque);
qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
}
| 1threat
|
static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
SVQ1EncContext *const s = avctx->priv_data;
AVFrame *const p = avctx->coded_frame;
int i, ret;
if (!pkt->data &&
(ret = av_new_packet(pkt, s->y_block_width * s->y_block_height *
MAX_MB_BYTES * 3 + FF_MIN_BUFFER_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) {
av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
return -1;
}
if (!s->current_picture->data[0]) {
ret = ff_get_buffer(avctx, s->current_picture, 0);
if (ret < 0)
return ret;
}
if (!s->last_picture->data[0]) {
ret = ff_get_buffer(avctx, s->last_picture, 0);
if (ret < 0)
return ret;
}
if (!s->scratchbuf) {
s->scratchbuf = av_malloc(s->current_picture->linesize[0] * 16 * 2);
if (!s->scratchbuf)
return AVERROR(ENOMEM);
}
FFSWAP(AVFrame*, s->current_picture, s->last_picture);
init_put_bits(&s->pb, pkt->data, pkt->size);
p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ?
AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;
p->quality = pict->quality;
svq1_write_header(s, p->pict_type);
for (i = 0; i < 3; i++)
if (svq1_encode_plane(s, i,
pict->data[i],
s->last_picture->data[i],
s->current_picture->data[i],
s->frame_width / (i ? 4 : 1),
s->frame_height / (i ? 4 : 1),
pict->linesize[i],
s->current_picture->linesize[i]) < 0)
return -1;
while (put_bits_count(&s->pb) & 31)
put_bits(&s->pb, 1, 0);
flush_put_bits(&s->pb);
pkt->size = put_bits_count(&s->pb) / 8;
if (p->pict_type == AV_PICTURE_TYPE_I)
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
}
| 1threat
|
void av_opt_set_defaults2(void *s, int mask, int flags)
{
#endif
const AVOption *opt = NULL;
while ((opt = av_opt_next(s, opt)) != NULL) {
#if FF_API_OLD_AVOPTIONS
if ((opt->flags & mask) != flags)
continue;
#endif
switch (opt->type) {
case AV_OPT_TYPE_CONST:
break;
case AV_OPT_TYPE_FLAGS:
case AV_OPT_TYPE_INT:
case AV_OPT_TYPE_INT64:
av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
break;
case AV_OPT_TYPE_DOUBLE:
case AV_OPT_TYPE_FLOAT: {
double val;
val = opt->default_val.dbl;
av_opt_set_double(s, opt->name, val, 0);
}
break;
case AV_OPT_TYPE_RATIONAL: {
AVRational val;
val = av_d2q(opt->default_val.dbl, INT_MAX);
av_opt_set_q(s, opt->name, val, 0);
}
break;
case AV_OPT_TYPE_STRING:
case AV_OPT_TYPE_IMAGE_SIZE:
case AV_OPT_TYPE_PIXEL_FMT:
case AV_OPT_TYPE_SAMPLE_FMT:
av_opt_set(s, opt->name, opt->default_val.str, 0);
break;
case AV_OPT_TYPE_BINARY:
break;
default:
av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
}
}
}
| 1threat
|
static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
{
IscsiLun *iscsilun = bs->opaque;
Error *local_err = NULL;
if (iscsilun->type != TYPE_DISK) {
return -ENOTSUP;
}
iscsi_readcapacity_sync(iscsilun, &local_err);
if (local_err != NULL) {
error_free(local_err);
return -EIO;
}
if (offset > iscsi_getlength(bs)) {
return -EINVAL;
}
if (iscsilun->allocationmap != NULL) {
g_free(iscsilun->allocationmap);
iscsilun->allocationmap =
bitmap_new(DIV_ROUND_UP(bs->total_sectors,
iscsilun->cluster_sectors));
}
return 0;
}
| 1threat
|
static SocketAddressLegacy *unix_build_address(const char *path)
{
SocketAddressLegacy *saddr;
saddr = g_new0(SocketAddressLegacy, 1);
saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
saddr->u.q_unix.data->path = g_strdup(path);
return saddr;
}
| 1threat
|
Can i do network connections in doInBackground of AsyncTask : <p>Can i do network connections in doInBackground of AsyncTask. If not what to use for this.</p>
<p>As per i know i can use intentService for long running operation but this will lead some complexity in code.</p>
<p>Please suggest for the same.</p>
| 0debug
|
Finding latest record from duplicates : I have a customers table with ID's and some date/time columns. But those ID's have duplicates and i just want to Analyse distinct values.
I tried using groupby but this makes the process very slow.
Due to data sensitivity can't share it.
Any suggestions would be helpful.
| 0debug
|
From where will hibenate fetch values : Can someone clarify my doubt.
public class MyClass{
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name + " Hello";
}
public static void main() {
User u = new User();
u.setName("Yethendra");
}
}
If I try to insert u record into db using hibernate, for name column which is the value that will be inserted?
Yethendra (OR) Yethendra Hello.
| 0debug
|
static int config_out_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
TInterlaceContext *tinterlace = ctx->priv;
int i;
tinterlace->vsub = desc->log2_chroma_h;
outlink->w = inlink->w;
outlink->h = tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD || tinterlace->mode == MODE_MERGEX2?
inlink->h*2 : inlink->h;
if (tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD || tinterlace->mode == MODE_MERGEX2)
outlink->sample_aspect_ratio = av_mul_q(inlink->sample_aspect_ratio,
av_make_q(2, 1));
if (tinterlace->mode == MODE_PAD) {
uint8_t black[4] = { 16, 128, 128, 16 };
int i, ret;
if (ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts))
black[0] = black[3] = 0;
ret = av_image_alloc(tinterlace->black_data, tinterlace->black_linesize,
outlink->w, outlink->h, outlink->format, 16);
if (ret < 0)
return ret;
for (i = 0; i < 4 && tinterlace->black_data[i]; i++) {
int h = i == 1 || i == 2 ? AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h) : outlink->h;
memset(tinterlace->black_data[i], black[i],
tinterlace->black_linesize[i] * h);
}
}
if ((tinterlace->flags & TINTERLACE_FLAG_VLPF
|| tinterlace->flags & TINTERLACE_FLAG_CVLPF)
&& !(tinterlace->mode == MODE_INTERLEAVE_TOP
|| tinterlace->mode == MODE_INTERLEAVE_BOTTOM)) {
av_log(ctx, AV_LOG_WARNING, "low_pass_filter flags ignored with mode %d\n",
tinterlace->mode);
tinterlace->flags &= ~TINTERLACE_FLAG_VLPF;
tinterlace->flags &= ~TINTERLACE_FLAG_CVLPF;
}
tinterlace->preout_time_base = inlink->time_base;
if (tinterlace->mode == MODE_INTERLACEX2) {
tinterlace->preout_time_base.den *= 2;
outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){2,1});
outlink->time_base = av_mul_q(inlink->time_base , (AVRational){1,2});
} else if (tinterlace->mode == MODE_MERGEX2) {
outlink->frame_rate = inlink->frame_rate;
outlink->time_base = inlink->time_base;
} else if (tinterlace->mode != MODE_PAD) {
outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){1,2});
outlink->time_base = av_mul_q(inlink->time_base , (AVRational){2,1});
}
for (i = 0; i<FF_ARRAY_ELEMS(standard_tbs); i++){
if (!av_cmp_q(standard_tbs[i], outlink->time_base))
break;
}
if (i == FF_ARRAY_ELEMS(standard_tbs) ||
(tinterlace->flags & TINTERLACE_FLAG_EXACT_TB))
outlink->time_base = tinterlace->preout_time_base;
if (tinterlace->flags & TINTERLACE_FLAG_CVLPF) {
tinterlace->lowpass_line = lowpass_line_complex_c;
if (ARCH_X86)
ff_tinterlace_init_x86(tinterlace);
} else if (tinterlace->flags & TINTERLACE_FLAG_VLPF) {
tinterlace->lowpass_line = lowpass_line_c;
if (ARCH_X86)
ff_tinterlace_init_x86(tinterlace);
}
av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n", tinterlace->mode,
(tinterlace->flags & TINTERLACE_FLAG_CVLPF) ? "complex" :
(tinterlace->flags & TINTERLACE_FLAG_VLPF) ? "linear" : "off",
inlink->h, outlink->h);
return 0;
}
| 1threat
|
static void coroutine_fn stream_run(void *opaque)
{
StreamBlockJob *s = opaque;
StreamCompleteData *data;
BlockBackend *blk = s->common.blk;
BlockDriverState *bs = blk_bs(blk);
BlockDriverState *base = s->base;
int64_t sector_num = 0;
int64_t end = -1;
uint64_t delay_ns = 0;
int error = 0;
int ret = 0;
int n = 0;
void *buf;
if (!bs->backing) {
goto out;
}
s->common.len = bdrv_getlength(bs);
if (s->common.len < 0) {
ret = s->common.len;
goto out;
}
end = s->common.len >> BDRV_SECTOR_BITS;
buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
if (!base) {
bdrv_enable_copy_on_read(bs);
}
for (sector_num = 0; sector_num < end; sector_num += n) {
bool copy;
block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, delay_ns);
if (block_job_is_cancelled(&s->common)) {
break;
}
copy = false;
ret = bdrv_is_allocated(bs, sector_num,
STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
if (ret == 1) {
} else if (ret >= 0) {
ret = bdrv_is_allocated_above(backing_bs(bs), base,
sector_num, n, &n);
if (ret == 0 && n == 0) {
n = end - sector_num;
}
copy = (ret == 1);
}
trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE,
n * BDRV_SECTOR_SIZE, ret);
if (copy) {
ret = stream_populate(blk, sector_num * BDRV_SECTOR_SIZE,
n * BDRV_SECTOR_SIZE, buf);
}
if (ret < 0) {
BlockErrorAction action =
block_job_error_action(&s->common, s->on_error, true, -ret);
if (action == BLOCK_ERROR_ACTION_STOP) {
n = 0;
continue;
}
if (error == 0) {
error = ret;
}
if (action == BLOCK_ERROR_ACTION_REPORT) {
break;
}
}
ret = 0;
s->common.offset += n * BDRV_SECTOR_SIZE;
if (copy && s->common.speed) {
delay_ns = ratelimit_calculate_delay(&s->limit,
n * BDRV_SECTOR_SIZE);
}
}
if (!base) {
bdrv_disable_copy_on_read(bs);
}
ret = error;
qemu_vfree(buf);
out:
data = g_malloc(sizeof(*data));
data->ret = ret;
block_job_defer_to_main_loop(&s->common, stream_complete, data);
}
| 1threat
|
static void sub2video_update(InputStream *ist, AVSubtitle *sub)
{
int w = ist->sub2video.w, h = ist->sub2video.h;
AVFrame *frame = ist->sub2video.frame;
int8_t *dst;
int dst_linesize;
int num_rects, i;
int64_t pts, end_pts;
if (!frame)
return;
if (sub) {
pts = av_rescale_q(sub->pts + sub->start_display_time * 1000,
AV_TIME_BASE_Q, ist->st->time_base);
end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000,
AV_TIME_BASE_Q, ist->st->time_base);
num_rects = sub->num_rects;
} else {
pts = ist->sub2video.end_pts;
end_pts = INT64_MAX;
num_rects = 0;
}
if (sub2video_get_blank_frame(ist) < 0) {
av_log(ist->dec_ctx, AV_LOG_ERROR,
"Impossible to get a blank canvas.\n");
return;
}
dst = frame->data [0];
dst_linesize = frame->linesize[0];
for (i = 0; i < num_rects; i++)
sub2video_copy_rect(dst, dst_linesize, w, h, sub->rects[i]);
sub2video_push_ref(ist, pts);
ist->sub2video.end_pts = end_pts;
}
| 1threat
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.