Bài đăng

Đang hiển thị bài đăng từ Tháng 12, 2015

Second element in each loop returns undefined

<p>From fields with the class <code>.edit-links</code> i´m able to retrieve the values but <code>$(this).next(".edit-url").val();</code> only returns the first found element then only returns undefined. In the console i can see that "this" is targeting the first element as expected but the second .edit-url is not found and returning prevObject.</p><div class="snippet" data-lang="js" data-hide="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"><br /><code>$('#edit').click(function() {<br /> edit.revertLink();<br />});<br /><br />var edit = {};<br />edit.revertLink = function() {<br /><br /> $('.edit-link').each(function(index) {<br /><br /> var currentName = $(this).val();<br /> var url = $(this).attr('data-tempurl');<b...

How to write extension method that work with base class

<p>Idea is to have extension method that extend my functionality.</p><p>So instead of having something like this:</p><pre><br /><code> return Add(Add(storage.GetFirst(), 3), 7);<br /></code><br /></pre><p>I want have something like this:</p><pre><br /><code>return storage.GetFirst().Add(3).Add(7);<br /></code><br /></pre><p>Problem with extension methods is that they have to be static in static class. This is simplify example of what I want to do.</p><pre><br /><code> public class Storage<br /> {<br /> public int GetFirst()<br /> {<br /> return 100;<br /> }<br /> public int GetAll(int x, int y)<br /> {<br /><br /> // ... <br /> return x + y;<br /> }<br /> }<br /> public abstract ...

How to understanding the expression "{} == true"?

<p>I try to understanding the expression <code>{} == true</code> following the section <code>7.2.12</code> of doc <a href="http://ift.tt/AmLIEB"><code>Ecma-262</code></a>.</p><blockquote><ol start="9"><li>If Type(y) is Boolean, return the result of the comparison <code>x == ToNumber(y)</code></li></ol></blockquote><p>The result of <code>ToNumber(true)</code> is <code>1</code>, then</p><p><code>{} == 1</code></p><blockquote><ol start="11"><li>If Type(x) is Object and Type(y) is either String, Number, or Symbol, then return the result of the comparison <code>ToPrimitive(x) == y</code>.</li></ol></blockquote><p>I am confused at the <code>ToPrimitive({})</code> now.</p><blockquote><ol start="3"><li...

array numbers wich summ is deviding on 4

<p>I want to print numbers on label from 1-to 100</p><p>The number's sum must be dividing on 4.</p><p>Example:<br />print 35. because 3+5 = 8 .<br />8 dividing on 4.</p><p>This is code<br />from loop printing numbers. but how choose those numbers?<br />print those numbers from 1 to 100 ;</p><pre><br /><code>for (int i = 1; i < 100; i++)<br />{<br /> //select numbers wich sum is dividing on 4<br /> label3.Text += Convert.ToString(i) + " | ";<br />}<br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526006/array-numbers-wich-summ-is-deviding-on-4">http://ift.tt/1VpgqNW</a></h2>

For loop confused as to which value to consider

<p>I have this loop here:</p><pre><br /><code>while(n != 0)<br /> {<br /> ld = n % 10;<br /> System.out.println(ld);<br /><br /> for ( i=1; i <= ld; i++)<br /> {<br /> f = f * i;<br /> }<br /><br /> System.out.println(f);<br /><br /> n /= 10;<br /> }<br /></code><br /></pre><p>Let us consider a number, say <code>123</code>. Now, this loop calculates the factorial of <code>3</code> accurately, but when it restarts to calculate the factorial of <code>2</code>, the for loop gets confused as to which value to take for the variable <code>ld</code>. Is there any solution to this?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526013/for-loop-confused-as-to-which-value-to-c...

Internet check with volley

<p>I have a static method , which returs boolean value by cheking if internet available or not. I am able to catch "NoerrorConnection" but can't return boolean false to calling function. How to send boolean value from ErrorListener ?</p><pre><br /><code>public static boolean isConnectingToInternet()<br /> {<br /> JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, "www.google.co.in", new Response.Listener<JSONObject>() {<br /> @Override<br /> public void onResponse(JSONObject response) {<br /><br /><br /> }<br /> }, new Response.ErrorListener() {<br /> @Override<br /> public void onErrorResponse(VolleyError error) {<br /> if (error instanceof NoConnectionError) {<br /><br /><br /> }<br /...

.prop() returns object rather than value

<p>I'll try to make my question as simple and clear as possible. So i recently read the <a href="http://ift.tt/1lHNK0R"><code>.prop()</code> vs <code>.attr()</code></a> page on the stackoverflow, and decided i'd start using <code>prop()</code> instead of <code>attr()</code>.</p><p>HTML</p><pre><br /><code><form action="php/select.php" method="POST" class="ajax"><br /> <fieldset><br /> <legend>Show</legend><br /> <div><br /> <input type="submit" value="Show Servers"/><br /> </div><br /> <div id="output"></div><br /> </fieldset><br /> <input type="hidden" name="action" value="SHOW_SERVERS"/><br /></form><br ...

Disable Gradle build running

<p>I have using Android Studio build project I click Run(Shift + F10) in Android Studio. Gradle build running ... Create in Background Tasks <a href="http://ift.tt/1IDabnX" rel="nofollow"><img src="http://ift.tt/1IDabnX" alt="enter image description here" /></a></p><p>How to disable gradle build running when Run(Shift + F10) project ??? Thanks.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526176/disable-gradle-build-running">http://ift.tt/1YSol6t</a></h2>

getting first array item in angular js service array

<p>i have 2 services. 1 uses the other to fetch data, this works... After that the service provides a getter and setter for a variable</p><p>` .service('ClickHandlers', ['$firebase','FirebaseData',function ($firebase,FirebaseData) { var lastClickedVisitedPlace;</p><pre><br /><code> return {<br /><br /> getLastClickedVisitedPlace: function () {<br /> console.log('getLastClickedVisitedPlace service function triggered');<br /> var destinations = FirebaseData.getDestinations();<br /> console.log('service destinations',destinations);<br /><br /> **var defaultVisitedplace = destinations[0];<br /> console.log('service defaultVisitedplace',defaultVisitedplace);<br /> lastClickedVisitedPlace = defaultVisitedplace.id;**<br /> console.log('service lastClickedV...

Parse -0 string as -0.0f

<p>I'm learning C++ using Visual Studio 2015.</p><p>I have this method:</p><pre><br /><code>double ConvertDegreesToDecimal(std::string value)<br />{<br /> using namespace std;<br /> vector<float> values;<br /> string item;<br /><br /> istringstream in(value);<br /><br /> while (getline(in, item, ' '))<br /> values.push_back(atof(item.c_str()));<br /><br /> DegreesCoordinate* coord = new DegreesCoordinate((short)values[0], (unsigned char)values[1], (double)values[2], NotSet);<br /><br /> return DegreesConverter::convertDegressToDecimal(coord);<br />}<br /></code><br /></pre><p>It works fine with all cases except with this one: <code>-0 17 25</code>. This number is a coordinate in degrees <code>-0 degrees 17 minutes 25 seconds</code>.</p><p>I have though...

Divide and conquer for function compositions

<p>I was searching the algorithm for finding the composition of 2 linear functions n times (where n can be as large as 10^18) in O(log n) time. I just got a pdf ( http://ift.tt/1JfjeLV ) containing polynomial composition of 2 functions with large degrees using divide and conquer algorithm.</p><p>I was wondering whether my problem for composition of linear function n times can also be solved using divide and conquer algorithm in O(log n) complexity?</p><p>If yes, please explain the algorithm.</p><p>Thanks, in advance.</p><p><strong>EDIT 1:</strong> The composition of function f(x) n times is fofof...n-times. Here the function is to be composed to itself n times. There are no 2 functions.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525433/divide-and-conquer-for-function-compositions">http://ift.tt/1Vpgopb</a></h2>

DATEDIFF - Replace NULL with NOW()

<p>I got following SQL Query</p><pre><br /><code>SELECT<br /> e.id,<br /> c.name,<br /> e.location,<br /> e.designation,<br /> e.time_period_from,<br /> e.time_period_to,<br /> DATEDIFF(e.time_period_to, time_period_from) AS tenure_in_days<br />FROM<br /> employment e<br />LEFT JOIN<br /> company c ON (c.id = e.company_id)<br />LIMIT<br /> 0, 10<br /></code><br /></pre><p>This is working perfectly, i have a scenario where <code>time_period_to</code> can have <code>NULL</code> values, in this case, i want to replace it with current date.</p><p>Here is what i tried.</p><pre><br /><code>SELECT<br /> e.id,<br /> c.name,<br /> e.location,<br /> e.designation,<br /> e.time_period_from,<br /> e.time_period_to,<br...

How to add space at the start and end of eachline

<p>I have created a custom textview class and I am using BackgroundColorSpan to apply color in the background. How can I add blank space before and after each line. I really appreciate any help.</p><pre><br /><code>final String test_str1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";<br /><br /><br />public class CustomTextView extends TextView {<br /> public CustomTextView(Context context) {<br /> super(context);<br /> setFont();<br /> }<br /><br /> public CustomTextView(Context context, AttributeSet attrs) {<br /> super(context, attrs);<br /> setFont();<br /> }<br /><br /> public CustomTextView(Context context, Attr...

Pointers to elements of a C++ class

<p>I have a <strong>C++</strong> class <em>c_image</em> which contains a vector of pointers to elements of class <em>c_pixel</em>:</p><pre><br /><code>class c_image {<br /><br /> public:<br /> vector<shared_ptr<c_pixel>> pixel;<br /> ...<br />};<br /></code><br /></pre><p>Class <em>c_pixel</em> elements contain an element <em>Z</em> of type double:</p><pre><br /><code>class c_pixel {<br /><br /> public:<br /> double Z;<br /> ...<br />};<br /></code><br /></pre><p>However, they are extended with class <em>c_pixel_pv</em>, which contains <em>pv</em>, an array of three elements of type double:</p><pre><br /><code>class c_pixel_pv : public c_pixel {<br /><br /> ...

Decode HTML string where ampersands are encoded as \\x26

<p>I got a string from html like:</p><pre><br /><code>var htmlStr = " \\x26lt;span\\x26gt; \\x26lt;/span\\x26gt;";<br /></code><br /></pre><p>I can't decode it to C# string like:</p><pre><br /><code> <span> </span><br /></code><br /></pre><p>If I modify the string to</p><pre><br /><code>var htmlStr = " \x26lt;span\x26gt; \x26lt;/span\x26gt;";<br /></code><br /></pre><p>It works good. But how can I do it by replacing string or others way?</p><p>BTW, I use Encoding.UTF8.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525485/decode-html-string-where-ampersands-are-encoded-as-x26">http://ift.tt/1Jfjf2f</a></h2>

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php

<p>i'm getting the following error</p><p>Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php</p><p>everything else work fine... except for this !</p><p>Here's my query :</p><pre><br /><code><?php<br /><br />$inputuser = $_POST["user"];<br />$inputpass = $_POST["pass"];<br /><br />$user = "root";<br />$password = "";<br />$database = "share";<br /><br />$connect = mysql_connect("localhost:3306",$user,$password);<br />@mysql_select_db($database) or ("Database not found");<br /><br />$query = "SELECT * FROM 'users' WHERE 'username'= '$inputuser'";<br />$querypass = "SELECT * FROM 'users' WHERE 'password'= '$inputpass'";<br /><br />$re...

PHP Bug or my misunderstanding of the language?

<p>This is the code that I don't understand (as the output).</p><pre><br /><code><?php<br />$x = ['test1', 'test2', 'test3', 'test4'];<br />echo "First FOREACH\n";<br />foreach ($x as &$y)<br />{<br /> echo $y."\n";<br />}<br />echo "\n\nSecond FOREACH\n";<br />foreach ($x as $y)<br />{<br /> echo $y."\n";<br />}<br /><br />?><br /></code><br /></pre><p><strong>Output:</strong></p><pre><br /><code>First FOREACH<br />test1<br />test2<br />test3<br />test4<br /><br />Second FOREACH<br />test1<br />test2<br />test3<br />test3<br /></code><br /></pre><p>PS: I'm running it under:</p><pre><br /><code>php -v<br /...

How to implement a closure in jQuery [on hold]

<p>I don't know much about jQuery. Here I am trying to implement a closure to attach a click event to each anchor tag so that each of them will alert a certain number once blicked. But I am getting the following error:</p><blockquote><pre><br /><code>SyntaxError: missing ) after argument list<br /><br /><br />};})(i);<br /></code><br /></pre></blockquote><p>can anyone help me with this problem?thanks :)</p><p>Code:</p><pre><br /><code><div id='pageBox'><br /> <ul id='pageContainer'><br /> <?php for($i=1;$i<=$pagenum;$i++){?><br /> <li><a href=''><?php echo $i;?></a></li><br /> <?php }?><br /> </ul><br /> </div><br /><script><br />for(i=1;i<=<?php echo $pagenum;?>;i++){<br ...

Check is user inputs Black, Green or Red. C#

<p>I'm working on a program where I want my user to enter one of the following Colors (Red, Green or Black). But I am stuck.</p><p>What I have done so far is this</p><pre><br /><code>Console.Write("Color To Bet on: ");<br />string tempColor = Console.ReadLine();<br /><br />while (String.IsNullOrWhiteSpace(tempColor))<br />{<br /> Console.Write("The color can't be null.");<br /> tempColor = Console.ReadLine().ToLower();<br />}<br /></code><br /></pre><p>But how can I make sure my users puts in the color I want, I've tried fiddling around with string. Contains method but haven't had any success so far.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525546/check-is-user-inputs-black-green-or-red-c-sharp">http://ift.tt/1VpgoFB</a></h2>

dplyr - how to select columns of certain type

<p>Is there a concise way to select columns of certain type in <code>dplyr</code>? For example, how to select all character columns within a <code>dplyr</code> chain?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525577/dplyr-how-to-select-columns-of-certain-type">http://ift.tt/1Jfjf2m</a></h2>

Find biggest value in a python dict

<p>I have a python dict like below:</p><pre><br /><code>{ '1': {'a': '0.6', 'b': '0.8', 'c': '2','d': '0.5'},<br /> '2': {'a': '0.7', 'b': '0.9', 'c': '0.1','d': '0.2'},<br /> '3': {'a': '0.5', 'b': '0.8', 'c': '3'},<br />}<br /></code><br /></pre><p>How could I get the following result?</p><pre><br /><code>('2','a','0.7') ('2',b','0.9') ('3','c', '3') ('1','d', '0.5')<br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525612/find-biggest-value-in-a-python-dict">http://ift.tt/1...

How/where to import Angular and Bootstrap .js files in my index.html?

<p>I'm new to web front-end programming and am teaching myself AngularJS.</p><p>I have created a very simple webapp that just lets users login and logout. I am running it locally on my Mac OSX.</p><p>Below is my <code>index.html</code> file. Although it works, I'm not sure if I'm doing it right. I need to know how and where to import the angular.js files and the bootstrap.js files.</p><p>My questions are as follows. I haven't been able to figure this stuff out by googling. I need someone to explain this stuff to me please.</p><ol><li>I'm currently importing the <code>angular.js</code> file from <code>http://ift.tt/Q55qZD</code>. Is that correct? Or should I download it and store that file in the same directory as <code>index.html</code>? Why? When should I use the non-minified file? What is the benefit of using non-minified?</li><li>I'm current...

Retrieving rows that have 2 columns matching and 1 different

<p>Below is my table called 'datapoints'. I am trying to retrieve instances where there are different instances of 'sensorValue' for the same 'timeOfReading' and 'sensorNumber'.</p><p>For example:</p><pre><br /><code> sensorNumber sensorValue timeOfReading<br /><br /> 5 5 6<br /> 5 5 6<br /> 5 6 10 <----same time/sensor diff value!<br /> 5 7 10 <----same time/sensor diff value!<br /></code><br /></pre><p>Should output: sensorNumber:5, timeOfReading: 10 as a result.</p><p><a href="http://ift.tt/1JfjfiI" rel="nofollow"><img src="http://ift.tt/1JfjfiI" alt="datapoints table" /></a></p><p>I understand this is a duplicate question, in fact I have one of the links pro...

Count how many times a conditional is true inside for loop with javascript

<p>I have a for loop that runs over a range of cell values in a Google Apps script I'm trying to write, and each time it loops, it checks to see if a certain condition is true. If it's true, for the time being, it's logging the results to Logger.log().</p><p>I need the total number of results that show up in Logger.log() (in this case, it would be 10) and the best way I was able to think of doing that would be to count up by 1 each time that conditional is true in the for loop. It should be very simple to get a numerical value of how many results.</p><p>Here's the code I'm using:</p><pre><br /><code>var currentsheet = SpreadsheetApp.getActiveSheet();<br />var values = currentsheet.getRange("A28:E").getValues();<br /><br />for (i=0; i<values.length; i++) {<br />if (values[i][3] === "Section 179 Depreciation") {<br /> var date = values[i][0];<br /> var am...

Why Fragment closes after closing FragmentActivity

<p>i have to do something like this</p><p>i have a fragment that reside in an activity and call fragment activity from the fragment like</p><pre><br /><code>Intent in = new Intent(getActivity(), ActivityShowGallery.class);<br /> in.putExtra(ActivityShowGallery.Gallery, m);<br /> in.putExtra(ActivityShowGallery.position, 0);<br /> getActivity().startActivity(in);<br /></code><br /></pre><p>but main problem occur when i close the fragment activity then my fragment also closes automatically, i don't know why this happen???</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525735/why-fragment-closes-after-closing-fragmentactivity">http://ift.tt/1VpgoW5</a></h2>

Should every class that is only used once be static?

<p>I've seen various discussions about this and I suppose it may be a bit opinion based, but what I'm trying to find out is if I know I will only use a class once (one instance), should I just make it static for convenience? Is that bad practice or will it create a problem?</p><p>For example. If I make a single player game, there will only be one player at all times. So do I make <code>public static class Player{}</code> or do I stick with <code>public class Player{}</code> <code>Player player = new Player();</code></p><p>The idea is that this would save time by not needing to pass around references.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525801/should-every-class-that-is-only-used-once-be-static">http://ift.tt/1VpgqNI</a></h2>

Singleton Overlaps?

<p>I have two classes using as singletons.</p><pre><br /><code>class Boss {<br /> static let sharedInstance = Boss()<br /> private init() {} <br /><br /> var user_id : String?<br /> var username : String?<br />}<br /><br /><br /><br />class Job {<br /> static let sharedInstance = Job()<br /> private init() {} <br /><br /> var job_id : String?<br /> var JobType : String?<br />}<br /></code><br /></pre><p>But after populating the <code>Boss.sharedInstance</code> first, <code>Job.sharedInstance</code> also containing Boss' class variables. But after replacing the <code>sharedInstance</code> with other name (for eg. <code>job_sharedInstance</code> and <code>boss_sharedInstance</code>) respectively, things are working fine. It's quite weird. Can a...

How to declare a self-referential container in C++?

<p>For a <code>typedef</code> of a <code>struct</code> in C, I can't do this:</p><pre><br /><code>typedef struct {<br /> unsigned id;<br /> node_t *left;<br /> node_t *right;<br />} node_t;<br /></code><br /></pre><p>because <code>node_t</code> is not known until it is defined, so it can't be used in its own definition. A bit of a Catch-22. However, I can use this workaround to make the desired self-referential type:</p><pre><br /><code>typedef struct node_s node_t;<br />struct node_s {<br /> unsigned id;<br /> node_t *left;<br /> node_t *right;<br />};<br /></code><br /></pre><p>Similarly, I would like to do something like this for a C++ container referring to itself:</p><pre><br /><code>typedef pair<unsigned, pair<node_t *, node...

Convert matching arrays to one single array

<p>i need your help, i have an array which look like this</p><pre><br /><code>Array<br />(<br /> [vaccine_id] => 1<br />)<br />Array<br />(<br /> [vaccine_id] => 1<br />)<br />Array<br />(<br /> [vaccine_id] => 1<br />)<br />Array<br />(<br /> [vaccine_id] => 2<br />)<br />Array<br />(<br /> [vaccine_id] => 2<br />)<br />Array<br />(<br /> [vaccine_id] => 2<br />)<br />Array<br />(<br /> [vaccine_id] => 12<br />)<br />Array<br />(<br /> [vaccine_id] => 12<br />)<br />Array<br />(<br /> [vaccine_id] => 12<br />)<br /></code><br /></pre><p>and i need to convert it so it can look some thing like this so that array with the same key and value should not repeat. e.g</p...

why the first statement is illegal while the second is legal?

<p>I'm new to C++. I'm trying to learn the concept of const. Could someone please tell me why the first statement is illegal while the second is legal?</p><pre><br /><code>int i = -1, &r = 0; <br /><br />const int i = -1, &r = 0; <br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525109/why-the-first-statement-is-illegal-while-the-second-is-legal">http://ift.tt/1ks1Pnb</a></h2>

how to manipulate private variable between classes

<p>I'm trying to build a stock inventory and cash register simulation, in the code I have 2 class, first is Inventory and second is Cash. Both have their own properties and method, when I'm trying to sell item the _balance property is giving Error undefined _balance and the _balance is still 0. How should I fix it? Just in case this question have been already asked please just give the link don't mark as duplicate. I just can't find it.</p><pre><br /><code><?php<br /> class Inventory {<br /> public $_name;<br /> public $_price;<br /> public $_stock;<br /> public function _addStock($item,$itemIn)<br /> {<br /> $this->_stock += $itemIn;<br /> }<br /> };<br /><br /> $item2 = new Inventory;<br /> $item2->_name = "item2";<br /> $item2-...

Recursive function not returning sum of object values

<p>Why <code>sum</code> is <code>undefined</code>. What am I doing wrong?</p><div class="snippet" data-lang="js" data-hide="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"><br /><code>var testData1 = [{<br /> "name": "Doctors",<br /> "category": "Doctors",<br /> "subCategory": [{<br /> "name": "Likes",<br /> "category": "Likes",<br /> "subCategory": [{<br /> "name": "Visit",<br /> "category": "Visit",<br /> "subCategory": [{<br /> "name": "Charges",<br /> "category": "Charges",<br /> "subCategory": null,<br />...

jquery alternative to change or keyup

<p>I have a form in which the user must initial a bunch of different sections.</p><pre><br /><code><script><br /> $.function(){<br /> $('.initialMe').change(function(){<br /> var id = $(this).attr('id');<br /> alert(id);<br /> }); <br /> });<br /></script><br /><br /><?php<br /> echo "<div class='signature'>Initial Here:<input type='text' class='initialMe' id='sign[service1]' name='sign[service1]' size='4'></div>";<br /> echo "<div class='signature'>Initial Here:<input type='text' class='initialMe' id='sign[service2]' name='sign[service2]' size='4'></div>";<br />?><br /></code><br /></pre><p>I want to fire off an action when they are done initializing th...

Destroy All Previous Activities After Specific Activity is Open

<p>This is the scenario</p><p><code>Activity A</code> -> <code>Activity B</code> -> <code>Activity C</code> -> <code>Activity D</code> (I would like to destroy Activity A, B, and C after <code>Activity D</code> is launched.</p><p>Any ideas please?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525281/destroy-all-previous-activities-after-specific-activity-is-open">http://ift.tt/1mpcqR7</a></h2>

javascript validation phone number

<p>alright, whats wrong with my script, JShint is throwing three lines of red code saying i have issues in my variable and my if/else statement. I am trying to validate if the phone number is a valid USA phone format</p><pre><br /><code> $( "#phone" ).focusout(function telephone() {<br /> if( this.value === "" || this.value === null ) {<br /> $( "#error_messages" ).text("");<br /> return false;<br /> } else {<br /> var re = \d{3}[\-]\d{3}[\-]\d{4};<br /> if(re.test(document.getElementById("phone").value)) {<br /> $( "#error_messages" ).text("");<br /> return true;<br /> } else {<br /> $( "#error_messages" ).text("Phone Number* not a valid format xxx-xxx-xxxx");<br /> return false;<br /> }<br /> ...

How to get the output of ping(bash) while it is running?

<p>I want to monitor round-trip time of my network, drawing the date using highcharts on linux</p><p>I know how to get the result of ping after it finished running. Like:</p><pre><br /><code>[root@localhost dev]# ping stackoverflow.com -c 5<br />PING stackoverflow.com (104.16.36.249) 56(84) bytes of data.<br />64 bytes from 104.16.36.249: icmp_seq=1 ttl=128 time=341 ms<br />64 bytes from 104.16.36.249: icmp_seq=2 ttl=128 time=351 ms<br />64 bytes from 104.16.36.249: icmp_seq=3 ttl=128 time=342 ms<br />64 bytes from 104.16.36.249: icmp_seq=4 ttl=128 time=294 ms<br />64 bytes from 104.16.36.249: icmp_seq=5 ttl=128 time=286 ms<br /><br />--- stackoverflow.com ping statistics ---<br />5 packets transmitted, 5 received, 0% packet loss, time 5622ms<br />rtt min/avg/max/mdev = 286.302/323.460/351.832/27.258 ms<br />[root@localhost dev]# <br /></code><br /></pre>...

Initializers from generic types won't be inherited in swift?

<p>Here is my code:</p><pre><br /><code>public class A<T:Any> { <br /> public init(n:Int) { <br /> print("A")<br /> } <br />} <br />public class B:A<Int>{}<br />public class C:B{}<br />let x = C(n:123)<br /></code><br /></pre><p>And this fails compilation and yells such error:</p><pre><br /><code>repl.swift:9:9: error: 'C' cannot be constructed because it has no accessible initializers<br /></code><br /></pre><p>And the following code can be compiled.</p><pre><br /><code>public class A { <br /> public init(n:Int) { <br /> print("A")<br /> } <br /> } <br /> public class B:A{}<br /> public class C:B{}<br /> let x = C(n:123)<br /></code><br /></pre><p...

Animating image on toggle

<p>I managed to create a div that toggled open and close and then stopped a hover animation while it was open. Which is good, and the div slides open nicely however, the image in the div does not slide open. How do I make the image follow the div instead of just blinking on?</p><p>Here is the div unopened: <a href="http://ift.tt/1mhPAvq" rel="nofollow"><img src="http://ift.tt/1mhPAvq" alt="enter image description here" /></a></p><p>Here is the div opened, and the .block overflow:visible (once I get this working Ill make the image fit the div:</p><p><a href="http://ift.tt/1mhPC6F" rel="nofollow"><img src="http://ift.tt/1mhPC6F" alt="enter image description here" /></a></p><p>At the moment the stuff below the image slides down nicely, but the image just changes from overflow hidden to overflow visible without animation. ...

Eclipse giving me a warning saying

<p>Code:</p><pre><br /><code> p.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)<br /> {<br /><br /> System.out.println("Welcome to Guess the number Game");<br /> System.out.println("You have 3 chances to guess a number between 0 and 10 excluding 10");<br /><br /> ne.remove(p);<br /><br /> //ne.removeAll();<br /> ne.revalidate();<br /> ne.repaint();}<br /> public void cam()<br /> {<br /><br /> gamer2 game=new gamer2();<br /> game.generatenum();<br /> }<br /> }<br /><br /> ); <br /></code><br /></pre><p><code>p</code> is a JButton.</p><p>Eclipse is giving me a warning saying:"The method cam() from the type new ActionListener(){} is never used locally....

use for each to get each input value [on hold]

<p>I'm expecting value 1 and 2 but it returned null instead. Any idea why is this happening?</p><div class="snippet" data-lang="js" data-hide="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"><br /><code>$(function() {<br /><br /> $('.agent_rows').each(function() {<br /> console.log($(this).find('input[name="associatedAgentId"]').val())<br /> })<br /><br />});</code><br /></pre><pre class="snippet-code-html lang-html prettyprint-override"><br /><code><script src="http://ift.tt/1oMJErh"></script><br /><div class="agent_rows"><br /> <input type="hidden" name="associatedAgentId" val="1"><br /></div><br /><br /><div class="age...

Updating global variable via callback

<p>I have the following function</p><pre><br /><code> var urls = '';<br /> handleFiles(f,function(url){<br /> urls = urls + url + ',';<br /> console.log("urls is " + urls);<br /> });<br /></code><br /></pre><p>I get the url after uploading and update my urls. But my Urls never gets updated, it shows the url of the last file uploaded.</p><p><strong>UPDATE 1</strong> This is my complete code now.</p><pre><br /><code>var urls = '';<br />document.getElementById('question-file-selector').addEventListener('change',handleFileSelect,false);<br /> function handleFileSelect(evt){<br /> var files = evt.target.files; //File list object<br /> // Loop through file list, render image files as thumbnails<br /> for (var i = 0,f;f = files[i];i++)...

Sessions in PHP 7

<p>I have been working with PHP 5.xx for years but recently updated to PHP 7. I can't create sessions.</p><p>I have read the documentation.</p><p>In earlier PHP, you just have to do:</p><pre><br /><code>session_start();<br /></code><br /></pre><p>to start session, but this doesn't work with PHP 7 and my page keeps loading. I provided the array in the parameter too as documented on the PHP website but still it keeps loading the page.</p><p>I have tried this:</p><pre><br /><code>session_start([<br />'cache_limiter' => 'private',<br />'read_and_close' => true,<br />]);<br /></code><br /></pre><p>But my browser keeps loading and after few seconds it displays 'This webpage is not available'</p><p>Apache restart errors:</p><blockquote><p>[Wed Dec 30 00...

PHP : sending reset password link in email

<p>i am sending password reset link using html email in php . this is structure of m code . First is html email</p><pre><br /><code><?php $bodymessage= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >;<br /> $bodoymessaage= .='<a href="$link"' .....?><br /></code><br /></pre><p>the i've setup heaeders</p><pre><br /><code> <?php $headers = 'MIME-Version: 1.0' . "\r\n";<br /> $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";<br /> ?><br /></code><br /></pre><p>and after this i recieve form fields and mail function like this</p><pre><br /><code>if($passreset){<br /> mail($to, $subject, $bodymessage, $headers);<br />} <br /></code><br /></...

Javascript OOP literal access variable inside method

<p>i have a problem accessing variable inside method in OOP.</p><p>this is my code :</p><pre><br /><code>var slideshow = {<br /><br /> elSet : $(".slideshow"),<br /> next : function() {<br /><br /> },<br /> swipe : function() {<br /> var clear = this.autorun().loop;<br /><br /> onSwipe(function() {<br /><br /> clearInterval(clear); // not working<br /> });<br /> },<br /> autorun : function() {<br /><br /> var self = this;<br /> var loop = setInterval(function() {<br /><br /> self.next();<br /><br /> }, 5000);<br /><br /> },<br /> initial : function() {<br /><br /> this.swipe();<br /> ...

How to convert an array all value without using foreach loop

<p>I want to convert an array value without using any loop and i have an array something like this</p><pre><br /><code>Array<br /> (<br />[0] => Array<br /> (<br /> [month] => August<br /> )<br /><br />[1] => Array<br /> (<br /> [month] => July<br /> )<br /><br />[2] => Array<br /> (<br /> [month] => October<br /> )<br />)<br /></code><br /></pre><p>I want to convert above array in to below format</p><pre><br /><code> Array<br /> (<br /> [month] => August <br /> )<br /> Array<br /> (<br /> [month] => July <br /> )<br /> Array<br /> (<br /> [month] => October<br /> )<br /></code><br /></pre><p>Without using any loop</p>...

Add data at the end of existing data in resource file

<p>I want to add data at the end of existing data in resource file on the click of button in windows form. I have a windows form with 3 text boxes -</p><pre><br /><code>text_box1: Name<br />text_box2: Value<br />text_box3: Comments<br />and a button named as Save.<br /></code><br /></pre><p>code for button:</p><pre><br /><code> private void button1_Click(object sender, EventArgs e)<br /> {<br /> myMethod.Create(textBox1.Text, textBox2.Text, textBox3.Text);<br /> }<br /></code><br /></pre><p>Method to add data in resource file:</p><pre><br /><code>public class myMethod<br /> {<br /> public static void Create(string myName, string myValue, string myComment)<br /> {<br /> try<br /> {<br /> ResXResourceRea...

How to listen a frame property of a view on iOS

<p>I have a view and I added a observer like this:</p><pre><br /><code>_aView = [UIView new];<br />[_aView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];<br />_aView.frame = CGRectMake(100, 100, 100, 100);<br /></code><br /></pre><p>In the observer method I get the new value : <code>- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"frame"]) { NSLog(@"%@", change[@"new"]); } }</code> The log is <code>NSRect: {{100, 100}, {100, 100}}</code>. The question is that I got the value type is <code>NSRect</code>, how to convert it to <code>CGRect</code>?</p><p>In the UIKit library have no type named <code>NSRect</code></p><br /><h2>Click here view mo...

Database for Android App

<p>How and where I can maintain my DB for my android app. I know we can use sqlite DB for android apps but, I don't have any idea of Storing the DB at some other location and then accessing it on the app.</p><p><strong>Example Structure:</strong></p><p><a href="http://ift.tt/1mhJwTM" rel="nofollow"><img src="http://ift.tt/1mhJwTM" alt="enter image description here" /></a></p><p>I want to know, where and how we can have DB at some different point of location, Do I need to buy space or rent? Or there are any other ways (Having DB Server at my own Desktop and accessing it via IP address. Will there be any difficulties or dependencies) I believe we can access it by creating a connection to the Db and writing queries to fetch by using Http Get and Post or Put methods.</p><p>If yes, then can we use SQL Server Management studio 2008 or what would be the simplest ...

Accessing a static variable and setting it outside the class

<p>Here is a SubtitleCustomField class.</p><pre><br /><code>Class SubtitleCustomField: CustomCellField {<br />static var CellIdentifier: String!<br /><br /> override init(frame: CGRect) {<br /> super.init(frame: frame)<br /> if CellIdentifier == "A" {<br /> //DO SOMETHINIG<br /> } else if CellIdentifier == "B" {<br /> //DO SOMETHING<br /> }<br /><br /> }<br />}<br /></code><br /></pre><p>Outside SubtitleCustomField class, I basically need to access static variable CellIdentifier, set value like "A", and trigger if statement to run.</p><p>In another class, Custom class, I've confirmed that I can access the static variable, Cell Identifier, in a following way:</p><pre><br /><code>Class Custom: CustomViewController {<br /> SubtitleCustomField.CellIdentifier = "part1_...

Concurrent access to a public field. Why is it possible to observe inconsistent state?

<p>I'm reading <a href="http://ift.tt/1Yt5dB6" rel="nofollow">B. Goetz Java Concurrency In practice</a> and now I'm at the <code>section 3.5</code> about safe publication. He stated:</p><pre><br /><code>// Unsafe publication<br />public Holder holder;<br />public void initialize() {<br /> holder = new Holder(42);<br />}<br /></code><br /></pre><blockquote><p>This improper publication could allow another thread to observe a partially constructed object.</p></blockquote><p>I don't see why it is possible to observe a partially constructed subobject. Assume, that the constructor <code>Holder(int)</code> does not allow <code>this</code> to escape. So, the constructed reference can be observed only by the caller. Now, as <a href="http://ift.tt/1RQTJDj" rel="nofollow">JLS 17.7...

how to use ng-repeat in append to get the key value?

<p>if i use ng-repeat in append html div, the content is not appending. how to get the label name key value on appended each fields. i want to change each label name from field label options from below code. click on appended div, it will shows filed label options, from there i have to change each label name seperately.. pls help me</p><div class="snippet" data-lang="js" data-hide="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"><br /><code>var app = angular.module('myapp', ['ngSanitize']);<br /><br />app.controller('AddCtrl', function ($scope, $compile) {<br /><br /> $scope.field = {single: 'untitled'};<br /> $scope.addNew_SingleField = function (index) {<br /> var singlehtml = '<fieldset ng-repeat="(fieldkey, field) in singleField" ng-click="se...

Align elements inside an tag vertically

<p>I have an <code><a></code> tag (which is part of multiple <code><li></code> tags). In the <code><a></code> tag I have an <code><i></code> tag and some text - the text of the link.</p><p>What I would like to achieve is to have the icon on top and the text under it (and then centered). So it would look like:</p><pre><br /><code> ICON<br />MYTEXTHERE<br /></code><br /></pre><p>However they are always placed next to each other. I tried using <code>display: inline-block</code> - because my <code><a></code> is <em>inline</em> and the content inside should be <em>block</em> but without success.</p><p>The fiddle is here: <a href="http://ift.tt/1mFkDBp" rel="nofollow">http://ift.tt/1mFkDBp</a></p><br /><h2>Click here view more a...

Show / Hide contents base on radio button selection

<p>I am trying to toggle a content DIV base on the selection of radio buttons.</p><p>HTML for radio button.</p><pre><br /><code><div class="row-fluid"><br /> <label class="radio"><br /> <input type="radio" name="account" id="yes" value="yes" checked><br /> Yes, I have an existing account<br /> </label><br /> <label class="radio"><br /> <input type="radio" name="account" id="no" value="no"><br /> No, I don't have an account<br /> </label><br /></div><br /></code><br /></pre><p>Content DIV</p><pre><br /><code><div id="account_contents"><br /> <p>This is account contents.......</p> <br /></div><br /...

Search in JSON api url with ajax

<p>I have an api URL it's output JSON, it is about daily deals like groupon.</p><p>I want to create a search form and client search in this json</p><p>Samle json url <a href="http://bit.ly/1NPSTkd" rel="nofollow">here</a></p><p>I'm decode JSON like that and show it but how to search in this api url i don't know.</p><pre><br /><code>$param = array(<br /> 'apiKey' => 'VN43ZG2LLHKHHIU6',<br /> 'publisherId' => 316,<br /> //'isPopular' => 'on',<br /> 'p' => $sayfasi,<br /> 'itemInPage' => $sayi<br />);<br /><br />if(isset($tagid) && $tagid !='')<br /> $param['tagIds[]'] = $tagid;<br /><br />if(isset($cityId) && $cityId !='')<br /> $param['cityId'] = $cityId;<br /><...

Compiler Error Message: CS1061 ASPX

<p>I am trying to code a drop down list that will have an <code>OnSelectedIndexChanged</code> event but i can't make it work.</p><p>So here's the code on my .aspx</p><pre><br /><code><asp:DropDownList ID="DDLSample" OnSelectedIndexChanged="DDLSample_SelectedIndexChanged" runat="server"><br /> <asp:ListItem Text="Sample1" Value="0"></asp:ListItem><br /> <asp:ListItem Text="Sample2" Value="1"></asp:ListItem><br /> <asp:ListItem Text="Others..." Value="2"></asp:ListItem><br /> </asp:DropDownList> <br /></code><br /></pre><p>and a textbox</p><pre><br /><code><asp:TextBox ID="txtOthers" runat="server" Visible ="false...