problem stringlengths 26 131k | labels class label 2 classes |
|---|---|
How to get current value of RxJS Subject or Observable? : <p>I have an Angular 2 service:</p>
<pre><code>import {Storage} from './storage';
import {Injectable} from 'angular2/core';
import {Subject} from 'rxjs/Subject';
@Injectable()
export class SessionStorage extends Storage {
private _isLoggedInSource = new Subject<boolean>();
isLoggedIn = this._isLoggedInSource.asObservable();
constructor() {
super('session');
}
setIsLoggedIn(value: boolean) {
this.setItem('_isLoggedIn', value, () => {
this._isLoggedInSource.next(value);
});
}
}
</code></pre>
<p>Everything works great. But I have another component which doesn't need to subscribe, it just needs to get the current value of isLoggedIn at a certain point in time. How can I do this?</p>
| 0debug |
HTML/CSS/JS/Jquery - Rearranging Divs : I am creating a site but want to rearrange the order of the items on the page depending on whether it is on desktop or mobile.
So for desktop it is something like this:
[![enter image description here][1]][1]
And then for mobile I want to do something like:
[![enter image description here][2]][2]
All these items are their own divs, I just want a way to rearrange them.
Any help or assistance with this would be greatly appreciated.
[1]: https://i.stack.imgur.com/NhFEm.png
[2]: https://i.stack.imgur.com/GRoyW.png | 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;
}
qdict = qobject_to_qdict(data);
assert(qdict);
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 |
regualr expression, match all text within two characters : gotta ask cuz this takes me to much time to go over again again everytime needed, how to match this:
Carina Costa(42353)
when given this:
"CN=Carina Costa(42353),OU=Administrativos,OU=Amadora,OU=Utilizadores,DC=hluz,DC=ess,DC=local"
using php preg_match() | 0debug |
static int vmdvideo_decode_init(AVCodecContext *avctx)
{
VmdVideoContext *s = avctx->priv_data;
int i;
unsigned int *palette32;
int palette_index = 0;
unsigned char r, g, b;
unsigned char *vmd_header;
unsigned char *raw_palette;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
dsputil_init(&s->dsp, avctx);
if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, "VMD video: expected extradata size of %d\n",
VMD_HEADER_SIZE);
return -1;
}
vmd_header = (unsigned char *)avctx->extradata;
s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
s->unpack_buffer = av_malloc(s->unpack_buffer_size);
if (!s->unpack_buffer)
return -1;
raw_palette = &vmd_header[28];
palette32 = (unsigned int *)s->palette;
for (i = 0; i < PALETTE_COUNT; i++) {
r = raw_palette[palette_index++] * 4;
g = raw_palette[palette_index++] * 4;
b = raw_palette[palette_index++] * 4;
palette32[i] = (r << 16) | (g << 8) | (b);
}
s->frame.data[0] = s->prev_frame.data[0] = NULL;
return 0;
}
| 1threat |
TypeScript typings give me "index.d.ts is not a module" : <p>I am getting <em>File node_modules/@types/webrtc/index.d.ts is not a module</em> with this code:</p>
<pre><code>import * as webrtc from "webrtc";
const peerConnection1 = new RTCPeerConnection();
</code></pre>
<p>I have installed the typings using <code>npm i @types/webrtc --save-dev</code>. Hovering over <code>RTCPeerConnection</code> in <code>const peerConnection1 = new RTCPeerConnection();</code> display type annotations in Visual Studio Code so at least the code editor sees the types. Running <code>tsc</code> (or <code>webpack</code> with <code>ts-loader</code>) fails with the error.</p>
<p>I have tried <code>npm i webrtc --save</code> in a misguided attempt for solving this, but it did not change anything and I really only want the typings anyway, WebRTC is right there in the browser, I don't need a package for that. (Support aside.)</p>
<p>The <code>index.d.ts</code> file indeed is not a module, it just references two other files with interfaces in them. So I thought to remove <code>import * as webrtc from "webrtc";</code> hoping the typings will still be visible by <code>tsc</code> somehow. (But that's impossible since I exclude <code>node_modules</code> in TypeScript config file.) When I do that <code>RTCPeerConnection</code> is no longer recognized.</p>
<p>Adding <code>/// <reference src="node_modules/@types/webrtc/" /></code> did not help, <code>tsc</code> says <em>Invalid reference directive syntax</em>.</p>
<p>You can view a repository with minimal repro <a href="https://gitlab.com/TomasHubelbauer/qr-signalling-channel" rel="noreferrer">here on GitLab</a>. I am not too well versed in TypeScript typings acquisition so please forgive my ignorance if I'm going about this all wrong.</p>
| 0debug |
UnityEngine.Input.GetTouch (System.Int32 index) : <p>This is ment to be an angry birds like slingshot, i need to detect the begining and end of a touch, the script works but when i lift my finger off the screen The error shows up is about line 24 (I put dots next to it). The error only appears if I dont touch the screen, if i touch it it goes away, it comes back when i lift my finger.</p>
<pre><code>public class BallShooting : MonoBehaviour
{
public Rigidbody2D rb;
private bool isPressed = false;
public bool isDead = false;
public bool hasShoot = false;
public int Damage;
public int BaseDamage = 1;
public BoxCollider2D DeathZone;
public Transform startingSpot;
public GameObject platform;
public float releaseTime = .15f;
void FixedUpdate()
{
if (Input.touchCount >= 0 && isDead == false)
{
... if (Input.GetTouch(0).phase == TouchPhase.Began)
{
// Debug.Log("TouchBegan");
isPressed = true;
rb.isKinematic = true;
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
// Debug.Log("TouchEnded");
isPressed = false;
rb.isKinematic = false;
StartCoroutine(Release());
}
}
if(isPressed && !hasShoot)
{
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
rb.position = touchPosition;
}
if (isDead)
{
this.transform.position = new Vector3(startingSpot.position.x, startingSpot.position.y, startingSpot.position.z);
isDead = false;
DeathZone.enabled = true;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Ground" && hasShoot == true)
{
isDead = true;
Debug.Log("Dead");
DeathZone.enabled = false;
}
}
IEnumerator Release()
{
yield return new WaitForSeconds(releaseTime);
GetComponent<SpringJoint2D>().enabled = false;
hasShoot = true;
}
}
</code></pre>
| 0debug |
static void slirp_smb_cleanup(SlirpState *s)
{
char cmd[128];
int ret;
if (s->smb_dir[0] != '\0') {
snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
ret = system(cmd);
if (!WIFEXITED(ret)) {
qemu_error("'%s' failed.\n", cmd);
} else if (WEXITSTATUS(ret)) {
qemu_error("'%s' failed. Error code: %d\n",
cmd, WEXITSTATUS(ret));
}
s->smb_dir[0] = '\0';
}
}
| 1threat |
Pandas: Count the first consecutive True values : <p>I am trying to implement a function that identifies the <em>first consecutive</em> occurrences in a Pandas <code>Series</code>, which has already been masked with the condition I wanted: (e.g.)</p>
<p><code>[True, True, True, False, True, False, True, True, True, True]</code></p>
<p>I want the above input to give the result of <code>3</code>, i.e., there are 3 <code>True</code> occurrences in a row from the beginning of the series.</p>
<p>I am aware that a big <code>for</code> loop would do the work, but are there any vectorized / Pandas-centric way to go around it?</p>
<p>Thank you very much.</p>
| 0debug |
static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, unsigned src_size)
{
const uint16_t *end;
#ifdef HAVE_MMX
const uint16_t *mm_end;
#endif
uint8_t *d = (uint8_t *)dst;
const uint16_t *s = (const uint16_t *)src;
end = s + src_size/2;
#ifdef HAVE_MMX
__asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
__asm __volatile("pxor %%mm7,%%mm7\n\t":::"memory");
mm_end = end - 3;
while(s < mm_end)
{
__asm __volatile(
PREFETCH" 32%1\n\t"
"movq %1, %%mm0\n\t"
"movq %1, %%mm1\n\t"
"movq %1, %%mm2\n\t"
"pand %2, %%mm0\n\t"
"pand %3, %%mm1\n\t"
"pand %4, %%mm2\n\t"
"psllq $3, %%mm0\n\t"
"psrlq $2, %%mm1\n\t"
"psrlq $7, %%mm2\n\t"
"movq %%mm0, %%mm3\n\t"
"movq %%mm1, %%mm4\n\t"
"movq %%mm2, %%mm5\n\t"
"punpcklwd %%mm7, %%mm0\n\t"
"punpcklwd %%mm7, %%mm1\n\t"
"punpcklwd %%mm7, %%mm2\n\t"
"punpckhwd %%mm7, %%mm3\n\t"
"punpckhwd %%mm7, %%mm4\n\t"
"punpckhwd %%mm7, %%mm5\n\t"
"psllq $8, %%mm1\n\t"
"psllq $16, %%mm2\n\t"
"por %%mm1, %%mm0\n\t"
"por %%mm2, %%mm0\n\t"
"psllq $8, %%mm4\n\t"
"psllq $16, %%mm5\n\t"
"por %%mm4, %%mm3\n\t"
"por %%mm5, %%mm3\n\t"
MOVNTQ" %%mm0, %0\n\t"
MOVNTQ" %%mm3, 8%0\n\t"
:"=m"(*d)
:"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r)
:"memory");
d += 16;
s += 4;
}
__asm __volatile(SFENCE:::"memory");
__asm __volatile(EMMS:::"memory");
#endif
while(s < end)
{
#if 0
int bgr= *s++;
*((uint32_t*)d)++ = ((bgr&0x1F)<<3) + ((bgr&0x3E0)<<6) + ((bgr&0x7C00)<<9);
#else
register uint16_t bgr;
bgr = *s++;
#ifdef WORDS_BIGENDIAN
*d++ = 0;
*d++ = (bgr&0x1F)<<3;
*d++ = (bgr&0x3E0)>>2;
*d++ = (bgr&0x7C00)>>7;
#else
*d++ = (bgr&0x1F)<<3;
*d++ = (bgr&0x3E0)>>2;
*d++ = (bgr&0x7C00)>>7;
*d++ = 0;
#endif
#endif
}
}
| 1threat |
static void init_demo(const char *filename)
{
int i, j;
int h;
int radian;
char line[3 * W];
FILE *fichier;
fichier = fopen(filename, "rb");
if (!fichier) {
perror(filename);
exit(1);
}
fread(line, 1, 15, fichier);
for (i = 0; i < H; i++) {
fread(line, 1, 3 * W, fichier);
for (j = 0; j < W; j++) {
tab_r[W * i + j] = line[3 * j ];
tab_g[W * i + j] = line[3 * j + 1];
tab_b[W * i + j] = line[3 * j + 2];
}
}
fclose(fichier);
for (i = 0; i < 360; i++) {
radian = 2 * i * MY_PI / 360;
h = 2 * FIXP + int_sin (radian);
h_cos[i] = h * int_sin(radian + MY_PI / 2) / 2 / FIXP;
h_sin[i] = h * int_sin(radian) / 2 / FIXP;
}
}
| 1threat |
int vnc_display_pw_expire(DisplayState *ds, time_t expires)
{
VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
vs->expires = expires;
return 0; | 1threat |
VS 2015 configurate SFML : I have got installed VS 2015 Enterprise. I want to prepare project for SFML
[Tutorial][1]
But in my version of VS I don't have got C/C++
[My VS][2]
What can i do to add this darectories ?
[1]: http://www.sfml-dev.org/tutorials/2.4/start-vc.php
[2]: http://prntscr.com/d3s56c | 0debug |
Error: Expected a "=" operator in assignment statement : <pre><code>Func trigger_gui_()
$guiG = WinGetPos($d3d)
If GUICtrlRead($1s) = "On" Then
$arr[8] = [$1, $1s, $af, $afs, $ms, $mss, $tk, $tkk]
For $i = 0 to 8 + 1
$var = ControlGetPos( "Crypt3x", "", $arr[$i] )
$math = $var[3] - 17
GUICtrlSetPos($arr[$i], 104, $guiG[3] - $math, 80, 17)
Next
EndIf
EndFunc
</code></pre>
<p>Im getting the above error in this function
can someone pls help me :|</p>
| 0debug |
static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
k->init = virtual_css_bridge_init;
dc->no_user = 1;
}
| 1threat |
JavaScript get td from table : <p>I have a table with tbodies. I want to create a array with the values in the first td of with tbody. How can I do that?</p>
<p>My html:</p>
<pre><code><table id="myTable">
<thead>
<tr>
<th>Test1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Val1</td>
<td></td>
<td></td>
</tr>
</tbody>
<tbody>
<tr>
<td>Val2</td>
<td></td>
<td></td>
</tr>
</tbody>
<tbody>
<tr>
<td>Val3</td>
<td></td>
<td></td>
</tr>
</tbody>
<tbody>
<tr>
<td>Val4</td>
<td></td>
<td></td>
</tr>
</tbody>
</code></pre>
<p></p>
<p>My array should have the values: Val1, Val2, Val3, Val4</p>
| 0debug |
static bool ranges_can_merge(Range *range1, Range *range2)
{
return !(range1->end < range2->begin || range2->end < range1->begin);
}
| 1threat |
Which is the most difficult to reverse the order of the sort (largest to smallest) from Insertions sort selection sort or merge sort? : I know that the answer to the question is that they are all equally difficult to reverse but I don't know why. Could someone explain this? | 0debug |
Write a string inside a PDF file using ASP.NET MVC : <p>In my ASP.NET MVC application, user can upload a PDF file. I want to write a string to a specific location of that file and let the user download the modified PDF. How can I do that? Is there a (hopefully free) library for this kind of task?
Thanks in advance.</p>
| 0debug |
python scikit-learn clustering with missing data : <p>I want to cluster data with missing columns. Doing it manually I would calculate the distance in case of a missing column simply without this column.</p>
<p>With scikit-learn, missing data is not possible. There is also no chance to specify a user distance function.</p>
<p>Is there any chance to cluster with missing data?</p>
<p>Example data:</p>
<pre><code>n_samples = 1500
noise = 0.05
X, _ = make_swiss_roll(n_samples, noise)
rnd = np.random.rand(X.shape[0],X.shape[1])
X[rnd<0.1] = np.nan
</code></pre>
| 0debug |
c++ char* + std::vector memory leak : <p>The following code is reading a big object collection (95G of compressed objects that are uncompressed via the WriteObject streamer) from disk and prints their content as strings.</p>
<p>object.cxx:</p>
<pre><code>std::vector<char> ObjectHandler::GetObject(const std::string& path)
{
TFile *file = new TFile(path.c_str());
// If file was not found or empty
if (file->IsZombie()) {
cout << "The object was not found at " << path << endl;
}
// Get the AliCDBEntry from the root file
AliCDBEntry *entry = (AliCDBEntry*)file->Get("AliCDBEntry");
// Create an outcoming buffer
TBufferFile *buffer = new TBufferFile(TBuffer::kWrite);
// Stream and serialize the AliCDBEntry object to the buffer
buffer->WriteObject((const TObject*)entry);
// Obtain a pointer to the buffer
char *pointer = buffer->Buffer();
// Store the object to the referenced vector
std::vector<char> vector(pointer, pointer + buffer->Length());
// Release the open file
delete file;
delete buffer;
return vector;
}
</code></pre>
<p>main.cxx:</p>
<pre><code>ObjectHandler objHandler;
boost::filesystem::path dataPath("/tmp");
boost::filesystem::recursive_directory_iterator endIterator;
if (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) {
for (static boost::filesystem::recursive_directory_iterator directoryIterator(dataPath); directoryIterator != endIterator;
++directoryIterator) {
if (boost::filesystem::is_regular_file(directoryIterator->status())) {
cout << directoryIterator->path().string() << endl;
std::vector<char> vector = objHandler.GetObject(directoryIterator->path().string());
cout << vector << endl;
}
}
}
</code></pre>
<p>1) Is calling by value the correct way to implement this method? Am i doing additional copies that could be avoided if calling by reference?</p>
<p>2) This code is leaking and i am suspecting that either the <em>char *pointer</em> is to blame, or the actual <em>std::vector</em> that is returned by the <em>ObjectHandler::GetObject()</em> method. I've tested the implementation with the following code:</p>
<pre><code>struct sysinfo sys_info;
sysinfo (&sys_info);
cout << "Total: " << sys_info.totalram *(unsigned long long)sys_info.mem_unit / 1024 << " Free: " << sys_info.freeram *(unsigned long long)sys_info.mem_unit/ 1024 << endl;
</code></pre>
<p>and the free ram is continuously reduced, until it reaches 0 and the program is killed. </p>
| 0debug |
static int do_attach(USBDevice *dev)
{
USBBus *bus = usb_bus_from_device(dev);
USBPort *port;
if (dev->attached) {
error_report("Error: tried to attach usb device %s twice\n",
dev->product_desc);
return -1;
}
if (bus->nfree == 0) {
error_report("Error: tried to attach usb device %s to a bus with no free ports\n",
dev->product_desc);
return -1;
}
if (dev->port_path) {
QTAILQ_FOREACH(port, &bus->free, next) {
if (strcmp(port->path, dev->port_path) == 0) {
break;
}
}
if (port == NULL) {
error_report("Error: usb port %s (bus %s) not found\n",
dev->port_path, bus->qbus.name);
return -1;
}
} else {
port = QTAILQ_FIRST(&bus->free);
}
if (!(port->speedmask & dev->speedmask)) {
error_report("Warning: speed mismatch trying to attach usb device %s to bus %s\n",
dev->product_desc, bus->qbus.name);
return -1;
}
dev->attached++;
QTAILQ_REMOVE(&bus->free, port, next);
bus->nfree--;
usb_attach(port, dev);
QTAILQ_INSERT_TAIL(&bus->used, port, next);
bus->nused++;
return 0;
}
| 1threat |
CPUState *mon_get_cpu(void)
{
if (!cur_mon->mon_cpu) {
monitor_set_cpu(0);
}
cpu_synchronize_state(cur_mon->mon_cpu);
return cur_mon->mon_cpu;
}
| 1threat |
static void xen_be_evtchn_event(void *opaque)
{
struct XenDevice *xendev = opaque;
evtchn_port_t port;
port = xc_evtchn_pending(xendev->evtchndev);
if (port != xendev->local_port) {
xen_be_printf(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n",
port, xendev->local_port);
return;
}
xc_evtchn_unmask(xendev->evtchndev, port);
if (xendev->ops->event) {
xendev->ops->event(xendev);
}
}
| 1threat |
void memory_region_add_subregion_overlap(MemoryRegion *mr,
hwaddr offset,
MemoryRegion *subregion,
unsigned priority)
{
subregion->may_overlap = true;
subregion->priority = priority;
memory_region_add_subregion_common(mr, offset, subregion);
}
| 1threat |
static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
{
HEVCLocalContext *lc = &s->HEVClc;
GetBitContext *gb = &lc->gb;
int ctb_addr_ts, ret;
ret = init_get_bits8(gb, nal, length);
if (ret < 0)
return ret;
ret = hls_nal_unit(s);
if (ret < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\n",
s->nal_unit_type);
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return ret;
return 0;
} else if (!ret)
return 0;
switch (s->nal_unit_type) {
case NAL_VPS:
ret = ff_hevc_decode_nal_vps(s);
if (ret < 0)
return ret;
break;
case NAL_SPS:
ret = ff_hevc_decode_nal_sps(s);
if (ret < 0)
return ret;
break;
case NAL_PPS:
ret = ff_hevc_decode_nal_pps(s);
if (ret < 0)
return ret;
break;
case NAL_SEI_PREFIX:
case NAL_SEI_SUFFIX:
ret = ff_hevc_decode_nal_sei(s);
if (ret < 0)
return ret;
break;
case NAL_TRAIL_R:
case NAL_TRAIL_N:
case NAL_TSA_N:
case NAL_TSA_R:
case NAL_STSA_N:
case NAL_STSA_R:
case NAL_BLA_W_LP:
case NAL_BLA_W_RADL:
case NAL_BLA_N_LP:
case NAL_IDR_W_RADL:
case NAL_IDR_N_LP:
case NAL_CRA_NUT:
case NAL_RADL_N:
case NAL_RADL_R:
case NAL_RASL_N:
case NAL_RASL_R:
ret = hls_slice_header(s);
if (ret < 0)
return ret;
if (s->max_ra == INT_MAX) {
if (s->nal_unit_type == NAL_CRA_NUT || IS_BLA(s)) {
s->max_ra = s->poc;
} else {
if (IS_IDR(s))
s->max_ra = INT_MIN;
if ((s->nal_unit_type == NAL_RASL_R || s->nal_unit_type == NAL_RASL_N) &&
s->poc <= s->max_ra) {
s->is_decoded = 0;
break;
} else {
if (s->nal_unit_type == NAL_RASL_R && s->poc > s->max_ra)
s->max_ra = INT_MIN;
if (s->sh.first_slice_in_pic_flag) {
ret = hevc_frame_start(s);
if (ret < 0)
return ret;
} else if (!s->ref) {
av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
if (!s->sh.dependent_slice_segment_flag &&
s->sh.slice_type != I_SLICE) {
ret = ff_hevc_slice_rpl(s);
if (ret < 0) {
av_log(s->avctx, AV_LOG_WARNING,
"Error constructing the reference lists for the current slice.\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return ret;
ctb_addr_ts = hls_slice_data(s);
if (ctb_addr_ts >= (s->sps->ctb_width * s->sps->ctb_height)) {
s->is_decoded = 1;
if ((s->pps->transquant_bypass_enable_flag ||
(s->sps->pcm.loop_filter_disable_flag && s->sps->pcm_enabled_flag)) &&
s->sps->sao_enabled)
restore_tqb_pixels(s);
if (ctb_addr_ts < 0)
return ctb_addr_ts;
break;
case NAL_EOS_NUT:
case NAL_EOB_NUT:
s->seq_decode = (s->seq_decode + 1) & 0xff;
s->max_ra = INT_MAX;
break;
case NAL_AUD:
case NAL_FD_NUT:
break;
default:
av_log(s->avctx, AV_LOG_INFO,
"Skipping NAL unit %d\n", s->nal_unit_type);
return 0; | 1threat |
Find the difference between two dates (Inclusive of start and end date) in Java : <p>I need to find the difference between two dates in Java and the difference should be inclusive of start and end date. I tried using below piece of code but it is not including start and end date.</p>
<pre><code>long diffDays = Days.daysBetween(new DateTime(startDate), new DateTime(endDate)).getDays();
</code></pre>
<p>Is there any utility method to achieve this?</p>
| 0debug |
Don't Match Numerical value starting with 4 up-to 5 digit : <i>I want to match all Numeric value except digit starting with 4 up-to 5 digit's
i wrote a regex which match Numeric starting with 4 up-to 5 digit but i want to invert this match.</i>
c = '475555'
e = (re.search(r'(\A4[0-9]{5})',c).group(0)) | 0debug |
static void test_qga_config(gconstpointer data)
{
GError *error = NULL;
char *cwd, *cmd, *out, *err, *str, **strv, **argv = NULL;
char *env[2];
int status;
gsize n;
GKeyFile *kf;
cwd = g_get_current_dir();
cmd = g_strdup_printf("%s%cqemu-ga -D",
cwd, G_DIR_SEPARATOR);
g_shell_parse_argv(cmd, NULL, &argv, &error);
g_assert_no_error(error);
env[0] = g_strdup_printf("QGA_CONF=tests%cdata%ctest-qga-config",
G_DIR_SEPARATOR, G_DIR_SEPARATOR);
env[1] = NULL;
g_spawn_sync(NULL, argv, env, 0,
NULL, NULL, &out, &err, &status, &error);
g_strfreev(argv);
g_assert_no_error(error);
g_assert_cmpstr(err, ==, "");
g_assert_cmpint(status, ==, 0);
kf = g_key_file_new();
g_key_file_load_from_data(kf, out, -1, G_KEY_FILE_NONE, &error);
g_assert_no_error(error);
str = g_key_file_get_start_group(kf);
g_assert_cmpstr(str, ==, "general");
g_free(str);
g_assert_false(g_key_file_get_boolean(kf, "general", "daemon", &error));
g_assert_no_error(error);
str = g_key_file_get_string(kf, "general", "method", &error);
g_assert_no_error(error);
g_assert_cmpstr(str, ==, "virtio-serial");
g_free(str);
str = g_key_file_get_string(kf, "general", "path", &error);
g_assert_no_error(error);
g_assert_cmpstr(str, ==, "/path/to/org.qemu.guest_agent.0");
g_free(str);
str = g_key_file_get_string(kf, "general", "pidfile", &error);
g_assert_no_error(error);
g_assert_cmpstr(str, ==, "/var/foo/qemu-ga.pid");
g_free(str);
str = g_key_file_get_string(kf, "general", "statedir", &error);
g_assert_no_error(error);
g_assert_cmpstr(str, ==, "/var/state");
g_free(str);
g_assert_true(g_key_file_get_boolean(kf, "general", "verbose", &error));
g_assert_no_error(error);
strv = g_key_file_get_string_list(kf, "general", "blacklist", &n, &error);
g_assert_cmpint(n, ==, 2);
#if GLIB_CHECK_VERSION(2, 44, 0)
g_assert_true(g_strv_contains((const char * const *)strv,
"guest-ping"));
g_assert_true(g_strv_contains((const char * const *)strv,
"guest-get-time"));
#endif
g_assert_no_error(error);
g_strfreev(strv);
g_free(out);
g_free(err);
g_free(env[0]);
g_key_file_free(kf);
} | 1threat |
Merge corresponding elements of 2 lists in python : <p>List 1:</p>
<pre><code>['buying','maint']
</code></pre>
<p>List 2:</p>
<pre><code>[['med', 'vhigh', 'low', 'high'],['med', 'small', 'big']]
</code></pre>
<p>Expected_output:</p>
<pre><code>[['buying_med', 'buying_vhigh','buying_low','buying_high'],['maint_med','maint_small','maint_big']]
</code></pre>
<p>Please let mw know on how to do this in python 3.</p>
| 0debug |
JButton size grater than specified : I had created a `jframe` and simply added a `jbutton` to it and had set the size of the `jframe` as 500,500 and size of the `jbutton`
as 40,60 but when I executed my program, my `jbutton` was covering the whole of my `jframe`. I
tried many things and looked into many sources but i could not find a solution. Please help me solve this.
| 0debug |
ECS unable to assume role : <p>From the console, I am invoking a lambda which submits a batch job. The batch job fails, indicating that ECS is unable to assume the role that is provided to execute the job definition.</p>
<p>For the role, I've added the lambda and ECS services.</p>
<p>The error message:</p>
<blockquote>
<p>"ECS was unable to assume the role
'arn:aws:iam::749340585813:role/golfnow-invoke-write-progress' that
was provided for this task. Please verify that the role being passed
has the proper trust relationship and permissions and that your IAM
user has permissions to pass this role."</p>
</blockquote>
<pre><code>"TrainingJobRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": "golfnow-invoke-write-progress",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"ecs.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/"
}
}
</code></pre>
<p>The batch job:</p>
<pre><code> "TrainingJob": {
"Type": "AWS::Batch::JobDefinition",
"Properties": {
"Type": "container",
"JobDefinitionName": {
"Fn::Sub": "c12e-golfnow-${Environment}-job"
},
"ContainerProperties": {
"Image": {
"Fn::Join": [
"",
[
"{{ image omitted }}",
{
"Ref": "AWS::Region"
},
".amazonaws.com/amazonlinux:latest"
]
]
},
"Vcpus": 2,
"Memory": 2000,
"Command": [
"while", "True", ";", "do", "echo", "'hello';", "done"
],
"JobRoleArn": {
"Fn::GetAtt": [
"TrainingJobRole",
"Arn"
]
}
},
"RetryStrategy": {
"Attempts": 1
}
}
},
"JobQueue": {
"Type": "AWS::Batch::JobQueue",
"Properties": {
"Priority": 1,
"ComputeEnvironmentOrder": [
{
"Order": 1,
"ComputeEnvironment": {
"Ref": "ComputeEnvironment"
}
}
]
}
}
</code></pre>
<p>Is the issue with the way it's being invoked? My user has admin privileges, so I don't think this is an issue with my user having insufficient permissions.</p>
| 0debug |
JAVASCRIPT (HELP) : Can you help me, please (
function getChar that takes 1 parameter - an array of words. I must concatenate the nth letter from each word which should be returned as a string( for example : getChar(["javascript", "is cool", "123"]). returned value js3)
what"S wrong?
function getChar(arr)
{
return arr.mao(function(v,i,a){
return v[i];}).join(" ");
} | 0debug |
Remove whitespace from SVG : <p>I cannot find a way to alter the code below to remove the whitespace from a SVG image. What should I modify or remove to achieve this? I am editing the code using this website: <a href="https://petercollingridge.appspot.com/svg-editor/" rel="noreferrer">https://petercollingridge.appspot.com/svg-editor/</a></p>
<p>How the SVG image looks like with this code: See <a href="http://i.stack.imgur.com/Y8ad8.png" rel="noreferrer">here</a>.</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="250.0px" height="100.0px" overflow="visible" viewBox="0.0 0.0 250.0 100.0" enable-background="new 0.0 0.0 250.0 100.0">
<defs>
<radialGradient id="Grad1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.0021972656 0.0 0.0 0.0040893555 120.8 38.55)" r="819.2" cx="0" cy="0">
</radialGradient>
<linearGradient id="Grad2" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.0 0.001739502 -0.015563965 0.0 108.05 40.25)" x1="-819.2" y1="0" x2="819.2" y2="0">
</linearGradient>
<radialGradient id="Grad3" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-0.0021972656 0.0 0.0 0.0040893555 95.3 38.55)" r="819.2" cx="0" cy="0">
</radialGradient>
<linearGradient id="Grad4" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.0 -0.001953125 0.015563965 0.0 108.05 36.95)" x1="-819.2" y1="0" x2="819.2" y2="0">
</linearGradient>
</defs>
<g>
<g transform="matrix(1.0 0.0 0.0 1.0 0.0 0.0)">
<path fill="#DC0100" stroke-linecap="round" stroke-linejoin="round" d="M 232.05 57.75 L 230.45 60.6 L 221.85 68.25 L 221.5 67.9 C 221.2 67.6 220.84999 67.36666 220.45 67.2 L 221.9 61.85 L 223.5 62.4 L 226.05 57.25 L 227.2 57.85 L 229.95 55.95 L 232.05 57.75 Z M 227.85 82.2 L 226.65 83.0 L 226.65 86.35 L 224.2 87.15 L 222.5 84.45 L 219.6 84.75 L 219.0 84.7 L 219.25 80.35 L 219.35 80.35 C 221.61667 80.35 223.61667 79.75 225.35 78.55 L 227.85 82.2 Z M 212.3 82.8 C 211.23334 82.166664 210.25 81.416664 209.35 80.55 L 207.8 78.75 L 212.6 75.35 L 213.5 76.35 L 214.5 77.25 L 217.1 73.7 L 218.45 74.35 L 216.4 81.6 C 215.4 81.36667 214.46666 81.01667 213.6 80.55 L 212.3 82.8 Z M 205.15 70.3 L 201.75 68.9 L 202.25 65.6 L 205.85 65.6 C 206.45 63.8 207.4 62.15 208.7 60.65 L 207.25 58.15 L 209.1 56.2 L 211.7 58.1 L 213.75 61.2 C 213.11667 61.566666 212.53334 62.033333 212.0 62.6 C 210.43333 64.166664 209.45 65.96667 209.05 68.0 L 208.85 70.25 L 205.15 70.3 Z M 208.85 70.25 L 208.85 70.3 Z M 218.15 67.9 L 217.8 68.2 C 217.4 68.63333 217.18332 69.15 217.15 69.75 L 211.1 68.45 C 211.43333 66.816666 212.23334 65.36667 213.5 64.1 L 214.9 62.95 L 218.15 67.9 Z M 232.15 70.2 C 232.15 72.13333 231.76666 73.916664 231.0 75.55 L 223.55 72.0 C 223.78333 71.46667 223.9 70.88333 223.9 70.25 L 223.85 69.7 L 232.1 68.65 L 232.15 70.2 Z"/>
<path fill="#6C0B0B" stroke-linecap="round" stroke-linejoin="round" d="M 226.05 57.25 L 223.5 62.4 L 221.9 61.85 L 220.45 67.2 C 220.85 67.36666 221.20001 67.6 221.5 67.9 L 221.85 68.25 L 230.45 60.6 C 231.85 62.166668 232.85 63.9 233.45 65.8 L 233.45 65.9 L 235.95 65.9 L 236.4 66.15 L 236.9 68.4 C 235.96666 68.86667 235.01666 69.35 234.05 69.85 L 234.05 69.95 L 234.05 70.3 C 234.05 72.23333 233.73334 74.01666 233.1 75.65 L 235.3 78.35 L 233.85 80.2 L 230.95 79.35 L 229.85 80.55 L 228.05 82.1 L 227.85 82.2 L 225.35 78.55 C 223.61667 79.75 221.61667 80.35 219.35 80.35 L 219.25 80.35 L 219.0 84.7 L 218.75 84.7 L 216.65 84.45 L 214.7 87.15 L 212.3 86.35 L 212.3 82.8 L 213.6 80.55 C 214.46666 81.01667 215.4 81.36667 216.4 81.6 L 218.45 74.35 L 217.1 73.7 L 214.5 77.25 L 213.5 76.35 L 212.6 75.35 L 207.8 78.75 L 205.55 80.35 L 203.85 78.2 L 206.05 75.5 C 205.45 73.9 205.15 72.16667 205.15 70.3 L 208.85 70.3 L 209.05 68.0 C 209.45 65.96667 210.43333 64.166664 212.0 62.6 C 212.53334 62.033333 213.11667 61.566666 213.75 61.2 L 211.7 58.1 C 213.43333 56.93333 215.35 56.216663 217.45 55.95 L 218.3 52.9 L 220.9 52.9 L 221.7 55.95 C 223.23334 56.11667 224.68333 56.550003 226.05 57.25 Z M 219.0 84.7 L 219.0 84.75 Z M 208.85 70.3 L 208.85 70.25 Z M 217.8 68.2 L 218.15 67.9 L 214.9 62.95 L 213.5 64.1 C 212.23334 65.36667 211.43333 66.816666 211.1 68.45 L 217.15 69.75 C 217.18333 69.15 217.40001 68.63333 217.8 68.2 Z M 231.0 75.55 C 231.76666 73.916664 232.15 72.13333 232.15 70.2 L 232.1 68.65 L 223.85 69.7 L 223.9 70.25 C 223.9 70.88333 223.78333 71.46667 223.55 72.0 L 231.0 75.55 Z"/>
</g>
</g>
</svg>
</code></pre>
| 0debug |
How to apply lazy loading in flatlist in react native : <p>What is the best possible way to apply lazy load in Flatlist in react native.
Currently there is infinite scroll in the flatlist.
I am new to React native so i dont have any idea.</p>
| 0debug |
int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
{
BDRVQcow2State *s = bs->opaque;
QCowSnapshot *new_snapshot_list = NULL;
QCowSnapshot *old_snapshot_list = NULL;
QCowSnapshot sn1, *sn = &sn1;
int i, ret;
uint64_t *l1_table = NULL;
int64_t l1_table_offset;
if (s->nb_snapshots >= QCOW_MAX_SNAPSHOTS) {
return -EFBIG;
}
memset(sn, 0, sizeof(*sn));
find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));
if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {
return -EEXIST;
}
sn->id_str = g_strdup(sn_info->id_str);
sn->name = g_strdup(sn_info->name);
sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
sn->vm_state_size = sn_info->vm_state_size;
sn->date_sec = sn_info->date_sec;
sn->date_nsec = sn_info->date_nsec;
sn->vm_clock_nsec = sn_info->vm_clock_nsec;
l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
if (l1_table_offset < 0) {
ret = l1_table_offset;
goto fail;
}
sn->l1_table_offset = l1_table_offset;
sn->l1_size = s->l1_size;
l1_table = g_try_new(uint64_t, s->l1_size);
if (s->l1_size && l1_table == NULL) {
ret = -ENOMEM;
goto fail;
}
for(i = 0; i < s->l1_size; i++) {
l1_table[i] = cpu_to_be64(s->l1_table[i]);
}
ret = qcow2_pre_write_overlap_check(bs, 0, sn->l1_table_offset,
s->l1_size * sizeof(uint64_t));
if (ret < 0) {
goto fail;
}
ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,
s->l1_size * sizeof(uint64_t));
if (ret < 0) {
goto fail;
}
g_free(l1_table);
l1_table = NULL;
ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
if (ret < 0) {
goto fail;
}
new_snapshot_list = g_new(QCowSnapshot, s->nb_snapshots + 1);
if (s->snapshots) {
memcpy(new_snapshot_list, s->snapshots,
s->nb_snapshots * sizeof(QCowSnapshot));
old_snapshot_list = s->snapshots;
}
s->snapshots = new_snapshot_list;
s->snapshots[s->nb_snapshots++] = *sn;
ret = qcow2_write_snapshots(bs);
if (ret < 0) {
g_free(s->snapshots);
s->snapshots = old_snapshot_list;
s->nb_snapshots--;
goto fail;
}
g_free(old_snapshot_list);
qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),
align_offset(sn->vm_state_size, s->cluster_size)
>> BDRV_SECTOR_BITS,
QCOW2_DISCARD_NEVER, false);
#ifdef DEBUG_ALLOC
{
BdrvCheckResult result = {0};
qcow2_check_refcounts(bs, &result, 0);
}
#endif
return 0;
fail:
g_free(sn->id_str);
g_free(sn->name);
g_free(l1_table);
return ret;
}
| 1threat |
db.execute('SELECT * FROM employees WHERE id = ' + user_input) | 1threat |
static ssize_t qio_channel_file_writev(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
int *fds,
size_t nfds,
Error **errp)
{
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
ssize_t ret;
retry:
ret = writev(fioc->fd, iov, niov);
if (ret <= 0) {
if (errno == EAGAIN ||
errno == EWOULDBLOCK) {
return QIO_CHANNEL_ERR_BLOCK;
}
if (errno == EINTR) {
goto retry;
}
error_setg_errno(errp, errno,
"Unable to write to file");
return -1;
}
return ret;
}
| 1threat |
Sql parameters and percentage increase : So how would one use a parameter to increase orders on the orderdetails database by 10 percent i did something like
add parameter named “In
cPercent”) to the value of an order if the value of IncPercent is under
10%, or if IncPercent is 10% or over, add 10% to the value of an order for all orders in the
OrderDetails table utilising IF/ELSE.*/
code what i have so far im kinda stuck
Use SKILLAGEITDB
go
Create procedure [spAddPercentage]
@incPercent decimal(5,4)
as
update OrderDetails
set @incPercent = @incpercent * 1.10
***********************************************
I cannot figure out how to use the if else statement in this code. Can anyone give me a better understanding or give me a example on what i should add for if/else? | 0debug |
How to understand and complete nested loop challenge provided below : <p>I need help with this challenge. I feel like I am brain dead when it comes to nesting loops. I had a better understanding of them last semester in a harder Java class than I do in a beginner C class.</p>
<p><a href="https://i.stack.imgur.com/G6cuN.png" rel="nofollow noreferrer">Challenege code</a></p>
| 0debug |
static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)
{
OpenRISCCPU *cpu = OPENRISC_CPU(dev);
OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(dev);
cpu_reset(CPU(cpu));
occ->parent_realize(dev, errp);
}
| 1threat |
Codeigniter loading a view into a view : I need to load a view into a view within Codeigniter, but cant seem to get it to work.
I have a loop.
I need to place that loop within multiple views (same data different pages)
So I have the loop by itself, as a view, to receive the array from the controller and display the data.
But I cant seem to load multiple views from a controller:
SO, I've tried many things, but according to the docs I can do something like this:
Controller:
$data['due_check_data'] = $combined_checks;
// gather data for view
$view_data = array(
'check_cats' => $this->check_model->get_check_cats(),
'page_title' => 'Due Checks & Tests'
);
$this->load->view('checks/due_checks',$view_data);
$this->load->view('checks/include/due_checks_table',$data, TRUE);
So then how do i call the loop in the view?
I've tried this:
<?=$due_check_data?>
And
<? echo $due_check_data; ?>
But I'm just getting this error, saying the variable is empty?
Message: Undefined variable: due_check_data | 0debug |
Increase width of entire HTML Rmarkdown output : <p>I am looking to increase the overall width of my HTML Rmarkdown output. </p>
<p>When producing PDF documents from Rmarkdowns there is an option to set the margin in the YAML section of the Rmd (ex. geometry: margin=.5in).</p>
<p>I am looking for something similar for HTML docs. The following link is a good example of my issue: <a href="https://rstudio.github.io/DT/extensions.html" rel="noreferrer">https://rstudio.github.io/DT/extensions.html</a> </p>
<p>As you can see on that html webpage, there is a lot of white space to the left and right of the datatables. Is there a way to reduce this margin space and thus increase the width of the datatables?</p>
<p>Thanks</p>
| 0debug |
Eclipse JFrame empty textField error : I'm working on eclipse JFrame and my purpose is calculating regression analysis with 26 variables x and y.But i have a problem with textField. For example; if the user have 10 variables x and y after enter the values the other textFields remains blank because of this frame gives an error like // Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" // how can ı fix it ? thanks | 0debug |
Understanding pointers in C/C++ : <p>I'm trying to understand how pointers work and I'm stuck at this line</p>
<pre><code>for (p = s + strlen(s) - 1; s < p; s++, p--)
</code></pre>
<p>I don't understand p what it's equated to.
can anyone help me?</p>
<p>here's the full code.</p>
<pre><code>void Reverse(char *s){
char c, *p;
for (p = s + strlen(s) - 1; s < p; s++, p--){
c = *s;
*s = *p;
*p = c;
}
}
int main(){
char ch[] = "!dlroW olleH";
Reverse(ch);
printf("%s", ch);
return 0;
}
</code></pre>
| 0debug |
Python: Finding all the max values in a 2D array, choosing the most North west point out of them, and identifying its index i,j? : Suppose there's a 2D array in python. I only need to find the index of an element that has the highest value.
However, there could be multiple elements that have the highest value. My objective is to find the index of any one of them, and the preference is to reduce time and space complexity.
How do I do this? | 0debug |
Create indicator from two groups : <p>I have this data frame:</p>
<pre><code>df<- data.frame(j = c("a", "a", "b", "b", "c", "c"),
t = c(2000,2010,2000,2010,2000,2010))
> df
j t
1 a 2000
2 a 2010
3 b 2000
4 b 2010
5 c 2000
6 c 2010
</code></pre>
<p>I am trying to create an indicator <code>jt</code> to identify the country/year:</p>
<pre><code> j t jt
1 a 2000 1
2 a 2010 2
3 b 2000 3
4 b 2010 4
5 c 2000 5
6 c 2010 6
7 c 2010 6
8 c 2010 6
</code></pre>
<p>The last two observations signal that I can have multiple occurrences.</p>
| 0debug |
android activity's intent and destroy, (between 3 activities) : I got three activities A, B ,C. A intent to B, B intent to C, when I finish the operation in C,I want to destroy C and straightly back to A, not B.
I've tried "finish();B b = new B();b.finish()" in C, doesn't work; And "finish();B b = new B();b.onDestroy()" in C, And called a nullpointerException .
So how to achieve that | 0debug |
My WSL terminal lost color : <p>For some reason when I start the Ubuntu terminal in Windows, it doesn't show colors until I type bash. What could be the reason and how do I fix it?
When I installed WSL it always showed colors.</p>
<p><a href="https://i.stack.imgur.com/OlwHE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OlwHE.png" alt="enter image description here"></a></p>
| 0debug |
uint64_t HELPER(get_cp_reg64)(CPUARMState *env, void *rip)
{
const ARMCPRegInfo *ri = rip;
return ri->readfn(env, ri);
}
| 1threat |
static int thp_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
ThpDemuxContext *thp = s->priv_data;
AVStream *st;
AVIOContext *pb = s->pb;
int64_t fsize= avio_size(pb);
int i;
avio_rb32(pb);
thp->version = avio_rb32(pb);
avio_rb32(pb);
avio_rb32(pb);
thp->fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
thp->framecnt = avio_rb32(pb);
thp->first_framesz = avio_rb32(pb);
thp->data_size = avio_rb32(pb);
if(fsize>0 && (!thp->data_size || fsize < thp->data_size))
thp->data_size= fsize;
thp->compoff = avio_rb32(pb);
avio_rb32(pb);
thp->first_frame = avio_rb32(pb);
thp->last_frame = avio_rb32(pb);
thp->next_framesz = thp->first_framesz;
thp->next_frame = thp->first_frame;
avio_seek (pb, thp->compoff, SEEK_SET);
thp->compcount = avio_rb32(pb);
avio_read(pb, thp->components, 16);
for (i = 0; i < thp->compcount; i++) {
if (thp->components[i] == 0) {
if (thp->vst != 0)
break;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
avpriv_set_pts_info(st, 64, thp->fps.den, thp->fps.num);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_THP;
st->codec->codec_tag = 0;
st->codec->width = avio_rb32(pb);
st->codec->height = avio_rb32(pb);
st->codec->sample_rate = av_q2d(thp->fps);
thp->vst = st;
thp->video_stream_index = st->index;
if (thp->version == 0x11000)
avio_rb32(pb);
} else if (thp->components[i] == 1) {
if (thp->has_audio != 0)
break;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_ADPCM_THP;
st->codec->codec_tag = 0;
st->codec->channels = avio_rb32(pb);
st->codec->sample_rate = avio_rb32(pb);
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
thp->audio_stream_index = st->index;
thp->has_audio = 1;
}
}
return 0;
}
| 1threat |
static void s390_pci_generate_error_event(uint16_t pec, uint32_t fh,
uint32_t fid, uint64_t faddr,
uint32_t e)
{
s390_pci_generate_event(1, pec, fh, fid, faddr, e);
}
| 1threat |
Is installing Visual studio 2015 enterprise edition sufficient to work with C++1/C++14? : I want to work with C++ 11 (if not C++ 14). I am installing visual studio 2015 enterprise edition. Is this sufficient?
Regards
PMJ | 0debug |
Need help fixing a nullreferenceexception occuring when initializing an object : I've tried searching the internet for a while now, and maybe I just suck at searching because I don't know how to properly phrase the problem.
Anyway, my code looks like this:
SystemOutput systemOutput = null;
SystemCL system = null;
WindowsForm wf = null;
wf = new WindowsForm(system);
systemOutput = new SystemOutput(wf);
system = new SystemCL(systemOutput, wf);
The rest of the code doesn't really matter for the matter of solving my problem (I think?)
So as you can see the objects reference eachother, which means that if the other objects hasn't been initialized yet, it will give me an error. So I tried first making them null, but now the first object get a nullreferencepointer, because the object is null.
How do I fix this puzzle? Is there a better way to do this? | 0debug |
how to merge two dataframes and sum the values of columns : <p>I have two dataframes</p>
<pre><code>df1
Name class value
Sri 1 5
Ram 2 8
viv 3 4
df2
Name class value
Sri 1 5
viv 4 4
</code></pre>
<p>My desired output is,</p>
<pre><code>df,
Name class value
Sri 2 10
Ram 2 8
viv 7 8
</code></pre>
<p>Please help, thanks in advance!</p>
| 0debug |
static MemTxResult memory_region_read_with_attrs_accessor(MemoryRegion *mr,
hwaddr addr,
uint64_t *value,
unsigned size,
unsigned shift,
uint64_t mask,
MemTxAttrs attrs)
{
uint64_t tmp = 0;
MemTxResult r;
r = mr->ops->read_with_attrs(mr->opaque, addr, &tmp, size, attrs);
if (mr->subpage) {
trace_memory_region_subpage_read(get_cpu_index(), mr, addr, tmp, size);
} else if (TRACE_MEMORY_REGION_OPS_READ_ENABLED) {
hwaddr abs_addr = memory_region_to_absolute_addr(mr, addr);
trace_memory_region_ops_read(get_cpu_index(), mr, abs_addr, tmp, size);
}
*value |= (tmp & mask) << shift;
return r;
} | 1threat |
How can i add Jenkinsfile support to visual studio 2017 : <p>I am using Visual Studio 2017 Pro, and i am being driven crazy by the lack of syntax highlighting for the Jenkinsfile in my project. I am using the Declarative Syntax, but i just cant seem to find anything on getting this to work. My research says that its based on groovy, but i dont see a way to map it to that language either. Any help is appreciated. </p>
| 0debug |
static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
pixman_format_code_t pformat;
struct virtio_gpu_simple_resource *res;
struct virtio_gpu_resource_create_2d c2d;
VIRTIO_GPU_FILL_CMD(c2d);
trace_virtio_gpu_cmd_res_create_2d(c2d.resource_id, c2d.format,
c2d.width, c2d.height);
if (c2d.resource_id == 0) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
__func__);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
return;
}
res = virtio_gpu_find_resource(g, c2d.resource_id);
if (res) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n",
__func__, c2d.resource_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
return;
}
res = g_new0(struct virtio_gpu_simple_resource, 1);
res->width = c2d.width;
res->height = c2d.height;
res->format = c2d.format;
res->resource_id = c2d.resource_id;
pformat = get_pixman_format(c2d.format);
if (!pformat) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: host couldn't handle guest format %d\n",
__func__, c2d.format);
g_free(res);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
return;
}
res->image = pixman_image_create_bits(pformat,
c2d.width,
c2d.height,
NULL, 0);
if (!res->image) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: resource creation failed %d %d %d\n",
__func__, c2d.resource_id, c2d.width, c2d.height);
g_free(res);
cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
return;
}
QTAILQ_INSERT_HEAD(&g->reslist, res, next);
}
| 1threat |
static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)
{
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
const char *value;
value = qemu_opt_get(opts, "cancel-path");
tb->cancel_path = g_strdup(value);
value = qemu_opt_get(opts, "path");
if (!value) {
value = TPM_PASSTHROUGH_DEFAULT_DEVICE;
}
tpm_pt->tpm_dev = g_strdup(value);
tb->path = g_strdup(tpm_pt->tpm_dev);
tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR);
if (tpm_pt->tpm_fd < 0) {
error_report("Cannot access TPM device using '%s': %s",
tpm_pt->tpm_dev, strerror(errno));
goto err_free_parameters;
}
if (tpm_passthrough_test_tpmdev(tpm_pt->tpm_fd)) {
error_report("'%s' is not a TPM device.",
tpm_pt->tpm_dev);
goto err_close_tpmdev;
}
return 0;
err_close_tpmdev:
qemu_close(tpm_pt->tpm_fd);
tpm_pt->tpm_fd = -1;
err_free_parameters:
g_free(tb->path);
tb->path = NULL;
g_free(tpm_pt->tpm_dev);
tpm_pt->tpm_dev = NULL;
return 1;
}
| 1threat |
int32_t ff_mlp_pack_output(int32_t lossless_check_data,
uint16_t blockpos,
int32_t (*sample_buffer)[MAX_CHANNELS],
void *data,
uint8_t *ch_assign,
int8_t *output_shift,
uint8_t max_matrix_channel,
int is32)
{
unsigned int i, out_ch = 0;
int32_t *data_32 = data;
int16_t *data_16 = data;
for (i = 0; i < blockpos; i++) {
for (out_ch = 0; out_ch <= max_matrix_channel; out_ch++) {
int mat_ch = ch_assign[out_ch];
int32_t sample = sample_buffer[i][mat_ch]
<< output_shift[mat_ch];
lossless_check_data ^= (sample & 0xffffff) << mat_ch;
if (is32)
*data_32++ = sample << 8;
else
*data_16++ = sample >> 8;
}
}
return lossless_check_data;
}
| 1threat |
SwsContext *sws_alloc_context(void)
{
SwsContext *c = av_mallocz(sizeof(SwsContext));
c->av_class = &sws_context_class;
av_opt_set_defaults(c);
return c;
}
| 1threat |
IEnumerable<T> returning function implemented using 'yield return' versus creating a collection : <p>I am debating which of the following is an efficient way to implement the function <code>CreatePlayerData</code></p>
<pre><code>Method1: yield return
private static IEnumerable<IPlayerData> CreatePlayerData(int gameId, PlayerProfiles profiles)
{
foreach (var data in profiles.data)
{
yield return new PlayerData
{
GameId = gameId,
GameName = data.GameName,
ProfileId = data.ProfileId
};
}
}
Method2: Creating a collection
private static IEnumerable<IPlayerData> CreatePlayerData(int gameId, PlayerProfiles profiles)
{
var collection = new List<IPlayerData>();
foreach (var data in profiles.data)
{
collection.Add(new PlayerData
{
GameId = gameId,
GameName = data.GameName,
ProfileId = data.ProfileId
});
}
return collection;
}
</code></pre>
<p>There is a log function that uses function <code>CreatePlayerData</code> as an argument:
The signature of the log function is:</p>
<pre><code>void LogPlayerData(IEnumerable<IPlayerData> players);
</code></pre>
<p>If I use <code>Method1</code> to implement <code>CreatePlayerData</code> function, I call the log function as:</p>
<pre><code>LogPlayerData(CreatePlayerData().ToArray());
</code></pre>
<p>Or if I use <code>Method2</code> to implement <code>CreatePlayerData</code> function, I call the log function as:</p>
<pre><code>LogPlayerData(CreatePlayerData());
</code></pre>
<p>Not sure which among <code>Method1</code> or <code>Method2</code> is the best way to implement the function <code>CreatePlayerData</code>. Any suggestions?</p>
| 0debug |
Message Box issues in C sharp : MessageBox.Show ("About Developer"+ "Mandelbrot by Milan." + Environment.NewLine +
"Email: xyz@abc.com" + Environment.NewLine +
"Contact No: +977123456789" + Environment.NewLine
);
I want About Developer as title. I searched but I didn't get suitable solution to my problem. Please Help me out. :)
[enter image description here][1]
[1]: https://i.stack.imgur.com/I0T9p.jpg | 0debug |
static uint64_t lsi_ram_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
LSIState *s = opaque;
uint32_t val;
uint32_t mask;
val = s->script_ram[addr >> 2];
mask = ((uint64_t)1 << (size * 8)) - 1;
val >>= (addr & 3) * 8;
return val & mask;
}
| 1threat |
static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d,
unsigned int qstride, unsigned int flag,
uint64_t alpha) {
unsigned int x, y, c0, c1, a = (!flag * 255u) << 24;
unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3;
uint32_t colors[4], pixels;
c0 = AV_RL16(s);
c1 = AV_RL16(s+2);
rb0 = (c0<<3 | c0<<8) & 0xf800f8;
rb1 = (c1<<3 | c1<<8) & 0xf800f8;
rb0 += (rb0>>5) & 0x070007;
rb1 += (rb1>>5) & 0x070007;
g0 = (c0 <<5) & 0x00fc00;
g1 = (c1 <<5) & 0x00fc00;
g0 += (g0 >>6) & 0x000300;
g1 += (g1 >>6) & 0x000300;
colors[0] = rb0 + g0 + a;
colors[1] = rb1 + g1 + a;
if (c0 > c1 || flag) {
rb2 = (((2*rb0+rb1) * 21) >> 6) & 0xff00ff;
rb3 = (((2*rb1+rb0) * 21) >> 6) & 0xff00ff;
g2 = (((2*g0 +g1 ) * 21) >> 6) & 0x00ff00;
g3 = (((2*g1 +g0 ) * 21) >> 6) & 0x00ff00;
colors[3] = rb3 + g3 + a;
} else {
rb2 = ((rb0+rb1) >> 1) & 0xff00ff;
g2 = ((g0 +g1 ) >> 1) & 0x00ff00;
colors[3] = 0;
}
colors[2] = rb2 + g2 + a;
pixels = AV_RL32(s+4);
for (y=0; y<4; y++) {
for (x=0; x<4; x++) {
a = (alpha & 0x0f) << 28;
a += a >> 4;
d[x] = a + colors[pixels&3];
pixels >>= 2;
alpha >>= 4;
}
d += qstride;
}
}
| 1threat |
av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
{
static int init_done=0;
int i;
common_init(s);
if(s->msmpeg4_version>=4){
s->min_qcoeff= -255;
s->max_qcoeff= 255;
}
if (!init_done) {
init_done = 1;
init_mv_table(&mv_tables[0]);
init_mv_table(&mv_tables[1]);
for(i=0;i<NB_RL_TABLES;i++)
init_rl(&rl_table[i], static_rl_table_store[i]);
for(i=0; i<NB_RL_TABLES; i++){
int level;
for(level=0; level<=MAX_LEVEL; level++){
int run;
for(run=0; run<=MAX_RUN; run++){
int last;
for(last=0; last<2; last++){
rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0);
}
}
}
}
}
}
| 1threat |
Android Manifest Duplicate Permissions : <p>We have an app that consists of a third party library (altbeacon), a locally built Android library and an app component. All three components have an AndroidManifest.xml which are merged during the build. The app is built using gradle.</p>
<p>THis app has been long published on the Google Play Store. In the last iteration we upgraded from API level 22 to 25. Everything built without error, the APK was installed on and tested on real devices without error, but when we came to update the app on Google Play, the upload of the APK failed with the error:</p>
<blockquote>
<p>Upload failed
<br>Duplicate declarations of permission
android.permission.ACCESS_COARSE_LOCATION with different
maxSdkVersions.</p>
</blockquote>
<p>Anaylyzing the AndroidManaifest.xml we found org.altbeacon.beacon has the following permission:</p>
<pre><code><uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="23" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
</code></pre>
<p>Our local Android library module the targetSdkVersion is set to 25 in build.gradle and the the AndroidManifest.xml contains:</p>
<pre><code><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</code></pre>
<p>In the app module the targetSdkVersion is set to 25 in build.gradle.</p>
<p>The generated AndroidManifest.xml in the app module contains:</p>
<pre><code><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
</code></pre>
<p>and just to confirm, looking in the APK itself and extracting the binary manifest:</p>
<pre><code>~/.android-sdk/build-tools/25.0.3/aapt l -a app-release.apk | grep -B1 COARSE
E: uses-permission (line=62)
A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")
--
E: uses-permission-sdk-23 (line=76)
A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")
</code></pre>
<p>So there is a duplicate tag, and I think the manifest merger should have recognized that and removed the one from the altbeacon library. My question is how do I remove the permission from the altbeacon library?</p>
<p>I have tried the following in the app module AndroidManifest.xml:</p>
<pre><code><uses-permission-sdk-23
android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:node="remove"
tools:selector="org.altbeacon.beacon"/>
</code></pre>
<p>This results in:</p>
<pre><code>AndroidManifest.xml:12:5-15:48 Warning:
uses-permission-sdk-23 was tagged at AndroidManifest.xml:12 to remove other declarations but no other declaration present
</code></pre>
<p>and</p>
<pre><code><uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:node="remove"
tools:selector="org.altbeacon.beacon"/>
</code></pre>
<p>This results in:</p>
<pre><code>AndroidManifest.xml:12:5-15:48 Warning:
uses-permission was tagged at AndroidManifest.xml:12 to remove other declarations but no other declaration present
</code></pre>
<p>The following does work, but it removes the wrong tag, it removes the one in the local Android library we build as part of our app.</p>
<pre><code> <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:node="remove"/>
</code></pre>
<p>The org.altbeacon.beacon permission is left:</p>
<pre><code>~/.android-sdk/build-tools/25.0.3/aapt l -a app-release.apk | grep -B1 COARSE
E: uses-permission-sdk-23 (line=72)
A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")
</code></pre>
<p>Which is unsatisfying because if the permission in org.altbeacon.beacon library chamge, or it is removed in the future, the ACCESS_COARSE_PERMISSION will be missing from our app.</p>
<p>Any suggestions on how to fix this properly?</p>
| 0debug |
Haskell program aborts with "loop" but I think it shouldn't : <p>I have this Haskell code which when compiled with GHC and run, aborts with a loop detected.</p>
<pre><code>data Foo = Foo ()
deriving (Eq,Show)
type Foop = Foo -> ((),Foo)
noOp :: Foop
noOp st = ((),st)
someOp :: Foop
someOp st@(Foo x) = ((),st)
(<+>) :: Foop -> Foop -> Foop
(<+>) f g st = let ((_,st'),(_,st'')) = ((f st),(g st')) in ((),st'')
main = print $ (noOp <+> someOp) $ Foo ()
</code></pre>
<p>I think it shouldn't, and here are some modifications. Each of them makes the loop go away:</p>
<ul>
<li>change <code>data Foo</code> to <code>newtype Foo</code></li>
<li>change <code>(noOp <+> someOp)</code> to <code>(someOp <+> noOp)</code></li>
<li>remove the deconstruction <code>@(Foo x)</code></li>
</ul>
<p>Is this a bug in GHC or is it my lack of understanding the evaluation process?</p>
| 0debug |
So i made a simple program in C, which calculates factorial of a number : So i made a simple program in C, which calculates factorial of a number, but at the end i want to run the program instead of "press any key to continue" I want it to show "press any key to find factorial of a number again"
code :
#include<stdio.h>
int main()
{
int facto, i, m ;
m=1 ;
printf("Ener a Value : ");
scanf("%d", &facto) ;
for( i=facto-1 ; i>m ; i-- )
facto *= i ;
printf("My Reg num:SP-16/BBS/033\nFactorial of the number : =%d\n",facto );
system ("pause") ;
} | 0debug |
c++ memory managment problem, std::vector nevere relase memory out of scope : <p>i am very confuse about this simple code.
why this code can release memory that allocated.</p>
<pre><code>double *a;
for(int i = 0 ; i < 1000000 ; i++)
{
if(1){
a = new double ;
}
if(1){
delete a;
}
}
</code></pre>
<p>but this code can not remove all memory that allocated.</p>
<pre><code>std::vector<double *>rubberList ;
for(int i = 0 ; i < 1000000 ; i++)
{
rubberList.push_back(new double);
//delete rubberList[i];
}
for(unsigned long j = 0 ; j < 1000000 ; j++)
{
delete rubberList.at(j);
}
</code></pre>
<p>and when delete items in allocator block correctly remove memory.</p>
<pre><code>for(int i = 0 ; i < 1000000 ; i++)
{
rubberList.push_back(new double);
delete rubberList[i];
}
</code></pre>
<p>tnx</p>
| 0debug |
int load_aout(const char *filename, target_phys_addr_t addr, int max_sz,
int bswap_needed, target_phys_addr_t target_page_size)
{
int fd, size, ret;
struct exec e;
uint32_t magic;
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
return -1;
size = read(fd, &e, sizeof(e));
if (size < 0)
goto fail;
if (bswap_needed) {
bswap_ahdr(&e);
}
magic = N_MAGIC(e);
switch (magic) {
case ZMAGIC:
case QMAGIC:
case OMAGIC:
if (e.a_text + e.a_data > max_sz)
goto fail;
lseek(fd, N_TXTOFF(e), SEEK_SET);
size = read_targphys(filename, fd, addr, e.a_text + e.a_data);
if (size < 0)
goto fail;
break;
case NMAGIC:
if (N_DATADDR(e, target_page_size) + e.a_data > max_sz)
goto fail;
lseek(fd, N_TXTOFF(e), SEEK_SET);
size = read_targphys(filename, fd, addr, e.a_text);
if (size < 0)
goto fail;
ret = read_targphys(filename, fd, addr + N_DATADDR(e, target_page_size),
e.a_data);
if (ret < 0)
goto fail;
size += ret;
break;
default:
goto fail;
}
close(fd);
return size;
fail:
close(fd);
return -1;
}
| 1threat |
static int apng_read_close(AVFormatContext *s)
{
APNGDemuxContext *ctx = s->priv_data;
av_freep(&ctx->extra_data);
ctx->extra_data_size = 0;
return 0;
}
| 1threat |
static void ide_drive_pre_save(void *opaque)
{
IDEState *s = opaque;
s->cur_io_buffer_len = 0;
if (!(s->status & DRQ_STAT))
return;
s->cur_io_buffer_offset = s->data_ptr - s->io_buffer;
s->cur_io_buffer_len = s->data_end - s->data_ptr;
s->end_transfer_fn_idx = transfer_end_table_idx(s->end_transfer_func);
if (s->end_transfer_fn_idx == -1) {
fprintf(stderr, "%s: invalid end_transfer_func for DRQ_STAT\n",
__func__);
s->end_transfer_fn_idx = 2;
}
}
| 1threat |
static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,
uint8_t devfn, VTDContextEntry *ce)
{
VTDRootEntry re;
int ret_fr;
ret_fr = vtd_get_root_entry(s, bus_num, &re);
if (ret_fr) {
return ret_fr;
}
if (!vtd_root_entry_present(&re)) {
trace_vtd_re_not_present(bus_num);
return -VTD_FR_ROOT_ENTRY_P;
} else if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD)) {
trace_vtd_re_invalid(re.rsvd, re.val);
return -VTD_FR_ROOT_ENTRY_RSVD;
}
ret_fr = vtd_get_context_entry_from_root(&re, devfn, ce);
if (ret_fr) {
return ret_fr;
}
if (!vtd_ce_present(ce)) {
trace_vtd_ce_not_present(bus_num, devfn);
return -VTD_FR_CONTEXT_ENTRY_P;
} else if ((ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI) ||
(ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO)) {
trace_vtd_ce_invalid(ce->hi, ce->lo);
return -VTD_FR_CONTEXT_ENTRY_RSVD;
}
if (!vtd_is_level_supported(s, vtd_ce_get_level(ce))) {
trace_vtd_ce_invalid(ce->hi, ce->lo);
return -VTD_FR_CONTEXT_ENTRY_INV;
} else {
switch (vtd_ce_get_type(ce)) {
case VTD_CONTEXT_TT_MULTI_LEVEL:
case VTD_CONTEXT_TT_DEV_IOTLB:
break;
default:
trace_vtd_ce_invalid(ce->hi, ce->lo);
return -VTD_FR_CONTEXT_ENTRY_INV;
}
}
return 0;
}
| 1threat |
static uint64_t watch_mem_read(void *opaque, hwaddr addr,
unsigned size)
{
check_watchpoint(addr & ~TARGET_PAGE_MASK, size, BP_MEM_READ);
switch (size) {
case 1: return ldub_phys(&address_space_memory, addr);
case 2: return lduw_phys(&address_space_memory, addr);
case 4: return ldl_phys(&address_space_memory, addr);
default: abort();
}
}
| 1threat |
static int tta_probe(AVProbeData *p)
{
const uint8_t *d = p->buf;
if (p->buf_size < 4)
return 0;
if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1')
return 80;
return 0;
}
| 1threat |
AWS CodeBuild + CodePipeline: "No matching artifact paths found" : <p>I am attempting to get CodePipeline to fetch my code from GitHub and build it with CodeBuild. The first (Source) step works fine. But the second (Build) step fails during the "UPLOAD_ARTIFACTS" part. Here are the relevant log statements:</p>
<pre><code>[Container] 2017/01/12 17:21:31 Assembling file list
[Container] 2017/01/12 17:21:31 Expanding MyApp
[Container] 2017/01/12 17:21:31 Skipping invalid artifact path MyApp
[Container] 2017/01/12 17:21:31 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2017/01/12 17:21:31 Phase context status code: ARTIFACT_ERROR Message: No matching artifact paths found
[Container] 2017/01/12 17:21:31 Runtime error (No matching artifact paths found)
</code></pre>
<p>My app has a buildspec.yml in its root folder. It looks like:</p>
<pre><code>version: 0.1
phases:
build:
commands:
- echo `$BUILD_COMMAND`
artifacts:
discard-paths: yes
files:
- MyApp
</code></pre>
<p>It would appear that the "MyApp" in my buildspec.yml should be something different, but I'm pouring through all of the AWS docs to no avail (what else is new?). How can I get it to upload the artifact correctly?</p>
| 0debug |
Second order generics seem to behave differently than first order generics : <p>I thought I have a reasonable grasp of generics. For example, I understand why</p>
<pre><code>private void addString(List<? extends String> list, String s) {
list.add(s); // does not compile
list.add(list.get(0)); // doesn't compile either
}
</code></pre>
<p>Does not compile. <a href="https://stackoverflow.com/a/10943340/66686">I even earned some internet karma with the knowledge</a>.</p>
<p>But I'd think by the same argument this shouldn't compile:</p>
<pre><code>private void addClassWildcard(List<Class<? extends String>> list, Class<? extends String> c) {
list.add(c);
list.add(list.get(0));
}
</code></pre>
<p>Nor should this:</p>
<pre><code>private void addClass(List<Class<? extends String>> list, Class<String> c) {
list.add(c);
list.add(list.get(0));
}
</code></pre>
<p>But both compile. Why? What is the difference to the example from the top?</p>
<p>I'd appreciate an explanation in common English as well as a pointer to the relevant parts of the Java Specification or similar. </p>
| 0debug |
static int scsi_block_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
int sg_version;
int rc;
if (!s->qdev.conf.bs) {
error_report("drive property not set");
return -1;
}
rc = bdrv_ioctl(s->qdev.conf.bs, SG_GET_VERSION_NUM, &sg_version);
if (rc < 0) {
error_report("cannot get SG_IO version number: %s. "
"Is this a SCSI device?",
strerror(-rc));
return -1;
}
if (sg_version < 30000) {
error_report("scsi generic interface too old");
return -1;
}
rc = get_device_type(s);
if (rc < 0) {
error_report("INQUIRY failed");
return -1;
}
if (s->qdev.type == TYPE_ROM || s->qdev.type == TYPE_WORM) {
s->qdev.blocksize = 2048;
} else {
s->qdev.blocksize = 512;
}
s->features |= (1 << SCSI_DISK_F_NO_REMOVABLE_DEVOPS);
return scsi_initfn(&s->qdev);
}
| 1threat |
Assumed role in AWS Lambda, access denied on SSM call : <p>I'm getting an error in my Lambda function, which calls SSM:</p>
<blockquote>
<p>AccessDeniedException: User: arn:aws:sts::redacted:assumed-role/LambdaBackend_master_lambda/SpikeLambda is not authorized to perform: ssm:GetParameter on resource: arn:aws:ssm:eu-west-1:redacted:parameter/default/key/api</p>
</blockquote>
<p>However, I'm pretty sure I configured this correctly:</p>
<p>Role, with AssumeRole for Lambda (although we know that works from the error message).</p>
<pre><code>λ aws iam get-role --role-name LambdaBackend_master_lambda
{
"Role": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"RoleId": "redacted",
"CreateDate": "2017-06-23T20:49:37Z",
"RoleName": "LambdaBackend_master_lambda",
"Path": "/",
"Arn": "arn:aws:iam::redacted:role/LambdaBackend_master_lambda"
}
}
</code></pre>
<p>And my policy:</p>
<pre><code>λ aws iam list-role-policies --role-name LambdaBackend_master_lambda
{
"PolicyNames": [
"ssm_read"
]
}
λ aws iam get-role-policy --role-name LambdaBackend_master_lambda --policy-name ssm_read
{
"RoleName": "LambdaBackend_master_lambda",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ssm:DescribeParameters"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ssm:GetParameters"
],
"Resource": "arn:aws:ssm:eu-west-1:redacted:parameter/*",
"Effect": "Allow"
}
]
},
"PolicyName": "ssm_read"
}
</code></pre>
<p>I've run it through the policy simulator and it seems to be fine!</p>
<p><a href="https://i.stack.imgur.com/RLPnL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RLPnL.png" alt="AWS IAM policy sim"></a></p>
| 0debug |
Does private inheritance always mean "HAS-A"? : <p>According to my favorite author , <a href="http://scottmeyers.blogspot.com/" rel="noreferrer">Mr Scott Meyers</a>, the <strong>private</strong> inheritance and composition means the same thing aka Has-A relationship. Thus everything that can be gained from composition (containment, when class A has class B as its member) can be gained by private inheritance, and visa-versa. </p>
<p>So the following code should be a Has-A relationship, but from my point of view, its not!</p>
<pre><code>class A : private boost::noncopyable {.. this is irrelevant };
</code></pre>
<p>Can anyone please tell me that I am missing? Or how this code can be implemented through composition?</p>
| 0debug |
void ioinst_handle_rsch(S390CPU *cpu, uint64_t reg1)
{
int cssid, ssid, schid, m;
SubchDev *sch;
int ret = -ENODEV;
int cc;
if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) {
program_interrupt(&cpu->env, PGM_OPERAND, 2);
return;
}
trace_ioinst_sch_id("rsch", cssid, ssid, schid);
sch = css_find_subch(m, cssid, ssid, schid);
if (sch && css_subch_visible(sch)) {
ret = css_do_rsch(sch);
}
switch (ret) {
case -ENODEV:
cc = 3;
break;
case -EINVAL:
cc = 2;
break;
case 0:
cc = 0;
break;
default:
cc = 1;
break;
}
setcc(cpu, cc);
}
| 1threat |
Set a double to byte array : <p>what's a fast way of assigning a double to 8 bytes inside a byte array?</p>
<p>I have a byte array that is about 4k bytes big and I am attempting to take 8 bytes out of that and copy it into a double. I am trying to avoid memmove and memcpy for speed reasons, as assigning variables is much faster. I am working in embedded world, any other fast implementations are appreciated.</p>
<pre><code>void foo(double *pdest)
{
// Try 1: I am using 1 element in the array, it won't work
*pdest = (double)p->stk[stkpos];
// Try 2: I am attempting to loose the single element element
*pdest = (double)((double*)&p->stk[stkpos]);
}
</code></pre>
<p>Neither solutions have worked for me, I am not sure how I can achieve this.</p>
| 0debug |
Creating a X-shaped matrix using R and Python : <p>I am a newbie regarding programming, and as part of a homework I am asked to create a X shaped matrix in R and Python. I have no data to use, so I am thinking about using some random numbers. The point is that I have no idea how to code to get an X shaped matrix. I don't even know where to start. </p>
<p>I appreciate all the help you can provide. Thanks in advance!</p>
| 0debug |
How to align this content using Flexbox? : [Example Picture][1] Don't worry about the css part. I'm trying to align the input and the anchor horizontally with the logo using flexbox. Example attached. The logo will be on the right and the input with the anchor will be on the left but all horizontal.
This is what I currently have. I'm not worried about the css just trying to get the layout correct.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
<!-- language: lang-html -->
<div class="small-12 cell footer-logo-container">
<a href="#">
LOGO
</a>
<div class="footer-email">
Sign Up for the Rock River Report Here
<input class="footer-input" type="email" placeholder="email">
<a href="#" class="link">
<div class="link-text">
SUBSCRIBE
</div>
</a>
</div>
<!-- end snippet -->
[1]: https://i.stack.imgur.com/1oBHV.png | 0debug |
How extern is working in C, inside function. : #include<stdio.h>
int a = 33;
int main()
{
int a = 40;
{
extern int a;
printf("\n%d",a);
}
return 0;
}
Output : 33
Can anyone please let me know how Extern is working here ? | 0debug |
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb,
const float *in, int size, int scale_idx,
int cb, const float lambda)
{
const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
const float CLIPPED_ESCAPE = 165140.0f*IQ;
const int dim = (cb < FIRST_PAIR_BT) ? 4 : 2;
int i, j, k;
#ifndef USE_REALLY_FULL_SEARCH
const float Q34 = sqrtf(Q * sqrtf(Q));
const int range = aac_cb_range[cb];
const int maxval = aac_cb_maxval[cb];
int offs[4];
float *scaled = s->scoefs;
#endif
if (!cb)
return;
#ifndef USE_REALLY_FULL_SEARCH
offs[0] = 1;
for (i = 1; i < dim; i++)
offs[i] = offs[i-1]*range;
abs_pow34_v(scaled, in, size);
quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval);
#endif
for (i = 0; i < size; i += dim) {
float mincost;
int minidx = 0;
int minbits = 0;
const float *vec;
#ifndef USE_REALLY_FULL_SEARCH
int (*quants)[2] = &s->qcoefs[i];
mincost = 0.0f;
for (j = 0; j < dim; j++)
mincost += in[i+j]*in[i+j];
minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;
minbits = ff_aac_spectral_bits[cb-1][minidx];
mincost = mincost * lambda + minbits;
for (j = 0; j < (1<<dim); j++) {
float rd = 0.0f;
int curbits;
int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;
int same = 0;
for (k = 0; k < dim; k++) {
if ((j & (1 << k)) && quants[k][0] == quants[k][1]) {
same = 1;
break;
}
}
if (same)
continue;
for (k = 0; k < dim; k++)
curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k];
curbits = ff_aac_spectral_bits[cb-1][curidx];
vec = &ff_aac_codebook_vectors[cb-1][curidx*dim];
#else
vec = ff_aac_codebook_vectors[cb-1];
mincost = INFINITY;
for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) {
float rd = 0.0f;
int curbits = ff_aac_spectral_bits[cb-1][j];
int curidx = j;
#endif
if (IS_CODEBOOK_UNSIGNED(cb)) {
for (k = 0; k < dim; k++) {
float t = fabsf(in[i+k]);
float di;
if (vec[k] == 64.0f) {
if (t < 39.0f*IQ) {
rd = INFINITY;
break;
}
if (t >= CLIPPED_ESCAPE) {
di = t - CLIPPED_ESCAPE;
curbits += 21;
} else {
int c = av_clip(quant(t, Q), 0, 8191);
di = t - c*cbrtf(c)*IQ;
curbits += av_log2(c)*2 - 4 + 1;
}
} else {
di = t - vec[k]*IQ;
}
if (vec[k] != 0.0f)
curbits++;
rd += di*di;
}
} else {
for (k = 0; k < dim; k++) {
float di = in[i+k] - vec[k]*IQ;
rd += di*di;
}
}
rd = rd * lambda + curbits;
if (rd < mincost) {
mincost = rd;
minidx = curidx;
minbits = curbits;
}
}
put_bits(pb, ff_aac_spectral_bits[cb-1][minidx], ff_aac_spectral_codes[cb-1][minidx]);
if (IS_CODEBOOK_UNSIGNED(cb))
for (j = 0; j < dim; j++)
if (ff_aac_codebook_vectors[cb-1][minidx*dim+j] != 0.0f)
put_bits(pb, 1, in[i+j] < 0.0f);
if (cb == ESC_BT) {
for (j = 0; j < 2; j++) {
if (ff_aac_codebook_vectors[cb-1][minidx*2+j] == 64.0f) {
int coef = av_clip(quant(fabsf(in[i+j]), Q), 0, 8191);
int len = av_log2(coef);
put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
put_bits(pb, len, coef & ((1 << len) - 1));
}
}
}
}
}
| 1threat |
db.execute('SELECT * FROM employees WHERE id = ' + user_input) | 1threat |
static int decode_555(GetByteContext *gB, uint16_t *dst, int stride,
int keyframe, int w, int h)
{
int last_symbol = 0, repeat = 0, prev_avail = 0;
if (!keyframe) {
int x, y, endx, endy, t;
#define READ_PAIR(a, b) \
a = bytestream2_get_byte(gB) << 4; \
t = bytestream2_get_byte(gB); \
a |= t >> 4; \
b = (t & 0xF) << 8; \
b |= bytestream2_get_byte(gB); \
READ_PAIR(x, endx)
READ_PAIR(y, endy)
if (endx >= w || endy >= h || x > endx || y > endy)
return AVERROR_INVALIDDATA;
dst += x + stride * y;
w = endx - x + 1;
h = endy - y + 1;
if (y)
prev_avail = 1;
}
do {
uint16_t *p = dst;
do {
if (repeat-- < 1) {
int b = bytestream2_get_byte(gB);
if (b < 128)
last_symbol = b << 8 | bytestream2_get_byte(gB);
else if (b > 129) {
repeat = 0;
while (b-- > 130)
repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
if (last_symbol == -2) {
int skip = FFMIN((unsigned)repeat, dst + w - p);
repeat -= skip;
p += skip;
}
} else
last_symbol = 127 - b;
}
if (last_symbol >= 0)
*p = last_symbol;
else if (last_symbol == -1 && prev_avail)
*p = *(p - stride);
} while (++p < dst + w);
dst += stride;
prev_avail = 1;
} while (--h);
return 0;
}
| 1threat |
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
{
assert(!s->allocating_write_reqs_plugged);
s->allocating_write_reqs_plugged = true;
}
| 1threat |
void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
{
uint64_t last = start + count - 1;
trace_hbitmap_reset(hb, start, count,
start >> hb->granularity, last >> hb->granularity);
start >>= hb->granularity;
last >>= hb->granularity;
hb->count -= hb_count_between(hb, start, last);
hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
} | 1threat |
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
{
int flags;
uint8_t data = 0;
const SDL_VideoInfo *vi;
char *filename;
#if defined(__APPLE__)
if (!keyboard_layout)
keyboard_layout = "en-us";
#endif
if(keyboard_layout) {
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
if (!kbd_layout)
exit(1);
}
if (no_frame)
gui_noframe = 1;
if (!full_screen) {
setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
}
#ifdef __linux__
setenv("SDL_VIDEODRIVER", "x11", 0);
#endif
setenv("SDL_DISABLE_LOCK_KEYS", "1", 1);
flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
if (SDL_Init (flags)) {
fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
SDL_GetError());
exit(1);
}
vi = SDL_GetVideoInfo();
host_format = *(vi->vfmt);
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu-icon.bmp");
if (filename) {
SDL_Surface *image = SDL_LoadBMP(filename);
if (image) {
uint32_t colorkey = SDL_MapRGB(image->format, 255, 255, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
SDL_WM_SetIcon(image, NULL);
}
g_free(filename);
}
if (full_screen) {
gui_fullscreen = 1;
sdl_grab_start();
}
dcl = g_malloc0(sizeof(DisplayChangeListener));
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
mouse_mode_notifier.notify = sdl_mouse_mode_change;
qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier);
sdl_update_caption();
SDL_EnableKeyRepeat(250, 50);
gui_grab = 0;
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
sdl_cursor_normal = SDL_GetCursor();
atexit(sdl_cleanup);
}
| 1threat |
How to store HEX in a unit8_t array? : Hi I want to store the HEX value into a unit8_t array.below is the code that i am trying to use and pass it to set the resource value
const static unit8_t PSK_KEY[]="31383031"
security->set_resource_value(M2MSecurity::Secretkey, PSK_KEY, sizeof(PSK_KEY) - 1);
or Do i need to set the PSK_KEY in ASCII?? | 0debug |
JHipster: java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0 : <p>I am trying to get familiar with Jhipster and I am having this error when I run my first <code>mvnw</code> is anyone had this already?:</p>
<pre><code>Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/wrapper/MavenWrapperMain : Unsupported major.minor version 51.0
</code></pre>
<p>I created the project by generating the sources on a github account.</p>
<p>Thanks for your help</p>
| 0debug |
any one can help me with this sql syntax error? what should i use near the select statement : Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Len(Trim(TextBox1.Text)) = 0 Then
MsgBox("Please Enter Current Odometer For Specified Vehicle", MsgBoxStyle.Critical, "Error")
TextBox1.Focus()
Else
Dim time As DateTime = DateTimePicker1.Value.Date
Dim format As String = "yy-MM-dd"
Dim newdate = time.ToString(format)
Dim SQLStatement As String = "IF EXISTS (SELECT * FROM services_list WHERE vehicle_id='" & Label7.Text & "' AND service='" & ComboBox1.Text & "') BEGIN UPDATE services_list Set service_date='" & newdate & "', note='" & RichTextBox1.Text & "', odometer='" & TextBox1.Text & "' WHERE vehicle_id='" & Label7.Text & "' AND service='" & ComboBox1.Text & "' End Else BEGIN INSERT INTO services_list(vehicle_id,service,service_date,note,odometer,milesorkm) VALUES('" & Label7.Text & "', '" & ComboBox1.Text & "', '" & newdate & "', '" & RichTextBox1.Text & "', '" & TextBox1.Text & "', '" & Label8.Text & "') END"
Dim Query2 As String = "Select * from customers_cars where vin_number='" & ComboBox3.Text & "'"
Dim cmd As MySqlCommand = New MySqlCommand(Query2, MySqlConn)
Reader = cmd.ExecuteReader
Try
While Reader.Read()
Dim lastod = Reader.GetInt32("last_visit_odometer").ToString
Label9.Text = lastod
If TextBox1.Text <= Label9.Text Then
MsgBox("Incorrect Odometer")
Else
Reader.Dispose()
cmd.CommandText = SQLStatement
cmd.CommandType = CommandType.Text
cmd.Connection = MySqlConn
cmd.ExecuteNonQuery()
MsgBox("Successfully Added!")
End If
Reader.Dispose()
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub | 0debug |
Ansible with_items vs loop : <p>What is the difference between using <a href="https://docs.ansible.com/ansible/2.4/playbooks_loops.html" rel="noreferrer">with_items</a> vs <a href="http://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html" rel="noreferrer">loops</a> in ansilbe?</p>
| 0debug |
int inet_connect_opts(QemuOpts *opts, Error **errp,
NonBlockingConnectHandler *callback, void *opaque)
{
struct addrinfo *res, *e;
int sock = -1;
bool in_progress;
ConnectState *connect_state = NULL;
res = inet_parse_connect_opts(opts, errp);
if (!res) {
return -1;
}
if (callback != NULL) {
connect_state = g_malloc0(sizeof(*connect_state));
connect_state->addr_list = res;
connect_state->callback = callback;
connect_state->opaque = opaque;
}
for (e = res; e != NULL; e = e->ai_next) {
if (error_is_set(errp)) {
error_free(*errp);
*errp = NULL;
}
if (connect_state != NULL) {
connect_state->current_addr = e;
}
sock = inet_connect_addr(e, &in_progress, connect_state, errp);
if (in_progress) {
return sock;
} else if (sock >= 0) {
if (callback != NULL) {
callback(sock, opaque);
}
break;
}
}
g_free(connect_state);
freeaddrinfo(res);
return sock;
}
| 1threat |
static void pollfds_poll(GArray *pollfds, int nfds, fd_set *rfds,
fd_set *wfds, fd_set *xfds)
{
int i;
for (i = 0; i < pollfds->len; i++) {
GPollFD *pfd = &g_array_index(pollfds, GPollFD, i);
int fd = pfd->fd;
int revents = 0;
if (FD_ISSET(fd, rfds)) {
revents |= G_IO_IN;
}
if (FD_ISSET(fd, wfds)) {
revents |= G_IO_OUT;
}
if (FD_ISSET(fd, xfds)) {
revents |= G_IO_PRI;
}
pfd->revents = revents & pfd->events;
}
}
| 1threat |
static void vga_draw_graphic(VGAState *s, int full_update)
{
int y1, y, update, page_min, page_max, linesize, y_start, double_scan, mask, depth;
int width, height, shift_control, line_offset, page0, page1, bwidth, bits;
int disp_width, multi_scan, multi_run;
uint8_t *d;
uint32_t v, addr1, addr;
vga_draw_line_func *vga_draw_line;
full_update |= update_basic_params(s);
if (!full_update)
vga_sync_dirty_bitmap(s);
s->get_resolution(s, &width, &height);
disp_width = width;
shift_control = (s->gr[0x05] >> 5) & 3;
double_scan = (s->cr[0x09] >> 7);
if (shift_control != 1) {
multi_scan = (((s->cr[0x09] & 0x1f) + 1) << double_scan) - 1;
} else {
multi_scan = double_scan;
}
multi_run = multi_scan;
if (shift_control != s->shift_control ||
double_scan != s->double_scan) {
full_update = 1;
s->shift_control = shift_control;
s->double_scan = double_scan;
}
depth = s->get_bpp(s);
if (s->line_offset != s->last_line_offset ||
disp_width != s->last_width ||
height != s->last_height ||
s->last_depth != depth) {
#if defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
if (depth == 16 || depth == 32) {
#else
if (depth == 32) {
#endif
if (is_graphic_console()) {
qemu_free_displaysurface(s->ds);
s->ds->surface = qemu_create_displaysurface_from(disp_width, height, depth,
s->line_offset,
s->vram_ptr + (s->start_addr * 4));
#if defined(WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
s->ds->surface->pf = qemu_different_endianness_pixelformat(depth);
#endif
dpy_resize(s->ds);
} else {
qemu_console_resize(s->ds, disp_width, height);
}
} else {
qemu_console_resize(s->ds, disp_width, height);
}
s->last_scr_width = disp_width;
s->last_scr_height = height;
s->last_width = disp_width;
s->last_height = height;
s->last_line_offset = s->line_offset;
s->last_depth = depth;
full_update = 1;
} else if (is_graphic_console() && is_buffer_shared(s->ds->surface) &&
(full_update || s->ds->surface->data != s->vram_ptr + (s->start_addr * 4))) {
s->ds->surface->data = s->vram_ptr + (s->start_addr * 4);
dpy_setdata(s->ds);
}
s->rgb_to_pixel =
rgb_to_pixel_dup_table[get_depth_index(s->ds)];
if (shift_control == 0) {
full_update |= update_palette16(s);
if (s->sr[0x01] & 8) {
v = VGA_DRAW_LINE4D2;
disp_width <<= 1;
} else {
v = VGA_DRAW_LINE4;
}
bits = 4;
} else if (shift_control == 1) {
full_update |= update_palette16(s);
if (s->sr[0x01] & 8) {
v = VGA_DRAW_LINE2D2;
disp_width <<= 1;
} else {
v = VGA_DRAW_LINE2;
}
bits = 4;
} else {
switch(s->get_bpp(s)) {
default:
case 0:
full_update |= update_palette256(s);
v = VGA_DRAW_LINE8D2;
bits = 4;
break;
case 8:
full_update |= update_palette256(s);
v = VGA_DRAW_LINE8;
bits = 8;
break;
case 15:
v = VGA_DRAW_LINE15;
bits = 16;
break;
case 16:
v = VGA_DRAW_LINE16;
bits = 16;
break;
case 24:
v = VGA_DRAW_LINE24;
bits = 24;
break;
case 32:
v = VGA_DRAW_LINE32;
bits = 32;
break;
}
}
vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
if (!is_buffer_shared(s->ds->surface) && s->cursor_invalidate)
s->cursor_invalidate(s);
line_offset = s->line_offset;
#if 0
printf("w=%d h=%d v=%d line_offset=%d cr[0x09]=0x%02x cr[0x17]=0x%02x linecmp=%d sr[0x01]=0x%02x\n",
width, height, v, line_offset, s->cr[9], s->cr[0x17], s->line_compare, s->sr[0x01]);
#endif
addr1 = (s->start_addr * 4);
bwidth = (width * bits + 7) / 8;
y_start = -1;
page_min = 0x7fffffff;
page_max = -1;
d = ds_get_data(s->ds);
linesize = ds_get_linesize(s->ds);
y1 = 0;
for(y = 0; y < height; y++) {
addr = addr1;
if (!(s->cr[0x17] & 1)) {
int shift;
shift = 14 + ((s->cr[0x17] >> 6) & 1);
addr = (addr & ~(1 << shift)) | ((y1 & 1) << shift);
}
if (!(s->cr[0x17] & 2)) {
addr = (addr & ~0x8000) | ((y1 & 2) << 14);
}
page0 = s->vram_offset + (addr & TARGET_PAGE_MASK);
page1 = s->vram_offset + ((addr + bwidth - 1) & TARGET_PAGE_MASK);
update = full_update |
cpu_physical_memory_get_dirty(page0, VGA_DIRTY_FLAG) |
cpu_physical_memory_get_dirty(page1, VGA_DIRTY_FLAG);
if ((page1 - page0) > TARGET_PAGE_SIZE) {
update |= cpu_physical_memory_get_dirty(page0 + TARGET_PAGE_SIZE,
VGA_DIRTY_FLAG);
}
update |= (s->invalidated_y_table[y >> 5] >> (y & 0x1f)) & 1;
if (update) {
if (y_start < 0)
y_start = y;
if (page0 < page_min)
page_min = page0;
if (page1 > page_max)
page_max = page1;
if (!(is_buffer_shared(s->ds->surface))) {
vga_draw_line(s, d, s->vram_ptr + addr, width);
if (s->cursor_draw_line)
s->cursor_draw_line(s, d, y);
}
} else {
if (y_start >= 0) {
dpy_update(s->ds, 0, y_start,
disp_width, y - y_start);
y_start = -1;
}
}
if (!multi_run) {
mask = (s->cr[0x17] & 3) ^ 3;
if ((y1 & mask) == mask)
addr1 += line_offset;
y1++;
multi_run = multi_scan;
} else {
multi_run--;
}
if (y == s->line_compare)
addr1 = 0;
d += linesize;
}
if (y_start >= 0) {
dpy_update(s->ds, 0, y_start,
disp_width, y - y_start);
}
if (page_max != -1) {
cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
VGA_DIRTY_FLAG);
}
memset(s->invalidated_y_table, 0, ((height + 31) >> 5) * 4);
}
| 1threat |
what is the suitable resources for 500 requests per second? : <p>the point that every request need some processing. I want to know if my resources enough or I have to upgrade it, or may be I have to test my code and optimize it.
My resources :
4 CPU and 8G ram.
Any outlines, test tools will be appreciated.</p>
| 0debug |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.