problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
Need advice on a form i am making on a website :
<p><strong>Would you like to receive the Stay Safe newsletter</strong>
<select name="newsletter"><!-- dropdown box allows user to select if they want to receive newsletter-->
<option value="yes">Yes</option>
<option value="no">No</option>
</select></p>
<p><textarea name="message" id="address" placeholder="Address"></textarea></p>
<p><input type="email" name="email" placeholder="Valid email"></p>
<button class="smallButton" type="submit" >Send</button><!-- submission button to send the form-->
</form>
I need help with coding my form what i want it to do is only show
</select></p>
<p><textarea name="message" id="address" placeholder="Address"></textarea></p>
<p><input type="email" name="email" placeholder="Valid email"></p>
<button class="smallButton" type="submit" >Send</button><!-- submission button to send the form-->
</form>
based on them selecting yes in the drop down box but unsure how to do this any help would be greatly appreciated | 0debug |
Initializing constexpr with const: Different treatment for int and double : <p>The following code fails to compile <a href="https://ideone.com/ubg5sQ" rel="noreferrer">live on Ideone</a>:</p>
<pre><code>#include <iostream>
using namespace std;
int main() {
const double kPi = 3.14;
constexpr double kPi2 = 2.0*kPi;
cout << kPi2;
}
</code></pre>
<p>The error message is:</p>
<blockquote>
<pre><code>prog.cpp: In function 'int main()':
prog.cpp:6:30: error: the value of 'kPi' is not usable in a constant expression
constexpr double kPi2 = 2.0*kPi;
^
prog.cpp:5:15: note: 'kPi' was not declared 'constexpr'
const double kPi = 3.14;
</code></pre>
</blockquote>
<p>Substituting the <code>const</code> declaration for <code>kPi</code> with <code>constexpr</code>, <a href="https://ideone.com/B1fTB7" rel="noreferrer">it compiles successfully</a>.</p>
<p>On the other hand, when <code>int</code> is used instead of <code>double</code>, seems like <code>const</code> <a href="https://ideone.com/WiXnua" rel="noreferrer">plays well</a> with <code>constexpr</code>:</p>
<pre><code>#include <iostream>
using namespace std;
int main() {
const int k1 = 10;
constexpr int k2 = 2*k1;
cout << k2 << '\n';
return 0;
}
</code></pre>
<p>Why do <code>int</code> and <code>double</code> get different treatments for initializing a <code>constexpr</code> with <code>const</code>?<br>
Is this a bug in the Ideone compiler? Is this required by the C++ standard? Why is that?<br>
Was the above code UB?</p>
<p><strong>P.S.</strong> I tried with Visual Studio 2015 C++ compiler, and it compiles the first code snippet (initializing <code>constexpr</code> with <code>const</code>) just fine.</p>
| 0debug |
int object_property_get_enum(Object *obj, const char *name,
const char *strings[], Error **errp)
{
StringOutputVisitor *sov;
StringInputVisitor *siv;
int ret;
sov = string_output_visitor_new(false);
object_property_get(obj, string_output_get_visitor(sov), name, errp);
siv = string_input_visitor_new(string_output_get_string(sov));
string_output_visitor_cleanup(sov);
visit_type_enum(string_input_get_visitor(siv),
&ret, strings, NULL, name, errp);
string_input_visitor_cleanup(siv);
return ret;
}
| 1threat |
static void msix_table_mmio_write(void *opaque, target_phys_addr_t addr,
uint64_t val, unsigned size)
{
PCIDevice *dev = opaque;
int vector = addr / PCI_MSIX_ENTRY_SIZE;
bool was_masked;
was_masked = msix_is_masked(dev, vector);
pci_set_long(dev->msix_table + addr, val);
msix_handle_mask_update(dev, vector, was_masked);
}
| 1threat |
data not loading in gridview from radiobutton : i have a code that i intend to use the radio button to retrieve data from a table and load it on a grid view.but once i click on the radio button , no data is loaded in the grid view.below is my code.`enter code here` protected void Radiobuttonlist1_CheckedChange(Object sender, EventArgs e)
{
string Value = Radiobuttonlist1.SelectedItem.Value.ToString();
if (Value == "Patients")
{
string connect = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;
SqlConnection conn = new SqlConnection(connect);
conn.Open();
SqlCommand cmd = new SqlCommand("select PatientName,PatientCellPhone from CustomerInformation", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
else if(Value== "Suppliers")
{
string connect = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;
SqlConnection conn = new SqlConnection(connect);
conn.Open();
SqlCommand cmd = new SqlCommand("select VendorName,VendorPhone from VendorInformation", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
else if ( Value== "Employees")
{
string connect = TraceBizCommon.Configuration.ConfigSettings.ConnectionString;
SqlConnection conn = new SqlConnection(connect);
conn.Open();
SqlCommand cmd = new SqlCommand("select EmployeeName,EmployeeMobilePhone from PayrollEmployees", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
}` | 0debug |
static void sdhci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
SDHCIClass *k = SDHCI_CLASS(klass);
dc->vmsd = &sdhci_vmstate;
dc->props = sdhci_properties;
dc->reset = sdhci_generic_reset;
dc->realize = sdhci_realize;
k->reset = sdhci_reset;
k->mem_read = sdhci_read;
k->mem_write = sdhci_write;
k->send_command = sdhci_send_command;
k->can_issue_command = sdhci_can_issue_command;
k->data_transfer = sdhci_data_transfer;
k->end_data_transfer = sdhci_end_transfer;
k->do_sdma_single = sdhci_sdma_transfer_single_block;
k->do_sdma_multi = sdhci_sdma_transfer_multi_blocks;
k->do_adma = sdhci_do_adma;
k->read_block_from_card = sdhci_read_block_from_card;
k->write_block_to_card = sdhci_write_block_to_card;
k->bdata_read = sdhci_read_dataport;
k->bdata_write = sdhci_write_dataport;
}
| 1threat |
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
IOReadHandler *fd_read, void *opaque)
{
VLANClientState *vc, **pvc;
vc = qemu_mallocz(sizeof(VLANClientState));
if (!vc)
return NULL;
vc->fd_read = fd_read;
vc->opaque = opaque;
vc->vlan = vlan;
vc->next = NULL;
pvc = &vlan->first_client;
while (*pvc != NULL)
pvc = &(*pvc)->next;
*pvc = vc;
return vc;
}
| 1threat |
No need for state in React components if using Redux and React-Redux? : <p><strong>Managing state with React only</strong></p>
<p>I understand that if you're creating an application using React only, you will end up managing all of your state within different React components you create.</p>
<p><strong>Managing state with React and Redux</strong></p>
<p>If you decide to use Redux in combination with React, you can then move all of the state from each of your React components into the overall Redux application state. Each component that requires a slice of the Redux application state can then hook into the state via React-Redux's <code>connect</code> function.</p>
<p><strong>Question</strong></p>
<p>Does this mean that you no longer need to write any React components that deal with React's <code>state</code> (i.e. <code>this.setState</code>) since React-Redux is <code>connect</code>ing the React components with Redux state by passing data into the <code>container</code> component as <code>props</code>?</p>
| 0debug |
ODCIAggregateMerge without parallel_enabled : <p>These are quotes from <a href="https://docs.oracle.com/cd/B28359_01/appdev.111/b28425/aggr_functions.htm" rel="noreferrer">Oracle docs</a>:</p>
<blockquote>
<p>[Optional] Merge by combining the two aggregation contexts and return a single context. This operation combines the results of aggregation over subsets in order to obtain the aggregate over the entire set. This extra step can be required during <strong>either serial or parallel</strong> evaluation of an aggregate. If needed, it is performed before step 4: </p>
</blockquote>
<p>,</p>
<blockquote>
<p>The ODCIAggregateMerge() interface is invoked to compute super aggregate values in such rollup operations.</p>
</blockquote>
<p>We have an aggregate function, that we do NOT want to ever run in parallel.<br>
The reason is that the merging of contexts would be resource consuming and would force us to use different data structures than we are using now, effectively offseting any performance benefits from parallel execution.</p>
<p>Thus, we did <strong>not</strong> declare our function as <em>parallel_enabled</em>, and instead return ODCIconst.Error in ODCIAggregateMerge 'just in case'.</p>
<p>However, the first quote docs claim, that merge may occur even in serial evaluation.<br>
Super-aggregates (rollup, cube) are obvious examples, but are there any others?</p>
<p>I've been totally unable to reproduce it with simple group by, merge is never called without parallel_enabled and it seems that always only one context is created within the group. </p>
<p>Is it safe to assume that without the parallel_enabled set, merge will never be run?<br>
Have you ever seen a counterexample to that rule?</p>
| 0debug |
Pl/SQL: Get the last active day of a user in each year since he/she signed up : I have DATE logs for users when he/she was active.<br> I want to filter out his/hers last active day in each year, since he/she joined the service.
example:<br><b>
logged dates:<br>
12-1-2015<br>
1-7-2015<br>
21-12-2015<br>
1-1-2016<br>
2-2-2017<br>
9-9-2017<br>
12-10-2017<br>
30-12-2017<br></b>
expected Output:<br><b>
21-12-2015<br>
1-1-2016<br>
30-12-2017<br></b>
| 0debug |
how to pick from an array depending on a certain number : <p>Lets say you use indexOf on an array to find all cases that say apple. If it comes back with three cases at positons 1, 2 and 3. </p>
<p>Now lets say there is an array = [10, 20, 30 ,40 ,50 ,60 ,70 ,80 ,90 ,100]</p>
<p>is there a way to use them cases 1,2 and 3 which come to 6. So is there a a way to go to position 6 "70" and produce that number. Depending on what the indexOf provides, is there a way to select that number from the array. Also if the indexOF produced 3.5 would there be a way to get 35 aka position 3.5.</p>
| 0debug |
python's chain assignment with no regard to order : <p>I started to learn python but find something annoying </p>
<pre><code>In [82]: a = b = 8
In [83]: id(b)
Out[83]: 94772909397088
In [84]: id(a)
Out[84]: 94772909397088
In [86]: id(8)
Out[86]: 94772909397088
</code></pre>
<p>The result is anti-intuitive</p>
<p>b pointing 8 and a pointing b, b hold 8's address, a hold b's address. but they return the same result.</p>
<p>What's more, If change b</p>
<pre><code>In [88]: b = 9
In [89]: a
Out[89]: 8
</code></pre>
<p>b changed to 9 but a does not change.</p>
<p>So it make no difference `a= b= c= 9' or 'c=b=a=9'</p>
<p>How could wrap brain on this intuitively?</p>
| 0debug |
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String, int) : <p>I'm typing this code: </p>
<pre><code>import java.util.Calendar; //Required to get the instance of date on the computer
import java.util.Date; //Required if you want to store instances of the calendar in a varaible
import java.util.Scanner; //Required to collect input from the user
public class L01ManagingDate
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
System.out.println(cal);
System.out.println("The current date list printed out, but not stored " + cal.getTime());
Date dateNow = cal.getTime();
System.out.println("The current date list stored in a variable " + dateNow);
System.out.printf("%-22s %d%n" , "Year" , cal.get(Calendar.YEAR));
System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.MONTH));
System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.DAY_OF_MONTH));
System.out.printf("%-22s %d%n" , "Week" , cal.get(Calendar.DAY_OF_WEEK));
System.out.printf("%-22s %d%n" , "Day" , cal.get(Calendar.DAY_OF_YEAR));
System.out.printf("%-22s %d%n" , "Week" , cal.get(Calendar.WEEK_OF_YEAR));
System.out.printf("%-22s %d%n" , "Month" , cal.get(Calendar.WEEK_OF_MONTH));
System.out.printf("%-22s %d%n" , "Day of week in month" , cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.printf("%-22s %d%n" , "AM (0) or PM (1)" , cal.get(Calendar.AM_PM));
System.out.printf("%-22s %d%n" , "Hour" , cal.get(Calendar.HOUR_OF_DAY));
System.out.printf("%-22s %d%n" , "Minute" , cal.get(Calendar.MINUTE));
System.out.printf("%-22s %d%n" , "Second" , cal.get(Calendar.SECOND));
System.out.printf("%-22s %d%n" , "Millisecond" , cal.get(Calendar.MILLISECOND));
</code></pre>
<p>And i got this error on all my print Fs The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String, int)
Please help</p>
| 0debug |
how to get account details on clicking email address on particular person in android : how to get account details on clicking email address on particular person in android[how to get account details on clicking email address on particular person in android as used in google application YouTubeGo][1]
[1]: https://i.stack.imgur.com/gNIqS.png | 0debug |
Storage of user data : <p>When looking at how websites such as Facebook stores profile images, the URLs seem to use randomly generated value. For example, Google's Facebook page's profile picture page has the following URL:</p>
<pre><code>https://scontent-lhr3-1.xx.fbcdn.net/hprofile-xft1/v/t1.0-1/p160x160/11990418_442606765926870_215300303224956260_n.png?oh=28cb5dd4717b7174eed44ca5279a2e37&oe=579938A8
</code></pre>
<p>However why not just organise it like so:</p>
<pre><code>https://scontent-lhr3-1.xx.fbcdn.net/{{ profile_id }}/50x50.png
</code></pre>
<p>Clearly this would be much easier in terms of storage and simplicity. Am I missing something? Thanks.</p>
| 0debug |
static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
{
unsigned int i;
x86_def_t *def;
char *s = g_strdup(cpu_model);
char *featurestr, *name = strtok(s, ",");
uint32_t plus_features = 0, plus_ext_features = 0;
uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
uint32_t plus_kvm_features = 0, plus_svm_features = 0;
uint32_t minus_features = 0, minus_ext_features = 0;
uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
uint32_t minus_kvm_features = 0, minus_svm_features = 0;
uint32_t numvalue;
for (def = x86_defs; def; def = def->next)
if (!strcmp(name, def->name))
break;
if (kvm_enabled() && strcmp(name, "host") == 0) {
cpu_x86_fill_host(x86_cpu_def);
} else if (!def) {
goto error;
} else {
memcpy(x86_cpu_def, def, sizeof(*def));
}
plus_kvm_features = ~0;
add_flagname_to_bitmaps("hypervisor", &plus_features,
&plus_ext_features, &plus_ext2_features, &plus_ext3_features,
&plus_kvm_features, &plus_svm_features);
featurestr = strtok(NULL, ",");
while (featurestr) {
char *val;
if (featurestr[0] == '+') {
add_flagname_to_bitmaps(featurestr + 1, &plus_features,
&plus_ext_features, &plus_ext2_features,
&plus_ext3_features, &plus_kvm_features,
&plus_svm_features);
} else if (featurestr[0] == '-') {
add_flagname_to_bitmaps(featurestr + 1, &minus_features,
&minus_ext_features, &minus_ext2_features,
&minus_ext3_features, &minus_kvm_features,
&minus_svm_features);
} else if ((val = strchr(featurestr, '='))) {
*val = 0; val++;
if (!strcmp(featurestr, "family")) {
char *err;
numvalue = strtoul(val, &err, 0);
if (!*val || *err) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
x86_cpu_def->family = numvalue;
} else if (!strcmp(featurestr, "model")) {
char *err;
numvalue = strtoul(val, &err, 0);
if (!*val || *err || numvalue > 0xff) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
x86_cpu_def->model = numvalue;
} else if (!strcmp(featurestr, "stepping")) {
char *err;
numvalue = strtoul(val, &err, 0);
if (!*val || *err || numvalue > 0xf) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
x86_cpu_def->stepping = numvalue ;
} else if (!strcmp(featurestr, "level")) {
char *err;
numvalue = strtoul(val, &err, 0);
if (!*val || *err) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
x86_cpu_def->level = numvalue;
} else if (!strcmp(featurestr, "xlevel")) {
char *err;
numvalue = strtoul(val, &err, 0);
if (!*val || *err) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
if (numvalue < 0x80000000) {
numvalue += 0x80000000;
}
x86_cpu_def->xlevel = numvalue;
} else if (!strcmp(featurestr, "vendor")) {
if (strlen(val) != 12) {
fprintf(stderr, "vendor string must be 12 chars long\n");
goto error;
}
x86_cpu_def->vendor1 = 0;
x86_cpu_def->vendor2 = 0;
x86_cpu_def->vendor3 = 0;
for(i = 0; i < 4; i++) {
x86_cpu_def->vendor1 |= ((uint8_t)val[i ]) << (8 * i);
x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i);
x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i);
}
x86_cpu_def->vendor_override = 1;
} else if (!strcmp(featurestr, "model_id")) {
pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),
val);
} else if (!strcmp(featurestr, "tsc_freq")) {
int64_t tsc_freq;
char *err;
tsc_freq = strtosz_suffix_unit(val, &err,
STRTOSZ_DEFSUFFIX_B, 1000);
if (!*val || *err) {
fprintf(stderr, "bad numerical value %s\n", val);
goto error;
}
x86_cpu_def->tsc_khz = tsc_freq / 1000;
} else {
fprintf(stderr, "unrecognized feature %s\n", featurestr);
goto error;
}
} else if (!strcmp(featurestr, "check")) {
check_cpuid = 1;
} else if (!strcmp(featurestr, "enforce")) {
check_cpuid = enforce_cpuid = 1;
} else {
fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
goto error;
}
featurestr = strtok(NULL, ",");
}
x86_cpu_def->features |= plus_features;
x86_cpu_def->ext_features |= plus_ext_features;
x86_cpu_def->ext2_features |= plus_ext2_features;
x86_cpu_def->ext3_features |= plus_ext3_features;
x86_cpu_def->kvm_features |= plus_kvm_features;
x86_cpu_def->svm_features |= plus_svm_features;
x86_cpu_def->features &= ~minus_features;
x86_cpu_def->ext_features &= ~minus_ext_features;
x86_cpu_def->ext2_features &= ~minus_ext2_features;
x86_cpu_def->ext3_features &= ~minus_ext3_features;
x86_cpu_def->kvm_features &= ~minus_kvm_features;
x86_cpu_def->svm_features &= ~minus_svm_features;
if (check_cpuid) {
if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
goto error;
}
g_free(s);
return 0;
error:
g_free(s);
return -1;
}
| 1threat |
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
const uint8_t *buf_end = avpkt->data + avpkt->size;
int buf_size = avpkt->size;
QdrawContext * const a = avctx->priv_data;
AVFrame * const p= (AVFrame*)&a->pic;
uint8_t* outdata;
int colors;
int i;
uint32_t *pal;
int r, g, b;
if(p->data[0])
avctx->release_buffer(avctx, p);
p->reference= 0;
if(avctx->get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1;
outdata = a->pic.data[0];
if (buf_end - buf < 0x68 + 4)
buf += 0x68;
colors = AV_RB32(buf);
buf += 4;
if(colors < 0 || colors > 256) {
av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
return -1;
}
if (buf_end - buf < (colors + 1) * 8)
pal = (uint32_t*)p->data[1];
for (i = 0; i <= colors; i++) {
unsigned int idx;
idx = AV_RB16(buf);
buf += 2;
if (idx > 255) {
av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
buf += 6;
continue;
}
r = *buf++;
buf++;
g = *buf++;
buf++;
b = *buf++;
buf++;
pal[idx] = (r << 16) | (g << 8) | b;
}
p->palette_has_changed = 1;
if (buf_end - buf < 18)
buf += 18;
for (i = 0; i < avctx->height; i++) {
int size, left, code, pix;
const uint8_t *next;
uint8_t *out;
int tsize = 0;
out = outdata;
size = AV_RB16(buf);
buf += 2;
left = size;
next = buf + size;
while (left > 0) {
code = *buf++;
if (code & 0x80 ) {
pix = *buf++;
if ((out + (257 - code)) > (outdata + a->pic.linesize[0]))
break;
memset(out, pix, 257 - code);
out += 257 - code;
tsize += 257 - code;
left -= 2;
} else {
if ((out + code) > (outdata + a->pic.linesize[0]))
break;
if (buf_end - buf < code + 1)
memcpy(out, buf, code + 1);
out += code + 1;
buf += code + 1;
left -= 2 + code;
tsize += code + 1;
}
}
buf = next;
outdata += a->pic.linesize[0];
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = a->pic;
return buf_size;
} | 1threat |
Passing user id in the url : <p>I am trying to pass the userId in the url. This is what I have, but it giving me error.</p>
<pre><code><?php echo "<li><a href='edit.php?userId= .$row[id].'>Edit</a></li>"?>
</code></pre>
| 0debug |
Using a text file as the input for a program : <p>In a program, you can simulate a magic square by using a two-dimensional list. Write a Python program that tests whether or not a 3 by 3 grid is a valid magic square. The program reads the input from a text file named input.txt. Each line in the file contains exactly 9 numbers that correspond to the the second row, and the last three values correspond to the last row. </p>
<p>I am not struggling with how to create the program to check to see if the square is a magic square, but how do I read in the "input.txt" into the program when I run it?</p>
| 0debug |
ECMAScript 6 alternatives to collapse and responsible Bootstrap menus? : <p>I'm trying to create some responsible hamburger menus in Bootstrap 4 without jQuery, relying only on ECMAScript 6 and it's features. I wasn't able to find alternatives to Bootstrap's collapse.js and animation.js, so i decided to tackle this myself.</p>
<p>What is the preferred way of manipulating the DOM and animating the changes in ES6? </p>
| 0debug |
void arm_cpu_realize(ARMCPU *cpu)
{
CPUARMState *env = &cpu->env;
if (arm_feature(env, ARM_FEATURE_V7)) {
set_feature(env, ARM_FEATURE_VAPA);
set_feature(env, ARM_FEATURE_THUMB2);
set_feature(env, ARM_FEATURE_MPIDR);
if (!arm_feature(env, ARM_FEATURE_M)) {
set_feature(env, ARM_FEATURE_V6K);
} else {
set_feature(env, ARM_FEATURE_V6);
if (arm_feature(env, ARM_FEATURE_V6K)) {
set_feature(env, ARM_FEATURE_V6);
set_feature(env, ARM_FEATURE_MVFR);
if (arm_feature(env, ARM_FEATURE_V6)) {
set_feature(env, ARM_FEATURE_V5);
if (!arm_feature(env, ARM_FEATURE_M)) {
set_feature(env, ARM_FEATURE_AUXCR);
if (arm_feature(env, ARM_FEATURE_V5)) {
set_feature(env, ARM_FEATURE_V4T);
if (arm_feature(env, ARM_FEATURE_M)) {
set_feature(env, ARM_FEATURE_THUMB_DIV);
if (arm_feature(env, ARM_FEATURE_ARM_DIV)) {
set_feature(env, ARM_FEATURE_THUMB_DIV);
if (arm_feature(env, ARM_FEATURE_VFP4)) {
set_feature(env, ARM_FEATURE_VFP3);
if (arm_feature(env, ARM_FEATURE_VFP3)) {
set_feature(env, ARM_FEATURE_VFP);
register_cp_regs_for_features(cpu);
| 1threat |
def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit()) | 0debug |
How to change page title with routing in Angular application? : <p>Is there any npm module/ other way like <a href="https://github.com/nfl/react-helmet" rel="noreferrer">React-Helmet</a> that allows us to change page title as we route through our Angular application?</p>
<p>PS: I am using Angular 5.</p>
| 0debug |
Swift: Is there a way to get the running apps in IOS? : <p>Is there a way to get the running apps info or the action of openning the app in IOS? There is a way to do that in android with getRunningTasks, maybe there is a way to do that in ios?</p>
| 0debug |
Deserialize JSON to 2 different models : <p>Does Newtonsoft.JSON library have a simple way I can automatically deserialize JSON into 2 different Models/classes?</p>
<p>For example I get the JSON:</p>
<pre><code>[{
"guardian_id": "1453",
"guardian_name": "Foo Bar",
"patient_id": "938",
"patient_name": "Foo Bar",
}]
</code></pre>
<p>And I need de-serialize this to the following models:</p>
<pre><code>class Guardian {
[JsonProperty(PropertyName = "guardian_id")]
public int ID { get; set; }
[JsonProperty(PropertyName = "guardian_name")]
public int Name { get; set; }
}
class Patient {
[JsonProperty(PropertyName = "patient_id")]
public int ID { get; set; }
[JsonProperty(PropertyName = "patient_name")]
public int Name { get; set; }
}
</code></pre>
<p>Is there a simple way to deserialize this JSON into 2 Models without having to iterate over the JSON? Maybe JSON property ids will just work?</p>
<pre><code>Pair<Guardian, Patient> pair = JsonConvert.DeserializeObject(response.Content);
</code></pre>
| 0debug |
Jquery accordion like tabs : I'm using bootstrap and jquery accordion. I have to do a like style tabs using accordion. I mean, the clickable items should to be inline (like tabs style) and not like a list (one below the other).
Is there any way to do this? | 0debug |
webpack-bundle-analyzer is not working : <p>I run below command to create stats.json:</p>
<blockquote>
<p>ng build --prod --stats-json</p>
</blockquote>
<p>After this I am executing below code:</p>
<blockquote>
<p>webpack-bundle-analyzer dist/stats.json</p>
</blockquote>
<p>once I execute it I am receiving below error in my terminal:</p>
<blockquote>
<p>'webpack-bundle-analyzer' is not recognized as an internal or external
command, operable program or batch file.</p>
</blockquote>
<p>I have installed webpack-bundle-analyzer.</p>
<p>In Package.json file it's available </p>
<blockquote>
<p>"webpack-bundle-analyzer": "^2.11.1"</p>
</blockquote>
<p>Please help me to resolve.</p>
<p>Note : Stats.json is available in dist folder</p>
| 0debug |
Django annotate specific keys in json fields : <p>I'm using Django 1.9 and Postgres 9.5. I have a model (<code>MyModel</code>) with a <code>JSONField</code> (<code>django.contrib.postgres.fields</code>). The JSON value has the same structure in all the objects in the model.</p>
<pre><code>{
"key1": int_val_1,
"key2": int_val_2
}
</code></pre>
<p>I want to order my queryset by a value of a specified key in my <code>JSONField</code>. Something like</p>
<pre><code>MyModel.objects.annotate(val=F('jsonfield__key1')).order_by('val')
</code></pre>
<p>This does not work - i get the following error </p>
<pre><code>Cannot resolve keyword 'key1' into field. Join on 'jsonfield' not permitted.
</code></pre>
<p>Is there anyway i can achieve this?</p>
| 0debug |
How can I get a string from a 2d character array in C? : <p>The 2d array:</p>
<pre><code>char c[4][3]={{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'}};
</code></pre>
<p>As I wanted to get 'def' after running the program, I tried this code:</p>
<pre><code>printf("%s\n",c[1]);
</code></pre>
<p>However, the result was 'defghijkl\262'. What's wrong with my code?</p>
| 0debug |
Unable to write keys.dev.pub to: /home/ubuntu/.composer : <p>I'm following the instructions to install composer (<a href="https://getcomposer.org/download/](https://getcomposer.org/download/" rel="noreferrer">found here</a>). I just ran the line <code>php composer-setup.php</code> and the terminal returned:</p>
<pre><code>All settings correct for using Composer
Unable to write keys.dev.pub to: /home/ubuntu/.composer
</code></pre>
<p>I'm installing into a Ubuntu VM in Vagrant.</p>
| 0debug |
static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory,
hwaddr base,
qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
omap_clk clk)
{
struct omap_mpuio_s *s = (struct omap_mpuio_s *)
g_malloc0(sizeof(struct omap_mpuio_s));
s->irq = gpio_int;
s->kbd_irq = kbd_int;
s->wakeup = wakeup;
s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
omap_mpuio_reset(s);
memory_region_init_io(&s->iomem, NULL, &omap_mpuio_ops, s,
"omap-mpuio", 0x800);
memory_region_add_subregion(memory, base, &s->iomem);
omap_clk_adduser(clk, qemu_allocate_irq(omap_mpuio_onoff, s, 0));
return s;
}
| 1threat |
How to make your XAML views flexible and customizable for users? : <p>Our manager want the WPF application we are working on to be fully customizable for the user. So let's say there is a textbox on a page. He wants the user to be able to put it in any position he wants, make it have any color or fontsize he wants, etc. Right now the implementation for this is to store every property in a SQL database and then build the view in your code behind. </p>
<p>This is a terrible implementation in my opinion because it slows the entire process down. When I navigate pages there is a loading time of at least 10 seconds where the code behind gets all the properties, turns them into objects, implement the objects into a view and then create that view. I think there must be a better way to do this, because it's sucking up so much time and resources. Are there any better implementations for this?</p>
| 0debug |
"attempt to extract more than one element" from an R data.frame-like object : I have an object (here named `rld`) which looks a bit like a data.frame in that it has columns that can be accessed using `$` or `[[]]`.
I have a vector (here named `groups`) containing names of some of its columns (here 3 column names).
I generate strings based on combinations of elements in the columns as follows:
paste(rld[[groups[1]]], rld[[groups[2]]], rld[[groups[3]]], sep="-")
I would like to generalize this so that I don't need to know how many elements are in `groups`.
The following attempt fails:
> paste(rld[[groups]], collapse="-")
Error in normalizeDoubleBracketSubscript(i, x, exact = exact, error.if.nomatch = FALSE) :
attempt to extract more than one element
How to do this in an elegant way ? | 0debug |
Override readonly variable lldb swift : <p>Is there a way in lldb to overwrite a readonly variable.</p>
<p>For example if you had a struct</p>
<pre><code>struct Object {
let name: String
}
</code></pre>
<p>Doing the following in at a breakpoint in Xcode with lldb</p>
<pre><code>(lldb) expression object.name = "Tom"
</code></pre>
<p>Will result in</p>
<pre><code>error: <EXPR>:2:19: error: cannot assign to property: 'name' is a get-only property
</code></pre>
<p>I fully understand why this happens, just want to know if there is an easy way to get around this during debugging?</p>
<p>Please note this is in Swift & <strong>NOT</strong> Objective-C</p>
| 0debug |
How to insert a struct into a set and print the members of the set? : <p>I have to use the struct mov</p>
<pre><code>struct mov {
string src;
string dst;
};
</code></pre>
<p>where src is the source and dst is the destination. The purpose of the program is to analyze the pieces on a chessboard and generate all of the possible moves. The possible moves must be represented in a set but it must be a set of moves, so set. I've found some methods saying to implement a comparator but I have no clue if it works because when printing the set (using an iterator) I get errors because of the "<<" when printing I guess its conflicting with the comparator since it uses "<"???</p>
| 0debug |
static int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb,
unsigned int addr, int option)
{
sPAPRPHBVFIOState *svphb = SPAPR_PCI_VFIO_HOST_BRIDGE(sphb);
struct vfio_eeh_pe_op op = { .argsz = sizeof(op) };
int ret;
switch (option) {
case RTAS_EEH_DISABLE:
op.op = VFIO_EEH_PE_DISABLE;
break;
case RTAS_EEH_ENABLE: {
PCIHostState *phb;
PCIDevice *pdev;
phb = PCI_HOST_BRIDGE(sphb);
pdev = pci_find_device(phb->bus,
(addr >> 16) & 0xFF, (addr >> 8) & 0xFF);
if (!pdev) {
return RTAS_OUT_PARAM_ERROR;
}
op.op = VFIO_EEH_PE_ENABLE;
break;
}
case RTAS_EEH_THAW_IO:
op.op = VFIO_EEH_PE_UNFREEZE_IO;
break;
case RTAS_EEH_THAW_DMA:
op.op = VFIO_EEH_PE_UNFREEZE_DMA;
break;
default:
return RTAS_OUT_PARAM_ERROR;
}
ret = vfio_container_ioctl(&svphb->phb.iommu_as, svphb->iommugroupid,
VFIO_EEH_PE_OP, &op);
if (ret < 0) {
return RTAS_OUT_HW_ERROR;
}
return RTAS_OUT_SUCCESS;
}
| 1threat |
Element printed shows unexpected value : <p>This is my code. It calls a few functions but nothing that is related to the issue.</p>
<pre><code>int main()
{
srand((unsigned int)time(NULL)); //initializing srand
struct card *deckAr = createDeck(); //creating the struct card deck array
for (int i = 0; i < 100000; i++)
{
shuffleDeck(deckAr);
}
struct card *player1hand = (struct card*)malloc(sizeof(player1hand));
struct card *player2hand = (struct card*)malloc(sizeof(player2hand));
struct card *househand = (struct card*)malloc(sizeof(househand));
player1hand = (struct card*)realloc(player1hand, sizeof(player1hand) * 2);
player1hand[0] = deckAr[0];
player1hand[1] = deckAr[1];
printf("Card 1 %s of %s\n\n", valueName(player1hand[0].suit), suitName(player1hand[0].suit));
printf("Card 2 %s of %s\n\n", valueName(player1hand[1].suit), suitName(player1hand[1].suit));
printf("%s of %s\n", valueName(deckAr[0].value), suitName(deckAr[0].suit));
return 0;
}
</code></pre>
<p>Output:</p>
<pre><code>Card 1 Three of Hearts
Card 2 Three of Hearts
Ten of Hearts
</code></pre>
<p>Since nothing is manipulating deckAr, shouldn't deckAr[0] be the same as player1hand[0]?</p>
| 0debug |
How to extract query results of an SQL in a comma delimited string variable in Python : <p>I have to extract query results from an Oracle table as a comma delimited string in Python.</p>
<p>Thanks,</p>
| 0debug |
SQL SERVER and MS ACCESS 2016 : I have a Stored procedure with multiple value parameters set up in SQL server but I am not sure How to call in the Store procedure using a table in access that serves as parameters.
Below is the parameter table in access
ID |EMPLOYEE NB
---------------
1 | A
2 | B
3 | C
The parameters in SQL server is set up as delimited.
So it would be EXEC MySToreProcedure 'A,B,C' | 0debug |
Using macro definition vs const variable : <p>I have few questions about pre-processor macros. Here is an example of 2 different code pieces to talk about;</p>
<pre><code>tmp.h
#define DEFAULT_STRING "default_value"
tmp.cpp
void tmpFunc(std::string newValue){
m_stringValue = newValue;
if(newValue.isEmpty())
newValue = DEFAULT_STRING;
}
</code></pre>
<p>And the second version </p>
<pre><code>tmp.h
const std::string m_defaultValue = "default_value"
tmp.cpp
void tmpFunc(std::string newValue){
m_stringValue = newValue;
if(newValue.isEmpty())
newValue = m_defaultValue;
}
</code></pre>
<p>So my questions are;</p>
<ul>
<li>Does the first version increase the binary size (comparing the first second)?</li>
<li>Does the second version consume more memory (comparing the first one)?</li>
<li>What are the performance impacts of both implementations? Which should run faster and why?</li>
<li>Which is preferable/beneficial in which condition?</li>
<li>Is there any better way for implementation of setting the default value?</li>
</ul>
<p>Thanks.</p>
| 0debug |
How to make HTTP POST request with url encoded body in flutter? : <p>I'm trying to make an post request in flutter with content type as url encoded. When I write <code>body : json.encode(data)</code>, it encodes to plain text. </p>
<p>If I write <code>body: data</code> I get the error <code>type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' in type cast</code></p>
<p>This is the data object</p>
<pre><code>var match = {
"homeTeam": {"team": "Team A"},
"awayTeam": {"team": "Team B"}
};
</code></pre>
<p>And my request</p>
<pre><code>var response = await post(Uri.parse(url),
headers: {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
body: match,
encoding: Encoding.getByName("utf-8"));
</code></pre>
| 0debug |
float32 HELPER(ucf64_muls)(float32 a, float32 b, CPUUniCore32State *env)
{
return float32_mul(a, b, &env->ucf64.fp_status);
}
| 1threat |
static void set_enum(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
int *ptr = qdev_get_prop_ptr(dev, prop);
if (dev->state != DEV_STATE_CREATED) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
visit_type_enum(v, ptr, prop->info->enum_table,
prop->info->name, prop->name, errp);
}
| 1threat |
Datediff from 2 colums : I am trying to get to know the days between 2 dates. But it will only return me errors. I tried searching it but non of the things really helped me, I am hoping you guys can help a boy out right here.
The error I get with this code:
> Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or
> access violation: 1582 Incorrect parameter count in the call to native
> function 'DATEDIFF' in
> C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php:197 Stack trace: #0
> C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php(197):
> PDO->query('SELECT DATEDIFF...') #1 {main} thrown in
> C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php on line 197
[my code to display it several times in the table][1]
[The database][2]
The sql codes that are used:
$sql1 = "SELECT * FROM factuur
LEFT JOIN factuurregel ON factuur.Factuurnummer = factuurregel.Factuurnummer
LEFT JOIN gebruiker ON factuur.Klantcode = gebruiker.Klantcode
LEFT JOIN auto ON factuur.Kenteken = auto.Kenteken";
$sql2 = "SELECT DATEDIFF (day, Begindatum, Einddatum) AS Tijd from factuurregel;";
[1]: https://i.stack.imgur.com/5RIY4.png
[2]: https://i.stack.imgur.com/5KqHz.png | 0debug |
int boot_sector_init(char *fname)
{
int fd, ret;
size_t len = sizeof boot_sector;
fd = mkstemp(fname);
if (fd < 0) {
fprintf(stderr, "Couldn't open \"%s\": %s", fname, strerror(errno));
return 1;
}
if (strcmp(qtest_get_arch(), "ppc64") == 0) {
len = sprintf((char *)boot_sector, "\\ Bootscript\n%x %x c! %x %x c!\n",
LOW(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET,
HIGH(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
}
ret = write(fd, boot_sector, len);
close(fd);
if (ret != len) {
fprintf(stderr, "Could not write \"%s\"", fname);
return 1;
}
return 0;
}
| 1threat |
static int msrle_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MsrleContext *s = avctx->priv_data;
int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8;
s->buf = buf;
s->size = buf_size;
s->frame.reference = 3;
s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, &s->frame)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
if (pal) {
s->frame.palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
}
}
memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
if (avctx->height * istride == avpkt->size) {
int linesize = (avctx->width * avctx->bits_per_coded_sample + 7) / 8;
uint8_t *ptr = s->frame.data[0];
uint8_t *buf = avpkt->data + (avctx->height-1)*istride;
int i, j;
for (i = 0; i < avctx->height; i++) {
if (avctx->bits_per_coded_sample == 4) {
for (j = 0; j < avctx->width - 1; j += 2) {
ptr[j+0] = buf[j>>1] >> 4;
ptr[j+1] = buf[j>>1] & 0xF;
}
if (avctx->width & 1)
ptr[j+0] = buf[j>>1] >> 4;
} else {
memcpy(ptr, buf, linesize);
}
buf -= istride;
ptr += s->frame.linesize[0];
}
} else {
bytestream2_init(&s->gb, buf, buf_size);
ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, &s->gb);
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
return buf_size;
}
| 1threat |
static int qdm2_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size)
{
QDM2Context *s = avctx->priv_data;
if((buf == NULL) || (buf_size < s->checksum_size))
return 0;
*data_size = s->channels * s->frame_size * sizeof(int16_t);
av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n",
buf_size, buf, s->checksum_size, data, *data_size);
qdm2_decode(s, buf, data);
if (s->sub_packet == 0) {
return s->checksum_size;
}
return 0;
}
| 1threat |
static av_always_inline int coeff_abs_level_remaining_decode(HEVCContext *s, int rc_rice_param)
{
int prefix = 0;
int suffix = 0;
int last_coeff_abs_level_remaining;
int i;
while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc->cc))
prefix++;
if (prefix == CABAC_MAX_BIN) {
av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
return 0;
}
if (prefix < 3) {
for (i = 0; i < rc_rice_param; i++)
suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc->cc);
last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
} else {
int prefix_minus3 = prefix - 3;
for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc->cc);
last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
<< rc_rice_param) + suffix;
}
return last_coeff_abs_level_remaining;
}
| 1threat |
db.execute('SELECT * FROM products WHERE product_id = ' + product_input) | 1threat |
Node 5.10 spread operator not working : <p><a href="https://nodejs.org/en/docs/es6/#which-features-ship-with-node-js-by-default-no-runtime-flag-required">According to the docs</a>, the latest node (Node 5+) should support the spread operator by default, like so:</p>
<pre><code>const newObj = {
...oldObj,
newProperty: 1
}
</code></pre>
<p>And I have node 5.10.1 installed (e.g. that's what 'node -v' tells me). But I am still getting this error:</p>
<pre><code>c:\[myprojectfolder]>node index.js
c:\[myprojectfolder]\index.js:21
...oldObj,
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3
</code></pre>
<p>What am I missing?</p>
| 0debug |
static av_cold int j2kenc_init(AVCodecContext *avctx)
{
int i, ret;
Jpeg2000EncoderContext *s = avctx->priv_data;
Jpeg2000CodingStyle *codsty = &s->codsty;
Jpeg2000QuantStyle *qntsty = &s->qntsty;
s->avctx = avctx;
av_log(s->avctx, AV_LOG_DEBUG, "init\n");
memset(codsty->log2_prec_widths , 15, sizeof(codsty->log2_prec_widths ));
memset(codsty->log2_prec_heights, 15, sizeof(codsty->log2_prec_heights));
codsty->nreslevels2decode=
codsty->nreslevels = 7;
codsty->log2_cblk_width = 4;
codsty->log2_cblk_height = 4;
codsty->transform = avctx->prediction_method ? FF_DWT53 : FF_DWT97_INT;
qntsty->nguardbits = 1;
s->tile_width = 256;
s->tile_height = 256;
if (codsty->transform == FF_DWT53)
qntsty->quantsty = JPEG2000_QSTY_NONE;
else
qntsty->quantsty = JPEG2000_QSTY_SE;
s->width = avctx->width;
s->height = avctx->height;
for (i = 0; i < 3; i++)
s->cbps[i] = 8;
if (avctx->pix_fmt == AV_PIX_FMT_RGB24){
s->ncomponents = 3;
} else if (avctx->pix_fmt == AV_PIX_FMT_GRAY8){
s->ncomponents = 1;
} else{
s->planar = 1;
s->ncomponents = 3;
avcodec_get_chroma_sub_sample(avctx->pix_fmt,
s->chroma_shift, s->chroma_shift + 1);
}
ff_jpeg2000_init_tier1_luts();
init_luts();
init_quantization(s);
if (ret=init_tiles(s))
return ret;
av_log(s->avctx, AV_LOG_DEBUG, "after init\n");
return 0;
}
| 1threat |
How to Change a Radio Button's Image When Another Radio Button has been Clicked HTML : So I have this table and I want the radio buttons to change images to a check mark, which they do (sort of, but more on that later), and I want whenever I click one of the radio buttons the other radio buttons change into a picture of a X Mark (http://i.imgur.com/RcuPIGF.png).
Here is my code so far: http://liveweave.com/4poY04.
As you can see no matter which radio button you click the first one always changes to the check mark image. I have tried changing the id of the radio buttons but that only makes the 2nd one always change to the check mark image. | 0debug |
void cpu_disable_ticks(void)
{
seqlock_write_lock(&timers_state.vm_clock_seqlock);
if (timers_state.cpu_ticks_enabled) {
timers_state.cpu_ticks_offset = cpu_get_ticks();
timers_state.cpu_clock_offset = cpu_get_clock_locked();
timers_state.cpu_ticks_enabled = 0;
}
seqlock_write_unlock(&timers_state.vm_clock_seqlock);
}
| 1threat |
static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta)
{
int isv34, tlen, unsync;
char tag[5];
int64_t next, end = avio_tell(s->pb) + len;
int taghdrlen;
const char *reason = NULL;
AVIOContext pb;
AVIOContext *pbx;
unsigned char *buffer = NULL;
int buffer_size = 0;
void (*extra_func)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta**) = NULL;
switch (version) {
case 2:
if (flags & 0x40) {
reason = "compression";
goto error;
}
isv34 = 0;
taghdrlen = 6;
break;
case 3:
case 4:
isv34 = 1;
taghdrlen = 10;
break;
default:
reason = "version";
goto error;
}
unsync = flags & 0x80;
if (isv34 && flags & 0x40)
avio_skip(s->pb, get_size(s->pb, 4));
while (len >= taghdrlen) {
unsigned int tflags = 0;
int tunsync = 0;
if (isv34) {
avio_read(s->pb, tag, 4);
tag[4] = 0;
if(version==3){
tlen = avio_rb32(s->pb);
}else
tlen = get_size(s->pb, 4);
tflags = avio_rb16(s->pb);
tunsync = tflags & ID3v2_FLAG_UNSYNCH;
} else {
avio_read(s->pb, tag, 3);
tag[3] = 0;
tlen = avio_rb24(s->pb);
}
if (tlen <= 0 || tlen > len - taghdrlen) {
av_log(s, AV_LOG_WARNING, "Invalid size in frame %s, skipping the rest of tag.\n", tag);
break;
}
len -= taghdrlen + tlen;
next = avio_tell(s->pb) + tlen;
if (tflags & ID3v2_FLAG_DATALEN) {
avio_rb32(s->pb);
tlen -= 4;
}
if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {
av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);
avio_skip(s->pb, tlen);
} else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)->read))) {
if (unsync || tunsync) {
int i, j;
av_fast_malloc(&buffer, &buffer_size, tlen);
if (!buffer) {
av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen);
goto seek;
}
for (i = 0, j = 0; i < tlen; i++, j++) {
buffer[j] = avio_r8(s->pb);
if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) {
j--;
}
}
ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
tlen = j;
pbx = &pb;
} else {
pbx = s->pb;
}
if (tag[0] == 'T')
read_ttag(s, pbx, tlen, tag);
else
extra_func(s, pbx, tlen, tag, extra_meta);
}
else if (!tag[0]) {
if (tag[1])
av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");
avio_skip(s->pb, tlen);
break;
}
seek:
avio_seek(s->pb, next, SEEK_SET);
}
if (version == 4 && flags & 0x10)
end += 10;
error:
if (reason)
av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
avio_seek(s->pb, end, SEEK_SET);
av_free(buffer);
return;
}
| 1threat |
Flawed Logic in If statement : <p>I tried the year 1900, which in my program prints its a leap year, however, 1900 shouldnt be a leap year. Can someone help me with the logic behind the if condition?</p>
<pre><code>class LeapYearTrial{
public static void main(String[]args){
String s;
int year;
s = JOptionPane.showInputDialog("Enter year");
year = Integer.parseInt(s);
if ((year % 100 == 0) && (year % 400 == 0) || (year % 4 == 0)){
JOptionPane.showMessageDialog(null, year + " is a leap year");
} else {
JOptionPane.showMessageDialog(null, year + " is not a leap year");
}
}
}
</code></pre>
| 0debug |
Difference between char** and char[][] : <p>I am trying to sort strings using stdlib qsort. I have created two sort functions sort1 and sort2. sort1 input argument is char** and sort2 input argument is char[][]. My program crashes when use sort1 function to sort array of strings.</p>
<pre><code>#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
int compare(const void* a, const void* b)
{
const char *ia = (const char *)a;
const char *ib = (const char *)b;
return strcmp(ia, ib);
}
//program crashes
void sort1(char **A, int n1) {
int size1 = sizeof(A[0]);
int s2 = n1;
qsort(A,s2,size1,compare);
}
//works perfectly
void sort2(char A[][10], int n1) {
int size1 = sizeof(A[0]);
int s2 = n1;
qsort(A,s2,10,compare);
}
int _tmain(int argc, _TCHAR* argv[])
{
char *names_ptr[5] = {"norma","daniel","carla","bob","adelle"};
char names[5][10] = {"norma","daniel","carla","bob","adelle"};
int size1 = sizeof(names[0]);
int s2 = (sizeof(names)/size1);
sort1(names_ptr,5); //doesnt work
sort2(names,5); //works
return 0;
}
</code></pre>
| 0debug |
How to extract my own page title using Rails : <p>I've seen multiple ways to extract metadata from other web pages, but is there a simple way to extract my own page title, description, etc? </p>
<p>I want to store the metadata in a variable so that I can call to_query on it and put it in a link. </p>
<p>Ideally, without using JavaScript.</p>
| 0debug |
OError: [Errno 26] Text file busy: '/...myvirtualenv/bin/python' : <p>I try to recreate the virtualenv:</p>
<pre><code>foo_bar_d@aptguettler:~$ virtualenv --system-site-packages .
</code></pre>
<p>I get this exception:</p>
<pre><code>foo_bar_d@aptguettler:~$ virtualenv --system-site-packages .
New python executable in /home/foo_bar_d/bin/python
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 711, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 924, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1230, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 26] Text file busy: '/home/foo_bar_d/bin/python'
</code></pre>
<p>Does someone know why this exception happens?</p>
| 0debug |
static void fsl_imx31_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
dc->realize = fsl_imx31_realize;
dc->desc = "i.MX31 SOC";
}
| 1threat |
static void r2d_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;
struct SH7750State *s;
ram_addr_t sdram_addr;
qemu_irq *irq;
PCIBus *pci;
DriveInfo *dinfo;
int i;
if (!cpu_model)
cpu_model = "SH7751R";
env = cpu_init(cpu_model);
if (!env) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
sdram_addr = qemu_ram_alloc(SDRAM_SIZE);
cpu_register_physical_memory(SDRAM_BASE, SDRAM_SIZE, sdram_addr);
s = sh7750_init(env);
irq = r2d_fpga_init(0x04000000, sh7750_irl(s));
pci = sh_pci_register_bus(r2d_pci_set_irq, r2d_pci_map_irq, irq, 0, 4);
sm501_init(0x10000000, SM501_VRAM_SIZE, irq[SM501], serial_hds[2]);
if ((dinfo = drive_get(IF_IDE, 0, 0)) != NULL)
mmio_ide_init(0x14001000, 0x1400080c, irq[CF_IDE], 1,
dinfo, NULL);
for (i = 0; i < nb_nics; i++)
pci_nic_init(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
if (kernel_filename) {
int kernel_size;
stl_phys(SH7750_BCR1, 1<<3);
stw_phys(SH7750_BCR2, 3<<(3*2));
if (kernel_cmdline) {
kernel_size = load_image_targphys(kernel_filename,
SDRAM_BASE + LINUX_LOAD_OFFSET,
SDRAM_SIZE - LINUX_LOAD_OFFSET);
env->pc = (SDRAM_BASE + LINUX_LOAD_OFFSET) | 0xa0000000;
pstrcpy_targphys(SDRAM_BASE + 0x10100, 256, kernel_cmdline);
} else {
kernel_size = load_image_targphys(kernel_filename, SDRAM_BASE, SDRAM_SIZE);
env->pc = SDRAM_BASE | 0xa0000000;
}
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
exit(1);
}
}
}
| 1threat |
static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta,
double precision, int cheby){
double cutoff = cutoff0? cutoff0 : 0.97;
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
int phase_count= 1<<phase_shift;
if (!c || c->phase_shift != phase_shift || c->linear!=linear || c->factor != factor
|| c->filter_length != FFMAX((int)ceil(filter_size/factor), 1) || c->format != format
|| c->filter_type != filter_type || c->kaiser_beta != kaiser_beta) {
c = av_mallocz(sizeof(*c));
if (!c)
return NULL;
c->format= format;
c->felem_size= av_get_bytes_per_sample(c->format);
switch(c->format){
case AV_SAMPLE_FMT_S16P:
c->filter_shift = 15;
break;
case AV_SAMPLE_FMT_S32P:
c->filter_shift = 30;
break;
case AV_SAMPLE_FMT_FLTP:
case AV_SAMPLE_FMT_DBLP:
c->filter_shift = 0;
break;
default:
av_log(NULL, AV_LOG_ERROR, "Unsupported sample format\n");
av_assert0(0);
c->phase_shift = phase_shift;
c->phase_mask = phase_count - 1;
c->linear = linear;
c->factor = factor;
c->filter_length = FFMAX((int)ceil(filter_size/factor), 1);
c->filter_alloc = FFALIGN(c->filter_length, 8);
c->filter_bank = av_calloc(c->filter_alloc, (phase_count+1)*c->felem_size);
c->filter_type = filter_type;
c->kaiser_beta = kaiser_beta;
if (!c->filter_bank)
if (build_filter(c, (void*)c->filter_bank, factor, c->filter_length, c->filter_alloc, phase_count, 1<<c->filter_shift, filter_type, kaiser_beta))
memcpy(c->filter_bank + (c->filter_alloc*phase_count+1)*c->felem_size, c->filter_bank, (c->filter_alloc-1)*c->felem_size);
memcpy(c->filter_bank + (c->filter_alloc*phase_count )*c->felem_size, c->filter_bank + (c->filter_alloc - 1)*c->felem_size, c->felem_size);
c->compensation_distance= 0;
if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2))
c->ideal_dst_incr= c->dst_incr;
c->index= -phase_count*((c->filter_length-1)/2);
c->frac= 0;
return c;
error:
av_freep(&c->filter_bank);
av_free(c);
return NULL; | 1threat |
Evaluate multiple scores on sklearn cross_val_score : <p>I'm trying to evaluate multiple machine learning algorithms with sklearn for a couple of metrics (accuracy, recall, precision and maybe more).</p>
<p>For what I understood from the documentation <a href="http://scikit-learn.org/stable/modules/model_evaluation.html#" rel="noreferrer">here</a> and from the source code(I'm using sklearn 0.17), the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.cross_val_score.html#sklearn.cross_validation.cross_val_score" rel="noreferrer">cross_val_score</a> function only receives one scorer for each execution. So for calculating multiple scores, I have to :</p>
<ol>
<li>Execute multiple times</li>
<li><p>Implement my (time consuming and error prone) scorer</p>
<p>I've executed multiple times with this code :</p>
<pre><code>from sklearn.svm import SVC
from sklearn.naive_bayes import GaussianNB
from sklearn.tree import DecisionTreeClassifier
from sklearn.cross_validation import cross_val_score
import time
from sklearn.datasets import load_iris
iris = load_iris()
models = [GaussianNB(), DecisionTreeClassifier(), SVC()]
names = ["Naive Bayes", "Decision Tree", "SVM"]
for model, name in zip(models, names):
print name
start = time.time()
for score in ["accuracy", "precision", "recall"]:
print score,
print " : ",
print cross_val_score(model, iris.data, iris.target,scoring=score, cv=10).mean()
print time.time() - start
</code></pre></li>
</ol>
<p>And I get this output: </p>
<pre><code>Naive Bayes
accuracy : 0.953333333333
precision : 0.962698412698
recall : 0.953333333333
0.0383198261261
Decision Tree
accuracy : 0.953333333333
precision : 0.958888888889
recall : 0.953333333333
0.0494720935822
SVM
accuracy : 0.98
precision : 0.983333333333
recall : 0.98
0.063080072403
</code></pre>
<p>Which is ok, but it's slow for my own data. How can I measure all scores ?</p>
| 0debug |
How do I add colors to my heading text for my online portfolio using html through wordpress? : I'm trying to add color to one of my headings using wordpress. When I add a style section, and ask for the h1 to be a heading (with its corresponding closing tag) I get the image below displayed. [codingstep1][1]
[codingstep2][2]
[1]: https://i.stack.imgur.com/Db89P.jpg
[2]: https://i.stack.imgur.com/d1tFG.jpg | 0debug |
Check if a string has space between all its letters : <p>Hi I need help to do this:
given that I have a string contains spaces and lower case letters only, I need to check if all the letters in the string separated from each other by at least one space. if the string follow this, print "is separated", otherwise print is not separated.
thank you :) </p>
| 0debug |
Smart keyboard internalization for IDEA : <p>When I start IntelliJ IDEA, that message comes up, but I couldn't find any information about that feature and how it could help me.</p>
<blockquote>
<p>Enable smart keyboard internalization for IDEA.: We have found out that you are using a non-english keyboard layout.
You can enable smart layout support for German language.You can change this option in the settings of IDEA more...</p>
</blockquote>
| 0debug |
document.write('<script src="evil.js"></script>'); | 1threat |
In Safari's "Responsive Design Mode" can you hide all of the device options on top for more screen real estate? : <p><a href="https://i.stack.imgur.com/a4yrk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/a4yrk.png" alt="enter image description here"></a></p>
<p>Can I hide this?</p>
<p>I'm having a poor user experience debugging my app in Safari (I decided to not use Chrome because it seems to demand more CPU). This bar takes up SOOO much screen real estate and almost forces me to dock the devtools on thee side. But as I said earlier can I hide this?</p>
| 0debug |
Non-Static Method cannot be called from Non-Static Method in Android Studio : <p>Of course I know that a <strong>Non-Static</strong> Method needs to be called from a <strong>Non-Static</strong> Context.</p>
<p>And am I missing something when I think that</p>
<pre><code>public void methodName(int i) { ... }
</code></pre>
<p>is <strong>Non-Static</strong> ?</p>
<p>Because Android Studio 2.3.2 flaged it as a Static Context so I can't call the following statement from the Method </p>
<p><a href="https://i.stack.imgur.com/QobJw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QobJw.jpg" alt="enter image description here"></a></p>
<p>Method:</p>
<pre><code>public void deleteCard(int id){
for(int i = 0; i < cards.size(); i++){
if(cards.get(i).id == id){
cards.remove(i);
notifyItemRemoved(i);
notifyItemRangeChanged(i, cards.size());
}
}
}
</code></pre>
| 0debug |
Gin: Resize image before sending : I want to have a route with gin that will send an image (jpeg) as the response but instead of sending the original image that's saved to disk I would like to resize it first (to a thumbnail size).
So far I can send images using `c.File(filepath string)` but that doesn't allow me to resize the image. Is there any way to do that without having to create a new file on the disk? | 0debug |
static void iscsi_co_generic_bh_cb(void *opaque)
{
struct IscsiTask *iTask = opaque;
iTask->complete = 1;
qemu_bh_delete(iTask->bh);
qemu_coroutine_enter(iTask->co, NULL);
}
| 1threat |
static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len)
{
uint32_t *p = qdev_get_prop_ptr(dev, prop);
return snprintf(dest, len, (*p & qdev_get_prop_mask(prop)) ? "on" : "off");
}
| 1threat |
static inline void RENAME(yuv2yuvX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW)
{
#ifdef HAVE_MMX
if(uDest != NULL)
{
asm volatile(
YSCALEYUV2YV12X(0, CHR_MMX_FILTER_OFFSET)
:: "r" (&c->redDither),
"r" (uDest), "p" (chrDstW)
: "%"REG_a, "%"REG_d, "%"REG_S
);
asm volatile(
YSCALEYUV2YV12X(4096, CHR_MMX_FILTER_OFFSET)
:: "r" (&c->redDither),
"r" (vDest), "p" (chrDstW)
: "%"REG_a, "%"REG_d, "%"REG_S
);
}
asm volatile(
YSCALEYUV2YV12X(0, LUM_MMX_FILTER_OFFSET)
:: "r" (&c->redDither),
"r" (dest), "p" (dstW)
: "%"REG_a, "%"REG_d, "%"REG_S
);
#else
#ifdef HAVE_ALTIVEC
yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, uDest, vDest, dstW, chrDstW);
#else
yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
chrFilter, chrSrc, chrFilterSize,
dest, uDest, vDest, dstW, chrDstW);
#endif
#endif
}
| 1threat |
Error inflating class for NavigationView : java.lang.RuntimeException Unable to start activity ComponentInfo, android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView
| 0debug |
static void v9fs_walk(void *opaque)
{
int name_idx;
V9fsQID *qids = NULL;
int i, err = 0;
V9fsPath dpath, path;
uint16_t nwnames;
struct stat stbuf;
size_t offset = 7;
int32_t fid, newfid;
V9fsString *wnames = NULL;
V9fsFidState *fidp;
V9fsFidState *newfidp = NULL;
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
err = pdu_unmarshal(pdu, offset, "ddw", &fid, &newfid, &nwnames);
if (err < 0) {
pdu_complete(pdu, err);
return ;
offset += err;
trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);
if (nwnames && nwnames <= P9_MAXWELEM) {
wnames = g_malloc0(sizeof(wnames[0]) * nwnames);
qids = g_malloc0(sizeof(qids[0]) * nwnames);
for (i = 0; i < nwnames; i++) {
err = pdu_unmarshal(pdu, offset, "s", &wnames[i]);
if (err < 0) {
offset += err;
} else if (nwnames > P9_MAXWELEM) {
err = -EINVAL;
fidp = get_fid(pdu, fid);
if (fidp == NULL) {
v9fs_path_init(&dpath);
v9fs_path_init(&path);
v9fs_path_copy(&dpath, &fidp->path);
v9fs_path_copy(&path, &fidp->path);
for (name_idx = 0; name_idx < nwnames; name_idx++) {
err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data, &path);
if (err < 0) {
goto out;
err = v9fs_co_lstat(pdu, &path, &stbuf);
if (err < 0) {
goto out;
stat_to_qid(&stbuf, &qids[name_idx]);
v9fs_path_copy(&dpath, &path);
if (fid == newfid) {
BUG_ON(fidp->fid_type != P9_FID_NONE);
v9fs_path_copy(&fidp->path, &path);
} else {
newfidp = alloc_fid(s, newfid);
if (newfidp == NULL) {
err = -EINVAL;
goto out;
newfidp->uid = fidp->uid;
v9fs_path_copy(&newfidp->path, &path);
err = v9fs_walk_marshal(pdu, nwnames, qids);
trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids);
out:
put_fid(pdu, fidp);
if (newfidp) {
put_fid(pdu, newfidp);
v9fs_path_free(&dpath);
v9fs_path_free(&path);
out_nofid:
pdu_complete(pdu, err);
if (nwnames && nwnames <= P9_MAXWELEM) {
for (name_idx = 0; name_idx < nwnames; name_idx++) {
v9fs_string_free(&wnames[name_idx]);
g_free(wnames);
g_free(qids);
| 1threat |
How to sort a list of java object by some property : <p>I have a simple class </p>
<pre><code>public class Address {
public String name;
public long mobile;
private String description;
private String address;
private boolean live;
}
</code></pre>
<p>and List addressList. I want to sort the AddressList object by name.
Please help me out as i am new to java. </p>
| 0debug |
Is there a way to stop/disable a Google Cloud Function? : <p>I have running multiple Google Cloud functions. One is not operating well, so I want to stop them until I've fixed the situation.</p>
<p>I have seen that I can remove the function, but is there a way to disable and later; enable the function?</p>
| 0debug |
Python Code. What is wrong with this basic code? : <p><strong>Just doing some basic code and then this error popped up. I have no idea what I should fix everything seems fine. (Using Python)</strong></p>
<p>Code:</p>
<pre><code>dict = {'name':'Bob','ref':'Python','sys':'Win'}
print('\nReference:',dict['ref'])
print('n\Keys:',dict.keys()
del dict[ 'name' ]
dict['user']='Tom'
print('\nDictionary:',dict)
print('\nIs There A name Key?:','name' in dict)
C:\Python>dictionary.py
File "C:\Python\dictionary.py", line 4
del dict[ 'name' ]
^
SyntaxError: invalid syntaxer code here
</code></pre>
| 0debug |
Will %= get a module of a collection? C# : This is what I have so far to get the modulus of the collection that is being passed into the Mod method.
public static void Mod(int[] nums)
{
int total = 0;
foreach (int num in nums)
{
if (total == 0)
{
total = num;
}
else
{
total %= num;
}
}
Console.WriteLine("Mod: " + total);
}
What I am wondering if this is the correct way to find this or will I get the totally wrong answer with this. | 0debug |
alert('Hello ' + user_input); | 1threat |
Free() bifore return 0; : What happen if I end the execution by passing return 0; after using a malloc and without freeing the part of memory allocated?
int * var;
var = (int *)malloc(sizeof(int)) ;
free(var) ;
return 0; | 0debug |
Recursively copying a direntory using native C code : I was looking to implement the behavior of lunux system commands
1) `cp <src_dir> <dst_dir>` that copies everything inside the 'src_dir' into 'dst_dir' recurcively, and
2) `cp <src_file> <dst_file>` that copies 'src_file' into 'dst_file'
I looked online for help and got a few solutions but they did either of the following that I do not want to do:
i) using `rename(src_dir, dst_dir)`, which essentially 'moves' the contents and not copies.
I need to keep the contents of the 'src_dir' intact.
ii) Opening the 'src_file' and reading/copying the contents into the 'dst_file'.
I would like to do this w/o opening the files and reading the content (i dont know if this makes sense in the 2nd 'cp' scenario above, but at least in the 1st one?).
Can the above be achieved using C (and no linux system calls)?
Thanks in advance! | 0debug |
would appreciate some assistance finding the error in my code. (TA and i spent 20 min then had to break for dinner) :
This program is the String of 3 numbers then 7 letters to be transformed into its equivalent number using methods
The user input is a string which is changed from letters to digits and back into a string of numbers separated by dashes.
So this is only week 3ish of learning and i got tripped up by methods. The error code I am receiving is telling me the string index is out of bounds. So, i suspect the error is in my conversion or where i concatenated the strings at the end around line 89. I spent 20 min with the TA and would appreciate any guidance. I still have more to do with the program so i am omitting some of it because I would only like help when i come to a place that I become stuck for more than 45 min.MAIN QUESTION- Where does the error occur and why?
I attempted to put print statements everywhere to see what was happening... however I may be stuck in a loop.
import java.util.Scanner;
public class ConvPhoneNumTwo{
public static void main(String[] args){
String s = getInput();
printPhone(convertToDigit(s));
}
public static String getInput() {
Scanner scan = new Scanner(System.in);
String s1 = "";
boolean length = false;
while (length==false){
System.out.println(" Please enter a telephone number in this format ###-AAA-AAAA") ;
s1 = scan.nextLine();
if(s1.length() != 12 ){
System.out.println( "this is an invalid choice try again Plz...");
length = false;
}
else{
length = true;
}
}
return s1;
}
public static String convertToDigit(String s010){
s010 = s010.toLowerCase();
String s001= s010.substring(0,3);
String s002 = s010.substring(4,6);
String s003 = s010.substring(8,12);
String s1 = (s001+s002+s003);
String s2 = "";
// Exceptions to our problem to stop invalid inputs
if (s1 == null) {
System.out.print (" invalid input null thing");
}
if (s1.length() != 10){
System.out.print (" invalid input");
}
String s6 = "";
for (int i=0; i < s1.length(); i++) {
if (Character.isDigit(s1.charAt(i))){
s2 += s1.charAt(i);
}
//sorting of the letter inputs
char ch = s1.charAt(i);
if (ch == 'a'||ch=='b'||ch== 'c'){
s2 += "2";
}
if (ch == 'd'||ch=='e'||ch=='f'){
s2 += "3";
}
if (ch == 'g'||ch=='h'||ch=='i'){
s2 += "4";
}
if (ch == 'j'||ch=='k'||ch=='l'){
s2 += "5";
}
if (ch == 'm'||ch=='n'||ch=='o'){
s2 += "6";
}
if (ch == 'p'||ch=='q'||ch=='r'|| ch=='s'){
s2 += "7";
}
if (ch == 't'||ch=='u'||ch=='v'){
s2 += "8";
}
if (ch == 'w'||ch=='x'||ch=='y'|| ch=='z')
{
s2 += "9";
}
else{
}
String s3 = s2.substring(0,3);
String s4 = s2.substring(3,6);
String s5 = s2.substring(6);
s6 = ( s3 +"-"+ s4 + "-"+ s5);
}
return s6;
}
public static void printPhone(String message) { //print out whatever string it is given, basically System.out.println(), but through a method instead
System.out.println(message);
}
}
Not sure about how much more detail i can put into this.
| 0debug |
Convert Array to String Swift : <p>How can I convert a array to a string in Swift?</p>
<p>i have an array like:</p>
<pre><code>["ghjh","hbvvv","hfkfjfi","ufufu"]
</code></pre>
<p>how convert to string like <code>ghjh, hbvvv, hfkfjfi , ufufu</code></p>
| 0debug |
Is there a ways to save variabel in string? : Is there a ways to save variabel in string and use it later? in code i expect the stdout should `41`
#include <iostream>
int main(){
std::string number [5] = {1,2,3,4,5};
std::string join = "number[3]+number[0]";
std::cout << join; // Expect result should 41.
return 0;
} | 0debug |
Color combination for my Button(Android) : <p>My LinearLayout has this image for background:
<a href="https://i.stack.imgur.com/N9px7.png" rel="nofollow noreferrer">Background image</a></p>
<p>I have this drawable:</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="COLOR1"
android:startColor="COLOR2"
android:endColor="COLOR3"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>
</code></pre>
<p>Instead of COLOR1, COLOR2, color3 what colors I could use to the best possible contrast with the colors of the background.</p>
| 0debug |
What happens when back button or home or application removed from recent apps : <p>I want to know what happens when back button pressed, is there any data loss? Or we simply press back button what could be possibly done to that state or there is data loss when we press home button, and lastly when we remove application from recent app, what happens when we remove application from recent app is there a data loss or something </p>
<p>Thanks!</p>
| 0debug |
Delete method not working in ruby : the destroy method doesn't work but i get redirected to index page but record is not deleted.[enter image description here][1]
HTML.erb link:
<%= link_to "Delete", posts_path(@post), method: :delete, data: {confirm: 'are you sure?'},:class => 'btn btn-danger' %>
Controller:
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path
[1]: https://i.stack.imgur.com/UGqKI.png | 0debug |
static inline void fimd_swap_data(unsigned int swap_ctl, uint64_t *data)
{
int i;
uint64_t res;
uint64_t x = *data;
if (swap_ctl & FIMD_WINCON_SWAP_BITS) {
res = 0;
for (i = 0; i < 64; i++) {
if (x & (1ULL << (64 - i))) {
res |= (1ULL << i);
}
}
x = res;
}
if (swap_ctl & FIMD_WINCON_SWAP_BYTE) {
x = bswap64(x);
}
if (swap_ctl & FIMD_WINCON_SWAP_HWORD) {
x = ((x & 0x000000000000FFFFULL) << 48) |
((x & 0x00000000FFFF0000ULL) << 16) |
((x & 0x0000FFFF00000000ULL) >> 16) |
((x & 0xFFFF000000000000ULL) >> 48);
}
if (swap_ctl & FIMD_WINCON_SWAP_WORD) {
x = ((x & 0x00000000FFFFFFFFULL) << 32) |
((x & 0xFFFFFFFF00000000ULL) >> 32);
}
*data = x;
}
| 1threat |
How to delete a locally uploaded file on google colab? : <p>I'm trying to delete a file that I uploaded on Google colab using the following code:</p>
<pre><code>from google.colab import files
uploaded = files.upload()
</code></pre>
<p>How to delete the file now? e.g If the file's name is 'sample.jpg' .</p>
| 0debug |
Rotate matrix in c without [] : I need to rotate a matrix and call the funcion without use [ ],
I can't even think on a solution.
void _90DegClockwise(int *pS, int row, int col) {
for (int i = 0; i < row; ++i)
{
for (int j = i + 1; j < col; j++) {
int temp;
temp = (int)(pS);
*((int*)((pS + i) + j)) = (int*)((pS + j) + i);
(int*)((pS + j) + i) = temp;
}
}
}
I don't know hou to insert a value to matrix or how to swap
| 0debug |
vue js push array component : 1.vue js problem component
i want insert a new message in new array with method on click event but
not work for me because function is incomplete
where is the problem.
help me please.
<div class="col-lg-12">
<h1>{{message.title}}</h1>
<h4>{{message.subtitle}}</h4>
</p> {{message.body}}</p>
<button v-on:click="reverseMessage">Reverse Message</button>
</div>
import { VueTabs, VTab } from "vue-nav-tabs";
import "vue-nav-tabs/themes/vue-tabs.css";
export default {
components: {
VueTabs,
VTab
},
data() {
return {
title: "elenco",
messages: [
{
id: 1,
title: "titolo",
subtitle: "sottotitolo",
body: "argomento",
author: "Amedeo",
date: "17/07/2017",
files: [
{
id: 1,
title: "Allegatoriunione",
openfile: "Allegato.pdf"
},
],
methods: {
reverseMessage: function() {
this.message.title = this.message.title
.push()
.split("")
.reverse()
.join("");
} | 0debug |
How to add report_tensor_allocations_upon_oom to RunOptions in Keras : <p>I'm trying to train a neural net on a GPU using Keras and am getting a "Resource exhausted: OOM when allocating tensor" error. The specific tensor it's trying to allocate isn't very big, so I assume some previous tensor consumed almost all the VRAM. The error message comes with a hint that suggests this:</p>
<blockquote>
<p>Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.</p>
</blockquote>
<p>That sounds good, but how do I do it? RunOptions appears to be a Tensorflow thing, and what little documentation I can find for it associates it with a "session". I'm using Keras, so Tensorflow is hidden under a layer of abstraction and its sessions under another layer below that.</p>
<p>How do I dig underneath everything to set this option in such a way that it will take effect?</p>
| 0debug |
static void qmp_input_type_bool(Visitor *v, const char *name, bool *obj,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true, errp);
QBool *qbool;
if (!qobj) {
return;
}
qbool = qobject_to_qbool(qobj);
if (!qbool) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"boolean");
return;
}
*obj = qbool_get_bool(qbool);
}
| 1threat |
static void test_read_without_media(void)
{
uint8_t ret;
ret = send_read_command();
g_assert(ret == 0);
}
| 1threat |
Which piece of code is 'better?' : <p>I have two pieces of code. Can you please tell me which one is correct and more secure?</p>
<pre><code><input type="text" class="form-control contact__form-control" placeholder="Your Name *" id="name" value="<?php echo htmlspecialchars ($name); ?>">
<?php echo "<span class='text-danger'>$nameError</span>";?>
</code></pre>
<p>or</p>
<pre><code><input type="text" class="form-control contact__form-control" placeholder="Your Name *" id="name" value="<?php echo htmlspecialchars ($name); ?>">
<?php echo htmlspecialchars ("<span class='text- danger'>$nameError</span>");?>
</code></pre>
<p>I have seen everyone to use the 1st one but i read that in PHP when you echo something its good to add htmlspecialchars for security reason. So i am wondering if the second piece of code is correct. Will the bootstrap alert class will work after the htmlspecialchars</p>
| 0debug |
Pass output as input argument for the callback : <p>I have a situation where I need to get a value from ajax call, then pass that value to a callback function. Just like this:</p>
<pre><code>function getValue(callback){
var val = getfromajax();
//need to return value and then execute the callback here
return val;
callback();
}
var myval = getValue(function(){
alert(myvalue)
})
</code></pre>
<p>In the example above in the functon showValue I need to call getValue and use the returned value and pass it to callback function (which alerts it).</p>
<p>Is there a way to do that?</p>
| 0debug |
static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts, int64_t *pkt_dts)
{
AVFrame *decoded_frame, *filtered_frame = NULL;
void *buffer_to_free = NULL;
int i, ret = 0;
float quality = 0;
#if CONFIG_AVFILTER
int frame_available = 1;
#endif
int duration=0;
int64_t *best_effort_timestamp;
AVRational *frame_sample_aspect;
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
return AVERROR(ENOMEM);
else
avcodec_get_frame_defaults(ist->decoded_frame);
decoded_frame = ist->decoded_frame;
pkt->pts = *pkt_pts;
pkt->dts = *pkt_dts;
*pkt_pts = AV_NOPTS_VALUE;
if (pkt->duration) {
duration = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
} else if(ist->st->codec->time_base.num != 0) {
int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
duration = ((int64_t)AV_TIME_BASE *
ist->st->codec->time_base.num * ticks) /
ist->st->codec->time_base.den;
}
if(*pkt_dts != AV_NOPTS_VALUE && duration) {
*pkt_dts += duration;
}else
*pkt_dts = AV_NOPTS_VALUE;
ret = avcodec_decode_video2(ist->st->codec,
decoded_frame, got_output, pkt);
if (ret < 0)
return ret;
quality = same_quant ? decoded_frame->quality : 0;
if (!*got_output) {
return ret;
}
best_effort_timestamp= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "best_effort_timestamp");
if(*best_effort_timestamp != AV_NOPTS_VALUE)
ist->next_pts = ist->pts = *best_effort_timestamp;
ist->next_pts += duration;
pkt->size = 0;
pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
#if CONFIG_AVFILTER
frame_sample_aspect= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "sample_aspect_ratio");
for(i=0;i<nb_output_streams;i++) {
OutputStream *ost = ost = &output_streams[i];
if(check_output_constraints(ist, ost)){
if (!frame_sample_aspect->num)
*frame_sample_aspect = ist->st->sample_aspect_ratio;
decoded_frame->pts = ist->pts;
if (ist->dr1) {
FrameBuffer *buf = decoded_frame->opaque;
AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays(
decoded_frame->data, decoded_frame->linesize,
AV_PERM_READ | AV_PERM_PRESERVE,
ist->st->codec->width, ist->st->codec->height,
ist->st->codec->pix_fmt);
avfilter_copy_frame_props(fb, decoded_frame);
fb->pts = ist->pts;
fb->buf->priv = buf;
fb->buf->free = filter_release_buffer;
buf->refcount++;
av_buffersrc_buffer(ost->input_video_filter, fb);
} else
if((av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE)) < 0){
av_log(0, AV_LOG_FATAL, "Failed to inject frame into filter network\n");
exit_program(1);
}
}
}
#endif
rate_emu_sleep(ist);
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = &output_streams[i];
int frame_size;
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
continue;
#if CONFIG_AVFILTER
if (ost->input_video_filter) {
frame_available = av_buffersink_poll_frame(ost->output_video_filter);
}
while (frame_available) {
if (ost->output_video_filter) {
AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0){
av_log(0, AV_LOG_WARNING, "AV Filter told us it has a frame available but failed to output one\n");
goto cont;
}
if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) {
av_free(buffer_to_free);
return AVERROR(ENOMEM);
} else
avcodec_get_frame_defaults(ist->filtered_frame);
filtered_frame = ist->filtered_frame;
*filtered_frame= *decoded_frame;
if (ost->picref) {
avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref);
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
}
}
if (ost->picref->video && !ost->frame_aspect_ratio)
ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
#else
filtered_frame = decoded_frame;
#endif
do_video_out(output_files[ost->file_index].ctx, ost, ist, filtered_frame, &frame_size,
same_quant ? quality : ost->st->codec->global_quality);
if (vstats_filename && frame_size)
do_video_stats(output_files[ost->file_index].ctx, ost, frame_size);
#if CONFIG_AVFILTER
cont:
frame_available = ost->output_video_filter && av_buffersink_poll_frame(ost->output_video_filter);
avfilter_unref_buffer(ost->picref);
}
#endif
}
av_free(buffer_to_free);
return ret;
}
| 1threat |
How do you inherit the template from a parent component in angular 4? : <p>How would you inherit the template from a parent component in angular 4? Most materials exemplify overriding the parent component like this:</p>
<pre><code>import { Component } from '@angular/core';
import { EmployeeComponent } from './employee.component';
@Component({
selector: 'app-employee-list',
template: `
<h1>{{heading}}</h1>
<ul>
<li *ngFor="let employee of employees">
{{employee.firstName}} {{employee.lastName}} <br>
{{employee.email}} <br>
<button (click)="selectEmployee(employee)">Select</button>
</li>
</ul>
`
})
export class EmployeeListComponent extends EmployeeComponent {
heading = 'Employee List';
}
</code></pre>
<p>but I want to inherit the template from EmployeeComponent, instead of overriding it with my own custom version. How can this be achieved? </p>
| 0debug |
Define a livenessProbe with secret httpHeaders : <p>I want to define a livenessProbe with an httpHeader whose value is secret.</p>
<p>This syntax is invalid:</p>
<pre><code>livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: X-Custom-Header
valueFrom:
secretKeyRef:
name: my-secret-key
value: secret
</code></pre>
<p>If I specify <code>my-secret-key</code> with value <code>secret</code> as an environment variable named <code>MY_SECRET_KEY</code>, the following could work:</p>
<pre><code>livenessProbe:
exec:
command:
- curl
- --fail
- -H
- "X-Custom-Header: $MY_SECRET_KEY"
- 'http://localhost:8080/healthz'
</code></pre>
<p>Unfortunately it doesn't due to the way the quotations are being evaluated. If I type the command <code>curl --fail -H "X-Custom-Header: $MY_SECRET_KEY" http://localhost:8080/healthz</code> directly on the container, it works.</p>
<p>I've also tried many combinations of single quotes and escaping the double quotes.</p>
<p>Does anyone know of a workaround?</p>
| 0debug |
Where can I log & debug Velocity Template Language (VTL) in AWS AppSync? : <ol>
<li><p>Is there any easy way to log or debug VTL coming from Request Mapping Template & Response Mapping Template rather than sending <strong>Queries</strong> & <strong>Mutations</strong> to debug & log?</p></li>
<li><p>Also, is there any Playground to check & play with VTL just like we can do with JavaScript in Web Console?</p></li>
<li><p>Can we work with AWS AppSync offline & check if everything written in VTL works as expected? </p></li>
</ol>
| 0debug |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.