problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
qio_channel_socket_accept(QIOChannelSocket *ioc,
Error **errp)
{
QIOChannelSocket *cioc;
cioc = qio_channel_socket_new();
cioc->remoteAddrLen = sizeof(ioc->remoteAddr);
cioc->localAddrLen = sizeof(ioc->localAddr);
retry:
trace_qio_channel_socket_accept(ioc);
cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr,
&cioc->remoteAddrLen);
if (cioc->fd < 0) {
trace_qio_channel_socket_accept_fail(ioc);
if (errno == EINTR) {
goto retry;
}
goto error;
}
if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
&cioc->localAddrLen) < 0) {
error_setg_errno(errp, errno,
"Unable to query local socket address");
goto error;
}
#ifndef WIN32
if (cioc->localAddr.ss_family == AF_UNIX) {
QIOChannel *ioc_local = QIO_CHANNEL(cioc);
qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS);
}
#endif
trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
return cioc;
error:
object_unref(OBJECT(cioc));
return NULL;
}
| 1threat |
static int find_pte32(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, int h,
int rw, int type, int target_page_bits)
{
hwaddr pteg_off;
target_ulong pte0, pte1;
int i, good = -1;
int ret, r;
ret = -1;
pteg_off = get_pteg_offset32(env, ctx->hash[h]);
for (i = 0; i < HPTES_PER_GROUP; i++) {
pte0 = ppc_hash32_load_hpte0(env, pteg_off + i*HASH_PTE_SIZE_32);
pte1 = ppc_hash32_load_hpte1(env, pteg_off + i*HASH_PTE_SIZE_32);
r = pte_check_hash32(ctx, pte0, pte1, h, rw, type);
LOG_MMU("Load pte from %08" HWADDR_PRIx " => " TARGET_FMT_lx " "
TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
pteg_off + (i * 8), pte0, pte1, (int)(pte0 >> 31), h,
(int)((pte0 >> 6) & 1), ctx->ptem);
switch (r) {
case -3:
return -1;
case -2:
ret = -2;
good = i;
break;
case -1:
default:
break;
case 0:
ret = 0;
good = i;
goto done;
}
}
if (good != -1) {
done:
LOG_MMU("found PTE at addr %08" HWADDR_PRIx " prot=%01x ret=%d\n",
ctx->raddr, ctx->prot, ret);
pte1 = ctx->raddr;
if (ppc_hash32_pte_update_flags(ctx, &pte1, ret, rw) == 1) {
ppc_hash32_store_hpte1(env, pteg_off + good * HASH_PTE_SIZE_32,
pte1);
}
}
if (target_page_bits != TARGET_PAGE_BITS) {
ctx->raddr |= (ctx->eaddr & ((1 << target_page_bits) - 1))
& TARGET_PAGE_MASK;
}
return ret;
}
| 1threat |
static void __attribute__((constructor)) coroutine_init(void)
{
if (!g_thread_supported()) {
g_thread_init(NULL);
}
coroutine_cond = g_cond_new();
} | 1threat |
Difference between "detach()" and "with torch.nograd()" in PyTorch? : <p>I know about two ways to exclude elements of a computation from the gradient calculation <code>backward</code></p>
<p><strong>Method 1:</strong> using <code>with torch.no_grad()</code></p>
<pre><code>with torch.no_grad():
y = reward + gamma * torch.max(net.forward(x))
loss = criterion(net.forward(torch.from_numpy(o)), y)
loss.backward();
</code></pre>
<p><strong>Method 2:</strong> using <code>.detach()</code></p>
<pre><code>y = reward + gamma * torch.max(net.forward(x))
loss = criterion(net.forward(torch.from_numpy(o)), y.detach())
loss.backward();
</code></pre>
<p>Is there a difference between these two? Are there benefits/downsides to either?</p>
| 0debug |
static void curses_calc_pad(void)
{
if (is_graphic_console()) {
width = gwidth;
height = gheight;
} else {
width = COLS;
height = LINES;
}
if (screenpad)
delwin(screenpad);
clear();
refresh();
screenpad = newpad(height, width);
if (width > COLS) {
px = (width - COLS) / 2;
sminx = 0;
smaxx = COLS;
} else {
px = 0;
sminx = (COLS - width) / 2;
smaxx = sminx + width;
}
if (height > LINES) {
py = (height - LINES) / 2;
sminy = 0;
smaxy = LINES;
} else {
py = 0;
sminy = (LINES - height) / 2;
smaxy = sminy + height;
}
}
| 1threat |
def sort_dict_item(test_dict):
res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])}
return (res)
| 0debug |
ParallelState *parallel_init(int index, CharDriverState *chr)
{
ISADevice *dev;
dev = isa_create("isa-parallel");
qdev_prop_set_uint32(&dev->qdev, "index", index);
qdev_prop_set_chr(&dev->qdev, "chardev", chr);
if (qdev_init(&dev->qdev) < 0)
return NULL;
return &DO_UPCAST(ISAParallelState, dev, dev)->state;
}
| 1threat |
static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
TranslationBlock *orig_tb, bool ignore_icount)
{
TranslationBlock *tb;
if (max_cycles > CF_COUNT_MASK)
max_cycles = CF_COUNT_MASK;
tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags,
max_cycles | CF_NOCACHE
| (ignore_icount ? CF_IGNORE_ICOUNT : 0));
tb->orig_tb = tcg_ctx.tb_ctx.tb_invalidated_flag ? NULL : orig_tb;
cpu->current_tb = tb;
trace_exec_tb_nocache(tb, tb->pc);
cpu_tb_exec(cpu, tb);
cpu->current_tb = NULL;
tb_phys_invalidate(tb, -1);
tb_free(tb);
}
| 1threat |
static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
{
if (version_id != 1) {
return -EINVAL;
}
return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
}
| 1threat |
Is Dispose() necessary before recreating a large bitmap inside a loop? : <p>Suppose I have the code: </p>
<pre><code>void Method1() {
Bitmap bitmap1;
foreach (string name in OpenFileDialog1.FileNames) {
bitmap1 = new Bitmap(name);
... // process bitmap
bitmap1.Dispose();
}
}
</code></pre>
<p>Is Dispose() necessary inside the loop?</p>
| 0debug |
static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
FsCred *credp)
{
char buffer[PATH_MAX];
if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) {
return -1;
}
if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
credp->fc_gid) < 0) {
if (fs_ctx->fs_sm != SM_NONE) {
return -1;
}
}
return 0;
}
| 1threat |
static void rtas_event_log_queue(int log_type, void *data)
{
sPAPREventLogEntry *entry = g_new(sPAPREventLogEntry, 1);
g_assert(data);
entry->log_type = log_type;
entry->data = data;
QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next);
}
| 1threat |
How can I see how TypeScript computes types? : <p>Problem: I'm working on a file that has a lot of conditional types that derive their types from previously defined conditional types and this has become very complex and difficult to debug how a type is being derived.</p>
<p>I'm trying to find a way to "debug" or list how the TypeScript compiler is making its determination on a conditional type and picking a path to derive the ultimate type.</p>
<p>I've looked through the <a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" rel="noreferrer">compiler options</a> and have not found anything in that area yet...</p>
<p>An analogy to what I'm looking for right now is the equivalent of the <code>DEBUG=express:*</code> type of setting that one might use if you wanted to see what an express server was doing.</p>
<p>However, the actual problem I'm trying to solve is to be able to deconstruct and debug how a type is derived in a large complex hierarchical type definition.</p>
<p>Important Note: I'm not trying to debug the runtime execution of TypeScript project. I'm trying to debug how the types are computed by the TypeScript compiler.</p>
| 0debug |
Use SCRUM for website maintenance - Deal with single task : <p>I am new to Scrum and I am trying to use it for website support and maintenance. </p>
<p>For website support and maintenance, we often receive small tasks, for example: replace a banner on homepage, change phone number on contact page, remove image xyz on article 123, etc... I don't know how to deal with these small tasks in Scrum. </p>
<p>At the moment, I create a single task in backlog, and a single Sprint for each task. Then, execute each task individually. Am I right? </p>
| 0debug |
static av_always_inline void fic_idct(int16_t *blk, int step, int shift, int rnd)
{
const int t0 = 27246 * blk[3 * step] + 18405 * blk[5 * step];
const int t1 = 27246 * blk[5 * step] - 18405 * blk[3 * step];
const int t2 = 6393 * blk[7 * step] + 32139 * blk[1 * step];
const int t3 = 6393 * blk[1 * step] - 32139 * blk[7 * step];
const unsigned t4 = 5793U * (t2 + t0 + 0x800 >> 12);
const unsigned t5 = 5793U * (t3 + t1 + 0x800 >> 12);
const unsigned t6 = t2 - t0;
const unsigned t7 = t3 - t1;
const unsigned t8 = 17734 * blk[2 * step] - 42813 * blk[6 * step];
const unsigned t9 = 17734 * blk[6 * step] + 42814 * blk[2 * step];
const unsigned tA = (blk[0 * step] - blk[4 * step]) * 32768 + rnd;
const unsigned tB = (blk[0 * step] + blk[4 * step]) * 32768 + rnd;
blk[0 * step] = (int)( t4 + t9 + tB) >> shift;
blk[1 * step] = (int)( t6 + t7 + t8 + tA) >> shift;
blk[2 * step] = (int)( t6 - t7 - t8 + tA) >> shift;
blk[3 * step] = (int)( t5 - t9 + tB) >> shift;
blk[4 * step] = (int)( -t5 - t9 + tB) >> shift;
blk[5 * step] = (int)(-(t6 - t7) - t8 + tA) >> shift;
blk[6 * step] = (int)(-(t6 + t7) + t8 + tA) >> shift;
blk[7 * step] = (int)( -t4 + t9 + tB) >> shift;
}
| 1threat |
static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
{
uint8_t lens[MAX_ELEMS];
uint16_t codes[MAX_ELEMS];
int counts[17], prefixes[18];
int i, cur_len;
int max_bits = 0;
GetBitContext gb;
init_get_bits(&gb, data, elems * 4);
for (i = 0; i <= 16; i++)
counts[i] = 0;
for (i = 0; i < elems; i++) {
cur_len = get_bits(&gb, 4) + 1;
counts[cur_len]++;
max_bits = FFMAX(max_bits, cur_len);
lens[i] = cur_len;
}
prefixes[1] = 0;
for (i = 1; i <= 16; i++)
prefixes[i + 1] = (prefixes[i] + counts[i]) << 1;
for (i = 0; i < elems; i++)
codes[i] = prefixes[lens[i]]++;
return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), elems,
lens, 1, 1, codes, 2, 2, NULL, 0, 0, 0);
}
| 1threat |
"sql.run is not a function" TypeError in Node.JS (Discord.JS) : I have the following code for a Discord bot I am making in Discord.JS
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
if(msg.content.startsWith(prefix+'bank')){
var i = 0
var total = 0
sql.run("SELECT SUM(money) FROM money");
msg.channel.send('** :earth_americas: | The current *GLOBAL* bank is worth e$'+total+'.**')
}
<!-- end snippet -->
I get the error:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
sql.run("SELECT SUM(money) FROM money");
^
TypeError: sql.run is not a function
at Client.client.on.msg (/Users/jack/Documents/Code/EcoBot/bot.js:105:16)
at emitOne (events.js:96:13)
at Client.emit (events.js:188:7)
at MessageCreateHandler.handle (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/Users/jack/Documents/Code/EcoBot/node_modules/ws/lib/event-target.js:120:16)
at emitOne (events.js:96:13)
at WebSocket.emit (events.js:188:7)
<!-- end snippet -->
Here is where `sql` is defined:
`const SQLite = require("better-sqlite3");
const sql = new SQLite('./money.sqlite');
`
I have tried to find the answer, and I've been through the docs, but I have gotten nowhere. Docs are [here][1]. Any and all help is appreciated.
[1]: https://github.com/mapbox/node-sqlite3/wiki/API#databaserunsql-param--callback | 0debug |
How do I set a string value inside an if statement? (C++) : <p>This may seem like a stupid question but how do I keep a variable value when it is assigned inside a if statement?
For example:</p>
<pre><code>#include <iostream>
#include <string>
using namespace std;
int main()
{
string usability;
string bent;
string usable;
string input = "bent";
if(input.find(bent) != string::npos)
{
string usability = "bent";
}
if(input.find(usable) != string ::npos)
{
string usability = "usable";
}
cout << usability;
return 0;
}
</code></pre>
<p>The string usability at the end is still empty. (I assume because the variable is only set in its own if statement?) How do I get it to print "bent" or "usable"?</p>
<p>Thanks</p>
| 0debug |
cannot convert parameter 1 from 'int (__thiscall A::* *)(void)' to 'int (__cdecl *)(void)' : I am getting this error while running this code, Please look in to my code and assist me,
#include "stdafx.h"
#include <iostream>
class A
{
public:
void PrintTwoNumbers(int (*numberSource)(void))
{
int val1= numberSource();
}
int overNineThousand(void)
{
return (rand()%1000) + 9001;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int (A::*fptr) (void) = &A::overNineThousand;
A a;
a.PrintTwoNumbers(&fptr); //-> how to pass fptr here
getchar();
return 0;
}
> i fed up by searching this one, no body giving perfect solution for this.Can anybody edit this code as working code and help me.
| 0debug |
What does a ? mean between a variable and a method in C# : <p>My code looks like this: </p>
<pre><code>var newVariable = originalVariable?.method1().method2();
</code></pre>
<p>What does the "?" do between the originalVariable and the first method? </p>
| 0debug |
How to count rows before while() : <p>I need to count rows before while(). </p>
<p>On page there are 10 questions. 5 questions on left, 5 questions on right. </p>
<p>It looks like this: </p>
<pre><code><div class="left">
<div>question 1</div>
<div>question 2</div>
<div>question 3</div>
<div>question 4</div>
<div>question 5</div>
</div> <!-- /left close -->
<div class="right">
<div>question 6</div>
<div>question 7</div>
<div>question 8</div>
<div>question 9</div>
<div>question 10</div>
</div> <!-- /right close -->
</code></pre>
<p>Data getting from mysql.</p>
| 0debug |
static int targa_encode_frame(AVCodecContext *avctx,
unsigned char *outbuf,
int buf_size, void *data){
AVFrame *p = data;
int bpp, picsize, datasize;
uint8_t *out;
if(avctx->width > 0xffff || avctx->height > 0xffff) {
av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n");
return -1;
}
picsize = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
if(buf_size < picsize + 45) {
av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
p->pict_type= FF_I_TYPE;
p->key_frame= 1;
memset(outbuf, 0, 11);
AV_WL16(outbuf+12, avctx->width);
AV_WL16(outbuf+14, avctx->height);
outbuf[17] = 0x20;
switch(avctx->pix_fmt) {
case PIX_FMT_GRAY8:
outbuf[2] = 3;
outbuf[16] = 8;
break;
case PIX_FMT_RGB555:
outbuf[2] = 2;
outbuf[16] = 16;
break;
case PIX_FMT_BGR24:
outbuf[2] = 2;
outbuf[16] = 24;
break;
default:
return -1;
}
bpp = outbuf[16] >> 3;
out = outbuf + 18;
datasize = targa_encode_rle(out, picsize, p, bpp, avctx->width, avctx->height);
if(datasize >= 0)
outbuf[2] |= 8;
else datasize = targa_encode_normal(out, p, bpp, avctx->width, avctx->height);
out += datasize;
memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26);
return out + 26 - outbuf;
}
| 1threat |
plsql insert 10000 data into 3 tables : I have 3 tables. tours, tour_hotels and tour_transfers. Tour table has columns named id, tour_name, start_date. Tour_hotels table has columns named id, tour_id, hotel_name. Tour_transfers table has id, tour_id, from_where, to_where columns. Now I need to insert 10000 rows into each table. My code must be plsql and for loop. I must use only one for loop to insert all datas into 3 tables. And I must pay attention, id in tours table must match with tour_id in tour_hotels and tour_transfers tables. I am new learner in plsql, so please write sample and simple code for me.
begin
for i in 1 .. 10000 loop
insert into tour.tours values
(i, ('Tour ' || i), trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/15, 'ddd'), trunc(to_date('01/03/2019', 'mm/dd/yyyy')+i/15+i/777, 'ddd'),
trunc(2+i/777), trunc(100 + i/6), trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/99, 'ddd'), trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/98, 'ddd'),
1, ('Country ' || trunc(i/60)));
if(mod(i, 300) = 0) then
insert into tour.tour_hotels
values
(i, i, ('Hotel ' || i), ('Country ' || trunc(i/60)), 3 + mod(i, 3), 0, 0, 1, trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/99, 'ddd'),
trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/98, 'ddd'), 1);
elsif (mod(i, 200) = 0) then
insert into tour.tour_hotels
values
(i, i, ('Hotel ' || i), ('Country ' || trunc(i/60)), 3 + mod(i, 3), 1, 0, 0, trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/99, 'ddd'),
trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/98, 'ddd'), 1);
elsif (mod(i, 700) = 0) then
insert into tour.tour_hotels
values
(i, i, ('Hotel ' || i), ('Country ' || trunc(i/60)), 3 + mod(i, 3), 1, 1, 1, trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/99, 'ddd'),
trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/98, 'ddd'), 1);
else
insert into tour.tour_hotels
values
(i, i, ('Hotel ' || i), ('Country ' || trunc(i/60)), 3 + mod(i, 3), 1, 0, 1, trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/99, 'ddd'),
trunc(to_date('01/01/2019', 'mm/dd/yyyy')+i/98, 'ddd'), 1);
end if;
insert into TOUR.TOUR_TRANSFERS values
(i, i, ('Buradan ' || i), ('Buraya ' || i), trunc(to_date('01/01/2019', 'dd/mm/yyyy')+i/99, 'ddd'),
trunc(to_date('01/01/2019', 'dd/mm/yyyy')+i/98, 'ddd'), 1);
end loop;
end; | 0debug |
uint32_t HELPER(get_r13_banked)(CPUState *env, uint32_t mode)
{
return env->banked_r13[bank_number(mode)];
}
| 1threat |
int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size)
{
int64_t offset;
int ret;
BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC);
offset = alloc_clusters_noref(bs, size);
if (offset < 0) {
return offset;
}
ret = update_refcount(bs, offset, size, 1, QCOW2_DISCARD_NEVER);
if (ret < 0) {
return ret;
}
return offset;
}
| 1threat |
DrJava tells me there's no main. But as far I'm concern main is the first line after the class canine declaration : **Background:** *I don't know what I am doing, or why I'm doing it.
I'm trying to learn Java. I'm using DrJava. No reason for either, but that's what will happen until frustration is so great, that I quit.*
**Problem:** When I try to run this bit of code DrJava tells me:
Static Error: This class does not have a static void main method accepting String[]. What I don't get is why DrJava tells me there's no main. It's the first line after the class canine declaration; and I don't see any typos or missing punctuation. What did I do to deserve this?
**Steps taken:** *Naturally, I googled it. I don't understand what **[they are talking about][1]**.*
**Disclaimer:** *Before you come at me with "read the encyclopedia Britannica" let me save you the trouble. Get out of my face with that. That's not going to happen. It's idiotic to think that I am going to understand, let alone retain what the hell those tomes say.*
Would be nice if someone can clue me in, in a way that doesn't actually give me the answer, but leads me figure it out on my own why this is happening to me -but if the problem is too basic to create a learning opportunity, then I'll take a solution; I guess.
/*
* This is an exercise designed to practice creating a class Animal
* And then creating another class canine in which to create an object dog.
* The reason I want to call from one class to another is because I want
* to understand how classes, objects, inheritance, etc. works.
* Clearly, class canine is -in my mind at least, a child of class Animal.
* The main method of canine then calls method attributes I think are being
* inherited by dog and wolf,from the class Animal.
*/
public class Animal {
void growl() {
System.out.println("Grrr");
}
void bark() {
System.out.println("Arf! Arf!");
}
}
class canine {
public static void main(String[]args) {
Animal dog = new Animal();
dog.bark();
Animal wolf = new Animal();
wolf.growl();
}
}
[1]: https://stackoverflow.com/questions/14657147/static-error-this-class-does-not-have-a-static-void-main-method-accepting-strin | 0debug |
I, Octavian, desire assistance with wrapping a 2D array : Octavian has found himself caught in limitations of thought, a truly horrifyin notion. He's striving to write his own version of the Game of Life simulator in python. Octavian has a 2d array, and needs to make conditional statements based upon the values of the neighbours to each element. Ex: grid[y][x + 1], grid[y - 1][x], etc. What brings Octavian pain is how exactly to refer to the other end of each grid axis in the case that +1 or -1 takes it out of range. Is there some way of wrapping around to refer to the opposite end of the x and y axes of the array?
Render answers unto Octavian, and you shall be granted the gift of a swift death! | 0debug |
Can you stream videos from Android to Google Drive? : <p>Using Google Drive API for Android, can one stream videos in real time directly to Google Drive storage?</p>
| 0debug |
Which atom python linting packages are stable? : <p>It seems that there are too many Python linting packages and I am wonder which one should we use. </p>
<p>I suspect installing two will provide a confusing experience, if not even triggering weird bugs.</p>
<ul>
<li><a href="https://atom.io/packages/python-autopep8" rel="noreferrer">python-autopep8</a> - 20+</li>
<li><a href="https://atom.io/packages/linter-python-pyflakes" rel="noreferrer">linter-python-flaks</a> - 6+</li>
<li><a href="https://atom.io/packages/linter-flake8" rel="noreferrer">linter-flake8</a> - 153+</li>
<li><a href="https://atom.io/packages/linter-pylint" rel="noreferrer">linter-pylint</a> - 119+</li>
</ul>
<p>Here are few areas I want to clarify:</p>
<ul>
<li>is ok to use more than one?</li>
<li>wouldn't be better to ask authors to join efforts and focus on a single one?<br>
What are the pros and cons for them?</li>
</ul>
| 0debug |
Chrome 49 timing and loading errors using require.js modules : <p>My web app (which has lots of JS) has been working fine until this Chrome 49 update. (I know it's the update because it was working, then I updated my browser, and now its not).</p>
<p>There seems to be a timing issue on when the require.js <code>define()</code> functions are called. Although the require.js files are loaded first, my non-amd JS loaded after are firing first and causing issues like:</p>
<p><code>Uncaught Error: Module name [name] has not been loaded...</code></p>
<p>Is anyone else having this problem?</p>
| 0debug |
window.location.href = 'http://attack.com?user=' + user_input; | 1threat |
static inline int media_present(IDEState *s)
{
return (s->nb_sectors > 0);
}
| 1threat |
def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | 0debug |
Flyweight in java, what is the purpose? : Hi I have a below code:
public class Sentence {
private String [] words;
private Map<Integer, WordToken> tokens = new HashMap<>();
public Sentence(String plainText) {
words = plainText.split(" ");
}
public WordToken getWord(int index) {
WordToken wt = new WordToken();
tokens.put(index, wt);
return tokens.get(index);
}
@Override
public String toString() {
List<String> ws = new ArrayList<>();
for (int i = 0; i < words.length; ++i) {
String w = words[i];
if (tokens.containsKey(i) && tokens.get(i).capitalize) {
w = w.toUpperCase();
}
ws.add(w);
}
return String.join(" ", ws);
}
}
and test:
@Test
public void test() {
Sentence s = new Sentence("alpha beta gamma");
s.getWord(1).capitalize = true;
assertEquals("alpha BETA gamma", s.toString());
}
My question is: what is the purpose of use flyweight pattern in that way? | 0debug |
Program to calculate the number of zeros in an array : <p>myArray = [1,0,2,4,5,10,4,0,3,0]
How to calculate the number of zeros in the the above array?</p>
| 0debug |
void bdrv_io_limits_enable(BlockDriverState *bs, const char *group)
{
assert(!bs->throttle_state);
throttle_group_register_bs(bs, group);
}
| 1threat |
Test suite failed to run TypeError: Cannot read property 'default' of undefined : <p>I'm trying to setup Jest on my react-native project but it hasn't been playing nice with <a href="https://github.com/bugsnag/bugsnag-react-native" rel="noreferrer">bugsnag-react-native</a>.</p>
<p>With my current test configuration I'm seeing errors related to bugsnag's <code>leaveBreadcrumb</code> function seen below: </p>
<pre><code> FAIL app/__tests__/NetworkReducer.test.js
● Test suite failed to run
TypeError: Cannot read property 'default' of undefined
at Object.<anonymous> (app/__tests__/NetworkReducer.test.js:10:20)
at Generator.next (<anonymous>)
at Promise (<anonymous>)
</code></pre>
<p>I have a helper file that instantiates bugsnag:</p>
<pre><code>helpers/bugSnag.js
//-------------------------------------------------------------------------------------------------
// Create a single instance of the bugsnag client so we don't have to duplicate our configuration
// anywhere.
//-------------------------------------------------------------------------------------------------
// https://docs.bugsnag.com/platforms/react-native/#basic-configuration
import { Client, Configuration } from 'bugsnag-react-native';
const config = new Configuration();
config.consoleBreadcrumbsEnabled = true;
config.notifyReleaseStages = ['testflight', 'production'];
const bugSnag = new Client(config);
export default bugSnag;
</code></pre>
<p>So in all my files I'm importing bugSnag from this helper file rather than declaring a new Client in each file, notably in my <code>NetworkReducer.js</code> where <code>bugSnag.leaveBreadcrumb('someData')</code> is causing me issues.</p>
<p>In my <code>NetworkReducer.test.js</code> I'm calling a mock:</p>
<pre><code> jest.mock(bugSnag, () => {
return {
leaveBreadcrumb: jest.fn()
};
});
</code></pre>
<p>where I'm also importing <code>bugSnag from path/to/helpers/bugSnag</code></p>
<p>If I comment out the mock, I get a different error message on each of my reducer types that have a <code>bugSnag.leaveBreadcrumb('someData')</code> as seen below:</p>
<pre><code>TypeError: _bugSnag2.default.leaveBreadcrumb is not a function
at Object.network_prop_update (app/reducers/NetworkReducer.js:29:19)
at app/reducers/createReducer.js:4:29
at Object.<anonymous> (app/__tests__/NetworkReducer.test.js:80:29)
at tryCallTwo (node_modules/promise/lib/core.js:45:5)
at doResolve (node_modules/promise/lib/core.js:200:13)
at new Promise (node_modules/promise/lib/core.js:66:3)
</code></pre>
<p>I thought I had a handle on this jest thing, and mocking, but I guess I've been proven wrong. I've attached my Jest's <code>setup.js</code> for extra reference:</p>
<pre><code> jest.mock('Linking', () => {
return {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
};
});
jest.mock('PushNotificationIOS', () => {
return {
addEventListener: jest.fn(),
requestPermissions: jest.fn(() => Promise.resolve()),
getInitialNotification: jest.fn(() => Promise.resolve()),
};
});
jest.mock('react-native-intercom', () => {
return {
registerIdentifiedUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
registerUnidentifiedUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
updateUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
reset: jest.genMockFn().mockReturnValue(Promise.resolve()),
logEvent: jest.genMockFn().mockReturnValue(Promise.resolve()),
handlePushMessage: jest.genMockFn().mockReturnValue(Promise.resolve()),
displayMessenger: jest.genMockFn().mockReturnValue(Promise.resolve()),
hideMessenger: jest.genMockFn().mockReturnValue(Promise.resolve()),
displayMessageComposer: jest.genMockFn().mockReturnValue(Promise.resolve()),
displayMessageComposerWithInitialMessage: jest.genMockFn().mockReturnValue(Promise.resolve()),
displayConversationsList: jest.genMockFn().mockReturnValue(Promise.resolve()),
getUnreadConversationCount: jest.genMockFn().mockReturnValue(Promise.resolve()),
setLauncherVisibility: jest.genMockFn().mockReturnValue(Promise.resolve()),
setInAppMessageVisibility: jest.genMockFn().mockReturnValue(Promise.resolve()),
setupAPN: jest.genMockFn().mockReturnValue(Promise.resolve()),
registerForPush: jest.genMockFn().mockReturnValue(Promise.resolve()),
setUserHash: jest.genMockFn().mockReturnValue(Promise.resolve()),
setBottomPadding: jest.genMockFn().mockReturnValue(Promise.resolve()),
addEventListener: jest.fn(),
removeEventListener: jest.fn()
};
});
jest.mock('bugsnag-react-native', () => {
return {
leaveBreadcrumb: jest.fn(),
Configuration: jest.fn(),
Client: jest.fn()
};
});
</code></pre>
| 0debug |
How To Correctly Use Arry-Lists In Java? : For my school work I've been given the task to create a simple bookstore program for Java. So far I've managed to create a working program to display and store data once its been inputted by the user, my problem now is that I want to show the data once the user ends the program so all the data they entered will be displayed. What I want is for the Author, Price, Publisher and ISBN inputted data be displayed under these headings. I know you use arry lists to do this but I don't have any idea how to do this in Java, any help is much appreciated.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[]
title=new String[100],
author=new String[100],
publisher=new String[100],
ISBN=new String[100];
boolean endinput = false;
boolean Yes = true;
double[] price=new double[100];
System.out.println("Welcome To Kieran's Bookstore");
while (Yes) {
System.out.println("Input The Title:");
title[0] = scan.next();
System.out.println("Input The Author:");
author[0] = scan.next();
System.out.println("Input The Price Of The Book:");
scan.next();
System.out.println("Input The Publisher:");
publisher[0] = scan.next();
System.out.println("Input The ISBN:");
ISBN[0] = scan.next();
System.out.println("Would you like to continue?(Yes/endinput)");
String ans = scan.next();
if (ans.equals("endinput") || (scan.equals("endinput"))) {
Yes = false;
System.exit(0);
}
}
}
}
| 0debug |
static int adx_decode_header(AVCodecContext *avctx,const unsigned char *buf,size_t bufsize)
{
int offset;
int channels,freq,size;
offset = is_adx(buf,bufsize);
if (offset==0) return 0;
channels = buf[7];
freq = read_long(buf+8);
size = read_long(buf+12);
avctx->sample_rate = freq;
avctx->channels = channels;
avctx->bit_rate = freq*channels*18*8/32;
return offset;
}
| 1threat |
int blk_co_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
{
int ret = blk_check_request(blk, sector_num, nb_sectors);
if (ret < 0) {
return ret;
}
return bdrv_co_discard(blk_bs(blk), sector_num, nb_sectors);
}
| 1threat |
Difference requiresMainQueueSetup and dispatch_get_main_queue? : <p>I am trying to learn about creating react-native modules for iOS and there is one aspect that came up</p>
<p><a href="https://facebook.github.io/react-native/docs/native-modules-ios.html#threading" rel="noreferrer">Official documentation on threading</a> mentions this block of code alongside its variations</p>
<pre><code>- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
</code></pre>
<p>There is another undocumented peace I saw a lot in the third party libraries which is this</p>
<pre><code>+ (BOOL)requiresMainQueueSetup
{
return NO;
}
</code></pre>
<p>To me, these look kinda similar yet different, hence I wanted to ask for an explanation of following questions</p>
<ol>
<li><p>When should <code>dispatch_get_main_queue</code> be added to the module and what happens if it is omitted?</p></li>
<li><p>When should <code>requiresMainQueueSetup</code> be added to the module and what happens if it is omitted?</p></li>
<li><p>Can <code>dispatch_get_main_queue</code> and <code>requiresMainQueueSetup</code> be used together, if so why and when?</p></li>
<li><p>What is the difference between returning <code>YES</code> and <code>NO</code> from <code>requiresMainQueueSetup</code>?</p></li>
</ol>
| 0debug |
static size_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
{
size_t nbytes;
char *buf;
if (!(aiocb->aio_type & QEMU_AIO_MISALIGNED)) {
if (aiocb->aio_niov == 1)
return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base);
if (preadv_present) {
nbytes = handle_aiocb_rw_vector(aiocb);
if (nbytes == aiocb->aio_nbytes)
return nbytes;
if (nbytes < 0 && nbytes != -ENOSYS)
return nbytes;
preadv_present = 0;
}
}
buf = qemu_memalign(512, aiocb->aio_nbytes);
if (aiocb->aio_type & QEMU_AIO_WRITE) {
char *p = buf;
int i;
for (i = 0; i < aiocb->aio_niov; ++i) {
memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_len);
p += aiocb->aio_iov[i].iov_len;
}
}
nbytes = handle_aiocb_rw_linear(aiocb, buf);
if (!(aiocb->aio_type & QEMU_AIO_WRITE)) {
char *p = buf;
size_t count = aiocb->aio_nbytes, copy;
int i;
for (i = 0; i < aiocb->aio_niov && count; ++i) {
copy = count;
if (copy > aiocb->aio_iov[i].iov_len)
copy = aiocb->aio_iov[i].iov_len;
memcpy(aiocb->aio_iov[i].iov_base, p, copy);
p += copy;
count -= copy;
}
}
qemu_vfree(buf);
return nbytes;
}
| 1threat |
gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,
bool search_pc)
{
CPUState *cs = CPU(cpu);
CPUMBState *env = &cpu->env;
uint32_t pc_start;
int j, lj;
struct DisasContext ctx;
struct DisasContext *dc = &ctx;
uint32_t next_page_start, org_flags;
target_ulong npc;
int num_insns;
int max_insns;
pc_start = tb->pc;
dc->cpu = cpu;
dc->tb = tb;
org_flags = dc->synced_flags = dc->tb_flags = tb->flags;
dc->is_jmp = DISAS_NEXT;
dc->jmp = 0;
dc->delayed_branch = !!(dc->tb_flags & D_FLAG);
if (dc->delayed_branch) {
dc->jmp = JMP_INDIRECT;
}
dc->pc = pc_start;
dc->singlestep_enabled = cs->singlestep_enabled;
dc->cpustate_changed = 0;
dc->abort_at_next_insn = 0;
dc->nr_nops = 0;
if (pc_start & 3) {
cpu_abort(cs, "Microblaze: unaligned PC=%x\n", pc_start);
}
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
#if !SIM_COMPAT
qemu_log("--------------\n");
log_cpu_state(CPU(cpu), 0);
#endif
}
next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
lj = -1;
num_insns = 0;
max_insns = tb->cflags & CF_COUNT_MASK;
if (max_insns == 0)
max_insns = CF_COUNT_MASK;
gen_tb_start(tb);
do
{
#if SIM_COMPAT
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
gen_helper_debug();
}
#endif
check_breakpoint(env, dc);
if (search_pc) {
j = tcg_op_buf_count();
if (lj < j) {
lj++;
while (lj < j)
tcg_ctx.gen_opc_instr_start[lj++] = 0;
}
tcg_ctx.gen_opc_pc[lj] = dc->pc;
tcg_ctx.gen_opc_instr_start[lj] = 1;
tcg_ctx.gen_opc_icount[lj] = num_insns;
}
LOG_DIS("%8.8x:\t", dc->pc);
if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
gen_io_start();
dc->clear_imm = 1;
decode(dc, cpu_ldl_code(env, dc->pc));
if (dc->clear_imm)
dc->tb_flags &= ~IMM_FLAG;
dc->pc += 4;
num_insns++;
if (dc->delayed_branch) {
dc->delayed_branch--;
if (!dc->delayed_branch) {
if (dc->tb_flags & DRTI_FLAG)
do_rti(dc);
if (dc->tb_flags & DRTB_FLAG)
do_rtb(dc);
if (dc->tb_flags & DRTE_FLAG)
do_rte(dc);
dc->tb_flags &= ~D_FLAG;
if (dc->jmp == JMP_INDIRECT) {
eval_cond_jmp(dc, env_btarget, tcg_const_tl(dc->pc));
dc->is_jmp = DISAS_JUMP;
} else if (dc->jmp == JMP_DIRECT) {
t_sync_flags(dc);
gen_goto_tb(dc, 0, dc->jmp_pc);
dc->is_jmp = DISAS_TB_JUMP;
} else if (dc->jmp == JMP_DIRECT_CC) {
int l1;
t_sync_flags(dc);
l1 = gen_new_label();
tcg_gen_brcondi_tl(TCG_COND_NE, env_btaken, 0, l1);
gen_goto_tb(dc, 1, dc->pc);
gen_set_label(l1);
gen_goto_tb(dc, 0, dc->jmp_pc);
dc->is_jmp = DISAS_TB_JUMP;
}
break;
}
}
if (cs->singlestep_enabled) {
break;
}
} while (!dc->is_jmp && !dc->cpustate_changed
&& !tcg_op_buf_full()
&& !singlestep
&& (dc->pc < next_page_start)
&& num_insns < max_insns);
npc = dc->pc;
if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) {
if (dc->tb_flags & D_FLAG) {
dc->is_jmp = DISAS_UPDATE;
tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
sync_jmpstate(dc);
} else
npc = dc->jmp_pc;
}
if (tb->cflags & CF_LAST_IO)
gen_io_end();
if (dc->is_jmp == DISAS_NEXT
&& (dc->cpustate_changed || org_flags != dc->tb_flags)) {
dc->is_jmp = DISAS_UPDATE;
tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
}
t_sync_flags(dc);
if (unlikely(cs->singlestep_enabled)) {
TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG);
if (dc->is_jmp != DISAS_JUMP) {
tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
}
gen_helper_raise_exception(cpu_env, tmp);
tcg_temp_free_i32(tmp);
} else {
switch(dc->is_jmp) {
case DISAS_NEXT:
gen_goto_tb(dc, 1, npc);
break;
default:
case DISAS_JUMP:
case DISAS_UPDATE:
tcg_gen_exit_tb(0);
break;
case DISAS_TB_JUMP:
break;
}
}
gen_tb_end(tb, num_insns);
if (search_pc) {
j = tcg_op_buf_count();
lj++;
while (lj <= j)
tcg_ctx.gen_opc_instr_start[lj++] = 0;
} else {
tb->size = dc->pc - pc_start;
tb->icount = num_insns;
}
#ifdef DEBUG_DISAS
#if !SIM_COMPAT
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
qemu_log("\n");
#if DISAS_GNU
log_target_disas(env, pc_start, dc->pc - pc_start, 0);
#endif
qemu_log("\nisize=%d osize=%d\n",
dc->pc - pc_start, tcg_op_buf_count());
}
#endif
#endif
assert(!dc->abort_at_next_insn);
}
| 1threat |
Is there a way to make flake8 check for type hints in the source : <p>I'm starting a new python project (python 3.5+) and I would like to enforce type hints in the entire codebase. Is there a way to do that with <code>flake8</code> or any other tool?</p>
| 0debug |
Show Only First Row In MS SQL Query : I want only the first row to show up in this query. However, because each user has a distinct service, the users show up more than once. I only want to show the first row then the other rows in a separate query `ORDERING BY 'id'`.
SELECT DISTINCT TOP (7)
id,
fname,
lname,
dob,
services
FROM T1
ORDER BY id
id fname lname dob services
100 Joe Blue 2/20/2001 JDT
100 Joe Blue 2/20/2001 VOCP
101 Mark Pink 1/5/2000 OPAP
101 Mark Pink 1/5/2000 AARCHD
102 Wally Green 1/2/2000 AARCHD
102 Wally Green 1/2/2000 OPAP
103 Steve Yellow 1/10/2000 AARCHD
| 0debug |
Gradle: Error: Program type already present: androidx.activity.R$attr : <p>When adding</p>
<pre><code> implementation
('com.google.android.ads.consent:consent-library:1.0.0') {
exclude module: 'androidx.activity'
}
</code></pre>
<p>to my app/build.gradle file i get this error:
Error: Program type already present: androidx.activity.R$attr</p>
<p>What i did do:
1. gradlew androidDependencies
But i cannot find any duplicates</p>
<ol start="2">
<li><p>Read: <a href="https://developer.android.com/studio/build/dependencies#duplicate_classes" rel="noreferrer">https://developer.android.com/studio/build/dependencies#duplicate_classes</a>.</p></li>
<li><p>Other stackoverflow answers suggesting excluding support library versions dont help me</p></li>
</ol>
<pre><code>repositories {
maven { url 'https://maven.fabric.io/public' }
}
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
configurations.all {exclude group: 'com.android.support', module: 'support-v13'}
dependencies {
def nav_version = "1.0.0"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:core-ktx:1.1.0'
implementation "com.vorlonsoft:androidrate:1.2.1"
implementation 'com.github.THEAccess:SuspendRx:1.0.10'
implementation 'com.github.THEAccess:privacydialog:0.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'com.yqritc:android-scalablevideoview:1.0.4'
implementation 'com.timqi.sectorprogressview:library:2.0.1'
implementation 'com.github.Angtrim:Android-Five-Stars-Library:v3.1'
implementation 'com.stepstone.apprating:app-rating:2.3.0'
implementation 'com.google.firebase:firebase-dynamic-links:16.1.8'
implementation 'com.google.firebase:firebase-ads:16.0.1'
api ('com.google.android.ads.consent:consent-library:1.0.0') {
exclude module: 'androidx.activity'
}
//Navigation
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
//Kodein
def kodein_version = "6.0.1"
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
implementation "org.kodein.di:kodein-di-conf-jvm:$kodein_version"
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-config:16.4.0'
implementation 'com.google.firebase:firebase-perf:16.2.4'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.1.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
transitive = true;
}
implementation 'androidx.cardview:cardview:1.0.0'
}
</code></pre>
<p>Please help me understanding where the dependencies have duplicates</p>
| 0debug |
db.execute('SELECT * FROM employees WHERE id = ' + user_input) | 1threat |
Code not working (C++ Unions and structures) : No matter how many times I reformat this, I keep getting all kinds of errors. The end result will be a program that can save functions targeting motors in a telescope and set coordinates. Any help in explaining what I am doing wrong with this setup would be greatly appreciated. here is the code:
`//IDENTIFY RECEIVER OF MESSAGE / TYPE OF MESSAGE / VIEW ALL TO 1 DEVICE / VIEW SPECIFIC MESSAGE`
#include "messaging.h"
#include <string.h>
#include <stdio.h>
using namespace std;
typedef struct MGR{
mess_types messagetype;
int DeviceID;
union E{
//why arte these underlined?
char INST[STRSIZE];
int codes[NBRCODES];
float coords[NBRCOORDS];
} message;
};// info;
void messager(){
MGR my_data;
my_data.messagetype = INST;
my_data.DeviceID = TECH1;
strcpy(my_data.message.INST, "GO HOME");
my_data.messagetype = CODES;
my_data.DeviceID = MOTOR1;
for (int nbr = 0; nbr < NBRCODES; nbr++){
my_data.message.codes[nbr] = nbr;
print_message(my_data);
}
}
int print_message(MGR mydata){
MGR noot;
scanf("%s", &mydata);
switch (mydata.messagetype){
case INST:
printf("Message to Device %d", noot.DeviceID);
break;
case CODES:
printf("The setup codes for device %d are: \n", noot.DeviceID);
for (int code = 0; code < NBRCODES + OFFSET; code++){
printf("%4d\t", noot.message);
}
break;
case COORDS:
printf("The setup codes for device %d are: \n", noot.DeviceID);
for (int code = 0; code < NBRCODES + OFFSET; code++){
printf("%4d\t", noot.message);
}
break;
}
printf("%c", mydata.messagetype);
return(0)
}
void Sendmessage(){
printf("This program does not work... it is under construction...");
}
Just in case: here is the header file
#include "sprint1.h"
#include <string.h>
#include <stdio.h>
#define STRSIZE 50
#define NBRCODES 200
#define NBRCOORDS 200
#define OFFSET 100
#define FACTOR 50
#define TECH1 123
#define MOTOR1 4556
void messager();
int print_message(MGR mydata);
void Sendmessage();
enum mess_types {INST, CODES, COORDS};
| 0debug |
How can I open a file/folder when I click a button - Java Windowbuilder : I'm developing a Screen Share tool for my Minecraft server and I want for you to be able to click a button and it will open an application like \program.exe and another button open a directory like %appdata%\.minecraft
Here is my code that you could edit as an example:
`import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JButton;
public class Minenow {
private JFrame frmMinenow;
/**
* Launch the application.
*/
public static void NewScreen() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Minenow window = new Minenow();
window.frmMinenow.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Minenow() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmMinenow = new JFrame();
frmMinenow.setTitle("Minenow");
frmMinenow.setBounds(100, 100, 793, 503);
frmMinenow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frmMinenow.getContentPane().setLayout(null);
JButton btnNewButton = new JButton(".minecraft");
btnNewButton.setBounds(58, 50, 161, 80);
frmMinenow.getContentPane().add(btnNewButton);
}
`} | 0debug |
how to make Decimal conform LosslessStringConvertible in swift 5 : Hi here I want to convert Decimal to String.
It says Decimal needs to conform LosslessStringConvertible so I add an extension looks like
```
extension Decimal: LosslessStringConvertible {
public init?(_ description: String) {
}
}
```
But it won't work. My understanding is to extract the description, which is of String type, to a Decimal. But not sure how to do this... | 0debug |
def rearrange_numbs(array_nums):
result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i)
return result | 0debug |
static int waveformat_to_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as)
{
if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
dolog ("Invalid wave format, tag is not PCM, but %d\n",
wfx->wFormatTag);
return -1;
}
if (!wfx->nSamplesPerSec) {
dolog ("Invalid wave format, frequency is zero\n");
return -1;
}
as->freq = wfx->nSamplesPerSec;
switch (wfx->nChannels) {
case 1:
as->nchannels = 1;
break;
case 2:
as->nchannels = 2;
break;
default:
dolog (
"Invalid wave format, number of channels is not 1 or 2, but %d\n",
wfx->nChannels
);
return -1;
}
switch (wfx->wBitsPerSample) {
case 8:
as->fmt = AUD_FMT_U8;
break;
case 16:
as->fmt = AUD_FMT_S16;
break;
case 32:
as->fmt = AUD_FMT_S32;
break;
default:
dolog ("Invalid wave format, bits per sample is not "
"8, 16 or 32, but %d\n",
wfx->wBitsPerSample);
return -1;
}
return 0;
}
| 1threat |
How can I correctly converted this? : I tried a couple of times converting this date format Wed, 02 April 2015 15:50:53 SAST to this format YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] but with no luck so far.
Is there any better way to this, that I might have missed?
Will appreciate any help | 0debug |
Install programm on computer : <p>I have jar file. </p>
<p>Also I have batch file, which contains:</p>
<blockquote>
<p>start javaw -jar Name.jar</p>
</blockquote>
<p>I want make .exe-file, which copy jar-file in choosen folder and add batch-file to autorun. </p>
<p>How I may make it?</p>
| 0debug |
Regex on numbers - python : <p>I am new to regex and I need some help please. I have a dataframe in which I got column with amount, which is in most cases something like 869,850.0 and I need only rows where the number is ending with 950.00 or 999.00 I dont need something like 999.1 . I did not came up with any idea how to filer these values in pandas. </p>
<p>So I am trying to apply match with regex and because I am new to this I only know how to get number unit . something like [^.]*. but I dont know how to apply if and how to continue, can someone please help me?</p>
| 0debug |
if else statements formulation : <p>Maybe there was same question, but I don't know how to formulate it.
Is it any difference between:</p>
<pre><code>int x = 0;
if( someCondition )
{
x = 1;
}
</code></pre>
<p>And</p>
<pre><code>int x;
if( someCondition )
{
x = 1;
}
else
{
x = 0;
}
</code></pre>
| 0debug |
Parse string to float/double : <p>I am getting values from jTable and putting it in my DataBase (MySQL). In my DB table there is column PAYMENT that is double. When I try to put values from my jTable there is a problem with it:</p>
<pre><code>String payment=(String) jTable1.getValueAt(row, 2);
double pay=double .parseDouble (payment);
........
pst.setDouble(3, zar);
</code></pre>
<p>I am getting this exception: </p>
<blockquote>
<p>Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "84,21834324"</p>
</blockquote>
<p>How can I put this column from jTable as double in my DB table?
P.S.: I tried with float too.</p>
| 0debug |
int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
intptr_t offset, const char *name)
{
TCGContext *s = &tcg_ctx;
TCGTemp *ts, *base_ts = &s->temps[GET_TCGV_PTR(base)];
int idx, reg = base_ts->reg;
idx = s->nb_globals;
#if TCG_TARGET_REG_BITS == 32
if (type == TCG_TYPE_I64) {
char buf[64];
tcg_temp_alloc(s, s->nb_globals + 2);
ts = &s->temps[s->nb_globals];
ts->base_type = type;
ts->type = TCG_TYPE_I32;
ts->fixed_reg = 0;
ts->mem_allocated = 1;
ts->mem_reg = reg;
#ifdef HOST_WORDS_BIGENDIAN
ts->mem_offset = offset + 4;
#else
ts->mem_offset = offset;
#endif
pstrcpy(buf, sizeof(buf), name);
pstrcat(buf, sizeof(buf), "_0");
ts->name = strdup(buf);
ts++;
ts->base_type = type;
ts->type = TCG_TYPE_I32;
ts->fixed_reg = 0;
ts->mem_allocated = 1;
ts->mem_reg = reg;
#ifdef HOST_WORDS_BIGENDIAN
ts->mem_offset = offset;
#else
ts->mem_offset = offset + 4;
#endif
pstrcpy(buf, sizeof(buf), name);
pstrcat(buf, sizeof(buf), "_1");
ts->name = strdup(buf);
s->nb_globals += 2;
} else
#endif
{
tcg_temp_alloc(s, s->nb_globals + 1);
ts = &s->temps[s->nb_globals];
ts->base_type = type;
ts->type = type;
ts->fixed_reg = 0;
ts->mem_allocated = 1;
ts->mem_reg = reg;
ts->mem_offset = offset;
ts->name = name;
s->nb_globals++;
}
return idx;
}
| 1threat |
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
const BdrvChildRole *child_role,
uint64_t perm, uint64_t shared_perm,
void *opaque, Error **errp)
{
BdrvChild *child;
int ret;
ret = bdrv_check_update_perm(child_bs, perm, shared_perm, NULL, errp);
if (ret < 0) {
return NULL;
}
child = g_new(BdrvChild, 1);
*child = (BdrvChild) {
.bs = NULL,
.name = g_strdup(child_name),
.role = child_role,
.perm = perm,
.shared_perm = shared_perm,
.opaque = opaque,
};
bdrv_replace_child(child, child_bs);
return child;
}
| 1threat |
static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
int stride, int x, int y)
{
uint8_t *dst = s->frames[VP56_FRAME_CURRENT]->data[plane] + s->block_offset[b];
uint8_t *src_block;
int src_offset;
int overlap_offset = 0;
int mask = s->vp56_coord_div[b] - 1;
int deblock_filtering = s->deblock_filtering;
int dx;
int dy;
if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
&& !s->frames[VP56_FRAME_CURRENT]->key_frame))
deblock_filtering = 0;
dx = s->mv[b].x / s->vp56_coord_div[b];
dy = s->mv[b].y / s->vp56_coord_div[b];
if (b >= 4) {
x /= 2;
y /= 2;
}
x += dx - 2;
y += dy - 2;
if (x<0 || x+12>=s->plane_width[plane] ||
y<0 || y+12>=s->plane_height[plane]) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
src + s->block_offset[b] + (dy-2)*stride + (dx-2),
stride, 12, 12, x, y,
s->plane_width[plane],
s->plane_height[plane]);
src_block = s->edge_emu_buffer;
src_offset = 2 + 2*stride;
} else if (deblock_filtering) {
s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer,
src + s->block_offset[b] + (dy-2)*stride + (dx-2),
stride, 12);
src_block = s->edge_emu_buffer;
src_offset = 2 + 2*stride;
} else {
src_block = src;
src_offset = s->block_offset[b] + dy*stride + dx;
}
if (deblock_filtering)
vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
if (s->mv[b].x & mask)
overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
if (s->mv[b].y & mask)
overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
if (overlap_offset) {
if (s->filter)
s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
stride, s->mv[b], mask, s->filter_selection, b<4);
else
s->vp3dsp.put_no_rnd_pixels_l2(dst, src_block+src_offset,
src_block+src_offset+overlap_offset,
stride, 8);
} else {
s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
}
}
| 1threat |
static int open_self_cmdline(void *cpu_env, int fd)
{
int fd_orig = -1;
bool word_skipped = false;
fd_orig = open("/proc/self/cmdline", O_RDONLY);
if (fd_orig < 0) {
return fd_orig;
}
while (true) {
ssize_t nb_read;
char buf[128];
char *cp_buf = buf;
nb_read = read(fd_orig, buf, sizeof(buf));
if (nb_read < 0) {
fd_orig = close(fd_orig);
return -1;
} else if (nb_read == 0) {
break;
}
if (!word_skipped) {
cp_buf = memchr(buf, 0, sizeof(buf));
if (cp_buf) {
cp_buf++;
nb_read -= cp_buf - buf;
word_skipped = true;
}
}
if (word_skipped) {
if (write(fd, cp_buf, nb_read) != nb_read) {
return -1;
}
}
}
return close(fd_orig);
} | 1threat |
Why does printf modify previous local variables? : <p>I tried to understand C behavior and found some weird things.
I debugged and found out that table values are correct until calling printf.
I create a void function to test whether it is a problem of scope but after calling this function the table values still remained correct.
I wonder now if printf delete previous local variables.</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
void invertTable(int** tableau,int size){
int temp[size];
for(int i = 0; i < size; i++)
{
temp[i]=-1*tableau[0][i];
}
tableau[0]=temp;
}
void test(){
}
int main(int argc, char const *argv[])
{
int* table=(int*)malloc(5*sizeof(int));
table[0]=1;
table[1]=2;
table[2]=3;
table[3]=4;
table[4]=5;
invertTable(&table,5);
test();
for(int i = 0; i < 5; i++)
{
//Here is the problem
printf("\n %d \n",table[i]);
}
free(table);
return 0;
}
</code></pre>
<p>Expected -1 -2 -3 -4 -5</p>
<p>Output: -1 1962295758 1 1962550824 1962295741</p>
| 0debug |
Binary XML file line #1: invalid drawable tag vector : <p>I have an app that runs perfectly on most devices. However, I'm getting a <strong>FATAL exception</strong> whenever I try to run my application on devices with API < 21.</p>
<p>Here is the log:</p>
<pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aceinteract.sleak/com.aceinteract.sleak.activity.LoginRegisterActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_person_accent_24dp.xml from drawable resource ID #0x7f07006f
at android.content.res.Resources.loadDrawable(Resources.java:2842)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:1023)
at android.widget.EditText.<init>(EditText.java:76)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:64)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:681)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
at android.content.res.Resources.loadDrawable(Resources.java:2839)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:1023)
at android.widget.EditText.<init>(EditText.java:76)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:64)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:681)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
</code></pre>
<p>Here is the <strong>layout XML</strong></p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout_register"
android:visibility="gone"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditText
android:id="@+id/edit_register_full_name"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:drawableEnd="@drawable/ic_person_accent_24dp"
android:padding="20dp"
android:layout_width="0dp"
android:hint="@string/hint_full_name"
android:singleLine="true"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:drawableRight="@drawable/ic_person_accent_24dp" />
<EditText
android:id="@+id/edit_register_email"
app:layout_constraintTop_toBottomOf="@id/edit_register_full_name"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:drawableEnd="@drawable/ic_email_accent_24dp"
android:padding="20dp"
android:layout_width="0dp"
android:hint="@string/hint_email"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_email_accent_24dp" />
<EditText
android:id="@+id/edit_register_password"
app:layout_constraintTop_toBottomOf="@id/edit_register_email"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:drawableEnd="@drawable/ic_vpn_key_accent_24dp"
android:padding="20dp"
android:inputType="textPassword"
android:layout_width="0dp"
android:hint="@string/hint_password"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_vpn_key_accent_24dp" />
<CheckBox
android:id="@+id/check_register_show_password"
android:text="@string/desc_show_password"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/edit_register_password"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
</code></pre>
<p>And the <strong>gradle</strong> file:</p>
<pre><code>apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.aceinteract.sleak"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.2'
}
androidExtensions {
experimental = true
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:customtabs:27.0.2'
implementation 'com.android.support:support-vector-drawable:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:animated-vector-drawable:27.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:gridlayout-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:palette-v7:27.0.2'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.mikhaellopez:circularimageview:3.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
}
</code></pre>
<p>I have tried changing to <strong>AppComaptEditText</strong>, but it still just gives the same error.</p>
<p>Thanks in advance :)</p>
| 0debug |
Is it correct to bind a ViewModel to a Service? : <p>I've started using Architecture Components in my application and I'm still learning how to use it. </p>
<p>In my app I have an Activity showing different Fragments sequentially. In some of them I need to communicate with a background service in order to receive data from external BLE sensors. Since I need to interact with the service in more than one Fragment, I'm wondering if ViewModel is the right place where to make the binding. <a href="https://github.com/googlesamples/android-architecture-components/issues/20" rel="noreferrer">I've looked around</a> but I didn't found an answer.</p>
<p>Are there any problems binding a service inside a ViewModel?</p>
| 0debug |
JavaScript - When I declare a var named 'location', it gets sent to the URL? : <p>I just encountered the weirdest thing ever.</p>
<p>When I declare a variable called 'location', whatever the value of the variable gets sent to the URL.</p>
<pre><code>var location = 1;
// Results in http://localhost:8000/1
var location = document.getElementById('element');
// Results in http://localhost:8000/[object%20HTMLSelectElement]
</code></pre>
<p>This only happens for <code>location</code>. If I use let's say <code>locations</code>:</p>
<pre><code>var location2 = 1;
// Nothing weird happens
</code></pre>
<p>I'm using Django. I checked both my frontend and backend code and there doesn't seem to be any conflicting names.</p>
<p>What could be causing this?</p>
| 0debug |
int bdrv_flush(BlockDriverState *bs)
{
Coroutine *co;
FlushCo flush_co = {
.bs = bs,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
bdrv_flush_co_entry(&flush_co);
} else {
co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co);
qemu_coroutine_enter(co);
BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE);
}
return flush_co.ret;
}
| 1threat |
KVM bridged networking in a wirelss host : <p>I'm learning about KVM networking and I came up with this question:
When I set a KVM domain to use a bridged network (no NAT), I see that KVM (or libvirt) creates a <strong>tap0</strong> having <strong>virbr0</strong> as master in my case.
Now, I don't see any other interface participating in the bridge (brctl show).
I'm using a wireless connection in my host while doing the experiment, and I have connection in the guest.</p>
<ul>
<li>So how the host ends up providing connection to the guest?</li>
<li>As far as I understand, a bridge should connect one interface to another. So what sense makes a bridge with a single interface?</li>
<li>Besides, wireless interfaces are not supposed to be able to be included in a bridge right?</li>
</ul>
<p>Well, I'm confused at this point. I would appreciate some enlightenment from the experts. Thank you!</p>
| 0debug |
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
int log2_trafo_size)
{
HEVCLocalContext *lc = &s->HEVClc;
MvField *tab_mvf = s->ref->tab_mvf;
int log2_min_pu_size = s->sps->log2_min_pu_size;
int log2_min_tu_size = s->sps->log2_min_tb_size;
int min_pu_width = s->sps->min_pu_width;
int min_tu_width = s->sps->min_tb_width;
int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
(x0 >> log2_min_pu_size)].is_intra;
int i, j, bs;
if (y0 > 0 && (y0 & 7) == 0) {
int yp_pu = (y0 - 1) >> log2_min_pu_size;
int yq_pu = y0 >> log2_min_pu_size;
int yp_tu = (y0 - 1) >> log2_min_tu_size;
int yq_tu = y0 >> log2_min_tu_size;
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
int x_pu = (x0 + i) >> log2_min_pu_size;
int x_tu = (x0 + i) >> log2_min_tu_size;
MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu];
uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
x0 + i, y0 - 1);
bs = boundary_strength(s, curr, curr_cbf_luma,
top, top_cbf_luma, top_refPicList, 1);
if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
lc->boundary_flags & BOUNDARY_UPPER_SLICE &&
(y0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0;
else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
lc->boundary_flags & BOUNDARY_UPPER_TILE &&
(y0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0;
if (bs)
s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs;
}
}
if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra)
for (j = 8; j < (1 << log2_trafo_size); j += 8) {
int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
int yq_pu = (y0 + j) >> log2_min_pu_size;
int yp_tu = (y0 + j - 1) >> log2_min_tu_size;
int yq_tu = (y0 + j) >> log2_min_tu_size;
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
int x_pu = (x0 + i) >> log2_min_pu_size;
int x_tu = (x0 + i) >> log2_min_tu_size;
MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu];
uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
x0 + i,
y0 + j - 1);
bs = boundary_strength(s, curr, curr_cbf_luma,
top, top_cbf_luma, top_refPicList, 0);
if (bs)
s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs;
}
}
if (x0 > 0 && (x0 & 7) == 0) {
int xp_pu = (x0 - 1) >> log2_min_pu_size;
int xq_pu = x0 >> log2_min_pu_size;
int xp_tu = (x0 - 1) >> log2_min_tu_size;
int xq_tu = x0 >> log2_min_tu_size;
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
int y_pu = (y0 + i) >> log2_min_pu_size;
int y_tu = (y0 + i) >> log2_min_tu_size;
MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
x0 - 1, y0 + i);
bs = boundary_strength(s, curr, curr_cbf_luma,
left, left_cbf_luma, left_refPicList, 1);
if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
lc->boundary_flags & BOUNDARY_LEFT_SLICE &&
(x0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0;
else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
lc->boundary_flags & BOUNDARY_LEFT_TILE &&
(x0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0;
if (bs)
s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs;
}
}
if (log2_trafo_size > log2_min_pu_size && !is_intra)
for (j = 0; j < (1 << log2_trafo_size); j += 4) {
int y_pu = (y0 + j) >> log2_min_pu_size;
int y_tu = (y0 + j) >> log2_min_tu_size;
for (i = 8; i < (1 << log2_trafo_size); i += 8) {
int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
int xq_pu = (x0 + i) >> log2_min_pu_size;
int xp_tu = (x0 + i - 1) >> log2_min_tu_size;
int xq_tu = (x0 + i) >> log2_min_tu_size;
MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
x0 + i - 1,
y0 + j);
bs = boundary_strength(s, curr, curr_cbf_luma,
left, left_cbf_luma, left_refPicList, 0);
if (bs)
s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs;
}
}
}
| 1threat |
static void dump_stream_format(AVFormatContext *ic, int i,
int index, int is_output)
{
char buf[256];
int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
AVStream *st = ic->streams[i];
int g = av_gcd(st->time_base.num, st->time_base.den);
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
avcodec_string(buf, sizeof(buf), st->codec, is_output);
av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
if (flags & AVFMT_SHOW_IDS)
av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
if (lang)
av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
st->time_base.num / g, st->time_base.den / g);
av_log(NULL, AV_LOG_INFO, ": %s", buf);
if (st->sample_aspect_ratio.num &&
av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
AVRational display_aspect_ratio;
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
st->codec->width * st->sample_aspect_ratio.num,
st->codec->height * st->sample_aspect_ratio.den,
1024 * 1024);
av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
display_aspect_ratio.num, display_aspect_ratio.den);
}
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (st->avg_frame_rate.den && st->avg_frame_rate.num)
print_fps(av_q2d(st->avg_frame_rate), "fps");
#if FF_API_R_FRAME_RATE
if (st->r_frame_rate.den && st->r_frame_rate.num)
print_fps(av_q2d(st->r_frame_rate), "tbr");
#endif
if (st->time_base.den && st->time_base.num)
print_fps(1 / av_q2d(st->time_base), "tbn");
if (st->codec->time_base.den && st->codec->time_base.num)
print_fps(1 / av_q2d(st->codec->time_base), "tbc");
}
if (st->disposition & AV_DISPOSITION_DEFAULT)
av_log(NULL, AV_LOG_INFO, " (default)");
if (st->disposition & AV_DISPOSITION_DUB)
av_log(NULL, AV_LOG_INFO, " (dub)");
if (st->disposition & AV_DISPOSITION_ORIGINAL)
av_log(NULL, AV_LOG_INFO, " (original)");
if (st->disposition & AV_DISPOSITION_COMMENT)
av_log(NULL, AV_LOG_INFO, " (comment)");
if (st->disposition & AV_DISPOSITION_LYRICS)
av_log(NULL, AV_LOG_INFO, " (lyrics)");
if (st->disposition & AV_DISPOSITION_KARAOKE)
av_log(NULL, AV_LOG_INFO, " (karaoke)");
if (st->disposition & AV_DISPOSITION_FORCED)
av_log(NULL, AV_LOG_INFO, " (forced)");
if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
av_log(NULL, AV_LOG_INFO, " (visual impaired)");
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
av_log(NULL, AV_LOG_INFO, " (clean effects)");
av_log(NULL, AV_LOG_INFO, "\n");
dump_metadata(NULL, st->metadata, " ");
dump_sidedata(NULL, st, " ");
} | 1threat |
Access to configuration without dependency injection : <p>I was wondering if there was a way to access Configuration (Microsoft.Extensions.Configuration) without the use of dependency injection. Only examples I see are through constructor injection (using IOptions or injecting Configuration directly). </p>
<p>My dilemma is that I have a utility class-- not a service-- that has static methods to do things on the fly. In a few of those static methods I would like to retrieve a couple of properties from appsettings.json dynamically. Since this is strictly a utility class, I don't want have to inject this class into every other class that needs to use a method or two from the utility.</p>
<p>Any ideas on how to access the properties of appsettings.json without some sort of dependency injection.</p>
<p>FYI: using c# and .net core 1.1</p>
| 0debug |
How can I prevent overloading for extern "C" functions? : <p>I'm writing a c++ library that exposes some functions which are used only by C# code. However, as I accidently mistyped the paramter, I found that this code can be succesfully compiled and linked even without any warning as long as I don't use the (not mistyped version) function in the cpp file.</p>
<pre><code>struct Dummy { int a; double b; };
extern "C" void SetArray(Dummy* x, int cnt);
void SetArray(Dummy x, int cnt)
{
// a TODO placeholder.
}
</code></pre>
<p>How can I let compiler throw an error or a warning for this case? The compiler option -Wall is set but there's still no warning. Using tdmgcc 5.1.0.</p>
| 0debug |
static void qxl_exit_vga_mode(PCIQXLDevice *d)
{
if (d->mode != QXL_MODE_VGA) {
return;
}
trace_qxl_exit_vga_mode(d->id);
qxl_destroy_primary(d, QXL_SYNC);
} | 1threat |
Average a list of matrix : <p>For example, I have a list of matrix like this </p>
<pre><code>list2<-lapply(1:2, function(x) matrix(rnorm(6, 10, 1), nrow=2, ncol=3))
list2
</code></pre>
<p>How do I get a matrix which has the same size with each matrix in each list, and the value in each cell equal to the average of corresponding cell across lists. </p>
| 0debug |
how to change class from data frame to spatial polygon? : I have found the same in here <http://stackoverflow.com/questions/29736577/how-to-convert-data-frame-to-spatial-coordinates>. But in my case, I got very large data and i can do like the answer given. So anyone can help me to change classfrom data.frame to spatial polygon? | 0debug |
combine statechart and pedestrian block #anylogic : can I ask some question? I am very new and beginner user for AnyLogic. How I can combine the statechart and pedestrian library (ped block). From statechart linking to ped block and return to statechart again. I illustrate it here. Thanks in advance.[enter image description here][1]
I try to follow the steps in youtube (agents in process flow), but it has error. I do not very understand it. [enter image description here][2][enter image description here][2]
[1]: https://i.stack.imgur.com/pzVNe.jpg
[2]: https://i.stack.imgur.com/lNUFy.jpg | 0debug |
static void lm32_evr_init(MachineState *machine)
{
const char *cpu_model = machine->cpu_model;
const char *kernel_filename = machine->kernel_filename;
LM32CPU *cpu;
CPULM32State *env;
DriveInfo *dinfo;
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
qemu_irq *cpu_irq, irq[32];
ResetInfo *reset_info;
int i;
hwaddr flash_base = 0x04000000;
size_t flash_sector_size = 256 * 1024;
size_t flash_size = 32 * 1024 * 1024;
hwaddr ram_base = 0x08000000;
size_t ram_size = 64 * 1024 * 1024;
hwaddr timer0_base = 0x80002000;
hwaddr uart0_base = 0x80006000;
hwaddr timer1_base = 0x8000a000;
int uart0_irq = 0;
int timer0_irq = 1;
int timer1_irq = 3;
reset_info = g_malloc0(sizeof(ResetInfo));
if (cpu_model == NULL) {
cpu_model = "lm32-full";
}
cpu = cpu_lm32_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "qemu: unable to find CPU '%s'\n", cpu_model);
exit(1);
}
env = &cpu->env;
reset_info->cpu = cpu;
reset_info->flash_base = flash_base;
memory_region_init_ram(phys_ram, NULL, "lm32_evr.sdram", ram_size,
&error_abort);
vmstate_register_ram_global(phys_ram);
memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
dinfo = drive_get(IF_PFLASH, 0, 0);
pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
flash_sector_size, flash_size / flash_sector_size,
1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1);
env->pic_state = lm32_pic_init(*cpu_irq);
for (i = 0; i < 32; i++) {
irq[i] = qdev_get_gpio_in(env->pic_state, i);
}
sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
env->juart_state = lm32_juart_init();
reset_info->bootstrap_pc = flash_base;
if (kernel_filename) {
uint64_t entry;
int kernel_size;
kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
1, ELF_MACHINE, 0);
reset_info->bootstrap_pc = entry;
if (kernel_size < 0) {
kernel_size = load_image_targphys(kernel_filename, ram_base,
ram_size);
reset_info->bootstrap_pc = ram_base;
}
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
kernel_filename);
exit(1);
}
}
qemu_register_reset(main_cpu_reset, reset_info);
}
| 1threat |
here iOS SDK creating draggable marker : I want to create draggable marker but it doesn't work. What I have missing?
'''
let marker = NMAMapMarker(geoCoordinates: coordinates, image: markerImage!)
marker.isDraggable = true
mapView.add(mapObject: maker)
mapView.respond(to: .markerDragBegan) { (drag, map, marker) -> Bool in
return true
}
''' | 0debug |
R: issue with line chart : I am having a problem to construct a line chart. Here is the output of my line chart. Why is the output like this, I mean the lines don`t touch (are not continuous). Maybe the issue is connected with my data format or type?[enter image description here][1]
Thank you,
Hayk.
[1]: https://i.stack.imgur.com/Yt7Ft.jpg | 0debug |
What is the best way to refactor a class which has 1000 lines of code : <p>What is the best way to refactor a class which has 1000 lines of code? I have a class which generates a report. All methods in that class are private (No where else used). </p>
<p>How to split that class into multiple classes?</p>
| 0debug |
Ansible: create a user with sudo privileges : <p>I have taken over a Ubuntu 14.04 server. It has a user called "deployer" (used with capistrano), and as such, it needs sudo privileges. With this setup, I can log into the server and do stuff like:</p>
<pre><code>workstation> ssh deployer@myserver
myserver> sudo apt-get install git
myserver> exit
workstation>
</code></pre>
<p>I am trying to figure out how to use Ansible (version 2.0.2.0 and python 2.7.3) to create a user called "deployer" and be able to log into the server with that id and then so sudo-ish things like "apt-get install". My playbook looks like this:</p>
<pre><code>---
- hosts: example
become: yes
tasks:
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
- group: name=sudo state=present
- name: Add deployer user and add it to sudo
user: name=deployer
state=present
createhome=yes
become: yes
become_method: "sudo"
- name: Set up authorized keys for the deployer user
authorized_key: user=deployer key="{{item}}"
with_file:
- /home/jaygodse/.ssh/id_rsa.pub
</code></pre>
<p>After running this playbook, I am able to ssh into the machine as "deployer", (e.g. ssh deployer@myserver) but if I run a sudo command, it always asks me for my sudo password. </p>
<p>I understand that the "deployer" user ultimately has to find its way into the visudo users file, but I cannot figure out which magical Ansible incantations to invoke so that I can ssh into the machine as deployer and then run a sudo command (e.g. sudo apt-get install git") without being prompted for a sudo password. </p>
<p>I have searched high and low, and I can't seem to find an Ansible playbook fragment which puts the user "deployer" into the sudo group without requiring a password. How is this done?</p>
| 0debug |
Display negative currency with parentheses in Angular 2 / Typescript : <p>Angular's en-us localization has been updated since 1.3 to display negative currency with a negative sign instead of parentheses. I am using AngularJS 2 / Typescript and would like to override the default negative sign with parentheses (or even something else). </p>
<p><a href="https://github.com/angular/angular.js/issues/12870" rel="noreferrer" title="github angular issue">Discussion</a> on this shows to override negPre & negSuf however I do not see how to do this with Angular2. Or maybe a more elegant way to achieve this.</p>
| 0debug |
static int encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){
const int w= b->width;
const int h= b->height;
int x, y;
if(1){
int run=0;
int runs[w*h];
int run_index=0;
for(y=0; y<h; y++){
for(x=0; x<w; x++){
int v, p=0;
int l=0, lt=0, t=0, rt=0;
v= src[x + y*stride];
if(y){
t= src[x + (y-1)*stride];
if(x){
lt= src[x - 1 + (y-1)*stride];
}
if(x + 1 < w){
rt= src[x + 1 + (y-1)*stride];
}
}
if(x){
l= src[x - 1 + y*stride];
}
if(parent){
int px= x>>1;
int py= y>>1;
if(px<b->parent->width && py<b->parent->height)
p= parent[px + py*2*stride];
}
if(!(l|lt|t|rt|p)){
if(v){
runs[run_index++]= run;
run=0;
}else{
run++;
}
}
}
}
runs[run_index++]= run;
run_index=0;
run= runs[run_index++];
put_symbol2(&s->c, b->state[1], run, 3);
for(y=0; y<h; y++){
if(s->c.bytestream_end - s->c.bytestream < w*40){
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
for(x=0; x<w; x++){
int v, p=0;
int l=0, lt=0, t=0, rt=0;
v= src[x + y*stride];
if(y){
t= src[x + (y-1)*stride];
if(x){
lt= src[x - 1 + (y-1)*stride];
}
if(x + 1 < w){
rt= src[x + 1 + (y-1)*stride];
}
}
if(x){
l= src[x - 1 + y*stride];
}
if(parent){
int px= x>>1;
int py= y>>1;
if(px<b->parent->width && py<b->parent->height)
p= parent[px + py*2*stride];
}
if(l|lt|t|rt|p){
int context= av_log2(3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p));
put_rac(&s->c, &b->state[0][context], !!v);
}else{
if(!run){
run= runs[run_index++];
put_symbol2(&s->c, b->state[1], run, 3);
assert(v);
}else{
run--;
assert(!v);
}
}
if(v){
int context= av_log2(3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p));
int l2= 2*ABS(l) + (l<0);
int t2= 2*ABS(t) + (t<0);
put_symbol2(&s->c, b->state[context + 2], ABS(v)-1, context-4);
put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0);
}
}
}
}
return 0;
}
| 1threat |
How to install the latest openjdk 12 on Ubuntu 18.04 : <p>I've installed the default jdk by issuing the command:</p>
<pre><code>apt-get install default-jdk
</code></pre>
<p>This will install openjdk 11 and apt-get seems to install the files all over the place. Examples:</p>
<pre><code>/etc/java-11-openjdk/management
/usr/lib/jvm/java-11-openjdk-amd64/lib
/usr/share/doc/openjdk-11-jre-headless/JAVA_HOME
/var/lib/dpkg/info/openjdk-11-jre:amd64.postinst
</code></pre>
<p>As you can see by the example locations above, there are files scattered everywhere.</p>
<p>I've just installed a web app that's giving a warning that it only supports jdk 12 (I think it's the latest openjdk version). How can I install version 12 so that it replaces version 11? What is the best way to upgrade the openjdk version on Ubuntu 18.04 so that it doesn't mingle with the previous version?</p>
| 0debug |
readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
int total;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = atoi(optarg);
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > argc - 2)
return command_usage(&readv_cmd);
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
gettimeofday(&t1, NULL);
cnt = do_aio_readv(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
return 0;
}
if (Pflag) {
void* cmp_buf = malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %lld, "
"%zd bytes\n",
(long long) offset, qiov.size);
}
free(cmp_buf);
}
if (qflag)
return 0;
if (vflag)
dump_buffer(buf, offset, qiov.size);
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
qemu_io_free(buf);
return 0;
}
| 1threat |
static void spapr_phb_vfio_instance_init(Object *obj)
{
error_report("spapr-pci-vfio-host-bridge is deprecated");
}
| 1threat |
START_TEST(qint_from_int_test)
{
QInt *qi;
const int value = -42;
qi = qint_from_int(value);
fail_unless(qi != NULL);
fail_unless(qi->value == value);
fail_unless(qi->base.refcnt == 1);
fail_unless(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
g_free(qi);
}
| 1threat |
Decimal Rounding in VB.NET : I have a project where I need to round a decimal in the following manner:
If the number is between 12.01 up to 12.49 then it should round to 12.00
If the number is between 12.50 and 12.99,it should round to 13.00
I have tried function Math.Abs and Math.Round but could not achieve the exact results as required above.
Thank You,
Khalid. | 0debug |
Django rest framework permission_classes of ViewSet method : <p>I'm writing a rest API with the Django REST framework, and I'd like to protect certain endpoints with permissions. The permission classes look like they provide an elegant way to accomplish this. My problem is that I'd like to use different permission classes for different overridden ViewSet methods.</p>
<pre><code>class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
def create(self, request, *args, **kwargs):
return super(UserViewSet, self).create(request, *args, **kwargs)
@decorators.permission_classes(permissions.IsAdminUser)
def list(self, request, *args, **kwargs):
return super(UserViewSet, self).list(request, *args, **kwargs)
</code></pre>
<p>In the code above I'd like to allow registration (user creation) for unauthenticated users too, but I don't want to let list users to anyone, just for staff.</p>
<p>In the <a href="http://www.django-rest-framework.org/api-guide/permissions/" rel="noreferrer">docs</a> I saw examples for protecting API views (not ViewSet methods) with the <code>permission_classes</code> decorator, and I saw setting a permission classes for the whole ViewSet. But it seems not working on overridden ViewSet methods. Is there any way to only use them for certain endpoints? </p>
| 0debug |
static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
int *golden_frame)
{
VP56RangeCoder *c = &s->c;
int rows, cols;
ff_vp56_init_range_decoder(&s->c, buf, buf_size);
s->framep[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
vp56_rac_get(c);
ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
if (s->framep[VP56_FRAME_CURRENT]->key_frame)
{
vp56_rac_gets(c, 8);
if(vp56_rac_gets(c, 5) > 5)
vp56_rac_gets(c, 2);
if (vp56_rac_get(c)) {
av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
rows = vp56_rac_gets(c, 8);
cols = vp56_rac_gets(c, 8);
vp56_rac_gets(c, 8);
vp56_rac_gets(c, 8);
vp56_rac_gets(c, 2);
if (!s->macroblocks ||
16*cols != s->avctx->coded_width ||
16*rows != s->avctx->coded_height) {
avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
return 2;
} else if (!s->macroblocks)
return 1;
| 1threat |
typdef ignored on Visual Studio 2017 : Really simple, this photo explains the problem, Visual Studio 2017 error: **variable "InputCode" is not a type name**
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/9Ojef.png | 0debug |
static TileExcp decode_y1(DisasContext *dc, tilegx_bundle_bits bundle)
{
unsigned opc = get_Opcode_Y1(bundle);
unsigned ext = get_RRROpcodeExtension_Y1(bundle);
unsigned dest = get_Dest_Y1(bundle);
unsigned srca = get_SrcA_Y1(bundle);
unsigned srcb;
int imm;
switch (get_Opcode_Y1(bundle)) {
case RRR_1_OPCODE_Y1:
if (ext == UNARY_RRR_1_OPCODE_Y0) {
ext = get_UnaryOpcodeExtension_Y1(bundle);
return gen_rr_opcode(dc, OE(opc, ext, Y1), dest, srca);
}
case RRR_0_OPCODE_Y1:
case RRR_2_OPCODE_Y1:
case RRR_3_OPCODE_Y1:
case RRR_4_OPCODE_Y1:
case RRR_5_OPCODE_Y1:
case RRR_6_OPCODE_Y1:
case RRR_7_OPCODE_Y1:
srcb = get_SrcB_Y1(bundle);
return gen_rrr_opcode(dc, OE(opc, ext, Y1), dest, srca, srcb);
case SHIFT_OPCODE_Y1:
ext = get_ShiftOpcodeExtension_Y1(bundle);
imm = get_ShAmt_Y1(bundle);
return gen_rri_opcode(dc, OE(opc, ext, Y1), dest, srca, imm);
case ADDI_OPCODE_Y1:
case ADDXI_OPCODE_Y1:
case ANDI_OPCODE_Y1:
case CMPEQI_OPCODE_Y1:
case CMPLTSI_OPCODE_Y1:
imm = (int8_t)get_Imm8_Y1(bundle);
return gen_rri_opcode(dc, OE(opc, 0, Y1), dest, srca, imm);
default:
return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
}
}
| 1threat |
static void v4l2_free_buffer(void *opaque, uint8_t *unused)
{
V4L2Buffer* avbuf = opaque;
V4L2m2mContext *s = buf_to_m2mctx(avbuf);
atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel);
if (s->reinit) {
if (!atomic_load(&s->refcount))
sem_post(&s->refsync);
return;
}
if (avbuf->context->streamon) {
ff_v4l2_buffer_enqueue(avbuf);
return;
}
if (!atomic_load(&s->refcount))
ff_v4l2_m2m_codec_end(s->avctx);
}
| 1threat |
Convert arrays with object to array : <pre><code>{"result":[{"id":1,"currency":"USD"},{"id":2,"currency":"PLN"},{"id":3,"currency":"EUR"}],"success":true}
</code></pre>
<p>I would like to have array with only id:</p>
<pre><code>[1, 2, 3]
</code></pre>
| 0debug |
static void update_sono_yuv(AVFrame *sono, const ColorFloat *c, int idx)
{
int x, fmt = sono->format, w = sono->width;
uint8_t *lpy = sono->data[0] + idx * sono->linesize[0];
uint8_t *lpu = sono->data[1] + idx * sono->linesize[1];
uint8_t *lpv = sono->data[2] + idx * sono->linesize[2];
for (x = 0; x < w; x += 2) {
*lpy++ = c[x].yuv.y + 0.5f;
*lpu++ = c[x].yuv.u + 0.5f;
*lpv++ = c[x].yuv.v + 0.5f;
*lpy++ = c[x+1].yuv.y + 0.5f;
if (fmt == AV_PIX_FMT_YUV444P) {
*lpu++ = c[x+1].yuv.u + 0.5f;
*lpv++ = c[x+1].yuv.v + 0.5f;
}
}
}
| 1threat |
How to upgrade AWS RDS Aurora MySQL 5.6 to 5.7 : <p>We are using AWS RDS Aurora MySQL 5.6 for our production database.
AWS launched MySQL 5.7 compatible Aurora engine on 6th Feb, 2018.</p>
<p>I dont see any option in "modify instance" to change engine to MySQL 5.7
I dont see any option in restore snapshot to database with MySQL 5.7 either.</p>
<p>We want to do this upgrade with least downtime. Pls suggest what could be done here.</p>
| 0debug |
build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
unsigned facs, unsigned dsdt,
const char *oem_id, const char *oem_table_id)
{
AcpiFadtDescriptorRev1 *fadt = acpi_data_push(table_data, sizeof(*fadt));
fadt->firmware_ctrl = cpu_to_le32(facs);
bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
ACPI_BUILD_TABLE_FILE,
table_data, &fadt->firmware_ctrl,
sizeof fadt->firmware_ctrl);
fadt->dsdt = cpu_to_le32(dsdt);
bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
ACPI_BUILD_TABLE_FILE,
table_data, &fadt->dsdt,
sizeof fadt->dsdt);
fadt_setup(fadt, pm);
build_header(linker, table_data,
(void *)fadt, "FACP", sizeof(*fadt), 1, oem_id, oem_table_id);
}
| 1threat |
upgrading a symfony project from version 2 to version 3 : I have a project running using symfony version 2 and I wanted to immigate this same project to symfony version 3.Anybody knows how to do that,I will be very gratefull cause right now I'm stuck!!! | 0debug |
use of [] on variables : <p>hi there i got a php code from some tutorial but i can't understand the use of [] in front of the variables, can someone explain this code please.</p>
<pre><code>$text= "KKE68TSA76 Confirmed on 30/03/17 at 2:12PM Ksh100.00 received from 254786740098";
}
$mpesa =explode(" ", $text);
$receipt=$mpesa[0]; // Code
$pesa=$mpesa[5]; //
$p = explode("h", $pesa);
$decimal=$p[1]; // Amount with decimal
$dc = explode(".", $decimal);
$koma=$dc[0]; // Payment
$ondoa = explode(",", $koma);
$kwanza=$ondoa[0]; // Payment
$pili=$ondoa[1]; // Payment
$payment=$kwanza.$pili;
$phone=$mpesa[8]; // Phone
</code></pre>
| 0debug |
void helper_stq_raw(uint64_t t0, uint64_t t1)
{
stq_raw(t1, t0);
}
| 1threat |
def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd | 0debug |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.