input stringlengths 51 42.3k | output stringlengths 18 55k |
|---|---|
Symfony Form div css class <p>Using Symfony 3 and building a form field like this:</p>
<pre><code>$builder
->add('tittle')
->add('price');
</code></pre>
<p>The result is something like:</p>
<pre><code><div>
<label ...></label>
<input ...>
</div>
</code></pre>
<p>a... | <p>I hope this answer can helps you:</p>
<p>I do not think it's possible to create div element inside the formbuilder.</p>
<p>If you can use Twig then you can render each of the three parts of the field individually inside a div having your custom class</p>
<pre><code><div class=wrap-title"">
{{ form_label... |
Positioning an element in the top right corner of the parent element and ensuring wrapping around it <p>I would like to create a container for an arbitrary number of elements, with an expand/collapse button. The button should be in the top right corner of the container, and the elements inside the container should wrap... | <p>You can achieve this purely with CSS, if you use the <code>flex</code> property of CSS3's flexbox, just like you said. I made a small demo to prove the point.</p>
<p>The core part in CSS lies here:</p>
<pre><code> display: flex;
flex-flow: row-reverse wrap;
</code></pre>
<p>The <code>display: flex</code> will ... |
Java jdbc connect to mariadb on remote lan server <p>I know this has been asked a lot but after trying many solution found here I am stil unable to connect to my db.</p>
<p>I'm working on PC and I want to connect to mariadb mysql server on another machine in my LAN. But I want to do it in such a way that my program ca... | <p>Check for the MySQL/MariaDB <code>bind-address</code> variable in the configuration file for the database. <a href="https://mariadb.com/kb/en/mariadb/configuring-mariadb-for-remote-client-access/" rel="nofollow">Then configure it appropriately</a>. It's probably set up so that it's only binding to localhost.</p>
|
object created inside jQuery 'click' persists even though a new one is created <p>very new to JQuery so my code is probably not the best approach, so tips there would be nice...</p>
<p>But the problem is that the <code>reqObj</code> created inside the click function doesn't ever seem to be dismissed. If the function r... | <p>You shouldn't really bind and event inside another event callback, and as you are using event delegation you don't really need to. What you are trying to do is pass data from the callback of one event to another.</p>
<p>You can achieve this through using global variables that all functions have access to, however t... |
Sails.js redirect with param <p>what is the best way to redirect inside a Sails.js Controller from one route to another and transfer some data at the same time.
My situation is that I've got one route that creates some data and the redirects back to another route. My problem is that I don't know how to transfer an err... | <blockquote>
<p>My problem is that I don't know how to transfer an error message (if
one happens) back to the other route (because I want to display it
there).</p>
</blockquote>
<p>Sails@v0.12 includes flash middleware in form of <a href="https://github.com/jaredhanson/connect-flash" rel="nofollow">https://githu... |
Send a MySQL query when pressing checkbox with AJAX <p>I am trying to send an update query when a checkbox is pressed, using AJAX. How can I do this?</p>
<h3>HTML imports:</h3>
<pre><code><link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
... | <p>I guess your javascript code runs before your html exists, so when your browser is trying to find <code>$(".checkbox")</code>, there aren't any elements with the <code>checkbox</code> class yet.</p>
<p>You should have the code running only after the document is ready:</p>
<pre><code>$(function() {
$(".checkbox... |
How to know if a fraction will be rounded up when represented in floating point format (re: java remainder [%] results when using fp's) <p>Is there a simple way to tell whether a particular number gets rounded up in it's floating point representation? The reason I ask is related to a question I asked <a href="http://st... | <p>Let's consider the case when floats <code>a > b > 0</code>. Each float is a multiple of it's ulp and we can write:</p>
<p><code>a = na*ulp(a). ulp(a)=2^ea</code>. na is the integer significand of a. ea is its biased exponent.<br>
<code>b = nb*ulp(b). ulp(b)=2^eb</code>. nb is the integer significand of b. eb ... |
Hashmap value getting overwritten <p>I'm having my <code>Hashmap</code> as such as a global variable within my class:</p>
<pre><code>private Map<String, CodaReportDTO> dateAndDTO = new TreeMap<>(); //hashmap for date and the dto
</code></pre>
<p>So the value here is a <code>DTO</code> which has properties... | <p>You are using the same instance of your DTO for all the map's entries. This is why, each change is reflected on all values. If you dont want changes to be overriden, you need to create a new instance for each of the map's keys.</p>
|
getchar() in a for loop condition <p>Consider following code:</p>
<pre><code>int main()
{
char c;
for(;(c=getchar())+1;)
printf("%c\n",c);
}
</code></pre>
<p>It gets characters what I enter in terminal and prints them. When I remove <code>+1</code> in condition, program works but it doesnt stop when <code>EOF</co... | <p>That is because the int value of <code>EOF</code> is <code>-1</code>, so what you're doing is loop until the expression<code>(c=getchar())+1</code>) gets the value 0 which is when you read <code>EOF</code> (where value of exrpession is: -1+1=0). Also as wll pointed out in the comments you should declare c as int si... |
How to customize WebView in Android <p>I want load data from <code>json</code> into <code>WebView</code>! for this job i should use custom <code>webView</code>! such as : <strong>custom Font, Background, Direction</strong> and more ... <br><br>
I write this codes for custom <code>webView</code> : </p>
<pre><code> S... | <p>Try this codes : </p>
<pre><code>if (content != null) {
post_content_web.getSettings().setJavaScriptEnabled(true);
WebSettings settings = post_content_web.getSettings();
settings.setDefaultTextEncodingName("utf-8");
String myCustomStyleString = "<style type=\"text/css\">@font-face {font-fam... |
How to Dynamically $set Field Name From Variable in Mongo Script <p>I'm working on a script that will run in the shell in MongoDB. I am only using pure Javascript not node.js or Meteor. I have an array that contains key and value pairs for field names and field values respectively. I'm trying to use the key value from ... | <pre><code>function setFields(key, value){
var update = {$set:{}};
update.$set[key] = value;
db.Test.update(
{userId : userId},
update
);
}
var userId = "daniele";
var myArray = [
{ key : "dynamic_key_002", value : "Sammy" }
]
for(var i = 0; i < myArray.length; i++){
setFields(... |
How can this phantom type example possibly be valid? <pre><code>data Expr a
= C a
| Add (Int -> a) (Expr Int) (Expr Int)
| Eq (Bool -> a) (Expr Int) (Expr Int)
add = Add id
eq = Eq id
eval :: Expr a -> a
eval (C x) = x
eval (Add f e1 e2) = f (eval e1 + eval e2)
eval (Eq f e1 e2) = f (eval e1 == eval ... | <p>Take a look at the following type:</p>
<pre><code>eval :: Expr a -> a
</code></pre>
<p>This says, "given a value of type <code>Expr a</code>, for any <code>a</code> at all, I can produce an <code>a</code>". Your implementation of <code>eval</code> needs to be a proof of this statement.</p>
<p>Going back to the... |
In racket how do I replace word in string using string->list or list->string function only? <p>So I was practicing racket beginner language when I came along this question.</p>
<p>Write a function <code>str-replace</code> which consumes a string, a target character, and a
replacement character. The function produces a... | <p>Define a conversion function which operates on lists:</p>
<pre><code>(define (replace-in-list input-list from-char to-char)
(if (null? input-list)
...
(cons ...
(replace-in-list ... from-char to-char))))
</code></pre>
<p><sup>(You have to fill the blank <code>...</code>)</sup></p>
<p>An... |
Ionic - Firebase : Get Current Time and Disable Past Dates <p>I am working on a project where you book hotel reservations.In the add booking page, I have an input datetime-local where the user selects the date and the time of the booking.</p>
<p>I want to get the online time and not use the device time to disable the... | <p>For firebase3, use firebase.database.ServerValue.TIMESTAMP</p>
<pre><code>$scope.createdDate = firebase.database.ServerValue.TIMESTAMP
</code></pre>
<p><a href="https://www.firebase.com/docs/web/guide/offline-capabilities.html#server-timestamps" rel="nofollow">doc is available here</a> </p>
<p>and for date time p... |
AppEngine deployment error: java.lang.UnsupportedClassVersionError <p>I donât know what changed. This is an api that I have on AppEngine. For the past two days I have not been able to push. Does anyone know what may be causing this? I am using Android Studio on Mac El Capitan.</p>
<pre><code>Failed startup of contex... | <p>The error message you received:</p>
<pre><code>Unsupported major.minor version 52.0
</code></pre>
<p>just confirms that the JRE used on the Google App Engine cannot handle the bytecode version you tried to run:</p>
<p>52.0 means: <strong>Java SE 8 = 52 (0x34 hex)</strong></p>
<p>This is indeed cannot be handled,... |
How to add more space between tabs in TabPane with css? <p><a href="https://i.stack.imgur.com/TB6Vy.png" rel="nofollow">I need to add more a gap between tabs with css in JavaFX</a></p>
| <p>Sorry this might not be exactly what you need but by simply hard-coding a tab in between the visible tabs and settings its opacity to 0.</p>
<pre><code>Tab bufferTab = new Tab();
bufferTab.setDisable(true);
bufferTab.setStyle("-fx-opacity: 0");
tabPane.getTabs().addAll(visibleTab1,bufferTab,visibleTab2,bufferTab,... |
node's module function return value empty/undefined? <p>I'm trying to get the html encoded table row value, returned from the slqLite based logger. As I'm new to node modules I'm stuck at:</p>
<pre><code>var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
var html = '';
module.expor... | <p>You problem is directly related to a very common issue when starting with JavaScript:</p>
<p><a href="http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call">How do I return the response from an asynchronous call?</a></p>
<p>Which shows the simplest way to receive result... |
D3 axis origin changes as per its scales range <p>I am a little confused on how D3s axis object takes its origin position and where it is anchored(I assume its top left)</p>
<p>Also it seem like the origin point changes as per the range of the associated scale for instance,the two axis below would start at different p... | <p>The position of the origin of the axis (prior to <code>transform</code>) is determined by the minimum value of the range of the scale.</p>
<p>For axis 1, the range is <code>[0,150]</code> and the axis starts at screen x-coordinate <code>0</code> of the parent element. (The axis ends at x-coordinate 150.)</p>
<p>Fo... |
Android List View, In Alert Dialog Showing Same Item <p>I have created an Alert Dialog which shows a list view of addresses that the user has searched. However when the alert dialog is shown with the list view items, I get same item repeated, so if I got 6 addresses i'll get item 3 in the address collection repeating 6... | <p>Why are you using for loop in Adapter? There is no need of for loop. You can directly use </p>
<pre><code>Address thisAddress = addresses.get(position);
</code></pre>
<p>Adapter will create the view for the number of count returned by <strong>getCount()</strong> method. So, if you are returning correct count it wi... |
retrieving pointer to object from stack <p>I have problem with a stack of pointers. I have stack of pointers named ob1</p>
<pre><code>stack<object*> ob1;
</code></pre>
<p>then I create some pointer to object and pushed into stack. when I want retrieve these pointer from stack
I use this method;</p>
<pre><code>... | <p>You get this error, because pop doesn't return anything.</p>
<p>See <a href="http://www.cplusplus.com/reference/stack/stack/pop/" rel="nofollow">here</a>, the return type is <code>void</code>, nothing.
You'll need the <code>top ()</code> member to get the element.
N.B. pop () will call the destructor of your elemen... |
Implementing specific count query in php <pre><code>class memberclass {
function Available()
{
if(!$this->DBLogin()) {
$this->HandleError("Database login failed!");
return false;
}
$ux = $_SESSION['username_of_user'];
$qry = "Select (one='Not done') + (two='Not ... | <p>You need cast the expressions to INT and then sum them. For MySQL database your query could look like this:</p>
<pre><code>SELECT (CAST(one='Not done' AS UNSIGNED) +
CAST(two='Not done' AS UNSIGNED) +
CAST(three='Not done' AS UNSIGNED) +
CAST(four='Not done' AS UNSIGNED) +
... |
Composite key with manual increment <p>How do I, in a multiple session / transaction environment, safely insert a row into a table containing a primary composite key with a (manual) increment key.</p>
<p>And how do I get hold of the latest incremented value of <code>column_c</code>, <code>LAST_INSERT_ID()</code> don't... | <pre><code>BEGIN;
SELECT @c := MAX(c) + 1
FROM t
WHERE a = ? AND b = ?
FOR UPDATE; -- important
INSERT INTO t (a,b,c)
VALUES
(?, ?, @c);
COMMIT;
</code></pre>
<p>The hope is that the <code>FOR UPDATE</code> will stall until it can get a lock and the desired <code>c</code> value. Then the... |
How to correctly use {$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI} in Smarty? <p>I have a blog page in my website, which uses Smarty to create the posts, and I want to add a WhatsApp share button to them using it. I already searched on the whole internet, and I found this:</p>
<pre><code>{$smarty.server.HTTP_... | <p>Your code doesn't work because of several reasons:</p>
<ul>
<li><p>The obvious one is that the message you generate is not an URL. It reads something like: <code>stackoverflow/questions/40062450/...</code>. An URL starts with a protocol (usually <code>http://</code>). The text you send should be:</p>
<pre><code>ht... |
xtext scope code generation dependant on different file <p>I have two grammars <strong>A</strong> and <strong>B</strong> and two files <strong>a</strong> and <strong>b</strong> (using grammars <strong>A</strong> and <strong>B</strong> respectively). The file <strong>a</strong> specify variables names, <strong>b</strong... | <p>In the past we used to use importURI for that, but you can do that through scoping on your own also.</p>
<p>If you for instance want to use the simple name of the file, you should make the name in B a reference to the root element of A.</p>
<pre><code>Model:
ref_model=RefModel
ref_vars+=[Vars]+
;
RefModel... |
Function which applies a groupby <p>I have numerous dataframes I want to apply a function to.</p>
<p>My dataframes look like this:</p>
<pre><code>Year ID Pressure
1984 1 0.2
1985 2 0.5
1986 3 0.7
</code></pre>
<p>I am trying:</p>
<pre><code>def f(x):
return x.groupby(['ID']).Pressure.mean().to_fra... | <p>apply is used when you want to <code>apply</code> a <code>function</code> to every values of a dataframe. since you just want to apply something to the entire df you should just do:</p>
<pre><code>f(df)
f(df2)
</code></pre>
|
Get value from textview in ListView Android <p>I'm following this guide to create a listview with textviews and eddittexts in it.
<a href="http://www.webplusandroid.com/creating-listview-with-edittext-and-textwatcher-in-android/" rel="nofollow">http://www.webplusandroid.com/creating-listview-with-edittext-and-textwatc... | <p>Following: <a href="http://stackoverflow.com/questions/257514/android-access-child-views-from-a-listview">Android: Access child views from a ListView</a></p>
<pre><code>int wantedChild = 1;
View wantedView = listview.getChildAt(wantedChild);
mEditText = (EditText) wantedView.findViewById(R.id.edittext);
Log.d("resu... |
socket.io GET /socket.io/?EIO=3&transport=polling&t=LV9VGzC" Error (404): "Not found" <pre><code>//backend code
var express = require("express");
var app = express();
var http = require('http');
var startServer=http.createServer(app);
var socketIO = require('socket.io').listen(startServer);
startServer.listen(8080, fu... | <p>i have resolved the problem , the problem was in directory path app.use(express.static(path.join('public')))</p>
|
Finding values that exist for every dictionary in a list <p>I have a list of lists that each have several dictionaries. The first list represents every coordinate involved in a triangulation. The second list represents a list of dictionaries associated with that grid coordinate. Each dictionary within the list represen... | <p>There is no magic. You just need to be a bit more careful with your data structures. You are putting coordinates in a dict which are not hashable. So you cannot add them to a set. You need to use tuples. So your data structure should look like this:</p>
<pre><code>my_list = [
set([
(1, 0),
(-1, ... |
Need help referencing a pointer from a header file <p>I've asked a question similar to this and received help and figured it out, but this seems to be a bit different. I'm trying to reference a pointer from a struct in a header file but I keep getting a "expected identifier or ')' before '->' token" error.</p>
<p>what... | <p>In</p>
<pre><code>typedef struct HugeInteger
{
int *digits;
int length;
} HugeInteger;
</code></pre>
<p>the <code>typedef</code> makes <code>HugeInteger</code> an alias for <code>struct HugeInteger</code> (this is totally unnecessary on C++. Defining <code>struct HugeInteger</code> implies <code>HugeInte... |
Adding data to existing h5py file along new axis using h5py <p>I have some sample code that generates a 3d Numpy array -- I am then saving this data into a h5py file using h5 file. How can I then "append" the second dataset along the 4th dimension? Or, how can I write another 3d dataset along the 4th dimension (or new ... | <p>Using <a href="http://docs.h5py.org/en/latest/high/dataset.html" rel="nofollow">http://docs.h5py.org/en/latest/high/dataset.html</a> I experimented a bit:</p>
<pre><code>In [504]: import h5py
In [505]: f=h5py.File('data.h5','w')
In [506]: data=np.ones((3,5))
</code></pre>
<p>Make an ordinary <code>dataset</code>:<... |
digits to words from sys.stdin <p>I'm trying to convert digits to words from std input (txt file).
If the input is for example : 1234, i want the output to be one two three four, for the next line in the text file i want the output to be on a new line in the shell/terminal:
1234 one two three four
56 five six
The probl... | <p>Put the words in a list, join them, and print the line.</p>
<pre><code>#!/usr/bin/python3
import sys
import math
def main():
number_list = ["zero","one","two","three","four","five","six","seven","eight","nine"]
for line in sys.stdin:
digits = list(line.strip())
words... |
Save and Load data in Python 3 <p>I have to create a team roster that saves and loads the data. I have it to the point where everything else works but saving and loading.</p>
<pre><code>memberList = []
#get first menu selection from user and store in control value variable
def __init__(self, name, phone, number):
... | <p>Try <code>name = memberList[int(x)].getName()</code>. When it reads the data from a file it reads a string, and in order to put that into a list you need to make it an integer.</p>
|
Convert mapply output to dataframe variable <p>I have a data frame like this:</p>
<pre><code>df <- data.frame(x=c(7,5,4),y=c(100,100,100),w=c(170,170,170),z=c(132,720,1256))
</code></pre>
<p>I create a new column using mapply:</p>
<pre><code>set.seed(123)
library(truncnorm)
df$res <- mapply(rtruncnorm,df$x,df$... | <pre><code>df <- data.frame(x=c(7,5,4),y=c(100,100,100),w=c(170,170,170),z=c(132,720,1256))
set.seed(123)
l <- mapply(rtruncnorm,df$x,df$y,df$w,df$z,25)
cbind.data.frame(df[rep(seq_along(l), lengths(l)),],
res = unlist(l))
# x y w z res
# 1 7 100 170 132 117.9881
# 1.1 7 100 17... |
How to make a dynamic grid in Python <p>I am building an X's and O's (tic tac toe) application where the user can decide whether the grid is between 5X5 and 10X10, how do I write the code so that the grid is dynamic? </p>
<p>At the moment this is all I have to make a grid of one size:</p>
<pre><code> grid = [[0,0,0,0... | <p>Code:</p>
<pre><code>#defining size
x = y = 5
#create empty list to hold rows
grid = []
#for each row defined by Y, this loop will append a list containing X occurrences of "0"
for row in range(y):
grid.append(list("0"*x))
print grid
</code></pre>
<p>Output:</p>
<pre><code>[['0', '0', '0', '0', '0'], ['0', '... |
Neo4j - return only one node that has multiple relations <p>I'm having a small issue finding out how to return one node, that has multiple outgoing relations.</p>
<p>So what I want is to display only node, even if it has more than one relation; this is my query:</p>
<pre><code>MATCH total=(n:Employee)-[r:WorkedOn]-&g... | <p>You have two options to collapse this into one row. Either, as you suggested, removing role from your return, or returning <code>COLLECT(r.role) as roles</code>.</p>
|
How to use ResolveComponentFactory() but with a string as a key <p>what I'm trying to do:</p>
<ul>
<li>Use something similar to the "resolveComponentFactory()", but with a 'string' identifier to get Component Factories. </li>
<li>Once obtained, start leverage the "createComponent(Factory)" method.</li>
</ul>
<p>Plnkr... | <p>It's either defining a map of available components,</p>
<pre><code>const compMap = {
text: PictureBoxWidget,
image: TextBoxWidget
};
</code></pre>
<p>Or defining identifiers as static class property that will be used to generate a map,</p>
<pre><code>const compMap = [PictureBoxWidget, TextBoxWidget]
.map(widg... |
Getting error Resource violated directive 'script-src ms-appx: 'unsafe-eval'' in Host Defined Policy: inline script. Resource will be blocked <p>I am trying to use Visual studio to make a universal windows app. When I try to run the following code:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
&l... | <p>The error says it's all.</p>
<p>You aren't allowed to put <code><script src=...</code>out of head. </p>
<p>This should be the case when using CSP Directives <a href="https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/Secur... |
'SelectedIndex' : Undeclared identifier in C++ <p>I'm writing a simple program that references the state of
SelectedIndex which at any given point can be a number 0 - 9</p>
<p>SelectedIndex is controlled by a dropdownlist.</p>
<p>When I try and reference the state of SelectedIndex:</p>
<pre><code>if (SelectedIndex ... | <p>Nvm Sorry for the n00b question... I'm very new to C++ but I actually figured it out myself in VS just on a guess.</p>
<p>Problem was I should have been using</p>
<pre><code>if (comboBox1->SelectedIndex == 0)
{
textBox1->Text = "C Egyptian";
}
</code></pre>
<p>instead of</p>
<pre><code>if (SelectedIndex ==... |
Casting an array of C structs to a numpy array <p>A function I'm calling from a shared library returns a structure called info similar to this:</p>
<pre><code>typedef struct cmplx {
double real;
double imag;
} cmplx;
typedef struct info{
char *name;
int arr_len;
double *real_data
cmplx *cmplx_data;
} info... | <p>Define your field as double and make a complex view with numpy:</p>
<pre><code>class info(Structure):
_fields_ = [("name", c_char_p),
("arr_len", c_int),
("real_data", POINTER(c_double)),
("cmplx_data", POINTER(c_double))]
c_func.restype = info
ret_val = c_func()... |
How to reference another column in another table when writing a trigger? <p>I have a table <code>EmpSalary</code> which has a column <code>salaryPaid</code>, the current salary of the employee and a table <code>Emp</code> which has a column <code>baseSalary</code>, the lowest salary available for that employee's job. I... | <p>You can perform a SELECT in a trigger, as long as the table you're SELECTing data from isn't the one on which the trigger is defined. In this case you can SELECT the data from EMP:</p>
<pre><code>CREATE OR REPLACE TRIGGER Check_Salary
BEFORE INSERT OR UPDATE ON EmpSalary
FOR EACH ROW
DECLARE
v_salary ... |
http.ListenAndServe only works for localhost? <p>I've been successfully making use of </p>
<pre><code>http.ListenAndServe(":80", mux)
</code></pre>
<p>to host my web service in Go. It only appears to work with localhost however.</p>
<pre><code>http.ListenAndServe("192.168.1.83:80", mux)
</code></pre>
<p>This works ... | <p><code>http.ListenAndServe(":80", mux)</code> is the correct address. <a href="https://golang.org/pkg/net/http/" rel="nofollow"><code>net/http</code></a> uses the <a href="https://golang.org/pkg/net/" rel="nofollow"><code>net</code></a> package. Quoting from <a href="https://golang.org/pkg/net/#Listen" rel="nofollow"... |
Palindrome number in java doesn't seem to make sense <p>I'm doing some exercise programs in Java and came to this palindrome number exercise which tells if the number is palindrome, I'm getting the correct output but I'm trying to explain to myself how the program is working line by line, upon reaching a specific line ... | <p>You have to look what happens during the loop as it goes through its iterations.</p>
<p>For simple programs, such as this one, a paper-and-pencil approach works fine. For more complex programs adding "debug prints" help you understand what is going on:</p>
<pre><code>int iterationCount = 0;
while (num != 0) {
... |
Haskell: Random Coin Instance <p>I have defined a <code>Coin</code> data type:</p>
<pre><code>data Coin = H | T
deriving (Bounded, Eq, Enum, Ord, Show)
</code></pre>
<p>I now have to write a Random Coin instance, given the following framework:</p>
<pre><code>instance Random Coin where
randomR (l, h) g = undefine... | <p>The functions you are defining have types</p>
<pre><code>randomR :: RandomGen g => (Coin, Coin) -> StdGen -> (Coin, StdGen)
random :: RandomGen g => StdGen -> (Coin, StdGen)
</code></pre>
<p>In other words, you're already given a random generator -- the second argument of randomR an... |
Update or add value to list <p>How would you either update <code>inventory</code>(based on name) or add if name not found.</p>
<pre><code>var inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
</code></pre>
<p>For example, the following will upd... | <p>You can use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex" rel="nofollow"><code>findIndex</code></a>:</p>
<pre><code>var idx = inventory.findIndex(f => f.name === fruit.name);
inventory[idx < 0 ? inventory.length : idx] = fruit;
</code></pre>
<p><di... |
How can I change the memory address of char*? <p>I am dealing with a problem that I cannot get abs_path and query arrays filled with a data I am passing to them inside of the function parse. Inside this function logic seems to be correct, I have debugged it and both of the arrays are filled with a correct data. I know ... | <p>The problem is this:</p>
<pre><code>query = query_line;
</code></pre>
<p><code>char *query</code> means you are passed a pointer. It's just a number like any other number. Think of it this way.</p>
<pre><code>void set_number(int number) {
number = 6;
}
</code></pre>
<p>Do you expect this to do anything? Nope... |
Error Handling (Java) <p>Fairly easy question, but I was basically given code to debug and I've fixed all errors but one. When trying to make the program more friendly and include error handling, I found that the error message is thrown even if the condition is satisfied (that is, the number in the array that a user se... | <p><a href="https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#binarySearch(int[],%20int)" rel="nofollow"><code>Array.binarySearch</code></a> will return the index if it finds the value, otherwise it will return -1. </p>
<p>If <code>index == -1</code>, you can print the "not found message" without enterin... |
What is clazz used for in "private static Class clazz = SnappyDecompressor.class" source file? <p>I am studying the compressor implementation (in Java) for Snappy, Zlib and others. Near the top of the source file is this line below. Can anyone explain to me what it means?</p>
<pre><code>HACK - Use this as a global loc... | <p>As indicated in the comment: it is used from the JNI layer, seemingly for some locking from the JNI layer. (<a href="https://github.com/facebookarchive/hadoop-20/blob/2a29bc6ecf30edb1ad8dbde32aa49a317b4d44f4/src/native/src/org/apache/hadoop/io/compress/snappy/SnappyDecompressor.c" rel="nofollow">see the full Decompr... |
How do BluRay players or washing machine run Java programs? <p>What OS do they use for example and how to they boot up so quickly (compared to a raspberry pi)?</p>
| <p>Currently, they are two option exiting: </p>
<ul>
<li>they are running a custom piece of software that support a jvm</li>
<li>they are running a minimum version of a linux , just what's enough to run the jvm, everything else is disabled / removed.</li>
</ul>
<p>It's booting that fast because it has only the piece ... |
Find the patient who were attended by the highest number of doctors? <p>I'm working with these tables:</p>
<p><strong>TABLE Adm_Med:</strong></p>
<blockquote>
<p>Adm_ID /*ID Admission to the Hospital</p>
<p>Med_ID </p>
<p>Doc_ID /*ID Doctor who attended the patient of the corresponding Adm_ID</p>
</blockq... | <p>Since your previous question was related to MySQL I'm guessing that also this one uses MySQL.</p>
<p>And as such, MySQL sadly doesn't support Common Table Expressions (the WITH clause). Which would have allowed the re-use of a query to calculate the max.</p>
<p>So the sql below should return what I think you're lo... |
Gesture recognizer on a circular view <p>In each cell of my collection view is a circular UIView. This has been achieved by creating a custom subclass of <code>UIView</code>, which I have called <code>CircleView</code>, and setting <code>layer.cornerRadius = self.frame.size.width/2</code> in the subclass' <code>awakeFr... | <p>You can override this method in CircleView:</p>
<pre><code>override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let center = CGPoint(x: bounds.size.width/2, y: bounds.size.height/2)
return pow(center.x-point.x, 2) + pow(center.y - point.y, 2) <= pow(bounds.size.width/2, 2)
}
</co... |
Attributed string font formatting changes when dequeuing reusable UITableViewCell <p>I have a <code>UITableView</code> that contains cells where I'm setting an <code>NSAttributedString</code> on a <code>UILabel</code>. The <code>NSAttributedString</code> has sections that are HTML bolded using <code><b>%@</b&g... | <p>A couple ways to solve this:</p>
<p>1) </p>
<p>In your custom UITableViewCell, you should implement <code>prepareForReuse</code>:</p>
<pre><code>-(void)prepareForReuse{
[super prepareForReuse];
// Then Reset here back to default values that you want.
self.label.font = [UIFont systemFontOfSize: 12.0f]... |
Pandas flatten hierarchical index on non overlapping columns <p>I have a dataframe, and I set the index to a column of the dataframe. This creates a hierarchical column index. I want to flatten the columns to a single level. Similar to this question - <a href="http://stackoverflow.com/questions/14507794/python-pandas-h... | <p>You are misinterpreting what you are seeing.</p>
<pre><code> A B
id
101 3 x
102 5 y
</code></pre>
<p>Is not showing you a hierarchical column index. <code>id</code> is the name of the row index. In order to show you the name of the index, pandas is putting that space there for you.</p>
<p>The an... |
Get a Notification in Android when a Firebase child has been added <p>I am trying to get an android notification when a Fire base Database child has been added to the database using listeners, but unable to get the notification. I have coded this little test app which doesn't show an notification when the app is run, o... | <p>You should use ChildEventListener,</p>
<pre><code> super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRootRef = FirebaseDatabase.getInstance().getReference();
builder = new NotificationCompat.Builder(this);
mRootRef.addChildEventListener(new ChildEventListener() {
... |
Add Parse server to an already existing project <p>I have a project and I want to add Parse to it. I installed the Parse server in my PC, downloaded the SDK from their website and it worked perfectly fine.<br>
However, I don't want to use the SDK from their website, I just want to add the libraries to my project.</p>
... | <p>Firstly, adding those two libs lines to the Gradle file was not necessary. This one line includes all JAR files on its own. </p>
<pre><code>compile fileTree(dir: 'libs', include: ['*.jar'])
</code></pre>
<p>Now, I generally recommend that you try your best to avoid JAR libraries when you can find the dependencies ... |
Jersey multipart getFileName() has concatenated path <p>I am trying to get a file upload working with Java + Jersey + multipart + Tomcat + HTML/CSS/JS.</p>
<p>For testing purposes I'm just trying to upload some arbitrary file from my Downloads folder and have it written to my desktop.</p>
<p>My only problem seems to ... | <p>The concatenated file name is a result of using the browser internal to Eclipse, which may not properly support your HTML, CSS, JS, etc, especially if you're using Angular JS or any webkit technologies, even indirectly.</p>
<p>The eclipse internal browser is really just a native browser control :) On a Mac, that ma... |
What would be the best compound index for this MySQL query? <p>What would be the best compound index for this MySQL query?</p>
<pre><code>SELECT
c.id, c.customer_id, c.service_id, c.origin_id, c.title, c.state, c.start_date_time
FROM
calendar_events c
WHERE
c.customer_id = 1234
AND c.state IN ('unco... | <p>Probably this:</p>
<pre><code>INDEX(customer_id, -- '=' comes first
state, -- 'IN' sometimes works ok in the middle
start_datetime) -- nothing after a 'range' will be used
</code></pre>
<p>Run <code>EXPLAIN SELECT ...</code> It will probably say "MRR" in the <code>Other</code> column. I c... |
IOS Swift ongoing notifications <p>I wanted to know if it is possible to create ongoing notifications in IOS similar to the ones in Android. I have seen e.g. with Voice Recording applications, that after pressing record, the user can click the home button and red bar covers the top bar (same thing if the user is on a c... | <p>Modifying the status bar is not possible.</p>
<p>The best you can achieve is with a widget, where you can start/stop your stopwatch, etc. Starting with iOS 10, you can have rich notifications as well, but they still have to be triggered by the user, and I don't think that fits what you need.</p>
|
getId from selected EditText android <p>this is my first question, I've made a code to add views from a SQLite database and I'd like to select an EditText I've added and when I change this value do an action. I don't know the Id of this EditText so I can't use findByValue on this case. How can I get this? Here is my co... | <p>Ok guys, thanks for trying to help me, I found my solution with OnGlobalFocusChangeListener</p>
<p>I added this code on the OnCreate:</p>
<pre><code> pantalla.getViewTreeObserver().addOnGlobalFocusChangeListener(new ViewTreeObserver.OnGlobalFocusChangeListener() {
@Override
public void onGlobalF... |
Make python read 12 from file as 12 not 1 and 2 <p>Trying to make a program that provides the price to different numbers of stages. In "tripss.txt",third line is the number 12, python interprets it as 1 and 2 instead and gives the price for each rather than the number as a whole, any way to fix it to that it's read as ... | <p>In your code it seems that you want to consider customer_three as a list of strings. However in your code it is a string, not a list of strings, and so the for loop iterates on the characters of the string ("1" and "2").<br>
So I suggest you to replace: </p>
<pre><code>customer_three= infile.readline().strip("\n")... |
bind entry and button <p>i have a program which start by asking user his code so user will type code in Entry and click button or click enter in keyboard i made two similar function with different inputs to deal with this </p>
<pre><code>b1 = Button(root,text='login',command = Login_click)
b1.pack()
b1.bind('<Retu... | <p>You can simply define a function with <code>event=None</code> as a default value so that it is optional and then use the same function for both.</p>
<pre><code>b1 = Button(root,text='login',command = Login_click_and_bind)
b1.pack()
b1.bind('<Return>',Login_click_and_bind)
def Login_click_and_bind(self,event=... |
Replace [X] with [Y] in texarea on submit <p>I have a form, where users are to insert musical chords as [Am], [D], etc inside a textarea. A chord letter enclosed by brackets.</p>
<p>I want to prevent users from entering northern europian variations of [H], and have them replaced by english [B] on form submit.</p>
<p>... | <p>You could use this <code>replace()</code> call:</p>
<pre><code>.replace(/\[H(.*?)\]/gi, '[B$1]')
</code></pre>
<p>Snippet:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><co... |
Java unchecked method invocation with ArrayList <p>When I run my code I get this warning: </p>
<pre><code>warning: [unchecked] unchecked method invocation: method addAll in interface List is applied to given types
snakeDotlist.addAll(genFirstDots());
required: Collection<? extends E>
found: List
wh... | <p>You should change this:</p>
<pre><code>public static List genFirstDots()
</code></pre>
<p>to this:</p>
<pre><code>public static List<Sprite> genFirstDots()
</code></pre>
<p>The reason why the warning appears is because you are returning a <code>List</code> in <code>genFirstDots()</code> but you're adding t... |
Convert QueryDict into list of arguments <p>I'm receiving via POST request the next payload through the view below:</p>
<pre><code>class CustomView(APIView):
"""
POST data
"""
def post(self, request):
extr= externalAPI()
return Response(extr.addData(request.data))
</code></pre>
<p>And in the ... | <p>You can write a helper function that walks through the <em>QueryDict</em> object and converts valid <em>JSON</em> objects to Python objects, string objects that are digits to integers and returns the first item of lists from lists:</p>
<pre><code>import json
def restruct(d):
for k in d:
# convert value... |
Cmake don't find Freetype on Windows 10 <p>I'm trying to use Cmake <a href="https://cmake.org/download/" rel="nofollow">https://cmake.org/download/</a> to convert the source code of EmulationStation (<a href="https://github.com/Herdinger/EmulationStation" rel="nofollow">https://github.com/Herdinger/EmulationStation</a>... | <p>Sorry if someone thinks the question is "low quality". Anyway, more people can be facing the same issue, so I'll elaborate my own answer and show what I did to solve it (partially).</p>
<p>As explained on EmulationStation page, download all dependencies: SDL2, Boost, FreeImage, FreeType, Eigen3, and cURL. You have ... |
Random Generator max/min values? <p>I have written a method variation:</p>
<pre><code>private int variation() {
int randomNumber = randomGenerator.nextInt(90);
return (randomNumber + handicap)/18 - 2;
}
</code></pre>
<p>Assuming that the handicap is = 18, what are the minimum and maximum values that this meth... | <pre><code>Maximum=3;
Minimum=-1.
</code></pre>
<p>From the <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Random.html" rel="nofollow">docs</a> for random </p>
<blockquote>
<p>Returns a pseudorandom, uniformly distributed int value between 0
(inclusive) and the specified value (exclusive)</p>
</blo... |
Is there a programmatic way in C to determine the number of processes ever used in a group of processes under Linux? <p>I know of the <code>sysinfo()</code> function that returns a <code>procs</code> parameter representing the total number of processes currently running on your Linux system.</p>
<p>However, there is t... | <p>To enforce the <code>RLIMIT_NPROC</code> limit, linux kernel reads <code>&p->real_cred->user->processes</code> field in <code>copy_process</code> function (on <code>fork()</code> for example)
<a href="http://lxr.free-electrons.com/source/kernel/fork.c?v=4.8#L1371" rel="nofollow">http://lxr.free-electro... |
Buttons Dont Work While On Iphone 6 plus and Iphone 7 plus <p>Inside a XIB file I have several buttons. Each button moves to a different point inside the ScrollView. The buttons only work on iPhone 6 Plus and 7 Plus. There is a button in each phrase below:</p>
<p><a href="https://i.stack.imgur.com/JTrjK.png" rel="nofo... | <p>Add this code to the view that all the buttons are contained in.</p>
<pre><code>view.layer.borderWidth = 1
</code></pre>
<p>The above will allow you to see where the view is located. My guess is that you will find that the buttons that can't be tapped on are not inside the rectangle defined by their parent view. T... |
How to Edit This <p>I'm trying to mod SKyrim and have to edit my batch file. I need to change each line to look like:</p>
<pre><code>Player.GetInFaction "<Faction ID>" ;;; <Description>
</code></pre>
<p>E.g. :</p>
<pre><code>FACT: (00000013) 'Creature Faction'
</code></pre>
<p>would be:</p>
<pre><co... | <p>Press <code>i</code> to enter edit mode, then <code>esc</code> to exit it. To close vim saving the file just type <code>:wq</code> and press <code>enter</code></p>
|
D3 Brush events - which brush was moved? The left one or the right one? <p>Hopefully the title says it all.</p>
<p>I am handling a D3 brush moved event. And am trying to work out, whether the user moved the left brush or the right brush...?</p>
<p>I really want to avoid storing the mouse position somewhere.</p>
<p>I... | <p>Easiest way I can see:</p>
<pre><code>// bind to at least start and end events
var brush = d3.brushX()
.extent([[0, 0], [width, height]])
.on("start brush end", brushmoved);
// handle it
var bs = "";
function brushmoved() {
var s = d3.event.selection;
if (d3.event.type === "start"){
bs = d3.event.... |
Access page element popup from another window <p>Open a url from base page open.php using </p>
<pre><code>window.location("open1.php");
</code></pre>
<p>in a pop up window</p>
<p>Now I opened another popup on click a button on open1.php using</p>
<pre><code>window.location("open2.php");
</code></pre>
<p>in a now ... | <p>Just use <code>opener.opener</code>.</p>
<p><strong>open.php</strong></p>
<pre><code><html>
<body>
<div id="myDiv">Hello world.</div>
<script>
open("open1.php");
</script>
</body>
</html>
</code></pre>
<p><strong>open1.php</strong></p>
<pre><cod... |
Sum of odd numbers between 2 integers divisible by 7 <p>I am using Java and want to find the sum of all odd numbers between 0 and 100, that are divisible by 7.</p>
<p>I got this:</p>
<pre><code>public class odd7{
public static void main(String[] args)
{
int i = 1;
int a;
int b;
... | <p>Starting at <code>7</code> and incrementing by <code>14</code> (to keep only the odd numbers):</p>
<pre><code>int sum = 0;
for(int i = 7; i <= 100; i += 14) {
sum += i;
}
System.out.println(sum);
</code></pre>
<p>(I understand it is kind of a hack but it is just a possible answer!)</p>
|
Servicestack - Authentication questions <p>I am currently fighting a bit with my custom <code>CredentialsAuthProvider</code> implementation. First it is important to say, that I am writing a WPF client as a reference for my API.</p>
<ol>
<li>A browser stores cookies and you can configure how to deal with them, e.g. de... | <p>You can populate ServiceStack Service Client Cookies just like you would a browser except it only retains permanent Session Ids where you'll need to authenticate with <code>RememberMe=true</code>, e.g:</p>
<pre><code>var response = client.Post(new Authenticate {
provider = "credentials",
UserName = ...,
... |
Can't connect to mac in visual studio <p>I'm trying to connect to mac in visual studio.</p>
<p>I did every step and I also connected to the Xamarin account.</p>
<p>In the Xamarin Mac Agent it found the mac which means I did the steps.</p>
<p>So sharing preferences are correctly configured at mac.</p>
<p>But when I ... | <p>The Xamarin.iOS SDK and Xcode both need to be installed on the Mac you're trying to connect to. See <a href="https://developer.xamarin.com/guides/ios/getting_started/installation/windows/#System_Requirements" rel="nofollow">Installing Xamarin.iOS on Windows</a> and the step-by-step <a href="https://developer.xamari... |
How to use volume's button to zoom in/out text in textview <p>How to override and use volume buttons to zoom IN/OUT text inside in layout, similar as when you are writing/reading SMS ?</p>
| <p>Please check this solution.</p>
<pre><code>public class MainActivity extends AppCompatActivity {
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView) findViewByI... |
Keyboard input of array of bits <p>I want to make a program that applies some logic gates (<code>AND</code>, <code>OR</code>, <code>XOR</code>) to elements of two arrays of 1 and 0. But I am having problems with the user input of these arrays. I don't know how to make the arrays store only 1 and 0, for example if I typ... | <p>In your first for loop, where you are reading the input, you should read the input first, and then decide whether you want to have the user try the input again. So, the first few lines of your for loop should look like this:</p>
<pre><code>for (i = 0; i < n; i++) {
scanf("%d", &v1[i]);
if (!(v1[i] == 0 |... |
Swift: Understanding NSLock deadlock <p>Seeing this message in our logs using <code>NSLock</code>:</p>
<pre><code>*** -[NSLock lock]: deadlock (<NSLock: 0x6100000cbec0> '(null)')
*** Break on _NSLockError() to debug.
</code></pre>
<p>Does this mean that the application has encountered a fatal error and will sto... | <p>A deadlock, by definition, means that the thread in question cannot proceed. Swift doesn't "handle" the deadlock, but is merely informing you that this occurred.</p>
<p>How this deadlock manifests itself in your app depends upon what the code associated with that thread was doing. But, obviously, whatever it was, i... |
Periodically update database <p>Given a database (currently <strong>MongoDB</strong>) is there a proper and efficient way to periodically update <strong>all</strong> the values of the database?.</p>
<p>Let's say I want certain values to decrease by 1 every second or so, and to get notified when those values reach 0 in... | <p>MongoDB don't have notification if something happen on the server (example, a Trigger). Even more you can't create this type of logic (decrease the time until is 0 second) also because i don't see benefit to have into the Database the "seconds left".</p>
<p>If you are making a kind of "eBay" where an Item has a "ti... |
Android Instrumented Test Database magically becomes read-only in @Before <p>I have been working through some exercises to learn android. The sample project I put together runs fine. But, when I run all of the Instrumented Tests together, the tests for my content provider fail because the database is read-only when d... | <p>To test a ContentProvider you should create a test that extends <a href="https://developer.android.com/reference/android/test/ProviderTestCase2.html" rel="nofollow">ProviderTestCase2</a>, add the <code>@RunWith(AndroidJUnit4.class)</code> annotation at the beginning of the test class definition, specify the test run... |
IndexError: list index of range. Python 3 <p>I was just trying to create a Matrix filled with zeros, like the function of numpy.</p>
<p>But it continues to give me that error. Here's the code:</p>
<pre><code>def zeros(a,b):
for i in range(a):
for j in range(b):
R[i][j]=0
return R
</c... | <p>You could do that:</p>
<pre><code>>>> def zeros(a,b):
... return [[0 for _ in range(a)] for _ in range(b)]
...
>>> zeros(3,2)
[[0, 0, 0], [0, 0, 0]]
</code></pre>
<p>Or something more close to your code:</p>
<pre><code>def zeros(a,b):
R = []
l = [0]*a
for _ in range(b):
R... |
How to properly crop an image to fit imageview <p>How do i crop an image that i use picasso with to properly fit the layouts parent width and a fixed height of e.g. 500 for both pictures taken in landscape mode and portrait mode. They may be scaled down or up, but without too great effect on the quality. A bit like how... | <p>Use the <code>scaleType</code> attr through xml on the <code>ImageView</code> or use Picasso's built in image manipulation methods for determining scale and size. A good tutorial can be found <a href="https://futurestud.io/tutorials/picasso-image-resizing-scaling-and-fit" rel="nofollow">here</a>.</p>
|
Vector of Generic Structs in Rust <p>I am creating an entity component system in Rust, and I would like to be able to store a <code>Vec</code> of components for each different <code>Component</code> type:</p>
<pre><code>pub trait Component {}
struct ComponentList<T: Component> {
components: Vec<T>,
}
... | <p>Create a trait that each <code>ComponentList<T></code> will implement but that will hide that <code>T</code>. In that trait, define any methods you need to operate on the component list (you will not be able to use <code>T</code>, of course, you'll have to use trait objects like <code>&Component</code>).</... |
Trying to compute payroll in java <p>I have to figure out if gross pay is between "so and so" it's "this" tax percentage, etc. I thought I was doing alright, but it keeps outputting every single tax answer as one answer if I enter a high number for hours worked... like this "Deductions are 275.0165.0770.0000000000001"... | <p>Please wrap your sum into parenthesis:</p>
<pre><code>System.out.println("Deductions are " + (socialSecurity + medical));
</code></pre>
<p>In this case it will create sum at first then concatenate result to string, otherwise it will concat socialSecurity then medical one by one.</p>
<p>The same rule is right for ... |
Python abundant, deficient, or perfect number <pre><code>def classify(numb):
i=1
j=1
sum=0
for i in range(numb):
for j in range(numb):
if (i*j==numb):
sum=sum+i
sum=sum+j
if sum>numb:
print("The value",numb,"is an abundan... | <p>I would highly recommend u to create a one function which creates the proper divisor of given N, and after that, the job would be easy.</p>
<pre><code>def get_divs(n):
return [i for i in range(1, n) if n % i == 0]
def classify(num):
divs_sum = sum(get_divs(num))
if divs_sum > num:
print('{}... |
API to Database? <p>Please presume that I do not know anything about any of the things I will be mentioning because I really do not.</p>
<hr>
<p>Most OpenData sites have the possibility of exporting the presented file either in for example .csv or .json formats (<a href="http://opendata.brussels.be/explore/dataset/as... | <blockquote>
<p>I presume using the API would mean that if the data is updated you
would receive the change whereas exporting it as .csv would mean the
content will not be changed anymore.</p>
</blockquote>
<p>You are correct in the sense that, if you download the csv to your computer, that csv file won't be upd... |
Arduino - 5 questions for real Wire.write() and Wire.read() explanation <p>I Googled this a lot, and it seems that I am not the only one having problems with really understanding Wire.write() and Wire.read(). Being novice, I almost never use libraries that are already written by somebody, I try to create my class for m... | <p>Questions 1. - 4.: Are all covered by <a href="http://www.avrfreaks.net/forum/tut-c-bit-manipulation-aka-programming-101?page=all" rel="nofollow">Bit Manipulation tutorial</a> on <a href="http://www.avrfreaks.net/" rel="nofollow">AVRFreaks</a> forum <a href="http://www.avrfreaks.net/?taxonomy_forums_tid=636&read... |
Conditional Segue while passing data? <p>I'm trying to make the segue from viewcontroller to 2ndviewcontroller only when my condition is met. I've connected the segue from the button in viewcontroller to the 2ndviewcontroller. So far I have:</p>
<pre><code>@IBAction func switchView(_ sender: AnyObject) {
// if... | <p>As discussed in the comments, the method name should be <code>prepareForSegue</code>, not <code>prepForSegue</code>.</p>
|
Always load entity for ApplicationUser (.NET MVC, Identity) <p>I am having problems loading a entity that I have assigned to the ApplicationUser in my .NET core MVC application.</p>
<p>I have added one of my entities to the user class, see code below:</p>
<pre><code>public class ApplicationUser : IdentityUser
{
pu... | <p>You need to implement your userstore</p>
<pre><code>public class ApplicationUser : IdentityUser {
public int? AzureBlobResourceId { get; set; }
[ForeignKey("AzureBlobResourceId")]
public AzureBlobResource AzureBlobResource { get; set; }
}
public class MyAppUserStore : UserStore<ApplicationUser>
{
... |
Shaman.EPPlus + ASP.NET Core MVC - Part already exist exception <p>I am using <a href="https://www.nuget.org/packages/Shaman.EPPlus/" rel="nofollow">Shaman.EPPlus</a>, a version of EPPlus that should be compatible with ASP.NET Core MVC.
I am trying to export a collection of object as xlxs file.
The code looks like this... | <p>The problem are these line:</p>
<pre><code>pck.Save();
....
var bytes = pck.GetAsByteArray();
</code></pre>
<p>Both calls will cause the package to be closed by Epplus. You do not need the <code>.Save</code> call since that will automatically be called by <code>.GetAsByteArray</code> anyway so simply remove the f... |
how to stop a function from running code until a condition is met <p>Here is a simplified version of my code. <code>function1()</code> has to check something on the internet. It has to do it in the background of the app(I cannot change that), which allows the rest of the code to run while it checks the internet. This f... | <p>Don't constantly check; this is called <em>busy waiting</em> and is inefficient, especially on mobile (since the device can't go into low-power mode). Instead, use an <code>AsyncCallback</code> to run your <code>function1</code> and put the log message in the callback.</p>
|
Check if elements in an array are inside of another array <p>So If I have these two arrays:</p>
<p><code>int array1[] = {1, 2 ,3};</code></p>
<p><code>int array2[] = {1, 2, 3, 4, 5};</code></p>
<p>How do I check if <code>1, 2 and 3</code> from array1 are in array2? `</p>
<p>Thanks in advance.</p>
| <p><a href="http://en.cppreference.com/w/cpp/algorithm/includes" rel="nofollow"><code>std::includes</code></a>:</p>
<pre><code>if (std::includes(std::begin(array2), std::end(array2),
std::begin(array1), std::end(array1)) {
// array2 includes array1
}
</code></pre>
<p>This requires the arrays are... |
fitEllipse returns ellipses that is twice as big as the actual contour <p><a href="https://i.stack.imgur.com/OcEsY.png" rel="nofollow"><img src="https://i.stack.imgur.com/OcEsY.png" alt="enter image description here"></a></p>
<p>As you can see the contour is much smaller than the fitted ellipse. Below is the relevant ... | <p>The <a href="http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#ellipse" rel="nofollow">draw function</a> expects half of the size:</p>
<blockquote>
<p><strong>axes</strong> â Half of the size of the ellipse main axes.</p>
</blockquote>
<p>A simpler way of doing this is:</p>
<pre><code>cv2.dra... |
How to validate PayPal data with IPN when using non-hosted PayPal button <p>I am rather new to PHP and adding payment gateways</p>
<p>However, I want to learn and am having a go at a small shop with a Paypal buy now button which is linked to a PHP cookies cart</p>
<p>It is working fine and shows a list of the items i... | <p>The best thing to do would be to use the <a href="https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReference/" rel="nofollow">Express Checkout API</a> instead of Payments Standard (HTML forms). This requires more programming and working with API calls, however, I have a <a href="https:... |
Google javascript API: catching HTTP errors <p><a href="http://stackoverflow.com/users/26406/abraham">Abraham</a>'s answer to <a href="http://stackoverflow.com/questions/29562774/google-calendar-api-backend-error-code-503">Google Calendar API : "Backend Error" code 503</a> exactly describes my situation. I ge... | <p>Exponential backoff is a fancy way of saying that at each attempt, you increase the wait time exponentially, for a certain number of times before giving up the request.</p>
<p><a href="https://developers.google.com/drive/v3/web/handle-errors#exponential-backoff" rel="nofollow">Implementing exponential backoff</a></... |
Bootstrap MYSQL PHP - Send Modal Content <p>I have data I'm displaying in a table, using bootstrap. For each of those I'm wanting to do a modal, on this you would confirm you want to send an email.</p>
<p>This is the link they would click:</p>
<pre><code><a data-toggle="modal" data-target="#email-'.$row['id'].'"&g... | <p>I think your <code><a data-toggle="modal" data-target="#email-'.$row['id'].'">Resend Email</a></code> anchor needs to have a class. </p>
<p>I would write it in a simpler manner than you: <code><a href="" class="modal-open">Resend Email</a></code>.</p>
<p>Then, you need to somehow, pass your... |
Google Sheets Formula to Extract and Convert Currency from ⬠or £ to USD <p>I'm trying to do the following:</p>
<ol>
<li>Check the cell for <code>N/A</code> or <code>No</code>; if it has either of these then it should output <code>N/A</code> or <code>No</code></li>
<li>Check the cell for either <code>£</code> or <... | <h1>Direct answer</h1>
<p>Try</p>
<pre>
=ArrayFormula(
IF(IFERROR(SEARCH("$",A1:A6),0),A1:A6,IF(A1:A6="N/A","N/A",IF(A1:A6="No","No",
SUBSTITUTE(
A1:A6,
REGEXEXTRACT(A1:A6, "[\£|\â¬]\d+"),
TEXT(
REGEXEXTRACT(A1:A6, "[\£|\â¬](\d+)")
*
VLOOKUP(
REGEXEXTRACT(... |
How can I "generalize" what R uses as my x and y values in a plot <p>I have written an executable script in R that will simply plot a graph given an input file in a tab delimited format. However, the script I wrote is specific to a single file in terms of what to use as x and y. I want to have this script be able to ... | <p>Instead of using <code>attach()</code> (which is almost never recommended), use data frame indexing to extract the relevant variables from your <code>data</code> variable.</p>
<pre><code>#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
data = read.table((args[1]), header=TRUE, fill=TRUE, sep="\t")
jpeg... |
Makefile findstring yields nonempty string even though the argument is not in the whitelist <p>I want my Makefile to require that an environment be specified, e.g.</p>
<pre><code>make ENV=beta all
</code></pre>
<p>My Makefile begins like this</p>
<pre><code>ifeq ($(findstring ${ENV}, dev beta prod),)
$(error ENV m... | <p>The <code>findstring</code> function is finding an instance of "d"; the documentation is ambiguous, not incorrect. Use <code>filter</code> instead.</p>
|
Trying to push_back into a vector pointing to an abstract class <p>Compiling my code that contains this class:</p>
<pre><code>class Dessin
{
private:
vector<Figures*>T;
public:
void ajouteFigure(const Figures& f) const
{
for(auto element: T)
{
... | <p>Assuming <code>Cercle</code> is a class name, you're trying to push a value where a pointer is expected. </p>
<p>To "fix" the error you should change your <code>ajouteFigure</code> prototype to accept <code>Figures</code> pointers and non-const <code>this</code>:</p>
<pre><code>void ajouteFigure(Figures* f)
</cod... |
Improving on chains of if/else statements <p>Given the discussion <a href="http://blog.demofox.org/2016/10/14/a-data-point-for-msvc-vs-clang-code-generation/" rel="nofollow">here</a>, which is roughly about getting the compiler to compute if/else at compile time...</p>
<pre><code>#include <initializer_list>
tem... | <p>Attempting to leverage the Turing completeness of the template system has been a thing since the early 90s :):)</p>
<p>But compilers usually courteously but adamantly, and wisely so, refuse to go too deep into template computation because it would imply extensive compile time spent extremely slowly evaluating somet... |
GGPLOT: Printing Stacked Bar Chart & Line to File <p>I know that it might not look like it from this question, but I've actually been programming for over 20 years, but I'm new to R. I'm trying to move away from Excel and to automate creation of about 100 charts I currently do in Excel by hand. I've asked two previous ... | <p>All right, I'm feeling generous. Your example code contains a lot of fluff that should not be in a minimal reproducible example and your <code>system</code> call is not portable, but I had a look anyway. </p>
<p>The good news: Your code works as expected.</p>
<p>Let's plot only the bars:</p>
<pre><code>ggplot(Soy... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.