problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
document.write('<script src="evil.js"></script>'); | 1threat |
Java project with Gradle and building jar file in Intellij IDEA - how to? : <p>Is there anywhere a tutorial on how to create Java project with Gradle and then build the jar file?</p>
<p>I'm running into various problems with that. When I create Java project and then add Gradle with File -> New -> Module -> Gradle -> ... then I get some errors about Java EE websocket's not available (I'm using Ultimate Edition) but nevermind about that, I managed to create that project by selecting File -> New -> Project... -> Gradle -> ... and now I have my Java project with Gradle working properly (I can debug it in IDE) but when I try to create an artifact (jar file) I get various errors depending on how much I messed up in project structure settings...</p>
<pre><code>Buildfile: build.xml does not exist!
Build failed
</code></pre>
<p>or</p>
<pre><code>Error: Could not find or load main class Main
</code></pre>
<p>I think that this project is such a mess right now that the best solution would be to create another new project and just copy Main.class and Gradle's dependencies into this new project.</p>
<p>But how to make it properly?</p>
| 0debug |
Need generic xpath/css_selectro for following html code : <p>Following is the html code for which I need generic xpath pr css_selector</p>
<pre><code><fieldset>
<legend>Forged Email:</legend>
<p class="custom-err-pos-handle">
<input id="domainforging" class="required custom-err-pos valid" name="forgedemailoption" value="f" aria-required="true" type="checkbox">
<label for="domainforging" style="width:auto" title="Checks that the envelope from domain matches the emails from domain">Envelope Domain Forging</label>
<br>
<input id="replytoheader" class="required custom-err-pos" name="forgedemailoption" value="r" type="checkbox">
<label for="replytoheader" style="width:auto" title="Checks that the domain of the reply-to address matches the envelope from domain">Reply-to Domain Forging</label>
<br>
<input id="headerdomain" class="required custom-err-pos" name="forgedemailoption" value="h" type="checkbox">
<label for="headerdomain" style="width:auto" title="Checks to see if the email From domain has been forged">Header Domain Forging</label>
</p>
</fieldset>
</code></pre>
<p>Need to pass values "Envelope Domain Forging" or "Reply-to Domain Forging" or "Header Domain Forging".</p>
| 0debug |
Interest rate program : <p>I am just beginning to learn C. So for practice I decided to write a interest rate calculator but for some reason my calculation always comes out as 0 and I can't figure it out. If you can please take a look.</p>
<pre><code>#include <stdio.h>
main()
{
int time;
float principle, rate, total;
printf("What is your starting amount? ");
scanf(" %f", &principle);
printf("What is your interest rate? ");
scanf(" %f", &rate);
printf("How long do you want to save? ");
scanf(" %d", &time);
total = principle * rate * time;
printf("You will have earned an interest amount of $%d", total);
return 0;
}
</code></pre>
| 0debug |
library not found for -lDoubleConversion : <p>I tried to build on XCode but <code>ld: library not found for -lDoubleConversion</code> error occurs. I could build <code>react-native run-ios</code>. That would work, but XCode could not build...</p>
<blockquote>
<p>ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/DoubleConversion'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Folly'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GTMOAuth2'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GTMSessionFetcher'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Google-Maps-iOS-Utils'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GoogleToolboxForMac'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Protobuf'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/React'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/glog'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/leveldb-library'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/nanopb'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/react-native-google-maps'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/react-native-maps'
ld: warning: directory not found for option '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/yoga'
ld: library not found for -lDoubleConversion
clang: error: linker command failed with exit code 1 (use -v to see invocation)</p>
</blockquote>
| 0debug |
void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict)
{
QObject *data;
int devfn;
if (do_pcie_aer_inject_error(mon, qdict, &data) < 0) {
return;
}
assert(qobject_type(data) == QTYPE_QDICT);
qdict = qobject_to_qdict(data);
devfn = (int)qdict_get_int(qdict, "devfn");
monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n",
qdict_get_str(qdict, "id"),
qdict_get_str(qdict, "root_bus"),
(int) qdict_get_int(qdict, "bus"),
PCI_SLOT(devfn), PCI_FUNC(devfn));
}
| 1threat |
import heapq as hq
def heap_replace(heap,a):
hq.heapify(heap)
hq.heapreplace(heap, a)
return heap | 0debug |
ogm_header(AVFormatContext *s, int idx)
{
struct ogg *ogg = s->priv_data;
struct ogg_stream *os = ogg->streams + idx;
AVStream *st = s->streams[idx];
const uint8_t *p = os->buf + os->pstart;
uint64_t time_unit;
uint64_t spu;
uint32_t size;
if(!(*p & 1))
return 0;
if(*p == 1) {
p++;
if(*p == 'v'){
int tag;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
p += 8;
tag = bytestream_get_le32(&p);
st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag);
st->codec->codec_tag = tag;
} else if (*p == 't') {
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codec->codec_id = CODEC_ID_TEXT;
p += 12;
} else {
uint8_t acid[5];
int cid;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
p += 8;
bytestream_get_buffer(&p, acid, 4);
acid[4] = 0;
cid = strtol(acid, NULL, 16);
st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid);
if (st->codec->codec_id != CODEC_ID_AAC)
st->need_parsing = AVSTREAM_PARSE_FULL;
}
size = bytestream_get_le32(&p);
size = FFMIN(size, os->psize);
time_unit = bytestream_get_le64(&p);
spu = bytestream_get_le64(&p);
p += 4;
p += 8;
if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
st->codec->width = bytestream_get_le32(&p);
st->codec->height = bytestream_get_le32(&p);
avpriv_set_pts_info(st, 64, time_unit, spu * 10000000);
} else {
st->codec->channels = bytestream_get_le16(&p);
p += 2;
st->codec->bit_rate = bytestream_get_le32(&p) * 8;
st->codec->sample_rate = spu * 10000000 / time_unit;
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
if (size >= 56 && st->codec->codec_id == CODEC_ID_AAC) {
p += 4;
size -= 4;
}
if (size > 52) {
av_assert0(FF_INPUT_BUFFER_PADDING_SIZE <= 52);
size -= 52;
st->codec->extradata_size = size;
st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
bytestream_get_buffer(&p, st->codec->extradata, size);
}
}
} else if (*p == 3) {
if (os->psize > 8)
ff_vorbis_comment(s, &st->metadata, p+7, os->psize-8);
}
return 1;
}
| 1threat |
Why the loop to search for a string that is present in a file returns True for first iteration and False for the rest? : <p>I have a file named text.txt which contains the following data:</p>
<pre><code>My
Name
Is
Lorem
Ipsum
</code></pre>
<p>My python code:</p>
<pre><code>with open("text.txt") as f:
for i in xrange(5):
print "Is\n" in f
</code></pre>
<p>Output:</p>
<pre><code>True
False
False
False
False
</code></pre>
<p>Why the output is True only when i=0?</p>
<p>What to do to get True for all the iterations? I do not want to store the contents of the file anywhere!</p>
| 0debug |
static struct omap_tipb_bridge_s *omap_tipb_bridge_init(
MemoryRegion *memory, hwaddr base,
qemu_irq abort_irq, omap_clk clk)
{
struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
g_malloc0(sizeof(struct omap_tipb_bridge_s));
s->abort = abort_irq;
omap_tipb_bridge_reset(s);
memory_region_init_io(&s->iomem, NULL, &omap_tipb_bridge_ops, s,
"omap-tipb-bridge", 0x100);
memory_region_add_subregion(memory, base, &s->iomem);
return s;
}
| 1threat |
when i write a Macro which C++,it precessing error with "the declaration has no storage type" : when i write a Macro which C++,it precessing error with "the declaration has no storage type", and this is my code,what's wrong with is?If i impletment with function,it works well.It doubts me.
#define FLAG_CLEAR_MUL_BIT(op,beg,end) do{\
long _dwFlag = 0;\
for (int _i = 0; _i < end - beg;++_i)\
{\
_dwFlag |= (1 << _i);\
}\
_dwFlag = _dwFlag << beg;\
_dwFlag = ~_dwFlag;\
op = op & _dwFlag;\ // preprocessing wrong:This declaration has no storage type,if impletment with inline function,it works well
} | 0debug |
static int sp5x_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AVPacket avpkt_recoded;
const int qscale = 5;
const uint8_t *buf_ptr;
uint8_t *recoded;
int i = 0, j = 0;
if (!avctx->width || !avctx->height)
return -1;
buf_ptr = buf;
recoded = av_mallocz(buf_size + 1024);
if (!recoded)
return -1;
recoded[j++] = 0xFF;
recoded[j++] = 0xD8;
memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
j += sizeof(sp5x_data_dqt);
memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
j += sizeof(sp5x_data_dht);
memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
AV_WB16(recoded+j+5, avctx->coded_height);
AV_WB16(recoded+j+7, avctx->coded_width);
j += sizeof(sp5x_data_sof);
memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
j += sizeof(sp5x_data_sos);
if(avctx->codec_id==CODEC_ID_AMV)
for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
recoded[j++] = buf[i];
else
for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
{
recoded[j++] = buf[i];
if (buf[i] == 0xff)
recoded[j++] = 0;
}
recoded[j++] = 0xFF;
recoded[j++] = 0xD9;
avctx->flags &= ~CODEC_FLAG_EMU_EDGE;
av_init_packet(&avpkt_recoded);
avpkt_recoded.data = recoded;
avpkt_recoded.size = j;
i = ff_mjpeg_decode_frame(avctx, data, data_size, &avpkt_recoded);
av_free(recoded);
return i;
}
| 1threat |
Shortcut for joining two lines : <p>What's the keyboard shortcut for joining two lines in VS Code?</p>
<p>If the cursor is anywhere in the first line of</p>
<pre><code> f(foo,
bar)
</code></pre>
<p>then when I hit the shortcut, I want to get</p>
<pre><code> f(foo, bar)
</code></pre>
| 0debug |
Cannot call void user defined function inside main function in C programming : <p>When I try to run the below program</p>
<pre><code>#include<stdio.h>
/* demo.c: My first C program on a Linux */
void main()
{
getString();
}
void getString()
{
printf("Hello World");
}
</code></pre>
<p>I get the below error:</p>
<pre><code>sample.c:8:6: warning: conflicting types for ‘getString’ [enabled by default]
void getString()
^
sample.c:5:5: note: previous implicit declaration of ‘getString’ was here
getString();
</code></pre>
<p>I cannot find out why this error is showing in Compilation time.</p>
<p>Any help is greatly appreciated. Thanks in advance.</p>
| 0debug |
void ff_put_h264_qpel16_mc22_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_mid_16w_msa(src - (2 * stride) - 2, stride, dst, stride, 16);
}
| 1threat |
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. (django 2.0.1)(Python 3.6) : <p>It's my first time trying to deploy a Django app(django 2.0.1)(Python 3.6) to pythonanywhere, it is a simple portfolio app with no models, no bootstrap.
Just Django, HTML, CSS & Javascript.</p>
<p>After pulling it from the Github repo onto pythnanywhere with their bash console, I run :</p>
<pre><code>python manage.py migrate
</code></pre>
<p>& was hit with this error :</p>
<pre><code>Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 216, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 12, in <module>
from django.db.migrations.autodetector import MigrationAutodetector
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/db/migrations/autodetector.py", line 11, in <module>
from django.db.migrations.questioner import MigrationQuestioner
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-
packages/django/db/migrations/questioner.py", line 9, in <module>
from .loader import MigrationLoader
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 8, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder:
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
class Migration(models.Model):
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "/home/Limerin555/.virtualenvs/projectenv/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
</code></pre>
<p>I tired looking for solutions everywhere I could possibly find but nothing really helps, I've even tried adding this line to my settings.py :</p>
<pre><code>import django
django.setup()
</code></pre>
<p>underneath this line :</p>
<pre><code>SECRET_KEY = os.environ.get("SECRET_KEY")
</code></pre>
<p>as suggested from <a href="https://stackoverflow.com/questions/34114427/django-upgrading-to-1-9-error-appregistrynotready-apps-arent-loaded-yet">this post</a>, but to no avail.</p>
<p>Here is my settings.py :</p>
<pre><code>import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
STATIC_DIR = os.path.join(BASE_DIR, "static")
SECRET_KEY = os.environ.get('SECRET_KEY')
import django
django.setup()
DEBUG = False
ALLOWED_HOSTS = ["limerin555.pythonanywhere.com"]
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'portfolio_showcase',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'limerin.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'limerin.wsgi.application'
DATABASE_PATH = os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': DATABASE_PATH,
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Singapore'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = [
STATIC_DIR,
]
</code></pre>
<p>I am really lost on this, hoping someone can help shed some light on what's the real problem here.</p>
| 0debug |
I keep getting an error that my app needs to be verified when either I or another user try to authorize with OAuth2. What does that mean? : <p>I received this error when trying to authorize my app with my own account:</p>
<pre><code>Your project is trying to access scopes that need to go through the verification process.
{invalid=https://www.googleapis.com/auth/contacts}
If you need to use one of these scopes, submit a verification request. Learn More
</code></pre>
<p>When I use a different account, the error message is different:</p>
<pre><code>This app hasn’t been verified to access:
{invalid=https://www.googleapis.com/auth/contacts}
Are you the developer? If this project needs these scopes, sign in to an account with access to edit your project and try again.
If not, contact the developer for help.
</code></pre>
| 0debug |
How to make a basic GGPLOT2 time series graph : I need to graph
sat -0.038685744
sun -0.004397419
mon -0.072163337
tue 0.123328564
wed 0.021875962
thu 0.005030862
fri 0.002869955
but the steps on r-graph-gallery are confusing, so can someone help me out with a simple graph that shows days of the week on the x axis in ggplot2 | 0debug |
static int xan_unpack(uint8_t *dest, const int dest_len,
const uint8_t *src, const int src_len)
{
uint8_t opcode;
int size;
uint8_t *orig_dest = dest;
const uint8_t *src_end = src + src_len;
const uint8_t *dest_end = dest + dest_len;
while (dest < dest_end) {
opcode = *src++;
if (opcode < 0xe0) {
int size2, back;
if ((opcode & 0x80) == 0) {
size = opcode & 3;
back = ((opcode & 0x60) << 3) + *src++ + 1;
size2 = ((opcode & 0x1c) >> 2) + 3;
} else if ((opcode & 0x40) == 0) {
size = *src >> 6;
back = (bytestream_get_be16(&src) & 0x3fff) + 1;
size2 = (opcode & 0x3f) + 4;
} else {
size = opcode & 3;
back = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;
size2 = ((opcode & 0x0c) << 6) + *src++ + 5;
if (size + size2 > dest_end - dest)
break;
}
if (src + size > src_end || dest + size + size2 > dest_end ||
dest - orig_dest + size < back)
return -1;
bytestream_get_buffer(&src, dest, size);
dest += size;
av_memcpy_backptr(dest, back, size2);
dest += size2;
} else {
int finish = opcode >= 0xfc;
size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
if (src + size > src_end || dest + size > dest_end)
return -1;
bytestream_get_buffer(&src, dest, size);
dest += size;
if (finish)
break;
}
}
return dest - orig_dest;
}
| 1threat |
Regular expression : I want to pull out the string after src like for the following two samples as:
1. Images/17/0000894189/0000894189-17-005831/image00003.jpg
2. Images/17/0000894189/0000894189-17-005831/image0.jpg
`<div style="TEXT-ALIGN: center"><img src="Images/17/0000894189/0000894189-17-005831/image00003.jpg"></div>`
`<div style="TEXT-ALIGN: justify"><iMg style="HEIGHT: 63px; WIDTH: 289px" src="Images/17/0000894189/0000894189-17-005831/image0.jpg"></div>`
Could you please suggest regular expression which can give me this value? The position of src attribute in the img tag can vary. | 0debug |
C# find changes between two generic lists : <p>I had a problem with comparing two generic lists to find the set of changes because the effect of change propagates to multiple destinations:</p>
<p><strong>The Problems was:</strong></p>
<ul>
<li>They are not simple types (I have to use comparer</li>
<li>I need to know the changes (Added and Removed Items)</li>
<li>I have to create a usable solution</li>
</ul>
<p>Ex:- </p>
<p>Assume you have a trip and you want to open the update screen to add or remove the coming students. However, a simple list update is not enough since you want to find the students that are newly added or removed and send an e-mail to their parents:</p>
<p>Some search and thinking, I have developed a generic Extension Method that Helped me much... Find it below</p>
| 0debug |
static void vector_fmul_reverse_vfp(float *dst, const float *src0, const float *src1, int len)
{
src1 += len;
asm volatile(
"fldmdbs %[src1]!, {s0-s3}\n\t"
"fldmias %[src0]!, {s8-s11}\n\t"
"fldmdbs %[src1]!, {s4-s7}\n\t"
"fldmias %[src0]!, {s12-s15}\n\t"
"fmuls s8, s3, s8\n\t"
"fmuls s9, s2, s9\n\t"
"fmuls s10, s1, s10\n\t"
"fmuls s11, s0, s11\n\t"
"1:\n\t"
"subs %[len], %[len], #16\n\t"
"fldmdbsge %[src1]!, {s16-s19}\n\t"
"fmuls s12, s7, s12\n\t"
"fldmiasge %[src0]!, {s24-s27}\n\t"
"fmuls s13, s6, s13\n\t"
"fldmdbsge %[src1]!, {s20-s23}\n\t"
"fmuls s14, s5, s14\n\t"
"fldmiasge %[src0]!, {s28-s31}\n\t"
"fmuls s15, s4, s15\n\t"
"fmulsge s24, s19, s24\n\t"
"fldmdbsgt %[src1]!, {s0-s3}\n\t"
"fmulsge s25, s18, s25\n\t"
"fstmias %[dst]!, {s8-s13}\n\t"
"fmulsge s26, s17, s26\n\t"
"fldmiasgt %[src0]!, {s8-s11}\n\t"
"fmulsge s27, s16, s27\n\t"
"fmulsge s28, s23, s28\n\t"
"fldmdbsgt %[src1]!, {s4-s7}\n\t"
"fmulsge s29, s22, s29\n\t"
"fstmias %[dst]!, {s14-s15}\n\t"
"fmulsge s30, s21, s30\n\t"
"fmulsge s31, s20, s31\n\t"
"fmulsge s8, s3, s8\n\t"
"fldmiasgt %[src0]!, {s12-s15}\n\t"
"fmulsge s9, s2, s9\n\t"
"fmulsge s10, s1, s10\n\t"
"fstmiasge %[dst]!, {s24-s27}\n\t"
"fmulsge s11, s0, s11\n\t"
"fstmiasge %[dst]!, {s28-s31}\n\t"
"bgt 1b\n\t"
: [dst] "+&r" (dst), [src0] "+&r" (src0), [src1] "+&r" (src1), [len] "+&r" (len)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
"s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
"s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
"cc", "memory");
}
| 1threat |
Swift Trimming String : <p>I am trying to trim a string so that i am left with everything on the right side of a colon in Swift.</p>
<p>For example</p>
<blockquote>
<p>"Sally: Hello My Name is Sally"</p>
</blockquote>
<p>Becomes</p>
<blockquote>
<p>"Hello My Name is Sally"</p>
</blockquote>
<p>What would the trim function be?</p>
| 0debug |
static void gen_neon_dup_high16(TCGv var)
{
TCGv tmp = new_tmp();
tcg_gen_andi_i32(var, var, 0xffff0000);
tcg_gen_shri_i32(tmp, var, 16);
tcg_gen_or_i32(var, var, tmp);
dead_tmp(tmp);
}
| 1threat |
How to convert String array to Int array in Kotlin? : <p>Kotlin has many shorthands and interesting features. So, I wonder if there is some fast and short way of converting array of string to array of integers. Similar to this code in Python:</p>
<pre><code>results = [int(i) for i in results]
</code></pre>
| 0debug |
void vnc_display_open(DisplayState *ds, const char *display, Error **errp)
{
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
const char *options;
int password = 0;
int reverse = 0;
#ifdef CONFIG_VNC_TLS
int tls = 0, x509 = 0;
#endif
#ifdef CONFIG_VNC_SASL
int sasl = 0;
int saslErr;
#endif
#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
int acl = 0;
#endif
int lock_key_sync = 1;
if (!vnc_display) {
error_setg(errp, "VNC display not active");
return;
}
vnc_display_close(ds);
if (strcmp(display, "none") == 0)
return;
vs->display = g_strdup(display);
vs->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
options = display;
while ((options = strchr(options, ','))) {
options++;
if (strncmp(options, "password", 8) == 0) {
if (fips_get_state()) {
error_setg(errp,
"VNC password auth disabled due to FIPS mode, "
"consider using the VeNCrypt or SASL authentication "
"methods as an alternative");
goto fail;
}
password = 1;
} else if (strncmp(options, "reverse", 7) == 0) {
reverse = 1;
} else if (strncmp(options, "no-lock-key-sync", 16) == 0) {
lock_key_sync = 0;
#ifdef CONFIG_VNC_SASL
} else if (strncmp(options, "sasl", 4) == 0) {
sasl = 1;
#endif
#ifdef CONFIG_VNC_WS
} else if (strncmp(options, "websocket", 9) == 0) {
char *start, *end;
vs->websocket = 1;
start = strchr(options, '=');
end = strchr(options, ',');
if (start && (!end || (start < end))) {
int len = end ? end-(start+1) : strlen(start+1);
if (len < 6) {
char *host = NULL, *port = NULL, *host_end = NULL;
port = g_strndup(start + 1, len);
end = strchr(display, ',');
host_end = g_strrstr_len(display, end - display, ":");
if (host_end) {
host = g_strndup(display, host_end - display + 1);
} else {
host = g_strndup(":", 1);
}
vs->ws_display = g_strconcat(host, port, NULL);
g_free(host);
g_free(port);
}
}
#endif
#ifdef CONFIG_VNC_TLS
} else if (strncmp(options, "tls", 3) == 0) {
tls = 1;
} else if (strncmp(options, "x509", 4) == 0) {
char *start, *end;
x509 = 1;
if (strncmp(options, "x509verify", 10) == 0)
vs->tls.x509verify = 1;
start = strchr(options, '=');
end = strchr(options, ',');
if (start && (!end || (start < end))) {
int len = end ? end-(start+1) : strlen(start+1);
char *path = g_strndup(start + 1, len);
VNC_DEBUG("Trying certificate path '%s'\n", path);
if (vnc_tls_set_x509_creds_dir(vs, path) < 0) {
error_setg(errp, "Failed to find x509 certificates/keys in %s", path);
g_free(path);
goto fail;
}
g_free(path);
} else {
error_setg(errp, "No certificate path provided");
goto fail;
}
#endif
#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
} else if (strncmp(options, "acl", 3) == 0) {
acl = 1;
#endif
} else if (strncmp(options, "lossy", 5) == 0) {
vs->lossy = true;
} else if (strncmp(options, "non-adaptive", 12) == 0) {
vs->non_adaptive = true;
} else if (strncmp(options, "share=", 6) == 0) {
if (strncmp(options+6, "ignore", 6) == 0) {
vs->share_policy = VNC_SHARE_POLICY_IGNORE;
} else if (strncmp(options+6, "allow-exclusive", 15) == 0) {
vs->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
} else if (strncmp(options+6, "force-shared", 12) == 0) {
vs->share_policy = VNC_SHARE_POLICY_FORCE_SHARED;
} else {
error_setg(errp, "unknown vnc share= option");
goto fail;
}
}
}
#ifdef CONFIG_VNC_TLS
if (acl && x509 && vs->tls.x509verify) {
if (!(vs->tls.acl = qemu_acl_init("vnc.x509dname"))) {
fprintf(stderr, "Failed to create x509 dname ACL\n");
exit(1);
}
}
#endif
#ifdef CONFIG_VNC_SASL
if (acl && sasl) {
if (!(vs->sasl.acl = qemu_acl_init("vnc.username"))) {
fprintf(stderr, "Failed to create username ACL\n");
exit(1);
}
}
#endif
if (password) {
#ifdef CONFIG_VNC_TLS
if (tls) {
vs->auth = VNC_AUTH_VENCRYPT;
if (x509) {
VNC_DEBUG("Initializing VNC server with x509 password auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_X509VNC;
} else {
VNC_DEBUG("Initializing VNC server with TLS password auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_TLSVNC;
}
} else {
#endif
VNC_DEBUG("Initializing VNC server with password auth\n");
vs->auth = VNC_AUTH_VNC;
#ifdef CONFIG_VNC_TLS
vs->subauth = VNC_AUTH_INVALID;
}
#endif
#ifdef CONFIG_VNC_SASL
} else if (sasl) {
#ifdef CONFIG_VNC_TLS
if (tls) {
vs->auth = VNC_AUTH_VENCRYPT;
if (x509) {
VNC_DEBUG("Initializing VNC server with x509 SASL auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_X509SASL;
} else {
VNC_DEBUG("Initializing VNC server with TLS SASL auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_TLSSASL;
}
} else {
#endif
VNC_DEBUG("Initializing VNC server with SASL auth\n");
vs->auth = VNC_AUTH_SASL;
#ifdef CONFIG_VNC_TLS
vs->subauth = VNC_AUTH_INVALID;
}
#endif
#endif
} else {
#ifdef CONFIG_VNC_TLS
if (tls) {
vs->auth = VNC_AUTH_VENCRYPT;
if (x509) {
VNC_DEBUG("Initializing VNC server with x509 no auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_X509NONE;
} else {
VNC_DEBUG("Initializing VNC server with TLS no auth\n");
vs->subauth = VNC_AUTH_VENCRYPT_TLSNONE;
}
} else {
#endif
VNC_DEBUG("Initializing VNC server with no auth\n");
vs->auth = VNC_AUTH_NONE;
#ifdef CONFIG_VNC_TLS
vs->subauth = VNC_AUTH_INVALID;
}
#endif
}
#ifdef CONFIG_VNC_SASL
if ((saslErr = sasl_server_init(NULL, "qemu")) != SASL_OK) {
error_setg(errp, "Failed to initialize SASL auth: %s",
sasl_errstring(saslErr, NULL, NULL));
goto fail;
}
#endif
vs->lock_key_sync = lock_key_sync;
if (reverse) {
int csock;
vs->lsock = -1;
#ifdef CONFIG_VNC_WS
vs->lwebsock = -1;
#endif
if (strncmp(display, "unix:", 5) == 0) {
csock = unix_connect(display+5, errp);
} else {
csock = inet_connect(display, errp);
}
if (csock < 0) {
goto fail;
}
vnc_connect(vs, csock, 0, 0);
} else {
char *dpy;
dpy = g_malloc(256);
if (strncmp(display, "unix:", 5) == 0) {
pstrcpy(dpy, 256, "unix:");
vs->lsock = unix_listen(display+5, dpy+5, 256-5, errp);
} else {
vs->lsock = inet_listen(display, dpy, 256,
SOCK_STREAM, 5900, errp);
if (vs->lsock < 0) {
g_free(dpy);
goto fail;
}
#ifdef CONFIG_VNC_WS
if (vs->websocket) {
if (vs->ws_display) {
vs->lwebsock = inet_listen(vs->ws_display, NULL, 256,
SOCK_STREAM, 0, errp);
} else {
vs->lwebsock = inet_listen(vs->display, NULL, 256,
SOCK_STREAM, 5700, errp);
}
if (vs->lwebsock < 0) {
if (vs->lsock) {
close(vs->lsock);
vs->lsock = -1;
}
g_free(dpy);
goto fail;
}
}
#endif
}
g_free(vs->display);
vs->display = dpy;
qemu_set_fd_handler2(vs->lsock, NULL,
vnc_listen_regular_read, NULL, vs);
#ifdef CONFIG_VNC_WS
if (vs->websocket) {
qemu_set_fd_handler2(vs->lwebsock, NULL,
vnc_listen_websocket_read, NULL, vs);
}
#endif
}
return;
fail:
g_free(vs->display);
vs->display = NULL;
#ifdef CONFIG_VNC_WS
g_free(vs->ws_display);
vs->ws_display = NULL;
#endif
}
| 1threat |
static void test_cipher_speed(const void *opaque)
{
QCryptoCipher *cipher;
Error *err = NULL;
double total = 0.0;
size_t chunk_size = (size_t)opaque;
uint8_t *key = NULL, *iv = NULL;
uint8_t *plaintext = NULL, *ciphertext = NULL;
size_t nkey = qcrypto_cipher_get_key_len(QCRYPTO_CIPHER_ALG_AES_128);
size_t niv = qcrypto_cipher_get_iv_len(QCRYPTO_CIPHER_ALG_AES_128,
QCRYPTO_CIPHER_MODE_CBC);
key = g_new0(uint8_t, nkey);
memset(key, g_test_rand_int(), nkey);
iv = g_new0(uint8_t, niv);
memset(iv, g_test_rand_int(), niv);
ciphertext = g_new0(uint8_t, chunk_size);
plaintext = g_new0(uint8_t, chunk_size);
memset(plaintext, g_test_rand_int(), chunk_size);
cipher = qcrypto_cipher_new(QCRYPTO_CIPHER_ALG_AES_128,
QCRYPTO_CIPHER_MODE_CBC,
key, nkey, &err);
g_assert(cipher != NULL);
g_assert(qcrypto_cipher_setiv(cipher,
iv, niv,
&err) == 0);
g_test_timer_start();
do {
g_assert(qcrypto_cipher_encrypt(cipher,
plaintext,
ciphertext,
chunk_size,
&err) == 0);
total += chunk_size;
} while (g_test_timer_elapsed() < 5.0);
total /= 1024 * 1024;
g_print("cbc(aes128): ");
g_print("Testing chunk_size %ld bytes ", chunk_size);
g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
g_print("%.2f MB/sec\n", total / g_test_timer_last());
qcrypto_cipher_free(cipher);
g_free(plaintext);
g_free(ciphertext);
g_free(iv);
g_free(key);
}
| 1threat |
NULL help please : I am currently using SQL Server 2008R2.
I am using this script:
SELECT a.productname, a.orderdate, a.workarea
FROM database1table1 AS a
WHERE a.orderdate >='2016/08/01'
Which gives the output:
PRODUCT NAME ORDER DATE WORKAREA
x 2016/08/07 NULL
y 2016/08/09 HOLDING
z 2016/08/10 ACTION
a 2016/08/12 ACTION
My problem arises when I amend the above script to read,
...
WHERE a.orderdate >='2016/08/01'
**AND a.workarea NOT IN ('HOLDING')**
When I do this, not only does it remove 'HOLDING', but it also removes the NULL rows as well, which I definitely do not want.
Please can you suggest an amendment to the script to prevent the NULLS being removed - I only want to see the value 'HOLDING' taken out.
With many thanks!
| 0debug |
static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);
if (!qobj || qobject_type(qobj) != QTYPE_QBOOL) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"boolean");
return;
}
*obj = qbool_get_bool(qobject_to_qbool(qobj));
}
| 1threat |
grlib_irqmp_writel(void *opaque, target_phys_addr_t addr, uint32_t value)
{
IRQMP *irqmp = opaque;
IRQMPState *state;
assert(irqmp != NULL);
state = irqmp->state;
assert(state != NULL);
addr &= 0xff;
switch (addr) {
case LEVEL_OFFSET:
value &= 0xFFFF << 1;
state->level = value;
return;
case PENDING_OFFSET:
return;
case FORCE0_OFFSET:
value &= 0xFFFE;
state->force[0] = value;
grlib_irqmp_check_irqs(irqmp->state);
return;
case CLEAR_OFFSET:
value &= ~1;
state->pending &= ~value;
return;
case MP_STATUS_OFFSET:
return;
case BROADCAST_OFFSET:
value &= 0xFFFE;
state->broadcast = value;
return;
default:
break;
}
if (addr >= MASK_OFFSET && addr < FORCE_OFFSET) {
int cpu = (addr - MASK_OFFSET) / 4;
assert(cpu >= 0 && cpu < IRQMP_MAX_CPU);
value &= ~1;
state->mask[cpu] = value;
grlib_irqmp_check_irqs(irqmp->state);
return;
}
if (addr >= FORCE_OFFSET && addr < EXTENDED_OFFSET) {
int cpu = (addr - FORCE_OFFSET) / 4;
assert(cpu >= 0 && cpu < IRQMP_MAX_CPU);
uint32_t force = value & 0xFFFE;
uint32_t clear = (value >> 16) & 0xFFFE;
uint32_t old = state->force[cpu];
state->force[cpu] = (old | force) & ~clear;
grlib_irqmp_check_irqs(irqmp->state);
return;
}
if (addr >= EXTENDED_OFFSET && addr < IRQMP_REG_SIZE) {
int cpu = (addr - EXTENDED_OFFSET) / 4;
assert(cpu >= 0 && cpu < IRQMP_MAX_CPU);
value &= 0xF;
state->extended[cpu] = value;
return;
}
trace_grlib_irqmp_unknown_register("write", addr);
}
| 1threat |
how can i take the textview text from custom listview contains 3 textviews and an imageview? : public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView textView = (TextView) listView.findViewById(R.id.namee);
String title = textView.getText().toString();
TextView textVieww = (TextView) listView.findViewById(R.id.cityy);
String city = textVieww.getText().toString();
TextView textViewww = (TextView) listView.findViewById(R.id.placee);
String place = textViewww.getText().toString();
Toast.makeText(getActivity(),title+" "+city+" "+place,Toast.LENGTH_SHORT).show();
Data.title = title;
Data.city = city;
Data.place = place;
final FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new ViewItemFrag()).commit();
} | 0debug |
import re
def text_match_three(text):
patterns = 'ab{3}?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | 0debug |
A beginner-made python number guessing game. Please help optimize and resolve issues : <p>I have just started to learn coding. This is a simple number guessing game that I created with Python. It works fine but I feel like the code can be simplified/optimized so it looks more neat. Another thing is that every time I try to input a non-integer, an error occurred. Is there a way to check if the user input is an integer or not and then proceed to the next step only if it is an integer. Thank you in advance!</p>
<pre><code>from random import randint
random_number = randint(1, 10)
guesses_taken = 0
print ("Hello! What is your name?")
guess_name = input()
print ("Well, " + guess_name + ", I am thinking of a number between 1-10.")
while guesses_taken < 4:
print ("Take a guess!")
guess = int(input())
if guess not in range(1, 11):
print ("Oops! That's not an option!")
elif guess == random_number:
print ("You're right! Congratulations!")
break
else:
guesses_taken += 1
if guesses_taken < 4:
print ("Nope! Try again,")
else:
print ("Out of chances. You lose.")
</code></pre>
| 0debug |
Weird output for echo and print_r : <p>I haver discovered some weird behavior and cannot explain what is going on:</p>
<pre><code>$e = 3;
echo "with array " . print_r($e);
</code></pre>
<p>gives:</p>
<pre><code>3with array 1
</code></pre>
<p>why?</p>
| 0debug |
static uint32_t nabm_readw (void *opaque, uint32_t addr)
{
PCIAC97LinkState *d = opaque;
AC97LinkState *s = &d->ac97;
AC97BusMasterRegs *r = NULL;
uint32_t index = addr - s->base[1];
uint32_t val = ~0U;
switch (index) {
case PI_SR:
case PO_SR:
case MC_SR:
r = &s->bm_regs[GET_BM (index)];
val = r->sr;
dolog ("SR[%d] -> %#x\n", GET_BM (index), val);
break;
case PI_PICB:
case PO_PICB:
case MC_PICB:
r = &s->bm_regs[GET_BM (index)];
val = r->picb;
dolog ("PICB[%d] -> %#x\n", GET_BM (index), val);
break;
default:
dolog ("U nabm readw %#x -> %#x\n", addr, val);
break;
}
return val;
}
| 1threat |
AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
enum AVSampleFormat sample_fmt, int size,
int64_t channel_layout, int packed)
{
return avfilter_get_audio_buffer(link->dst->outputs[0], perms, sample_fmt,
size, channel_layout, packed);
}
| 1threat |
How can I refresh a page when a database is updated(Laravel)? : <p>How can I refresh a page when a database is updated in Laravel?</p>
| 0debug |
Neural network weird prediction : <p>I try to implement a neural network. I'm using backpropagation to compute the gradients. After obtaining the gradients, I multiply them by the learning rate and subtract them from the corresponding weights. (basically trying to apply gradient descent, please tell me if this is wrong).
So the first thing I tried after having the backpropagation and gradient descent ready, was to train a simple XOR classifier where the inputs can be (0,0), (1,0), (0,1), (1,1) and the corresponding outputs are 0, 1, 1, 0. So my neural network contains 2 input units, 1 output unit and one hidden layer with 3 units on it. When training it with a learning rate of 3.0 for >100 (even tried >5000), the cost drops until a specific point where it gets stuck, so it's remaining constant. The weights are randomly initialized each time I run the program, but it always gets stuck at the same specific cost. Anyways, after the training is finished I tried to run my neural network on any of the above inputs and the output is always 0.5000. I thought about changing the inputs and outputs so they are : (-1,-1), (1, -1), (-1, 1), (1, 1) and the outputs -1, 1, 1, -1. Now when trained with the same learning rate, the cost is dropping continuously, no matter the number of iterations but the results are still wrong, and they always tend to be very close to 0. I even tried to train it for an insane number of iterations and the results are the following: [ iterations: (20kk), inputs:(1, -1), output:(1.6667e-08) ] and also [iterations: (200kk), inputs:(1, -1), output:(1.6667e-09) ], also tried for inputs(1,1) and others, the output is also very close to 0. It seems like the output is always mean(min(y), max(y)), it doesn't matter in what form I provide the input/output. I can't figure out what I'm doing wrong, can someone please help?</p>
| 0debug |
static void chr_read(void *opaque, const uint8_t *buf, int size)
{
TestServer *s = opaque;
CharDriverState *chr = s->chr;
VhostUserMsg msg;
uint8_t *p = (uint8_t *) &msg;
int fd;
if (size != VHOST_USER_HDR_SIZE) {
g_test_message("Wrong message size received %d\n", size);
return;
g_mutex_lock(&s->data_mutex);
memcpy(p, buf, VHOST_USER_HDR_SIZE);
if (msg.size) {
p += VHOST_USER_HDR_SIZE;
size = qemu_chr_fe_read_all(chr, p, msg.size);
if (size != msg.size) {
g_test_message("Wrong message size received %d != %d\n",
size, msg.size);
return;
switch (msg.request) {
case VHOST_USER_GET_FEATURES:
msg.flags |= VHOST_USER_REPLY_MASK;
msg.size = sizeof(m.payload.u64);
msg.payload.u64 = 0x1ULL << VHOST_F_LOG_ALL |
0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
p = (uint8_t *) &msg;
qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
break;
case VHOST_USER_SET_FEATURES:
g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
!=, 0ULL);
break;
case VHOST_USER_GET_PROTOCOL_FEATURES:
msg.flags |= VHOST_USER_REPLY_MASK;
msg.size = sizeof(m.payload.u64);
msg.payload.u64 = 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
p = (uint8_t *) &msg;
qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
break;
case VHOST_USER_GET_VRING_BASE:
msg.flags |= VHOST_USER_REPLY_MASK;
msg.size = sizeof(m.payload.state);
msg.payload.state.num = 0;
p = (uint8_t *) &msg;
qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
assert(msg.payload.state.index < 2);
s->rings &= ~(0x1ULL << msg.payload.state.index);
break;
case VHOST_USER_SET_MEM_TABLE:
memcpy(&s->memory, &msg.payload.memory, sizeof(msg.payload.memory));
s->fds_num = qemu_chr_fe_get_msgfds(chr, s->fds, G_N_ELEMENTS(s->fds));
g_cond_signal(&s->data_cond);
break;
case VHOST_USER_SET_VRING_KICK:
case VHOST_USER_SET_VRING_CALL:
qemu_chr_fe_get_msgfds(chr, &fd, 1);
qemu_set_nonblock(fd);
break;
case VHOST_USER_SET_LOG_BASE:
if (s->log_fd != -1) {
close(s->log_fd);
s->log_fd = -1;
qemu_chr_fe_get_msgfds(chr, &s->log_fd, 1);
msg.flags |= VHOST_USER_REPLY_MASK;
msg.size = 0;
p = (uint8_t *) &msg;
qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE);
g_cond_signal(&s->data_cond);
break;
case VHOST_USER_SET_VRING_BASE:
assert(msg.payload.state.index < 2);
s->rings |= 0x1ULL << msg.payload.state.index;
break;
default:
break;
g_mutex_unlock(&s->data_mutex); | 1threat |
How to repeatedly add the same element to an array : <p>How to repeatedly add the same element to an array, I am new beginner in Java, could anyone help me solve this problem</p>
<p>For example, </p>
<pre><code>When N = 1
int[] a1 = {1,2,3}
When N = 2
the result is
a1 = {1,2,3,1,2,3}
</code></pre>
<p>what's about 2-d array?</p>
<pre><code>N is the number of rows
When N = 1
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9}}
When N= 2
a2 = {{1,2,3},{4,5,6},{7,8,9}
{1,2,3},{4,5,6},{7,8,9}}
</code></pre>
| 0debug |
how to Finding Differences in two Images with PHP : How to find difference between two image?
[![Image][1]][1]
[1]: https://i.stack.imgur.com/KdbxZ.png
Please check above image i hopw you can clear. both image are same but one image have also text so how to different this things?
thank you so much in advance.. | 0debug |
JS: getElementById not working? : I have a function like this
function f(el){
var a = el.getElementsByName("name");
}
I know that I can use `arguments` for this but what if I want to do it like the method above? Thanks!
Also no jQuery please
| 0debug |
How do I Programmatically create a button and assign a macro to it upon opening spreadsheet? : What I need to do upon opening a spreadsheet is to execute some VBA to produce a button for me and automatically assign a macro I have created previously to it, let's call this macro "edit_colour" (which has been pre-recorded and saved).
Now, I know how to Automatically execute (AutoOpen) a MsgBox with "Hello World" using the following,
Private Sub Workbook_Open()
MsgBox "Hello World"
End Sub
However, to create a button programmatically (can't do it any other way unfortunately) and assign "edit_colour" to that macro seems a tad more complex. Can anyone assist with this please?
Thank you!
| 0debug |
static int bethsoftvid_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
BethsoftvidContext * vid = avctx->priv_data;
char block_type;
uint8_t * dst;
uint8_t * frame_end;
int remaining = avctx->width;
const int wrap_to_next_line = vid->frame.linesize[0] - avctx->width;
int code;
int yoffset;
if (avctx->reget_buffer(avctx, &vid->frame)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
bytestream2_init(&vid->g, avpkt->data, avpkt->size);
dst = vid->frame.data[0];
frame_end = vid->frame.data[0] + vid->frame.linesize[0] * avctx->height;
switch(block_type = bytestream2_get_byte(&vid->g)){
case PALETTE_BLOCK: {
int ret;
*data_size = 0;
if ((ret = set_palette(vid)) < 0) {
av_log(avctx, AV_LOG_ERROR, "error reading palette\n");
return ret;
}
return bytestream2_tell(&vid->g);
}
case VIDEO_YOFF_P_FRAME:
yoffset = bytestream2_get_le16(&vid->g);
if(yoffset >= avctx->height)
return -1;
dst += vid->frame.linesize[0] * yoffset;
}
while((code = bytestream2_get_byte(&vid->g))){
int length = code & 0x7f;
while(length > remaining){
if(code < 0x80)
bytestream2_get_buffer(&vid->g, dst, remaining);
else if(block_type == VIDEO_I_FRAME)
memset(dst, bytestream2_peek_byte(&vid->g), remaining);
length -= remaining;
dst += remaining + wrap_to_next_line;
remaining = avctx->width;
if(dst == frame_end)
goto end;
}
if(code < 0x80)
bytestream2_get_buffer(&vid->g, dst, length);
else if(block_type == VIDEO_I_FRAME)
memset(dst, bytestream2_get_byte(&vid->g), length);
remaining -= length;
dst += length;
}
end:
*data_size = sizeof(AVFrame);
*(AVFrame*)data = vid->frame;
return avpkt->size;
}
| 1threat |
Trying to write a function that will print all numbers from 1 to 1000 that the sum of their figures is divisible by 8 : So just like the topic says, I'm trying to write an efficient function that will print all numbers from 1 to 1000 that the sum of their figures is divisible by 10.
I'm using this 'for': `for (var i = 1; i <= 1000; i++) {`
but not sure about the mathematics.
Thanks for the kind help. | 0debug |
Tuples from postgresql not getting extracted onto the webpage using rails : stack overflow! I'm a newbie to using ROR. I'm trying to develop a simple blog app using rails 5.0.1 and psql.
The problem is that,although 3 tuples are stored in the db(I checked it),when I extract it using "@posts=Post.all "command, only 3 horizontal lines occur(I.e the 3 tuples are scanned but not displayed).
The code :
<% @posts.each do |post| %>
<h3> <%= post.title %></h3><hr/>
<p><%= post.body %></p>
<% end %>
The index view : (https://i.stack.imgur.com/1UtDq.jpg)
The psql db : (https://i.stack.imgur.com/htx52.jpg)
Can someone please help? | 0debug |
static void virtio_blk_handle_read(VirtIOBlockReq *req)
{
BlockDriverAIOCB *acb;
uint64_t sector;
sector = ldq_p(&req->out->sector);
if (sector & req->dev->sector_mask) {
acb = bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
req->qiov.size / BDRV_SECTOR_SIZE,
virtio_blk_rw_complete, req);
if (!acb) {
| 1threat |
static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,
unsigned size)
{
mv88w8618_eth_state *s = opaque;
switch (offset) {
case MP_ETH_SMIR:
if (s->smir & MP_ETH_SMIR_OPCODE) {
switch (s->smir & MP_ETH_SMIR_ADDR) {
case MP_ETH_PHY1_BMSR:
return MP_PHY_BMSR_LINK | MP_PHY_BMSR_AUTONEG |
MP_ETH_SMIR_RDVALID;
case MP_ETH_PHY1_PHYSID1:
return (MP_PHY_88E3015 >> 16) | MP_ETH_SMIR_RDVALID;
case MP_ETH_PHY1_PHYSID2:
return (MP_PHY_88E3015 & 0xFFFF) | MP_ETH_SMIR_RDVALID;
default:
return MP_ETH_SMIR_RDVALID;
}
}
return 0;
case MP_ETH_ICR:
return s->icr;
case MP_ETH_IMR:
return s->imr;
case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
return s->frx_queue[(offset - MP_ETH_FRDP0)/4];
case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
return s->rx_queue[(offset - MP_ETH_CRDP0)/4];
case MP_ETH_CTDP0 ... MP_ETH_CTDP3:
return s->tx_queue[(offset - MP_ETH_CTDP0)/4];
default:
return 0;
}
}
| 1threat |
Need specified regexp : https://regex101.com/r/YWgrlO/1
I have test data on the link "summer camp", "summer", "camp", me need to make a regular expression so that "summer camp" becomes the first match | 0debug |
How do you sync Postman with a git repository : <p>I'm wondering how you can sync your Postman config with a git repository.</p>
<p>I know you can export and import from Postman to a folder - which is OK - but I wondered if there was something more effortless.</p>
| 0debug |
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
{
BDRVBochsState *s = bs->opaque;
int64_t offset = sector_num * 512;
int64_t extent_index, extent_offset, bitmap_offset;
char bitmap_entry;
extent_index = offset / s->extent_size;
extent_offset = (offset % s->extent_size) / 512;
if (s->catalog_bitmap[extent_index] == 0xffffffff) {
return -1;
}
bitmap_offset = s->data_offset + (512 * s->catalog_bitmap[extent_index] *
(s->extent_blocks + s->bitmap_blocks));
if (bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
&bitmap_entry, 1) != 1) {
return -1;
}
if (!((bitmap_entry >> (extent_offset % 8)) & 1)) {
return -1;
}
return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset));
}
| 1threat |
void visit_get_next_type(Visitor *v, int *obj, const int *qtypes,
const char *name, Error **errp)
{
if (v->get_next_type) {
v->get_next_type(v, obj, qtypes, name, errp);
}
}
| 1threat |
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
const char *desc_file_path)
{
int ret;
char access[11];
char type[11];
char fname[512];
const char *p = desc;
int64_t sectors = 0;
int64_t flat_offset;
char extent_path[PATH_MAX];
BlockDriverState *extent_file;
while (*p) {
flat_offset = -1;
ret = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
access, §ors, type, fname, &flat_offset);
if (ret < 4 || strcmp(access, "RW")) {
goto next_line;
} else if (!strcmp(type, "FLAT")) {
if (ret != 5 || flat_offset < 0) {
return -EINVAL;
}
} else if (ret != 4) {
return -EINVAL;
}
if (sectors <= 0 ||
(strcmp(type, "FLAT") && strcmp(type, "SPARSE")) ||
(strcmp(access, "RW"))) {
goto next_line;
}
path_combine(extent_path, sizeof(extent_path),
desc_file_path, fname);
ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags);
if (ret) {
return ret;
}
if (!strcmp(type, "FLAT")) {
VmdkExtent *extent;
extent = vmdk_add_extent(bs, extent_file, true, sectors,
0, 0, 0, 0, sectors);
extent->flat_start_offset = flat_offset << 9;
} else if (!strcmp(type, "SPARSE")) {
ret = vmdk_open_sparse(bs, extent_file, bs->open_flags);
if (ret) {
bdrv_delete(extent_file);
return ret;
}
} else {
fprintf(stderr,
"VMDK: Not supported extent type \"%s\""".\n", type);
return -ENOTSUP;
}
next_line:
while (*p && *p != '\n') {
p++;
}
p++;
}
return 0;
}
| 1threat |
Stop objects from colliding using SpriteKit : <p>I am testing out the features of SpriteKit and I ran into a problem. I was reading into bit masks, colliding, category, and contact. I get what they are, mostly at least, I don't get the point of category bitmasks, but I get colliding bitmasks which are the ones I need to solve my problem.</p>
<p>Ok so my problem is I have two different types of sprites: <em>object</em> and <em>second.</em> The names don't really make much sense but it is just for the sake of testing. I want second to have an impulse, and I want object to have a force. I was able to apply the respective vectors on the sprites, but I do not want them to collide with each other. I want them to pass right through and ignore the existence of each other.</p>
<p>I tried to solve that issue by assigning different collision bitmasks to each other:</p>
<pre><code>override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let texture = SKTexture(imageNamed: "pokeball")
let object = SKSpriteNode(texture: texture)
object.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: object.size.width,height: object.size.height))
object.physicsBody?.affectedByGravity = false
object.yScale = 0.5
object.xScale = 0.5
for t in touches {
object.position = t.location(in: self)
}
self.addChild(object)
object.physicsBody?.collisionBitMask = UInt32(4)
object.physicsBody?.applyForce(CGVector(dx: 0, dy: 10))
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let texture = SKTexture(imageNamed: "purple")
let second = SKSpriteNode(texture: texture)
let impulse : Double = 20
let x = (impulse * Double(cosf(45)))
let y = Double(impulse * Double(sinf(45)))
let vector = CGVector(dx: x, dy: y)
second.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: second.size.width,height: second.size.height))
second.yScale = 1.5
second.xScale = 1.5
second.physicsBody?.isDynamic = true
for t in touches {
second.position = t.location(in: self)
}
self.addChild(second)
second.physicsBody?.collisionBitMask = UInt32(1)
second.physicsBody?.applyImpulse(vector)
}
</code></pre>
<p>So object has a bitmask of 4:</p>
<pre><code>object.physicsBody?.collisionBitMask = UInt32(4)
</code></pre>
<p>And second has a bitmask of 1:</p>
<pre><code>second.physicsBody?.collisionBitMask = UInt32(1)
</code></pre>
<p>I ran the simulator and they are still colliding with each other, so I went online and tried to look for some answers: I found one that says I must use numbers like:</p>
<blockquote>
<p>these are bitmasks, you can't use arbitrary numbers 1,2,3,4,5 - you must use 1,2,4,8,16 and so on –</p>
</blockquote>
<p>Can someone explain why? However, that wasn't the issue because I was using 1 and 4</p>
<p>Next question I ran into said that I had to use binary numbers (0100) and (0010), I tried them, same issue: still colliding.</p>
<p>I will leave a picture of the collisions:
<a href="https://i.stack.imgur.com/reKz7.png">Collisions</a></p>
<p>Does anyone know why this is happening? My apologies in advance if this is a really dumb mistake or something that has already been asked, I just couldn't find it.</p>
| 0debug |
How do i enable javascript autoload function : is there a way i can enhance my script to autoload instad of using button. Also is there a way i can include fade-in style sort of in this script.
<script>
var content = [
"Headline",
"Headline 1",
"Headline 2",
"Headline 3",
];
var msgPtr = 0;
var stopAction = null;
function change() {
var newMsg = content[msgPtr];
document.getElementById('change').innerHTML = 'Breaking News: '+msgPtr+'<p>'+newMsg;
msgPtr++; msgPtr = (msgPtr % content.length);
}
function startFunction() { change(); stopAction = setInterval(change, 4000); }
function stopFunction() { clearInterval(stopAction); }
</script>
| 0debug |
static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
KmvcContext *const ctx = avctx->priv_data;
AVFrame *frame = data;
uint8_t *out, *src;
int i, ret;
int header;
int blocksize;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
bytestream2_init(&ctx->g, avpkt->data, avpkt->size);
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
header = bytestream2_get_byte(&ctx->g);
if (bytestream2_peek_byte(&ctx->g) == 127) {
bytestream2_skip(&ctx->g, 3);
for (i = 0; i < 127; i++) {
ctx->pal[i + (header & 0x81)] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g);
bytestream2_skip(&ctx->g, 1);
}
bytestream2_seek(&ctx->g, -127 * 4 - 3, SEEK_CUR);
}
if (header & KMVC_KEYFRAME) {
frame->key_frame = 1;
frame->pict_type = AV_PICTURE_TYPE_I;
} else {
frame->key_frame = 0;
frame->pict_type = AV_PICTURE_TYPE_P;
}
if (header & KMVC_PALETTE) {
frame->palette_has_changed = 1;
for (i = 1; i <= ctx->palsize; i++) {
ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g);
}
}
if (pal) {
frame->palette_has_changed = 1;
memcpy(ctx->pal, pal, AVPALETTE_SIZE);
}
if (ctx->setpal) {
ctx->setpal = 0;
frame->palette_has_changed = 1;
}
memcpy(frame->data[1], ctx->pal, 1024);
blocksize = bytestream2_get_byte(&ctx->g);
if (blocksize != 8 && blocksize != 127) {
av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);
return AVERROR_INVALIDDATA;
}
memset(ctx->cur, 0, 320 * 200);
switch (header & KMVC_METHOD) {
case 0:
case 1:
memcpy(ctx->cur, ctx->prev, 320 * 200);
break;
case 3:
kmvc_decode_intra_8x8(ctx, avctx->width, avctx->height);
break;
case 4:
kmvc_decode_inter_8x8(ctx, avctx->width, avctx->height);
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);
return AVERROR_INVALIDDATA;
}
out = frame->data[0];
src = ctx->cur;
for (i = 0; i < avctx->height; i++) {
memcpy(out, src, avctx->width);
src += 320;
out += frame->linesize[0];
}
if (ctx->cur == ctx->frm0) {
ctx->cur = ctx->frm1;
ctx->prev = ctx->frm0;
} else {
ctx->cur = ctx->frm0;
ctx->prev = ctx->frm1;
}
*got_frame = 1;
return avpkt->size;
}
| 1threat |
Can any body help me to create this image in android by using shape : <p><a href="https://i.stack.imgur.com/BWBz8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BWBz8.png" alt="enter image description here"></a></p>
<p>Please suggest me which is the best way to create this image by just create png or jpeg or by using shape. I want an only bg image not "20% Off" written. I can do it by just using the circle. But I am not able to create the background image.</p>
| 0debug |
static void m68060_cpu_initfn(Object *obj)
{
M68kCPU *cpu = M68K_CPU(obj);
CPUM68KState *env = &cpu->env;
m68k_set_feature(env, M68K_FEATURE_M68000);
m68k_set_feature(env, M68K_FEATURE_USP);
m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
m68k_set_feature(env, M68K_FEATURE_BRAL);
m68k_set_feature(env, M68K_FEATURE_BCCL);
m68k_set_feature(env, M68K_FEATURE_BITFIELD);
m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
m68k_set_feature(env, M68K_FEATURE_SCALED_INDEX);
m68k_set_feature(env, M68K_FEATURE_LONG_MULDIV);
m68k_set_feature(env, M68K_FEATURE_FPU);
m68k_set_feature(env, M68K_FEATURE_CAS);
m68k_set_feature(env, M68K_FEATURE_BKPT);
m68k_set_feature(env, M68K_FEATURE_RTD);
} | 1threat |
static void blur(CoverContext *cover, AVFrame *in, int offx, int offy)
{
int x, y, p;
for (p=0; p<3; p++) {
int ox = offx>>!!p;
int oy = offy>>!!p;
int stride = in->linesize[p];
uint8_t *data = in->data[p] + ox + oy * stride;
int w = FF_CEIL_RSHIFT(cover->width , !!p);
int h = FF_CEIL_RSHIFT(cover->height, !!p);
int iw = FF_CEIL_RSHIFT(in->width , !!p);
int ih = FF_CEIL_RSHIFT(in->height, !!p);
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
int c = 0;
int s = 0;
if (ox) {
int scale = 65536 / (x + 1);
s += data[-1 + y*stride] * scale;
c += scale;
}
if (oy) {
int scale = 65536 / (y + 1);
s += data[x - stride] * scale;
c += scale;
}
if (ox + w < iw) {
int scale = 65536 / (w - x);
s += data[w + y*stride] * scale;
c += scale;
}
if (oy + h < ih) {
int scale = 65536 / (h - y);
s += data[x + h*stride] * scale;
c += scale;
}
data[x + y*stride] = (s + (c>>1)) / c;
}
}
}
}
| 1threat |
Creating mutiline text area in javascript : <!DOCTYPE html>
<html>
<body>
<p>Click the button to create a File Upload Button.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.createElement("INPUT");
var y = document.createElement("INPUT");
x.setAttribute("type", "textarea");
y.setAttribute("type", "file");
document.body.appendChild(x);
document.body.appendChild(y);
}
</script>
</body>
</html>
Please help us with the code for creating a visible multi-line text area in the same language as the code. | 0debug |
sql retrieve the name of every customer and how many pizzas they have ordered (NULL if no pizzas ordered) : I have to answer a question that has to be answered int a certain format.
SELECT blank 1
FROM blank 2(
SELECT blank 3 AS quantity
FROM ORDERS NATURAL JOIN ORDERCONTENTS
GROUP BY blank 4) as quantity
ON customers.customerID=quantity.customerID
ORDER BY name;
the outcome has to retrieve the name of every customer and how many pizzas they have ordered (NULL if no pizzas ordered).
the database contains 5 tables with a layout as such
Customers
columns
customerID,
name,
address,
phoneNumber,
email
Ordercontents
columns
orderID,
name,
quantity
orders
columns
orderID,
customerID,
postcode,
Date
products
columns
name,
price
stores
columns
postcode,
address,
phoneNumber
The numbered blanks have to be replaced to produce the outcome.
help I am stuck trying to solve this. | 0debug |
static void slavio_timer_init_all(target_phys_addr_t addr, qemu_irq master_irq,
qemu_irq *cpu_irqs, unsigned int num_cpus)
{
DeviceState *dev;
SysBusDevice *s;
unsigned int i;
dev = qdev_create(NULL, "slavio_timer");
qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
qdev_init(dev);
s = sysbus_from_qdev(dev);
sysbus_connect_irq(s, 0, master_irq);
sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
for (i = 0; i < MAX_CPUS; i++) {
sysbus_mmio_map(s, i + 1, addr + (target_phys_addr_t)CPU_TIMER_OFFSET(i));
sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
}
}
| 1threat |
When use String.Insert(int index, string text) insert at the end of the new string: "00000" [C#] : I need to insert in a specific position of "string line", another string, so I compute the specific position for start to insert:
string info1 = "info1";
string info2 = "info2";
string info3 = "info3";
string info4 = "info4";
string keyWord = "BELEGIT";
start = line.IndexOf(keyWord, 0) + keyWord.Length + 13;
var aStringBuilder = new StringBuilder(line);
aStringBuilder.Remove(start, 19);
line = aStringBuilder.ToString();
string newLine = line.Insert(start, "\r\n" + info1 + "\r\n" + "\r\n" + info2 + "\r\n" + info3 + "\r\n" + info4);
(NewLine will be the content of a file in my application). "NewLine" contains the correct content except the string "00000" that inserts after "info4". So in my new file with the content that is "newLine" there is "newLine" and immediately after "00000". I do not really understand why.
Thanks in advance.
| 0debug |
Desktop application through java netbeans : I want to design a desktop software in java through Netbeans.
So when creating a 'New Project' in Netbeans, what i would have to select - whether 'Java Application' under "java" or 'JavaFX Application under "JavaFX" ? | 0debug |
What is the optimal way to return a private value from inside a class? : <p>I'm attempting to optimize my code for maximum readability and for that I need my code to be in-line through and through. I will present two snippets of code as an example. In my eyes the below one is more easier for the eyes. These snippets (one of them) would be stored in a class and setting <em>width</em> should only be possible inside the class while getting <em>Width</em> should always be possible.</p>
<p><strong>A:</strong></p>
<pre><code>private int width;
public int Width
{
get { return width; }
private set { }
}
</code></pre>
<p><strong>B:</strong></p>
<pre><code>private int width;
public int Width()
{
return width;
}
</code></pre>
<p>As far as I am concerned these two ways of achieving the same end result are identical. Because I would like to be thoroughly in-line in all my classes I wouldn't want to use both ways mixed together. The B-approach seems cleaner in my eyes.</p>
<p><strong>Are there any downsides/upsides to either approach. Should one approach be favored over the other? Are A and B approaches really completely identical?</strong></p>
| 0debug |
Error:error: '' is incompatible with attribute android:background (attr) reference|color : <p>I can't run my app and some of the attributes are unrecognized, resources aren't supported as the app build results suggest.How do i fix all of the resource values? Can it be a problem from the dependencies? can the android studio read the dependecies and resource allocation.How is it related
to incompatablity issues of the android resources
Here is my xml</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="16dp"
android:background="@color/colorPrimary"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolBar"
android:id="@+id/add_reminder_layout_top"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/reminder_title"
android:layout_marginLeft="32dp"
android:layout_marginTop="10dp"
android:hint="Name"
android:textSize="20sp"
android:minLines="1"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_person_black_24dp"
android:drawablePadding="12dp"
android:gravity="center|start"
android:textColor="@android:color/background_dark"
android:scrollHorizontally="false"
android:textColorHint="@android:color/background_dark"
android:inputType="textCapWords"
android:layout_marginRight="16dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/phone_no"
android:layout_marginLeft="32dp"
android:hint="phone Number"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:textSize="20sp"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_phone_black_24dp"
android:drawablePadding="12dp"
android:gravity="center|start"
android:textColor="@android:color/background_dark"
android:scrollHorizontally="false"
android:textColorHint="@android:color/background_dark"
android:inputType="phone"
android:layout_marginRight="16dp"
/>
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/add_reminder_layout_top">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_marginTop="8dp"
android:text="@string/details"
android:id="@+id/details"
android:textSize="15sp"
android:gravity="center_vertical"
android:layout_marginLeft="72dp"
android:textColor="@android:color/primary_text_light"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:onClick="setDate"
android:id="@+id/date"
android:background="@drawable/ic_launcher_foreground"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_date"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/date_icon">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date_text"
android:textSize="15dp"
android:text="@string/date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_date"
android:textSize="15dp"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:onClick="setTime"
android:id="@+id/time"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_time"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/time_icon">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time_text"
android:textSize="15dp"
android:text="@string/time"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_time"
android:textSize="15dp"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:id="@+id/repeat">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_repeat"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/repeat_ll"
android:layout_toRightOf="@+id/repeat_icon">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_text"
android:textSize="15dp"
android:text="@string/repeat"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_repeat"
android:textSize="15dp"
/>
</LinearLayout>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_switch"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp"
android:onClick="onSwitchRepeat"
android:checked="true"
android:textOn="On"
android:textOff="Off"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:onClick="setRepeatNo"
android:id="@+id/repeat_no"
android:background=""
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_no_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_repeat_no"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/repeat_no_icon">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_no_text"
android:textSize="15dp"
android:text="@string/repetition_interval"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_repeat_no"
android:textSize="15dp"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:onClick="selectRepeatType"
android:id="@+id/repeat_type"
android:background="@mipmap/ic_launcher"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_type_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="32dp"
android:src="@drawable/ic_repeat_no"
android:layout_centerVertical="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/repeat_type_icon">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repeat_type_text"
android:textSize="15dp"
android:text="@string/type_of_repetitions"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/set_repeat_type"
android:textSize="15dp"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/starred1"
android:clickable="true"
android:onClick="selectFab1"
fab:fab_icon="@drawable/notification_off"
fab:fab_colorNormal="@color/colorAccent"
fab:fab_colorPressed="@color/colorPrimary"
app:fab_size="mini"
android:layout_alignParentRight="true"
android:layout_marginTop="170dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/starred2"
android:clickable="true"
android:onClick="selectFab2"
fab:fab_icon="@drawable/notification_on"
fab:fab_colorNormal="@color/colorAccent"
fab:fab_colorPressed="@color/colorPrimary"
app:fab_size="mini"
android:layout_alignParentRight="true"
android:layout_marginTop="170dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"/>
<CheckBox
android:id="@+id/checkBox_completed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/add_reminder_layout_top"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp"
android:layout_marginLeft="48dp"
android:layout_marginStart="48dp"
android:text="Completed" />
<CheckBox
android:id="@+id/checkBox_failed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox_completed"
android:layout_alignBottom="@+id/checkBox_completed"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
android:text="Failed" />
>
</code></pre>
<p></p>
<p>And here is my error</p>
<pre><code>Information:Gradle tasks [:app:generateReleaseSources, :app:mockableAndroidJar]
C:\Users\ghjsk\AndroidStudioProjects\NavDrawer\app\src\main\res\layout\activity_add_reminder.xml
Error:error: '' is incompatible with attribute android:background (attr) reference|color.
Error:'' is incompatible with attribute android:background (attr) reference|color.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processReleaseResources'.
> Failed to execute aapt
Information:BUILD FAILED in 18s
Information:7 errors
Information:0 warnings
Information:See complete output in console
</code></pre>
| 0debug |
void dpy_gl_scanout(QemuConsole *con,
uint32_t backing_id, bool backing_y_0_top,
uint32_t x, uint32_t y, uint32_t width, uint32_t height)
{
assert(con->gl);
con->gl->ops->dpy_gl_scanout(con->gl, backing_id,
backing_y_0_top,
x, y, width, height);
} | 1threat |
coudn't get value from text box : i have a text box called txtUprice.. which gets the value from a data grid view
**but when i tried get value of txtUprice text box in a message box.. (with or without changing the text box value) im getting an error "Input string was not in a correct format"**
i have tried changing the data type in sql where i get the value to the datagrid
//to get value for textbox from data grid i have used this code
txtUprice.Text = datagridview.SelectedRows[0].Cells[4].Value.ToString()
//to take the textbox value to messagebox i have used this code
int unitprice;
unitprice = int.Parse(txtUprice.Text);
MessageBox.Show(unitprice.ToString()); | 0debug |
static int recover(WtvContext *wtv, uint64_t broken_pos)
{
AVIOContext *pb = wtv->pb;
int i;
for (i = 0; i < wtv->nb_index_entries; i++) {
if (wtv->index_entries[i].pos > broken_pos) {
int ret = avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);
if (ret < 0)
return ret;
wtv->pts = wtv->index_entries[i].timestamp;
return 0;
}
}
return AVERROR(EIO);
}
| 1threat |
How to cast activity to fragment by converting activity to fragment? : As a beginner, I am struggling here to solve one issue in my programming code.
I have Navigation drawer -> If I click item from the Navigation drawer, it opens the separate Fragment which has two tabs named as "Lists" and "Photos".
My aim is , When I click the first tab ie. "Lists tab", I am trying to call "Listclassfragment class" which has to display listview. When I click or swipe the second tab ie. photos tab, "photosfragment" class will be called and it has to show photos in grid. I am achieving this by using ViewPagerAdapter
When I try to work on ListClassFragment, I am getting the Error,
**Error : incompatible types: Activity cannot be converted to ListClassFragment**
**ListClassFragment class:**
public class ListClassFragment extends Fragment {
private ListView listview;
private ArrayList<ListView_Model> books;
private ArrayAdapter<ListView_Model> adapter;
private final static String TAG = ListClassFragment.class.getSimpleName();
private final static String url = "http://myfee.org/apps/customer?id=1";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_listview, container, false);
listview = (ListView) view.findViewById(R.id.listview);
setListViewAdapter();
getDataFromInternet();
return view;
}
private void getDataFromInternet() {
new GetJsonFromUrlTask(getActivity(), url).execute();
}
private void setListViewAdapter() {
books = new ArrayList<ListView_Model>();
adapter = new CustomListViewAdapter(getActivity(), R.layout.item_listview, books);
listview.setAdapter(adapter);
}
//parse response data after asynctask finished
public void parseJsonResponse(String result) {
Log.i(TAG, result);
try {
JSONObject json = new JSONObject(result);
JSONArray jArray = new JSONArray(json.getString("customer"));
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
ListView_Model book = new ListView_Model();
book.setName(jObject.getString("name"));
book.setAuthorName(jObject.getString("email"));
book.setPhoneNo(jObject.getString("phone_no"));
/*Pay Button here*/
book.setImageUrl1(R.drawable.custom_button);
books.add(book);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}}
**GetJsonFromUrlTask class:**
public class GetJsonFromUrlTask extends AsyncTask<Void, Void, String> {
private Activity activity;
private String url;
private ProgressDialog dialog;
private final static String TAG = GetJsonFromUrlTask.class.getSimpleName();
public GetJsonFromUrlTask(Activity activity, String url) {
super();
this.activity = activity;
this.url = url;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progress dialog
dialog = new ProgressDialog(activity);
// Set progress dialog title
dialog.setTitle("Loading Datas....");
// Set progress dialog message
dialog.setMessage("Please wait!!");
dialog.setIndeterminate(false);
// Show progress dialog
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
// call load JSON from url method
return loadJSON(this.url).toString();
}
@Override
protected void onPostExecute(String result) {
((ListClassFragment) activity).parseJsonResponse(result);
dialog.dismiss();
Log.i(TAG, result);
}
public JSONObject loadJSON(String url) {
// Creating JSON Parser instance
JSONGetter jParser = new JSONGetter();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
return json;
}
private class JSONGetter {
private InputStream is = null;
private JSONObject jObj = null;
private String json = "";
// constructor
public JSONGetter() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"),
8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}}
**Error : incompatible types: Activity cannot be converted to ListClassFragment**
I don't know how to solve this issue, please can anyone help me here?.
| 0debug |
Open native iOS map application with specific lat and lng : <p>How to open native ios map application by adding pin at specific lat and lng from Objective C.</p>
| 0debug |
static void spapr_cpu_core_register(const SPAPRCoreInfo *info)
{
TypeInfo type_info = {
.parent = TYPE_SPAPR_CPU_CORE,
.instance_size = sizeof(sPAPRCPUCore),
.instance_init = info->initfn,
};
type_info.name = g_strdup_printf("%s-" TYPE_SPAPR_CPU_CORE, info->name);
type_register(&type_info);
g_free((void *)type_info.name);
}
| 1threat |
[C++]Calling multiple functions with multiple params from a function pointer? : im trying to define a function pointer for calling multiple functions with different parameters but now im stuck with my idea does anyone have a idea or can see what i do wrong because i can't :smile: It will be very helpfull if you can help me.
//Goal: Calling the sum function from the function pointer with the t1 struct as parameter
//Theory: As my theory after first param the function will go -4 down in memory and look for the second variable but nope
float sum(float &x, float &y) //a random test-foo function
{
float s = x + y;
printf_s("(%X)x: %f + (%X)y: %f | Result: %f\n",&x, x, &y, y, s);
return s;
}
typedef float(*fsum)(void* params);
fsum fsm = (fsum)∑
struct t1 {
float f[2]; //the params will be here
}tx1;
int main()
{
tx1.f[0] = 4.3; tx1.f[1] = 2; //setting values on the params
printf_s("tx1: 0x%X\ntx1.f[0]: 0x%X\ntx1.f[1]: 0x%X\n", &tx1, &tx1.f[0], &tx1.f[1]);
fsm(&tx1.f[0]); //calling the function pointer
getchar();
return 0;
}
My main goal is to use this later to call different functions with different parameters with just 1 function pointer and with 1 pointer to the params
like:
if(statement1)
funcPointer = func1; //change the func pointer to point to func1
else if(statement1)
funcPointer = func2; //change the func pointer to point to func2
funcPointer(paramPointer); //call the function pointer
And a second question: Let's say i have a .dll that i wrote in C++ it's have a function called "fuu" i have the dll loaded in an another process how can i load the "fuu" function with a second different C++ dll? | 0debug |
What is the Python operater ilshift (<<=)? : What is or what makes the Python operator ilshift (<<=) and where can I find infos about this?
Thanks
https://docs.python.org/2/library/operator.html#operator.ilshift
http://www.pythonlake.com/python/operators/operatorilshift
| 0debug |
VBScript - Read CSV file and output result depending on date : I have a csv file with 2 columns
02/07/2018,Week A
09/07/2018,Week B
16/07/2018,Week A
23/07/2018,Week B
30/07/2018,Summer Break
How do I read this in to a VBScript and then find the current week and then display a message to display the text from the 2nd column?
Eg... if today is 19/07/2018, the displayed message would be Week A
Many thanks | 0debug |
Airflow "This DAG isnt available in the webserver DagBag object " : <p>when I put a new DAG python script in the dags folder, I can view a new entry of DAG in the DAG UI but it was not enabled automatically. On top of that, it seems does not loaded properly as well. I can only click on the Refresh button few times on the right side of the list and toggle the on/off button on the left side of the list to be able to schedule the DAG. These are manual process as I need to trigger something even though the DAG Script was put inside the dag folder. </p>
<p>Anyone can help me on this ? Did I missed something ? Or this is a correct behavior in airflow ?</p>
<p>By the way, as mentioned in the post title, there is an indicator with this message "This DAG isn't available in the webserver DagBag object. It shows up in this list because the scheduler marked it as active in the metdata database" tagged with the DAG title before i trigger all this manual process.</p>
| 0debug |
Reorder a list of string randomly but constant in a period of time : <p>I need to reorder a list in a random way but I want to have the same result on a short period of time ... So I have:</p>
<pre><code>var list = new String[] { "Angie", "David", "Emily", "James" }
var shuffled = list.OrderBy(v => "4a78926c")).ToList();
</code></pre>
<p>But I always get the same order ... I could use Guid.NewGuid() but then I would have a different result in a short period of time.</p>
<p>How can I do this?</p>
| 0debug |
send command from node red to arduino : <p>Good morning everyone,</p>
<p>I want to send command to my Arduino board by clicking on a button on node red dashboard</p>
<p>my Arduino sketch send sensor data to be visualised in the dashboard of the node red (using serial), the data is sent every 2 seconds automatically (in the loop of the Arduino code). What I want to know is if there is a possibility to create a button in the node red, when we click on it, it let the Arduino send sensor data, else no communication permitted.</p>
<p>Is it possible??</p>
| 0debug |
static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
QString *qstr;
*obj = NULL;
if (!qobj) {
return;
}
qstr = qobject_to_qstring(qobj);
if (!qstr) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"string");
return;
}
*obj = g_strdup(qstring_get_str(qstr));
}
| 1threat |
void error_setg(Error **errp, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
error_setv(errp, ERROR_CLASS_GENERIC_ERROR, fmt, ap);
va_end(ap);
}
| 1threat |
Setting selected option of select control in an Angular 2 model-driven form : <p>I have researched many similar existing answers on SO and elsewhere, but just can't find the solution to this.</p>
<p>I'm using the model-driven approach in Angular 2 to build my form, which is both an add and edit form. When in edit mode, the values are populated with data retrieved from a service: this aspect is all fine because the simple text inputs all bind correctly.</p>
<p>One of the properties is 'Country' and this is an object as follows:</p>
<pre><code> export class Country {id: number; name: string;}
</code></pre>
<p>I want to bind this to a select control which will have the list of countries available, and the one from the model populated when the form loads. I want the value of the binding to be the country object, not just the id.</p>
<p>Here's the html of the select control:</p>
<pre><code> <select class="form-control" id="country" formControlName="country">
<option value="default">--Select a country--</option>
<option *ngFor="let c of countries" [value]="c">{{c.name}} </option>
</select>
</code></pre>
<p>And here is where i try to to populate the value from the component class:</p>
<pre><code> (<FormControl>this.personForm.controls['country'])
.setValue(this.person.country, { onlySelf: true });
</code></pre>
<p>But there is no selected option when the page loads, even though the console confirms that this.person.country exists and is populated with the correct object.</p>
<p>I can get it working with ids: changing to [value]="c.id" in the view and appending .id in the class, and then it works in that the right option is selected. The problem is that the select no longer emits an object for the country property, just the id. I tried changing [value] to [ngValue] and get the same result. I even added [ngModel]="country" to the select element and that didn't help either.</p>
<p>I'd be grateful for any help.</p>
| 0debug |
Check if username (Hashed) or email(Hashed) alredy exist with pdo : i am trying to verify if username or email are alredy taken in a registration form, but i can't understand how to do it, since both are hashed in my database with password_hash(), how can i compare, users input with the database in pdo?Please explain me the code, i am new in php... Thanks, in advice for your time, best regards
| 0debug |
static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
MpegEncContext * const s = &h->s;
int b8_stride = 2;
int b4_stride = h->b_stride;
int mb_xy = h->mb_xy, mb_y = s->mb_y;
int mb_type_col[2];
const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1;
const int is_b8x8 = IS_8X8(*mb_type);
unsigned int sub_mb_type;
int i8, i4;
assert(h->ref_list[1][0].f.reference & 3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) {
if (!IS_INTERLACED(*mb_type)) {
mb_y = (s->mb_y&~1) + h->col_parity;
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0;
}else{
mb_y += h->col_fieldoff;
mb_xy += s->mb_stride*h->col_fieldoff;
goto single_col;
}else{
if(IS_INTERLACED(*mb_type)){
mb_y = s->mb_y&~1;
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy];
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride];
b8_stride = 2+4*s->mb_stride;
b4_stride *= 6;
sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
&& (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
&& !is_b8x8){
*mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2;
}else{
*mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
}else{
single_col:
mb_type_col[0] =
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy];
sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
*mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
}else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){
*mb_type |= MB_TYPE_L0L1|MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));
}else{
if(!h->sps.direct_8x8_inference_flag){
sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
*mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]];
l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]];
l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy];
l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy];
if(!b8_stride){
if(s->mb_y&1){
l1ref0 += 2;
l1ref1 += 2;
l1mv0 += 2*b4_stride;
l1mv1 += 2*b4_stride;
{
const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
const int *dist_scale_factor = h->dist_scale_factor;
int ref_offset;
if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
ref_offset = (h->ref_list[1][0].mbaff<<4) & (mb_type_col[0]>>3);
if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
int y_shift = 2*!IS_INTERLACED(*mb_type);
assert(h->sps.direct_8x8_inference_flag);
for(i8=0; i8<4; i8++){
const int x8 = i8&1;
const int y8 = i8>>1;
int ref0, scale;
const int16_t (*l1mv)[2]= l1mv0;
if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
continue;
h->sub_mb_type[i8] = sub_mb_type;
fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
if(IS_INTRA(mb_type_col[y8])){
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
continue;
ref0 = l1ref0[x8 + y8*b8_stride];
if(ref0 >= 0)
ref0 = map_col_to_list0[0][ref0 + ref_offset];
else{
ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
l1mv= l1mv1;
scale = dist_scale_factor[ref0];
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
{
const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
int my_col = (mv_col[1]<<y_shift)/2;
int mx = (scale * mv_col[0] + 128) >> 8;
int my = (scale * my_col + 128) >> 8;
fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
return;
if(IS_16X16(*mb_type)){
int ref, mv0, mv1;
fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
if(IS_INTRA(mb_type_col[0])){
ref=mv0=mv1=0;
}else{
const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
: map_col_to_list0[1][l1ref1[0] + ref_offset];
const int scale = dist_scale_factor[ref0];
const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
int mv_l0[2];
mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
ref= ref0;
mv0= pack16to32(mv_l0[0],mv_l0[1]);
mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
}else{
for(i8=0; i8<4; i8++){
const int x8 = i8&1;
const int y8 = i8>>1;
int ref0, scale;
const int16_t (*l1mv)[2]= l1mv0;
if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
continue;
h->sub_mb_type[i8] = sub_mb_type;
fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
if(IS_INTRA(mb_type_col[0])){
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
continue;
assert(b8_stride == 2);
ref0 = l1ref0[i8];
if(ref0 >= 0)
ref0 = map_col_to_list0[0][ref0 + ref_offset];
else{
ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
l1mv= l1mv1;
scale = dist_scale_factor[ref0];
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
if(IS_SUB_8X8(sub_mb_type)){
const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
int mx = (scale * mv_col[0] + 128) >> 8;
int my = (scale * mv_col[1] + 128) >> 8;
fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
}else
for(i4=0; i4<4; i4++){
const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
AV_WN32A(h->mv_cache[1][scan8[i8*4+i4]],
pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]));
| 1threat |
How to specify the path of `package.json` to npm? : <p>I use <code>npm</code> scripts to build my project. I'd like to be able to run the scripts from a different directory. That is, instead of doing the following:</p>
<pre><code>cd project;
npm run build;
cd ..
</code></pre>
<p>...I'd like to simply do something like:</p>
<pre><code>npm run build -config project/package.json;
</code></pre>
<p>or</p>
<pre><code>npm run build -wd project;
</code></pre>
<p>Is this possible?</p>
| 0debug |
static void build_pci_bus_state_cleanup(AcpiBuildPciBusHotplugState *state)
{
build_free_array(state->device_table);
build_free_array(state->notify_table);
}
| 1threat |
regex match pattern in a string multiple times : <p>I have the following string "*&abc=123&**&defg=hh&*" and so on the pattern start and end is <em>&&</em> and I would like to have the following when I do regex.matches or regex.split</p>
<p>first match = <em>&abc=123&</em>
2 match = <em>&defg=hh&</em></p>
<p>appreciate any help</p>
| 0debug |
how to sort value based on index in javascript? : I have a data which resembles just the below format in javascript. i would like to sort descending order with the index 3 or the column 4. any help would be really helpfull.
sort desc on fourth column | 0debug |
selecting information from table : Hello i am new to sql server and used to work on normal sql , I have an issue
In table i have for example 591|15-MA TEST
i want to retrieve 15-MA TEST i tried to mix substring , charindex , left with no use , Can any one help me | 0debug |
static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
{
int r, b, lo;
b = cdt[p2];
r = cdt[p1] << 11;
lo = b + r;
return (lo + (lo << 16)) << 1;
}
| 1threat |
Swift 4 : 'init(_offset:)' is unavailable : > Swift 4 : 'init(_offset:)' is unavailable
Iam trying to expand variable names (enclosed by curly braces).
let message = "Hello {what}".expand(["what" : "world"])
print(message) // Hello World
I used this for dynamic url construction.
Upto Swift 3.2 it is working fine. When I tried to convert it to Swift 4 its throwing error. `'init(_offset:)' is unavailable` in the below line.
let templateStartChar = "{".utf16[String.UTF16View.Index(_offset: 0)] | 0debug |
Fused Location Provider: Is there a way to check if a location update failed? : <p><strong>Introduction</strong></p>
<p>In my app I want to get a one-off accurate location of where the user currently is. When I used <code>FusedLocationProviderApi.getLastLocation</code> sometimes this would be null or out of date location because I found out this just gets a cached location and does not request a new location update.</p>
<p>The solution was to request a location update only once as seen below.</p>
<pre><code> LocationRequest locationRequest = LocationRequest.create()
.setNumUpdates(1)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(0);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,locationRequest,this)
</code></pre>
<p>Now I get a more accurate location all the time.</p>
<p><strong>My Question</strong></p>
<p>How can I determine if a location update failed? Since I am only requesting 1. </p>
<p>When a location update is obtained this callback is invoked</p>
<pre><code> @Override
public void onLocationChanged(Location location) {
}
</code></pre>
<p>However this does not get called if a location update failed.</p>
<p><strong>What I have tried</strong></p>
<p>I saw there was a ResultCallback. However, onSuccess seems to be always called even if the one-off location update failed. </p>
<pre><code>LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,locationRequest,this).setResultCallback(new ResultCallbacks<Status>() {
@Override
public void onSuccess(@NonNull Status status) {
DebugUtils.log("requestLocationUpdates ResultCallback onSuccess + " + status.toString(),true,true);
}
@Override
public void onFailure(@NonNull Status status) {
DebugUtils.log("requestLocationUpdates ResultCallback onFailure + " + status.toString(),true,true);
}
});
</code></pre>
<p><strong>Other</strong></p>
<p>Using <code>com.google.android.gms:play-services-location:8.4.0</code></p>
<p>Thanks for reading, please help me out.</p>
| 0debug |
Regex for validating path : <p>How do I write a regex that passes for below conditions in C#</p>
<p>\segment\segment\ </p>
<p>a) each segment starts and ends with a backslash</p>
<p>b) segment can be alpha-numeric with dashes, underscore and period allowed (e.g. \some-name\some.other_name\ )</p>
<p>c) the sequence can repeat max 100 times (basically only 100 segments allowed)</p>
| 0debug |
QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp)
{
JSONParserContext ctxt = {};
QList *working;
QObject *result;
if (!tokens) {
return NULL;
}
working = qlist_copy(tokens);
result = parse_value(&ctxt, &working, ap);
QDECREF(working);
error_propagate(errp, ctxt.err);
return result;
}
| 1threat |
how to access elements from array using index : I am at the byebug and `object` has the following array
[{"a"=>nil, "b"=>79, "c"=>"mg/dL", "d"=>"high", "e"=>false}, {"a"=>80, "b"=>139, "c"=>"mg/dL", "d"=>"low", "e"=>true}, {"a"=>140, "b"=>199, "c"=>"mg/dL", "d"=>"moderate", "e"=>false}, {"a"=>200, "b"=>nil, "c"=>"mg/dL", "d"=>"high", "e"=>false}]
I am trying to pass the index and get the value of d but no luck
object.as_json.each_with_index.map { |range, i| range[i].d }
i get `undefined method d` for statement above
how can i just get the values of d? | 0debug |
Can you use python to solve a quadratic without teaching it the quadratic formula? : <pre><code>def f(x):
f(x) = x^2 + 2*x + 1
for x in range(-100, 100):
if f(x) == 0:
print(x)
</code></pre>
<p>Something like this? I get the error "cannot assign to function call" though</p>
| 0debug |
Bash fail if any single command fails but still run all commands : <p>Probably a simple question but an elegant solution is not coming to mind. I would like to run a series of commands (each one is a test) and return 1 if any of them returned non-zero. Typically I would do something like:</p>
<pre><code>thingA && thingB && thingC
exit $?
</code></pre>
<p>However, that won't run thingC if thingB fails and I want to ensure that all 3 run. I can easily think of an inelegant approach:</p>
<pre><code>final_result=0
retval=thingA
if [[ $retval != 0 ]] then
final_result=1
fi
retval=thingB
...
exit $final_result
</code></pre>
<p>Is there some simple, elegant way to get what I want?</p>
| 0debug |
What algorithm used to in Set to avoid duplicates? : May I know What algorithm used to in Set to avoid duplicates ?
I want to know just What is the name of the algorithm used to avoid the duplicates and If possible the same algorithm implementation as well. | 0debug |
static void init_excp_970 (CPUPPCState *env)
{
#if !defined(CONFIG_USER_ONLY)
env->excp_vectors[POWERPC_EXCP_RESET] = 0x00000100;
env->excp_vectors[POWERPC_EXCP_MCHECK] = 0x00000200;
env->excp_vectors[POWERPC_EXCP_DSI] = 0x00000300;
env->excp_vectors[POWERPC_EXCP_DSEG] = 0x00000380;
env->excp_vectors[POWERPC_EXCP_ISI] = 0x00000400;
env->excp_vectors[POWERPC_EXCP_ISEG] = 0x00000480;
env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
env->excp_vectors[POWERPC_EXCP_ALIGN] = 0x00000600;
env->excp_vectors[POWERPC_EXCP_PROGRAM] = 0x00000700;
env->excp_vectors[POWERPC_EXCP_FPU] = 0x00000800;
env->excp_vectors[POWERPC_EXCP_DECR] = 0x00000900;
#if defined(TARGET_PPC64H)
env->excp_vectors[POWERPC_EXCP_HDECR] = 0x00000980;
#endif
env->excp_vectors[POWERPC_EXCP_SYSCALL] = 0x00000C00;
env->excp_vectors[POWERPC_EXCP_TRACE] = 0x00000D00;
env->excp_vectors[POWERPC_EXCP_PERFM] = 0x00000F00;
env->excp_vectors[POWERPC_EXCP_VPU] = 0x00000F20;
env->excp_vectors[POWERPC_EXCP_IABR] = 0x00001300;
env->excp_vectors[POWERPC_EXCP_MAINT] = 0x00001600;
env->excp_vectors[POWERPC_EXCP_VPUA] = 0x00001700;
env->excp_vectors[POWERPC_EXCP_THERM] = 0x00001800;
env->excp_prefix = 0x00000000FFF00000ULL;
env->hreset_vector = 0x0000000000000100ULL;
#endif
}
| 1threat |
Can i use the following powershell command to theck the port availability "netstat -ano | findstr 161 " : I am trying to check the availability on UDP port 389,161 on a remote server
The windows server version is 2012R2
netstat -ano | findstr 161
I expect the output such as "Port 161 listening"
| 0debug |
static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst,
int pitch, const uint8_t *table)
{
int i;
int j;
int out = 0;
if (width & 1)
return AVERROR_INVALIDDATA;
while (out < width) {
int c = ir2_get_code(&ctx->gb);
if (c >= 0x80) {
c -= 0x7F;
if (out + c*2 > width)
return AVERROR_INVALIDDATA;
for (i = 0; i < c * 2; i++)
dst[out++] = 0x80;
} else {
dst[out++] = table[c * 2];
dst[out++] = table[(c * 2) + 1];
}
}
dst += pitch;
for (j = 1; j < height; j++) {
out = 0;
if (get_bits_left(&ctx->gb) <= 0)
return AVERROR_INVALIDDATA;
while (out < width) {
int c = ir2_get_code(&ctx->gb);
if (c >= 0x80) {
c -= 0x7F;
if (out + c*2 > width)
return AVERROR_INVALIDDATA;
for (i = 0; i < c * 2; i++) {
dst[out] = dst[out - pitch];
out++;
}
} else {
int t = dst[out - pitch] + (table[c * 2] - 128);
t = av_clip_uint8(t);
dst[out] = t;
out++;
t = dst[out - pitch] + (table[(c * 2) + 1] - 128);
t = av_clip_uint8(t);
dst[out] = t;
out++;
}
}
dst += pitch;
}
return 0;
}
| 1threat |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.