pid
int64 2.28k
41.1M
| label
int64 0
1
| text
stringlengths 1
28.3k
|
---|---|---|
2,828,051 | 0 | <p>Extend <code>java.util.Properties</code>, override both <code>put()</code> and <code>keys()</code>:</p> <pre><code>import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Properties; import java.util.HashMap; public class LinkedProperties extends Properties { private final HashSet<Object> keys = new LinkedHashSet<Object>(); public LinkedProperties() { } public Iterable<Object> orderedKeys() { return Collections.list(keys()); } public Enumeration<Object> keys() { return Collections.<Object>enumeration(keys); } public Object put(Object key, Object value) { keys.add(key); return super.put(key, value); } } </code></pre> |
14,935,714 | 0 | <p><code>add_csrf()</code> is a function which returns a dict. It is used to add a csrf token along with the request arguments.</p> <pre><code>from django.core.context_processors import csrf def add_csrf(request, **kwargs): """ Add CSRF to dictionary. """ d = dict(user=request.user, **kwargs) d.update(csrf(request)) return d </code></pre> <p>Where as <code>dict()</code> is a python built-in function used to create a dict </p> |
15,906,822 | 0 | <p>try this tutorial, it should do it</p> <p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/" rel="nofollow">http://net.tutsplus.com/tutorials/html-css-techniques/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/</a></p> |
20,114,461 | 0 | adding a layer mask to UIToolBar/UINavigationBar/UITabBar breaks translucency <p>Im upgrading my UI to iOS 7, and have been using a custom tab bar which has a CAShapeLayer used as a mask. Ive been trying to add dynamic blur by having a UIToolBar underneath, but if i try setting the layer.mask property on the toolbar translucency is gone, and i just have it semi transparent (but masking works of course). Is there a way to get this working? Ive also seen this behavior when adding a subview to these classes.</p> |
34,891,204 | 0 | Fact appears only once in the Knowledge Base <p>I have this KB (Knowledge Base):</p> <pre><code>%artist(ArtistId, ArtistName, YearofDebut). %album(AlbumId, AlbumName, YearOfRelease, Artists). %song(AlbumId, Songname, Duration). %artist/3 artist(1, 'MIEIC', 2006). artist(2, 'John Williams', 1951). artist(3, 'LEIC', 1995). artist(4, 'One Hit Wonder', 2013). %album/4 album(a1, 'MIEIC Reloaded', 2006,[1]). album(a2, 'Best Of', 2015, [2]). album(a3, 'Legacy', 2014, [1,3]). album(a4, 'Release', 2013, [4]). %song/3 song(a1, 'Rap do MIEIC', 4.14). song(a2, 'Indiana Jones', 5.25). song(a1, 'Pop do MIEIC', 4.13). song(a2, 'Harry Potter', 5.13). song(a1, 'Rock do MIEIC', 3.14). song(a2, 'Jaws', 3.04). song(a2, 'Jurassic Park', 5.53). song(a2, 'Back to the Future', 3.24). song(a2, 'Star Wars', 5.20). song(a2, 'E.T. the Extra-Terrestrial', 3.42). song(a3, 'Legacy', 3.14). song(a3, 'Inheritance', 4.13). song(a4, 'How did I do it?', 4.05). </code></pre> <p>And I want a query that asks if an album is a single (Got only one song).</p> <blockquote> <p>recentSingle(+AlbumId).</p> </blockquote> <pre><code>recentSingle(a1) ? No recentSingle(a4) ? Yes </code></pre> <p>How do I search in the whole KB and check if it only appears once?</p> <p><strong>ANSWER:</strong></p> <pre><code>recentSingle(AlbumId) :- album(AlbumId, _, Year, _), Year > 2010, \+ isNotSingle(AlbumId). isNotSingle(AlbumId) :- song(AlbumId, Name1, _), song(AlbumId, Name2, _), Name1 \= Name2. </code></pre> <p>Regards</p> |
19,221,749 | 0 | SSRS report in CRM 'try again' issue <p>I have an SSRS report with hyperlinks in. When I add this report in to CRM it runs fine, and you are able to click on the hyperlinks. What should happen is that it takes you to the related record.. however a CRM error box comes up with the options to 'try again' or cancel. If you click 'try again', it works fine and takes you to the record. I have declared the following expression in the placeholder properties;</p> <pre><code>=IIf(IsNothing(Fields!MyEntityid.Value), Nothing, String.Format (System.Globalization.CultureInfo.InvariantCulture, "{0}?ID={1}&amp;LogicalName={2}", Parameters! CRM_URL.Value, Fields!MyEntityid.Value, "MyEntity")) </code></pre> <p>Does anyone know a reason for this bizarre behaviour?</p> |
27,517,010 | 0 | <p>Do you set the constraint for the label. or the label is too height for the superview , so it covers the all subviews , so you can use the lldb po the label size ,when you set the text into the label.</p> |
28,169,229 | 0 | <blockquote> <p>on the second approach i will get a notification if the 'controller' object on self was replaced</p> </blockquote> <p>I would rephrase by saying that on the second approach you'll get notified if the controller object gets replaced <strong>or if its <code>isEnabled</code> property changes</strong>. In other word when <code>controller.isEnabled</code> changes (as explained by Ken's answer).</p> <p>Check this example:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.controller = [[ViewController2 alloc] init]; [self.controller addObserver:self forKeyPath:@"isEnabled" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"controller.isEnabled" options:NSKeyValueObservingOptionNew context:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.controller.isEnabled = !self.controller.isEnabled; // replace controller [self.controller removeObserver:self forKeyPath:@"isEnabled"]; self.controller = [[ViewController2 alloc] init]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.controller.isEnabled = !self.controller.isEnabled; }); }); } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"KVO %d %@ %p", self.controller.isEnabled, keyPath, self.controller); } </code></pre> <p>We'll get 4 KVO notifications:</p> <pre><code>KVO 1 controller.isEnabled 0x7fbbc2e4b4e0 <-- These 2 fire together when we toggle isEnbled KVO 1 isEnabled 0x7fbbc2e4b4e0 <-- So basically 1. and 2. behave the same KVO 0 controller.isEnabled 0x7fbbc2e58d30 <---- controller was replaced KVO 1 controller.isEnabled 0x7fbbc2e58d30 <---- Toggle on the new instance </code></pre> |
38,542,629 | 0 | <pre><code><div class="fb-page" data-href="https://www.facebook.com/Animantrn/" data-tabs="timeline" data-width="300" data-height="400" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/Animantrn/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/Animantrn/">XYZ Tech</a></blockquote></div> </code></pre> <p>Do you want this kind of page integration to web page?</p> |
33,093,104 | 0 | <pre><code>2751995 <-- address of identidade[0][0] 2751998 <-- address of identidade[1][0] 2752001 <-- address of identidade[2][0] 2752004 <-- address of ctbh[0][0] 2752007 <-- address of ctbh[1][0] 2752010 <-- address of ctbh[2][0] 2752013 <-- address of ctbah[0][0] 2752016 <-- address of ctbah[1][0] 2752019 <-- address of ctbah[2][0] </code></pre> <p>The addresses increase by three (within each <code>matriz3</code>) because you are iterating over the first dimension of each <code>matriz3</code>, not the second, like going down the leftmost column of a table without iterating along the rows. (The increment is steady when jumping from one <code>matriz3</code> to the next, because they occupy neighboring memory, because of the way you declared them and luck.)</p> <p>It is not clear what you are trying to do, but if you want to iterate over all elements, you must add a third nested loop-- because a <code>matriz4</code> is three-dimensional.</p> |
1,282,303 | 0 | Rebol Draw: how to load image from the internet? <p>This works </p> <pre><code>view layout [ image load http://i2.ytimg.com/vi/e3wShd_bX8A/default.jpg ] </code></pre> <p>But this doesn't</p> <pre><code>view layout [box 100x100 effect [draw [ image load http://i2.ytimg.com/vi/e3wShd_bX8A/default.jpg ] ] </code></pre> |
31,292,398 | 0 | <p>The way to do this is to use the <code><script></code> tag instead of <code><% ... %></code> for your code block:</p> <pre><code><script language="vbscript" runat="server"> Response.Write "<%= Count %>" </script> </code></pre> <p>Output:</p> <pre><code><%= Count %> </code></pre> |
2,374,361 | 0 | <p>While I don't know bash and don't see how <code>permutations</code> would solve your problem, it seems that <code>itertools.product</code> is a fairly straightforward way to do this:</p> <pre><code>>>> s = 'atgc' >>> d = dict(zip(s, 'tacg')) >>> import itertools >>> for i in itertools.product(s, repeat=10): sta = ''.join(i) stb = ''.join(d[x] for x in i) </code></pre> <p>while proposed method is valid in terms of obtaining all possible permutations with replacement of the <code>'atgc'</code> string, i.e., finding <code>sta</code> string, finding <code>stb</code> would be more efficient not through the dictionary look-up, but rather the translation mechanism:</p> <pre><code>>>> trans = str.maketrans(s, 'tacg') >>> for i in itertools.product(s, repeat=10): sta = ''.join(i) stb = sta.translate(trans) </code></pre> <p>Thanks to Dave, for highlighting more efficient solution.</p> |
38,109,983 | 0 | Cloud Sql Instance restart hanging for hours <p>My cloud sql instance became unresponsive today (unable to connect using my normal credentials via mysql-client or the google cloud console) so I decided to restart it to see if that would help, since I couldn't find any better debug suggestions. That was over two hours ago and the db still shows as restarting in my cloud sql dashboard. Others that had this issue were told to email [email protected] but it's been over an hour already with no response. I wonder if trying to kill the instance via google's api would clear things up but don't want to screw myself even more. </p> |
21,964,850 | 0 | <p>Try this:</p> <pre><code>echo 'class="active"'; </code></pre> |
16,121,678 | 0 | <p>In my case I had two models User and Admin and I am sticking with Devise, but I had a name collision issue with ActiveAdmin that requires me to remove the Admin model. But because there were so many references to Admin in devise, I had to take the steps below. I think it answers the original question above as well, though. I believe the correct way to do this is:</p> <p>1.Find the devise migration for the user model and roll it back <strong>[IMPORTANT: IF you DON'T want to remove the user table associated with Devise, then SKIP THIS STEP]</strong>:</p> <p><code>rake db:rollback VERSION=<insert the version number of the migration></code></p> <p>example: <code>rake db:rollback VERSION:20110430031806</code></p> <p>2.Run this command to remove Devise and associated files. <code>rails destroy devise Admin</code> (if Admin is the name of the model with user accounts).</p> <p>This produces this output:</p> <pre><code>invoke active_record remove db/migrate/20110430031806_devise_create_admins.rb remove app/models/admin.rb invoke test_unit remove test/unit/admin_test.rb remove test/fixtures/admins.yml route devise_for :admins </code></pre> <p>3.To completely remove Devise, you need to remove all references to it in your models, controllers and views. This is manual work. The answer above provides good details for finding this cruft, but was incomplete for my purposes. I hope this helps someone else.</p> |
7,515,056 | 0 | <p>thanks guys. i ended up setting the value of the option to <code>a</code> (my counter variable in the for loop). then i made the <code>var my_json</code> global. that way, in my onchange function for the select, i just do:</p> <pre><code>var passed_element_number = ($'#my_select_list').val(); var passed_id = my_json[passed_element_number].ID; var passed_otherfield = my_json[passed_element_number].OTHERFIELD; </code></pre> <p>i'm not sure why it wasn't letting me set the who json object as the value for the select option and then get the fields out 1 by 1 (probably my error, or maybe it's not possible), but this works ok....</p> |
36,449,620 | 0 | Specified sort in R <pre><code>id <- c(1:10) title <- c("Director", "Manager", "Associate", "Director", "Associate", "Director", "Manager", "Director", "Associate", "Director") df <- as.data.frame(cbind(id,title)) df[order(title),] </code></pre> <p>I want to sort this data by designation, but not alphabetically but in some specific order like (Director>Manager>Analyst) using tool R.</p> |
33,362,325 | 0 | <p>There are different errors or mistakes in your code. I will go through them from top to bottom.</p> <ol> <li><p>Your variable <code>a</code> is never used. You could delete the whole <code>double a=sc.nextInt();</code> line without affecting your program</p></li> <li><p>Your variable <code>m</code> is not initialized and has no value when you use it the first time</p></li> <li><p>When calling a method you don't specify the data types. The data types will be taken from the variables you pass into that method. So there could be methods with the same name but with different data types in their parameter list. Imagine a method <code>int sum(int a, int b)</code> taking the parameters <code>a</code> and <code>b</code> that have to be of integer type. You can easily imagine, that there may be a situation where you don't want to sum integers but doubles. So you could look out for a method <code>double sum (double a, double b)</code> and you could use this method just like the first one but this time for variables/literals of double type. Like I wrote you don't write the data types of the parameters you pass into a method because they are determined automatically. So your <code>Math.pow(..)</code> call has to look like <code>power = Math.pow(m, n);</code></p></li> <li><p>Your code is lacking two <code>}</code> at the end (for the main method and for the class)</p></li> <li><p>Try to use self-describing names for your variables. A counter named <code>i</code> may be ok but you could easily rename <code>m</code> to <code>base</code> and <code>n</code> to <code>exponent</code> and your program would automatically be easier to read.</p></li> </ol> |
30,040,231 | 0 | <p>I was able to solve this by putting Jasmine specific configuring up-front in a spec runner. In my <strong>spec/</strong> directory, I defined a file named <strong>spec_runner.js</strong> with the following:</p> <pre><code>var Jasmine = require('jasmine'), reporters = require('jasmine-reporters'); var junitReporter = new reporters.JUnitXmlReporter({ savePath: __dirname, consolidateAll: false }); var jasmine = new Jasmine(); jasmine.loadConfigFile("spec/support/jasmine.json"); jasmine.addReporter(junitReporter); jasmine.execute(); </code></pre> <p>Also inside <strong>spec/</strong>, I have a <strong>unit/</strong> and <strong>integration/</strong> directory where I have my unit and integration tests respectively. It's also important to have a <strong>spec/support/</strong> directory containing your configuration options for Jasmine. This directory should be created if you issue <strong>jasmine init</strong> from the root of your project.</p> <p><strong>spec/support/jasmine.json</strong> should look like the following for this example:</p> <pre><code>{ "spec_dir": "spec", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ] } </code></pre> <p>You should get JUnit XML output if you issue: <strong>jasmine spec/test_runner.js</strong> from the root of your project at a command line prompt.</p> <p>Lastly, to change the path to which your JUnit XML is written, you must change the <strong>savePath</strong> value in the object literal that is passed when creating a new instance of JUnitXmlReporter.</p> |
1,947,215 | 0 | <p>after searching for all available options , I found that the best way to set a variable in a process definition through the tag</p> |
5,833,026 | 0 | Extract IPTC information from JPEG using Javascript <p>I'm trying to extract IPTC photo caption information from a JPEG file using Javascript. (I know I can do this server-side, but I'm looking specifically for a Javascript solution.)</p> <p>I found <a href="https://gist.github.com/raw/161494/8b32c671198a24a947ad654c07e7e09b1470724f/Exif%20JS">this script</a>, which extracts EXIF information ... but I'm not sure how to adapt it to grab IPTC data.</p> <p>Are there any existing scripts that offer such functionality? If not, how would you modify the EXIF script to also parse IPTC data?</p> <p><b>UPDATE</b></p> <p>I've modified the EXIF script I linked above. It <i>sorta</i> does what I want, but it's not grabbing the right data 100 percent of the time.</p> <p>After line 401, I added:</p> <pre><code>else if (iMarker == 237) { // 0xED = Application-specific 13 (Photoshop IPTC) if (bDebug) log("Found 0xFFED marker"); return readIPTCData(oFile, iOffset + 4, getShortAt(oFile, iOffset+2, true)-2); } </code></pre> <p>And then elsewhere in the script, I added this function:</p> <pre><code>function readIPTCData(oFile, iStart, iLength) { exif = new Array(); if (getStringAt(oFile, iStart, 9) != "Photoshop") { if (bDebug) log("Not valid Photoshop data! " + getStringAt(oFile, iStart, 9)); return false; } var output = ''; var count = 0; two = new Array(); for (i=0; i<iLength; i++) { if (getByteAt(oFile, iStart + i) == 2 && getByteAt(oFile, iStart + i + 1) == 120) { var caption = getString2At(oFile, iStart + i + 2, 800); } if (getByteAt(oFile, iStart + i) == 2 && getByteAt(oFile, iStart + i + 1) == 80) { var credit = getString2At(oFile, iStart + i + 2, 300); } } exif['ImageDescription'] = caption; exif['Artist'] = credit; return exif; } </code></pre> <p>So let me now modify my question slightly. How can the function above be improved?</p> |
22,302,876 | 0 | <p>To answer your question: Yes, I experience the same problem. It seems to work fine when running my app. But when I run my XCTests on my device it seems that the keychain returns error -34018. The strange thing is that it doesn't happen when I run the tests on the simulator. </p> <p>EDIT: I found a solution which I have explained <a href="http://stackoverflow.com/a/22305193/1145289">in this answer</a></p> |
12,835,598 | 0 | <p>So in other words, your query is vulnerable with <code>SQL Injection</code>. Better use <code>PDO</code> or <code>MySQLi</code> Extension since you tagged `PHP.</p> <p>Take time to read on this article: <a href="http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php"><strong>Best way to prevent SQL injection in PHP?</strong></a></p> |
36,404,693 | 0 | Get latest version of table using hive union-all operator <p>I have versioned hive tables containing metrics partitioned by date that I want to join with other versioned hive tables containing different (but related) metrics also partitioned by date. For example: </p> <pre><code>Table A_v1 (exists for day 1) | col1 | col2 | | a1 | b1 | | a2 | b2 | Table A_v2 (exists for day 2, represents metrics derivation algorithm change) | col1 | col2 | | a3 | b3 | | a4 | b4 | Table B_v1 (exists for both day 1 and day 2) | col3 | col4 | | a1 | c1 | | a2 | c2 | | a3 | c3 | | a4 | c4 | </code></pre> <p>I know I can use the UNION ALL Hive operator to basically concatenate tables <code>A_v1</code> and <code>A_v2</code>. What I would like to do however is write something like</p> <pre><code>select a.col1, a.col2, b.col4 from union(A_v1, A_v2) a, B_v1 b where a.col1=b.col3 </code></pre> <p>I know the above syntax is wrong (intended only as a pseudo-code query) but is there some way of accomplishing the same thing in Hive?</p> |
23,710,767 | 0 | <p>Look at the query:</p> <pre><code>from HeadCategory where headCategoryName=Cash In Hand </code></pre> <p>That's not a valid query at all. What is Cash? What is Hand? A correct query would be</p> <pre><code>from HeadCategory where headCategoryName='Cash In Hand' </code></pre> <p>Learn to pass parameters correctly and safely to queries:</p> <pre><code>session.createQuery("from HeadCategory where headCategoryName = :name") .setString("name", headCategoryName) .list(); </code></pre> |
37,874,982 | 0 | <p>I assume redirect to <code>/</code> is handled by <code>BlogFront</code> handler. Seems you're hitting datastore eventual consistency. </p> <p><a href="http://stackoverflow.com/questions/27633835/google-app-engine-datastore-dealing-with-eventual-consistency">Google App Engine Datastore: Dealing with eventual consistency</a></p> <p><a href="http://stackoverflow.com/questions/15261099/gae-how-long-to-wait-for-eventual-consistency">GAE: How long to wait for eventual consistency?</a></p> |
40,971,656 | 0 | Data not storing in SQLite database <p>New to PHP. I am trying to create a register and Log In form using PHP and SQLite. Below is my code.</p> <p><strong>register.php</strong></p> <pre><code> <?php class MyDB extends SQLite3 { function __construct() { $this->open('db/db.db'); } } $db = new MyDB(); if(!$db) { echo $db->lastErrorMsg(); } else { echo 'Open successfull'; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>admin portal</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"> </head> <body> <div align="center"> <div class="form-area"> <form action="" method="post" enctype="multipart/form-data"> <input type="text" name="fname" value="" placeholder="First Name"> <input type="text" name="lname" value="" placeholder="Last Name"> <input type="text" name="username" value="" placeholder="Username"> <input type="email" name="email" value="" placeholder="Email"> <input type="password" name="password" value="" placeholder="Password"> <input type="password" name="cfpassword" value="" placeholder="Confirm Password"> <input type="submit" name="register" value="Register"><br> </form> </div> </div> </body> </html> <?php if (isset($_POST["submit"])) { $fname = $_POST['fname']; $lname = $_POST['lname']; $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $cfpassword = $_POST['cfpassword']; $sql = <<<EOF INSERT INTO USERS (ID, FNAME, LNAME, USERNAME, EMAIL, PASSWORD, PASSCONFIRM) VALUES (1, '$fname', '$lname', '$username', '$email', '$password', $cfpassword ); EOF; $ret = $db->exec($sql); if(!$ret){ echo $db->lastErrorMsg(); } else { echo "Registered Successfully\n"; } $db->close(); } ?> </code></pre> <p><strong>db.php</strong> </p> <pre><code><?php class MyDB extends SQLite3 { function __construct() { $this->open('db/db.db'); } } $db = new MyDB(); if(!$db) { echo $db->lastErrorMsg(); } else { echo 'Open successfull'; } $sql =<<<EOF CREATE TABLE USERS (ID INT PRIMARY KEY NOT NULL, EMAIL VARCHAR(250) NOT NULL, PASSWORD VARCHAR(250) NOT NULL, FNAME VARCHAR(250) NOT NULL, LNAME VARCHAR(250) NOT NULL, ACCESS VARCHAR(250) NOT NULL, IMAGE VARCHAR(250) NOT NULL, DATE DATETIME NOT NULL, USERNAME VARCHAR(250) NOT NULL, PASSCONFIRM VARCHAR(250) NOT NULL); EOF; $ret = $db->exec($sql); if(!$ret){ echo $db->lastErrorMsg(); } else { echo "Table created successfully"; } ?> </code></pre> <p>Please what's wrong with this code. The database opens but registered data is no stored into database. Would also appretiate if i can be linked to a material to read on SQLite3 and HTML forms.</p> |
14,199,897 | 0 | <p>Question abandoned because it seems unanswerable. Will update if I find a solution at a later date.</p> |
23,214,589 | 0 | <p>this values set in <a href="http://www.yiiframework.com/doc/api/1.1/CWebUser" rel="nofollow">CWebUser</a> class, in login method, look <a href="https://github.com/yiisoft/yii/blob/1.1.14/framework/web/auth/CWebUser.php#L715" rel="nofollow">this</a> and <a href="https://github.com/yiisoft/yii/blob/1.1.14/framework/web/auth/CWebUser.php#L227" rel="nofollow">this</a>.</p> <p>"8f9f85051824e063ad61f50fedc52f93" is prefix generated in method <a href="https://github.com/yiisoft/yii/blob/1.1.14/framework/web/auth/CWebUser.php#L542" rel="nofollow">getStateKeyPrefix</a></p> |
27,498,535 | 0 | how to config .htaccess to prevent www.parent.com/child access www.child.com <p>I have a unix shared hosting where I have: </p> <pre><code>/ .htaccess a.html .... child/ .htaccess b.html ...... </code></pre> <p>The www.parent.com points to /<br> The www.child.com points to /child </p> <p>I have to prevent the access to www.parent.com/child without stopping www.child.com from working.<br> The result can be a redirect, a 404 or access denied.<br> The .htaccess files are based on the html5boilerplate .htaccess file. </p> <p>I tried modified the /.htaccess without success:</p> <p>Attempt #1:</p> <pre><code><Directory /child> Order Deny,Allow Deny from all </Directory> </code></pre> <p>--> The child.com stopped working. </p> <p>Attempt #2:</p> <pre><code> RewriteCond %{HTTP_HOST} ^.*parent.com.*$ [NC] RewriteRule ^.*/child.*$ / [NC] </code></pre> <p>--> Nothing happens. I also tried different regex combinations. </p> <p>Attempt #3:</p> <pre><code> <IfModule mod_rewrite.c> RewriteCond %{REQUEST_URI} ^.*child.*$ [NC] RewriteRule ^ / [R=302.L] </IfModule> </code></pre> <p>--> Nothing happens. I known this one is brute force, but it was after trying main less aggressive options. </p> <p>I known that RewriteEngine is on, because this works: </p> <pre><code><IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteCond %{HTTP_HOST} !=localhost [NC] RewriteCond %{HTTP_HOST} !=127.0.0.1 RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule> </code></pre> |
10,222,978 | 0 | <p>Add backslashes to escape the qote</p> <pre><code>onmouseover="this.className=\''.$overclass.'\';" </code></pre> |
1,469,504 | 0 | <p>I think I found it:</p> <p>Check out this <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="nofollow noreferrer">link</a>. It will point you to the VS2008 code samples which contains a Dynamic Linq Query Library which contains the extension method below. This will allow you to go:</p> <pre><code>Object.OrderBy("ColumnName"); </code></pre> <p>Here is the extension methods, but you may want the whole library.</p> <pre><code>public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) { return (IQueryable<T>)OrderBy((IQueryable)source, ordering, values); } public static IQueryable OrderBy(this IQueryable source, string ordering, params object[] values) { if (source == null) throw new ArgumentNullException("source"); if (ordering == null) throw new ArgumentNullException("ordering"); ParameterExpression[] parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType, "") }; ExpressionParser parser = new ExpressionParser(parameters, ordering, values); IEnumerable<DynamicOrdering> orderings = parser.ParseOrdering(); Expression queryExpr = source.Expression; string methodAsc = "OrderBy"; string methodDesc = "OrderByDescending"; foreach (DynamicOrdering o in orderings) { queryExpr = Expression.Call( typeof(Queryable), o.Ascending ? methodAsc : methodDesc, new Type[] { source.ElementType, o.Selector.Type }, queryExpr, Expression.Quote(Expression.Lambda(o.Selector, parameters))); methodAsc = "ThenBy"; methodDesc = "ThenByDescending"; } return source.Provider.CreateQuery(queryExpr); } </code></pre> |
11,157,812 | 0 | <p>i like hamsterdb because i wrote it :)</p> <p><a href="http://www.hamsterdb.com" rel="nofollow">http://www.hamsterdb.com</a></p> <ul> <li>frequently used with database sizes of several GBs </li> <li>keys/values can have any size you wish</li> <li>random access + directional access (with cursors)</li> <li>concurrent reads: hamsterdb is thread safe, but not yet concurrent. i'm working on this.</li> <li>if your cache is big enough then access will be very fast (you can specify the cache size)</li> <li>written in c++</li> <li>python extension is available, but terribly outdated; will need fixes</li> </ul> <p>if you want to evaluate hamsterdb and need some help then feel free to drop me a mail.</p> |
16,242,306 | 0 | <p>Arjan van der Gaag made a gem specifically for this: <a href="https://github.com/avdgaag/nanoc-cachebuster" rel="nofollow">https://github.com/avdgaag/nanoc-cachebuster</a></p> <p><a href="http://arjanvandergaag.nl/blog/nanoc-cachebuster.html" rel="nofollow">To quote the man himself</a>:</p> <blockquote> <p>Usage is simple, as you only need to install the gem:</p> <pre><code>$ gem install nanoc-cachebuster </code></pre> <p>and require the gem and include the helpers to get going:</p> <pre><code># in default.rb require 'nanoc3/cachebuster' include Nanoc3::Helpers::CacheBusting </code></pre> <p>You can now use the #fingerprint method in your routing rules:</p> <pre><code>route '/assets/styles/' do item.identifier.chop + fingerprint(item) + '.' + item[:identifier] end </code></pre> <p>The gem will make sure that references to files you have fingerprinted will get updated when you compile your site.</p> </blockquote> |
35,813,904 | 0 | <p>If your compiler supports C++ 2011 then you can write the following way providing that letters will be listed in the order in which they are present in the string</p> <pre><code>#include <iostream> #include <string> #include <map> int main() { std::string s( "slowly" ); auto comp = [&]( char c1, char c2 ) { return s.find( c1 ) < s.find( c2 ); }; std::map<char, int, decltype( comp )> m( comp ); for ( char c : s ) ++m[c]; for ( auto p : m ) std::cout << p.first << ": " << p.second << std::endl; } </code></pre> <p>The program output is</p> <pre><code>s: 1 l: 2 o: 1 w: 1 y: 1 </code></pre> <p>Otherwise if the compiler does not support C++ 2011 then instead of the lambda you have to use a function class defined before main. Also youi should substitute the range-based for loop for an ordinary loop.</p> |
17,511,191 | 0 | <p>The <code><</code> and <code>></code> in code that is mixed with HTML usually cause trouble because these are special characters for html. It is always best to move your script to a separate file and link to it from the html.</p> |
13,420,281 | 0 | <p>You can store the values in MySQL as <code>INT UNSIGNED</code> which occupies 4 bytes (i.e. 32 bits).</p> <p>To insert the values into the database, you must use <code>sprintf()</code> with <code>%u</code> format on 32 bit machines:</p> <pre><code>$hash = crc32("The quick brown fox jumped over the lazy dog."); $stmt = $db->prepare('INSERT INTO mytable VALUES (:hash)'); $stmt->execute(array( ':hash' => sprintf('%u', $hash), )); </code></pre> <p><strong>Update</strong></p> <p>You could also make sure that you're always working with int32 types (signed long) on both 32 and 64-bit platforms. Currently, you can only accomplish this by using <a href="http://php.net/pack" rel="nofollow"><code>pack()</code></a> and <a href="http://php.net/unpack" rel="nofollow"><code>unpack()</code></a>:</p> <pre><code>echo current(unpack('l', pack('l', $hash))); // returns -2103228862 on both 32-bit and 64-bit platforms </code></pre> <p>The idea for this was contributed by <a href="http://stackoverflow.com/users/283851/mindplay-dk">mindplay.dk</a></p> |
14,942,189 | 0 | <p>You most definitely can by creating a new control template and set some triggers in it.</p> <p>See this <a href="http://stackoverflow.com/questions/1607066/wpf-watermark-passwordbox-from-watermark-textbox">SO post</a></p> |
17,860,884 | 0 | <p>As SLaks said best should be a List:</p> <pre><code>Dim sArray As New List(Of String) Dim fStream As New System.IO.FileStream("messages.txt", IO.FileMode.Open) Dim sReader As New System.IO.StreamReader(fStream) Do While sReader.Peek >= 0 sArray.add(sReader.ReadLine) Loop fStream.Close() sReader.Close() </code></pre> |
38,832,353 | 0 | <p>In Stata terms no loops are needed here at all, except those tacit in <code>generate</code> and <code>replace</code>. You want to set a counter going each time immediately after you hit a cutoff, and then identify counter values between 1 and 5. Here's some technique: </p> <pre><code>sysuse auto.dta, clear global cutoffs 3299,4424,5104,5788,10371 sort price gen counter = 0 if inlist(price, $cutoffs) replace counter = counter[_n-1] + 1 if missing(counter) gen wanted = inrange(counter, 1, 5) list price counter wanted +---------------------------+ | price counter wanted | |---------------------------| 1. | 3,291 . 0 | 2. | 3,299 0 0 | 3. | 3,667 1 1 | 4. | 3,748 2 1 | 5. | 3,798 3 1 | |---------------------------| 6. | 3,799 4 1 | 7. | 3,829 5 1 | 8. | 3,895 6 0 | 9. | 3,955 7 0 | 10. | 3,984 8 0 | |---------------------------| 11. | 3,995 9 0 | 12. | 4,010 10 0 | 13. | 4,060 11 0 | 14. | 4,082 12 0 | 15. | 4,099 13 0 | |---------------------------| 16. | 4,172 14 0 | 17. | 4,181 15 0 | 18. | 4,187 16 0 | 19. | 4,195 17 0 | 20. | 4,296 18 0 | |---------------------------| 21. | 4,389 19 0 | 22. | 4,424 0 0 | 23. | 4,425 1 1 | 24. | 4,453 2 1 | 25. | 4,482 3 1 | |---------------------------| 26. | 4,499 4 1 | 27. | 4,504 5 1 | 28. | 4,516 6 0 | 29. | 4,589 7 0 | 30. | 4,647 8 0 | |---------------------------| 31. | 4,697 9 0 | 32. | 4,723 10 0 | 33. | 4,733 11 0 | 34. | 4,749 12 0 | 35. | 4,816 13 0 | |---------------------------| 36. | 4,890 14 0 | 37. | 4,934 15 0 | 38. | 5,079 16 0 | 39. | 5,104 0 0 | 40. | 5,172 1 1 | |---------------------------| 41. | 5,189 2 1 | 42. | 5,222 3 1 | 43. | 5,379 4 1 | 44. | 5,397 5 1 | 45. | 5,705 6 0 | |---------------------------| 46. | 5,719 7 0 | 47. | 5,788 0 0 | 48. | 5,798 1 1 | 49. | 5,799 2 1 | 50. | 5,886 3 1 | |---------------------------| 51. | 5,899 4 1 | 52. | 6,165 5 1 | 53. | 6,229 6 0 | 54. | 6,295 7 0 | 55. | 6,303 8 0 | |---------------------------| 56. | 6,342 9 0 | 57. | 6,486 10 0 | 58. | 6,850 11 0 | 59. | 7,140 12 0 | 60. | 7,827 13 0 | |---------------------------| 61. | 8,129 14 0 | 62. | 8,814 15 0 | 63. | 9,690 16 0 | 64. | 9,735 17 0 | 65. | 10,371 0 0 | |---------------------------| 66. | 10,372 1 1 | 67. | 11,385 2 1 | 68. | 11,497 3 1 | 69. | 11,995 4 1 | 70. | 12,990 5 1 | |---------------------------| 71. | 13,466 6 0 | 72. | 13,594 7 0 | 73. | 14,500 8 0 | 74. | 15,906 9 0 | +---------------------------+ </code></pre> <p>In fact, your text says "the next five observations after" but your code implements not that only that, but the cutoff observation too. For the latter, use <code>inrange(counter, 0, 5)</code>. </p> <p>Understanding the principles explained <a href="http://www.stata.com/support/faqs/data-management/replacing-missing-values/" rel="nofollow">here</a> is crucial for this question. </p> <p>For <code>inrange()</code> and <code>inlist()</code> see their help entries and/or <a href="http://www.stata-journal.com/sjpdf.html?articlenum=dm0026" rel="nofollow">this paper</a>. </p> <p>So, what did you do wrong? </p> <p>This line </p> <pre><code> forval `i' = 0/25 { </code></pre> <p>in illegal unless you have previously defined the local macro <code>i</code> (and rather odd style even then). You perhaps meant </p> <pre><code> forval i = 0/25 { </code></pre> <p>although where the 25 comes from, given your problem statement, is unclear to me. The error message isn't especially helpful, but Stata is struggling to make sense of code with a hole in it, given that the local macro implied by your code is not defined. </p> |
38,324,594 | 0 | Funny grep situation <p>I have 99999 XML-files which I presume all contain the tag <code>"<A_ItemKey>"</code>.</p> <p>When I run this command:</p> <pre><code>cat *.xml | grep "<A_ItemKey>" | wc -l </code></pre> <p>I get the result 75140</p> <p>However if I run this command:</p> <pre><code>grep "<A_ItemKey>" *.xml | wc -l </code></pre> <p>I get the result 99999 (which I believe is correct).</p> <p>Why don't these two commands show the same results?</p> <p>Many thanks in advance:-)</p> <p>/Paul</p> |
19,812,756 | 0 | <p>You shutdown the input, you got EOFException when reading the input. That's exactly what's supposed to happen. You have to catch EOFException anyway when reading an ObjectInputStream. There is no 'complex problem' here at all. Just poor exception handling.</p> |
20,006,336 | 0 | <p>You should use the <a href="http://developer.android.com/reference/java/math/BigInteger.html#modPow%28java.math.BigInteger,%20java.math.BigInteger%29" rel="nofollow"><code>BigInteger.modPow</code></a> method or an equivalent solution that uses an efficient <a href="http://en.wikipedia.org/wiki/Modular_exponentiation" rel="nofollow">modular exponentiation</a> algorithm.</p> |
10,169,662 | 0 | <p>That package is a runtime package containing the VCL. You presumably also need to deploy rtl90.bpl for the RTL and possibly some others. By enabling runtime packages you are promising to deploy those packages where the executable can find them.</p> <p>You have 3 main options:</p> <ol> <li>Deploy the packages to a location that is contained in the PATH variable. Usually this means modifying PATH. You should never write to the system directory. It is owned by the system and you should respect that.</li> <li>Deploy the packages to the same directory as the executable file.</li> <li>Disable runtime packages and therefore build a single self-contained executable. The RTL/VCL code will be statically linked into your executable.</li> </ol> <p>Option 1 is poor in my view. Relying on the PATH variable and the ability to modify it is fragile. Option 2 works but seems rather pointless in comparison with option 3. You deploy more files and larger files when you choose 2, so why choose it.</p> <p>In summary I recommend option 3. Statically link all RTL/VCL code into your executable.</p> <p>The only situation where option 2 wins, in my view, is when you have multiple related executables that are all deployed to the same directory. In that situation sharing the RTL/VCL code can make sense.</p> |
32,779,952 | 0 | Windows Charts Forms C# Auto labeling of the points on X <p>I'm having some issues with Windows charts and the points displayed on the x-axis. </p> <p>I have two plots of data in a line chart based upon set data points, e.g. 200,400,600,800,1000. I also use a 3rd & 4th series to colour areas depending which line is higher. To do this I've had to add extra points where the two lines intersect. This then throws out the labels on the x axis as the chart automatically labels the points something odd such as:</p> <p>|<br> |<br> |<br> | </p> <p>=========================<br> 120......370.....590.....730......850</p> <p>Is there a way I can explicitly specify the datapoints on the axis that I want to use, other than the min-maximum value function?</p> |
2,038,097 | 0 | randomized binary search trees <p>Randomized binary search trees like treap give a good performance (in the order of O(log n)) with high probability while avoiding complicated (and costly) rebalancing operations that are needed for deterministic balanced trees like AVL, red-blackm, AA, etc.</p> <p>We know that if we add random keys to a simple BST, we can expect it is reasonably balanced. A simple reason is that the number of heavily non-balanced trees for n nodes it's much lower than the number of "almost balanced" trees and hence, a random order for the insertion of the keys is likely to end up with an acceptable tree.</p> <p>In this case, in "The Art of Computer Programming", Knuth gives a little bit more than 1.3*lg2(n) as the average length of a path which is rather good. He also says that <em>deleting</em> a random key from the a random tree preserves its randomness (and hence its good average balancing).</p> <p>It seems, then, that a binary search tree where keys are inserted and deleted in a random order would most likely give performance in the order of O(log n) for all three operations: search, insert and delete.</p> <p>That said, I wonder if the following approach would give the same good properties:</p> <ul> <li>take an hash function h(x) that is known to be "good" (e.g. it ensure an even spread of the keys)</li> <li>use the order set by h(x) on the keys instead of the ordering on k. </li> <li>in case of collision, order according the key. That should be rare if the hash key is good enough and the range of the hash function is much bigger than the set of the keys.</li> </ul> <p>To give an example a BST for the key { 4, 3, 5 , 1, 2} inserted in that order, would be:</p> <pre><code> 4 / \ 3 5 /\ 1 2 </code></pre> <p>Assuming the hash function would map them to (respectively) {221,142,12,380,18) we would get.</p> <pre><code> 221(4) / \ 142(3) 380(1) / \ 12(5) 18(2) </code></pre> <p>The key point is that a "regular" BST may degenerate because the keys are inserted according the same ordering relation that is used to store them in the tree (their "natural" ordering, for example the alphabetical order of string) but the hash function induces an ordering on the keys that is completely unrelated to the "natural" one and, hence, should give the same results as if the keys were inserted in random order.</p> <p>A strong assumption is that the hash function is "good", but it's not an unreasonable one, I think.</p> <p>I didn't find any reference to a similar approach in the literature so it might be completely wrong, but I can't see why!</p> <p>Do you see any drawback in my reasoning? Anyone has already attempted doing it?</p> |
17,402,672 | 0 | CSS width wierdness in Chrome and Firefox with Pure CSS <p>To start off with, I'm quite new to CSS still so I hope I haven't done anything horrendously stupid.</p> <p>Basically, I have a design I'm doing built using <a href="http://www.purecss.io" rel="nofollow">Pure</a> and the width is playing up in Google Chrome, while it works as intended in Firefox.</p> <p>Here's a link to what I've done: <a href="http://egf.me/Rushd/rushdtest.html" rel="nofollow">http://egf.me/Rushd/rushdtest.html</a> and screenshots:</p> <ul> <li>Firefox: <a href="http://i.imgur.com/mn3GIbT.png" rel="nofollow">http://i.imgur.com/mn3GIbT.png</a></li> <li>Chrome: <a href="http://i.imgur.com/44jLC6J.png" rel="nofollow">http://i.imgur.com/44jLC6J.png</a></li> </ul> <p>If you have a look at the page source, I haven't really done anything in my own CSS to change anything (I commented it all out as a check just to be sure) so I'm guessing I'm somehow using Pure wrong, since their own site renders fine on Chrome.</p> <p>Also, inspecting the elements with Chrome's dev tools show that the div elements which should be next to each other have widths which add up to less than that of the parent. And nothing there seems to have buffers or padding. Also, if I manually reduce the widths to be very very slightly less, Chrome seems to magically fix everything.</p> |
7,975,049 | 0 | <p>Netbeans has an option (in the project properties under c++), to have the file path as absolute or relative. So I all had to do was, set the relative option and push the changes . The project started working for everyone ! VOILA !!!!!!!!</p> |
1,338,585 | 0 | <p>I've found that <a href="http://craigsworks.com/projects/qtip/" rel="nofollow noreferrer">qTip</a> has met all of my tooltip needs:</p> |
35,245,296 | 0 | Calculating an average with an array in Java; Homework <p>I have a homework assignment, and these are the 5 questions,</p> <blockquote> <ol> <li>What is the total of all the elements in the array.</li> <li>What is the average of all the elements in the array.</li> <li>What are the largest and smallest numbers in the array. (one loop for both questions)</li> <li>Display all the odd numbers in the array. Use the modulus function (%) on page 46.</li> <li>Print every other number in the array.</li> </ol> </blockquote> <p>I am having trouble finding the average, or writing the code that finds it. </p> <pre><code>public class JavaApplication { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int nums[] = {33,66,77,88,60,91,87,92,76,90}; int sum = 0; for (int i = 0; i < 10; i++){ sum +=nums[i]; } System.out.println("The sum is " + sum); int average = 0; Here for (int i = 0; i < nums.length; i++) { | sum = sum + nums[i]; | } System.out.println("Average value is " + average); and here. int min, max; min = max = nums [0]; for(int i=1; i < 10; i++) { if(nums[i] < min) min = nums[i]; if(nums[i] > max) max = nums[i]; } System.out.println("min and max: " + min + " " + max); } } </code></pre> <p>This is my second week in this class, So please explain what needs to be added or not and thanks :)</p> |
9,497,778 | 0 | <p>You need to use single quotes instead of double quotes. </p> <p>You can find the MySQL date functions at <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html</a></p> |
12,824,913 | 0 | <p>SO, you don't want the lower bound to be inclusive, right?</p> <pre><code>SET @value = 2; SELECT * FROM table WHERE from > @value AND @value <= to; </code></pre> |
28,863,904 | 0 | <p>Basically you can get the element at a specific position in a list by using</p> <pre><code>list.get(index); </code></pre> <p>or in your case</p> <pre><code> playerItems.get(currentChoice); </code></pre> |
31,890,260 | 0 | Plugin created using java code is not working <p>My in tension is to create a plugin at at the run time using java code.First a created executable jar using the <code>java.util.jar.JarOutputStream</code> and used <code>javax.tools.JavaCompiler</code> for compiling the classes. And I was able to execute the jar from command line properly.</p> <p>Then I tried to create a pluign by including the plugin.xml file in the jar package and compiled the classes by using the above packages and plugin is created with out any errors.</p> <p>But I was using an extension point for the plugin and it is not detecting while I am putting my plugin in the eclipse product.</p> <p>Then I exported it by using eclispe export option and it is working properly for me. I unzipped both the jar created programtically and by using eclispe and the contents are same.</p> <p>How can I solve this issue?</p> |
11,717,856 | 0 | access div in iframe parent <p>I have a page which contains an iframe to another page, what I am looking for is to click something inside the iframe, which can then access or more specifically hide a div in the parent. I know some JQuery but for some reason just sit there blankly at the code editor when I try to write it on my own</p> |
27,554,301 | 0 | <p>The problem is that you have the same id for both accordions (<em>which is invalid html to start with</em>) which makes the plugin always match the first one.</p> <p>If you use classes it works fine</p> <pre><code><div class="accordion"> <h3>Home</h3> <div class="accordion"> <h3>Sub-Div1</h3> <div> <p>This is a sub-div</p> </div> </div> </div> </code></pre> <p>and</p> <pre><code>$(".accordion").accordion({ header: "> h3:not(.item)", heightStyle: "content", active: false, collapsible: true }); </code></pre> <p>Demo at <a href="http://jsfiddle.net/gaby/xmq8xhvp/" rel="nofollow">http://jsfiddle.net/gaby/xmq8xhvp/</a></p> |
2,041,501 | 0 | <p>In Autofac you use Modules for this purpose. Groups of related components are encapsulated in a module, which is configured by the programmatic API.</p> <p>Autofac's XML configuration has support for modules, so once you've decided to use one in an applicaiton, you can register the module (rather than all the components it contains) in the config file.</p> <p>Modules support parameters that can be forwarded to the components inside, e.g. connection strings, URIs, etc.</p> <p>The documentation here should get you started: <a href="http://code.google.com/p/autofac/wiki/StructuringWithModules" rel="nofollow noreferrer">http://code.google.com/p/autofac/wiki/StructuringWithModules</a></p> <p>HTH</p> <p>Nick</p> |
33,845,630 | 0 | Database with HTTP API out of the box <p>I am looking for a database with HTTP REST API out of the box. I want to skip the middle tier between client and database.</p> <p>One option I found is a HTTP Plugin for MySQL which operates with JSON format <a href="http://blog.ulf-wendel.de/2014/mysql-5-7-http-plugin-mysql/" rel="nofollow">http://blog.ulf-wendel.de/2014/mysql-5-7-http-plugin-mysql/</a></p> <p>Can someone suggest other similar solutions? I want to save development time and effort for some queries.</p> |
34,407,807 | 0 | <p>If your list of equipment is <code>list_of_shields</code>, you can achieve what you want like this:</p> <pre><code>choice = raw_input('choose a valid shield from the list please:') while choice not in list_of_shields: choice = raw_input('choose a valid shield from the list please:') </code></pre> |
31,202,400 | 0 | Menu field is not closing, when clicked on menu <p>I have one question with my code.</p> <p>I have created this <strong><a href="http://jsfiddle.net/mustafaozturk74/b6rhxaxd/10/">DEMO</a></strong> from jsfiddle.net</p> <p>When you click the red div then the menu will opening but if you click the menu items the menu area will not closing. </p> <p>What do i need to close the menu area when clicked the menu?</p> <pre><code><div class="p_change" tabindex="0" id="1"> <div class="pr_icon"><div class="icon-kr icon-globe"></div>CLICK</div> <div class="pr_type"> <div class="type_s change_pri md-ripple" data-id="0"><div class="icon-pr icon-globe"></div>1</div> <div class="type_s change_pri md-ripple" data-id="1"><div class="icon-pr icon-contacs"></div>2</div> <div class="type_s change_pri md-ripple" data-id="2"><div class="icon-pr icon-lock-1"></div>3</div> </div> </div> <div class="p_change" tabindex="0" id="2"> <div class="pr_icon"><div class="icon-kr icon-globe"></div>CLICK</div> <div class="pr_type"> <div class="type_s change_pri md-ripple" data-id="0"><div class="icon-pr icon-globe"></div>1</div> <div class="type_s change_pri md-ripple" data-id="1"><div class="icon-pr icon-contacs"></div>2</div> <div class="type_s change_pri md-ripple" data-id="2"><div class="icon-pr icon-lock-1"></div>3</div> </div> </div> </code></pre> <p>JS</p> <pre><code>$(document).ready(function() { $('.pr_icon').on('click',function(e){ // Change Post Privacy $('.change_pri').on('click',function(event){ event.stopPropagation(); var dataid = $(this).attr('data-id'); var id = $(this).closest('.p_change').attr('id'); var class_name = $(this).find(".icon-pr").attr("class"); class_name = class_name.replace(/icon\-pr\s+/gi, ""); $(this).closest(".p_change").find(".icon-kr").removeClass().addClass("icon-kr " + class_name); $.ajax({ type: "POST", url: "change_id.php", data: { dataid : dataid, id: id } }).success(function(html){ if (html.trim() === "1") { // Do Something } else { // Do something } }); }); }); </code></pre> |
21,847,566 | 0 | How to use checkbox in ruby on rails <p>I have a code of checkbox below in ruby on rails:</p> <pre><code><%= check_box(:Monday,{:id => "Monday",:value => "Monday"}) %> </code></pre> <p>But, it shows only the checkbox but not shows its text i.e "Monday".</p> <p>So what should I do to display the text of checkbox, kindly suggest me, waiting for reply. Thanks</p> |
40,681,324 | 0 | C++ STL vector Deep erase <p>How to deep erase a vector?</p> <p>Consider the following code.</p> <pre><code>#include<algorithm> #include<iostream> #include<iterator> #include<vector> using namespace std; int main(){ vector<int> v {1,2,3,4,5}; for_each(begin(v),end(v),[&v](int& n){ static auto i = (int)0; if(n == 2){ v.erase ( begin(v) +2, end(v)); } cout << n << " having index " << i++ << endl; }); v.erase ( begin(v) +2, end(v)); cout << v.size() << endl << v[4] << endl; } </code></pre> <p>Output is</p> <pre><code>1 having index 0 2 having index 1 3 having index 2 4 having index 3 5 having index 4 2 4 </code></pre> <p>What I want is accessing v[i] for any i from 2 to 4 to be invalid and compiler to throw an error.</p> <p>In simpler words how to deep erase a vector?</p> |
12,224,659 | 0 | <p>Your Action method is returning a collection of Objects, that would be structured like this;</p> <pre><code>[ { tagName: result1}, {tagName: result2} ... ] </code></pre> <p>Because you use the result directly for the autocomplete, the method needs to return data in one of the <a href="http://jqueryui.com/demos/autocomplete/#remote-jsonp" rel="nofollow">following two formats</a>;</p> <blockquote> <p>The data from local data, a url or a callback can come in two variants:</p> <p>An Array of Strings:<br> <code>[ "Choice1", "Choice2" ]</code></p> <p>An Array of Objects with label and value properties:<br> <code>[ { label: "Choice1", value: "value1" }, ... ]</code></p> </blockquote> <p>Alternatively, you could take the results and map them appropriately to one of the above formats before posting them to the response method.</p> |
19,888,087 | 0 | <p>You can use a common selector for your 'a lot of styles!':</p> <pre><code>#f1, #f2 { a lot of styles! } #f1 { order: 1; } #f2 { order: 2; } </code></pre> <p>A proper alternative, to reduce the first selector, is to assign a class to each element, for example .common and replacing <code>#f1, #f2, ...</code> by <code>.common</code></p> <p>More information : <a href="http://www.w3schools.com/cssref/sel_element_comma.asp" rel="nofollow">CSS element,element Selector</a></p> |
35,966,987 | 0 | Storing data to Flash in Wireless Sensor Networks on loosing connection <p>I have to implement an optimal solution to store values of sensor into NOR Flash with time stamps on loosing connection and send to the central server when connection comes back. A queue like implementation is needed. Will anyone please suggest an implementation Open source or proprietary, or any algorithms for same. It should have properties like wear leveling, write fail safe and erase fail safe.</p> <p>It is a 256Mb Spansion NOR flash(S25FL256S). I need to store only less than 64bytes (including time stamp) every 60 seconds, if there is no connection. Page size of flash is 256 bytes and sector size is 256KB. Erase cycle endurance of flash is 100,000</p> |
2,728,780 | 0 | <p>The Linq provider in NHibernate 2.x is very limited and it usually has problems with projections of entities.</p> <p>Your query probably works with the included Linq provider in NHibernate 3.x.</p> <p>HQL is easy:</p> <pre><code>select Sender from Enquiry where Created < current_timestamp </code></pre> <p>(You can also use a parameter for DateTime.Now)</p> |
39,048,052 | 0 | <p>You have to concatenate <code>$row['mykey']</code> to <code>stmt2</code> instead of including it directly because it might be interpreted as a string.</p> <p>It should be like this</p> <pre><code>$stmt2 = $conn->prepare("SELECT client_id, companyname, contact, contractor_lock FROM table two WHERE contractor_lock = ?"); $stmt2->execute($row['mykey']); </code></pre> |
39,492,677 | 0 | <p>The problem is the attaching thing, use <code>Add</code> instead.</p> <p>When you do the <code>context.sample_set.Attach(s1);</code>, what it really does is create the instance of all related objects in the new context and then add them to the sample_set, that why it works.</p> <p>When you try to <code>context.sample_set.Attach(s2);</code>, it tries to create again all shared <code>samples</code>, that is why it throws the exception.</p> <p>So my suggestion to you is :</p> <pre><code>context.sample_set.Add(s1); context.sample_set.Add(s2); context.SaveChanges(); </code></pre> <p>I hope it helps.</p> |
32,979,963 | 0 | Make POST JSon requests to HBase REST by CURL with PHP <p>[Solved] I have an HBase 1.1.2 standalone installation on Ubuntu 14 and I need to retrieve and update data by PHP POST request (I cannot use GET because of length limit) through a REST server. I was going to use a curl PHP object but my problem is I don't understand how to format the request (in JSON or XML) to be submitted in POST at REST server.</p> <p>Can anyone help me?</p> <p>Thanks</p> <p>Let me add my object i would like to use for all the request: getting rows by key and set\create row. My problem is how make $DATA field according different action.</p> <pre><code>function method($method, $data=NULL, & $http_code, & $response) { $ch = curl_init(); if(isset($header)) { curl_setop(CURLOPT_HTTPHEADER, $header); } curl_setopt($ch, CURLOPT_URL, "http://" . $GLOBALS['DBDW']['hostname'] . $GLOBALS['DBDW']['port']); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //nuovi curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json', 'Connection: ' . ( $this->options['alive'] ? 'Keep-Alive' : 'Close' ), )); // fine nuovi switch(strtoupper($method)){ case 'DELETE': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); // i have to set CURLOPT_POSTFIELDS and if yes how? break; case 'POST': curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // how setting CURLOPT_POSTFIELDS and if yes how? break; case 'GET': curl_setopt($curl, CURLOPT_HTTPGET, 1); // i have to set CURLOPT_POSTFIELDS and if yes how? break; } $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $this->log(LOG_DEBUG, "HTTP code: " . $http_code, __FILE__, __LINE__, __CLASS__); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); if ($response === false) { $this->log(LOG_ERR, "HTTP " . $method . " failed on url '" . $url . "'", __FILE__, __LINE__, __CLASS__); $this->log(LOG_ERR, "cURL error: " . $curl_errno . ":" . $curl_error, __FILE__, __LINE__, __CLASS__); $http_code=ERR_COMMUNICATION_FAILED; return false; } return true; } </code></pre> |
6,573,600 | 0 | <p>The MIME type for JPEG is <code>image/jpeg</code>. You have <code>image/jpg</code>.</p> |
12,726,216 | 0 | Saving a DIV as an Image <p>I have:</p> <pre><code>echo" <div id=IwantToSaveThisWholeDivAsAnImage)> <div id=OneOfMultipleDivs> <table>multiple tables rendered here </table> </div> </div>"; </code></pre> <p>I have tried (one of many):</p> <pre><code>$html_code = " <html> <head> <title>Image</title> <style> body { font-family:verdana; font-size:11px; color:black } </style> </head> <body> my tables here </body> </html>"; $img = imagecreate("300", "600"); $c = imagecolorallocate($img, 0, 0, 0); $c2 = imagecolorallocate($img, 255, 255, 255); imageline($img,0,0,300,600,$c); imageline($img,300,0,0,600,$c2); $white = imagecolorallocate($img, 255, 255, 255); imagettftext($img, 9, 0, 1, 1, $white, "arial.tff", '$html_code'); header("Content-type: image/jpeg"); imagejpeg($img); </code></pre> <p>I'm not allowed to use outside libaries. Read that it can be done with GD, but I have been unsuccessful thus far. Any ideas and help would be greatly appreciated! UB</p> |
22,006,372 | 0 | <p>it's better to add error recovery mechanism (if the request fails you will lose your token) and use asynchronous request (send token in background)</p> <p><strong>In your AppDelegate.m:</strong></p> <pre><code>- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { NSString * token = [NSString stringWithFormat:@"%@", deviceToken]; //Format token as you need: token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"apnsToken"]; //save token to resend it if request fails [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"apnsTokenSentSuccessfully"]; // set flag for request status [DataUpdater sendUserToken]; //send token } </code></pre> <p>To send token create new class (or use one of existing): <strong>DataUpdater.h</strong></p> <pre><code>#import <Foundation/Foundation.h> @interface DataUpdater : NSObject + (void)sendUserToken; @end </code></pre> <p><strong>DataUpdater.m</strong></p> <pre><code>#import "DataUpdater.h" @implementation DataUpdater + (void)sendUserToken { if ([[NSUserDefaults standardUserDefaults] boolForKey:@"apnsTokenSentSuccessfully"]) { NSLog(@"apnsTokenSentSuccessfully already"); return; } NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myhost.com/filecreate.php?token=%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"apnsToken"]]]; //set here your URL NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (error == nil) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"apnsTokenSentSuccessfully"]; NSLog(@"Token is being sent successfully"); //you can check server response here if you need } }]; } @end </code></pre> <p>Then you can call [DataUpdater sendUserToken]; in your controllers when internet connection appears, or periodically, or in <strong>-(void)viewDidLoad or -(void)viewWillAppear</strong> methods</p> <p>My advises: 1) I use AFNetworking to send async request and check server JSON response 2) Some times it's better to use services such as Parse to work with push notifications</p> |
32,857,191 | 0 | C++ Help (Integer Pattern) <p>The Question :</p> <p>If the sequence of digits in X forms a substring of the sequence of digits in Y, it outputs "X is a substring of Y"; otherwise, if the sequence of digits in X forms a subsequence of the sequence of digits in Y, then it outputs "X is a subsequence of Y"; otherwise, it outputs "X is neither substring nor subsequence of Y".</p> <p><strong>DO NOT</strong> use arrays or strings in this program</p> <p>The output should be as follows </p> <hr> <p>Enter Y : 239847239 </p> <p>Enter X : 847</p> <p>X is substring of Y</p> <p>Enter Y : 239847239</p> <p>Enter X : 3923</p> <p>X is subsequence of Y</p> <p>Enter Y : 239847239</p> <p>Enter X : 489</p> <p>X is neither substring nor subsequence of Y</p> <hr> <p>And below is what I got so far... (haven't coded anything for subsequence as i was clueless)</p> <p>I know my coding is very unefficient and is only suitble to use for the above model output. Any improvements or comments how to fix this would be greatly appreciated.</p> <pre><code> #include <cmath> #include <iostream> using namespace std; int main() { cout << "Enter Y: " ; int Y; cin >> Y; cout << "Enter X: "; int X; cin >> X; if (Y >= X){ // Below are all the possibilities of substrings up to 9 decimal places. if( X == (Y % 10)) cout << "X is substring of Y"; else if (X == (Y % 100)) cout << "X is substring of Y"; else if (X == (Y % 1000)) cout << "X is substring of Y"; else if (X == (Y % 10000)) cout << "X is substring of Y"; else if (X == (Y % 100000)) cout << "X is substring of Y"; else if (X == (Y % 1000000)) cout << "X is substring of Y"; else if (X == (Y % 10000000)) cout << "X is substring of Y"; else if (X == (Y % 100000000)) cout << "X is substring of Y"; else if (X == (Y % 1000000000)) cout << "X is substring of Y"; else cout << "X is neither substring nor subsequence of Y"; } else cout << "neither subsequence nor subset"; // prints out when Y is less than X. return 0; </code></pre> <p>}</p> |
14,221,583 | 0 | <p>Getting location from Android device go through this :</p> <p><a href="http://stackoverflow.com/questions/12286152/get-current-location-during-app-launch/12286444#12286444">Get current location during app launch</a></p> <p><strong>Process Initiated from device :</strong> now you have coordinates now in you application so what you can do on launching of a web make an AsyncTask to hit the webservice passing these longitude and latitude and get the corresponding message as response.</p> <p><strong>Process Initiated from server:</strong> for that you need to implement a GCM push functionality in your application what server needs to do it will push a message to device and after getting the push do the same thing as mentioned in process initiated from device.</p> |
16,115,641 | 0 | Is an image that is display: none loaded by the browser? <p>Are these images loaded by the browser:</p> <pre><code><div style="display: none"> <img src="/path/to/image.jpg" alt=""> </div> </code></pre> <p>or </p> <pre><code><img src="/path/to/image.jpg" alt="" style="display: none;"> </code></pre> <p>By "loaded by the browser" I mean, are these images loaded immediately by the browser so that they are available right away when the image is no longer displayed as none using css. Will it be taken from cache or loaded anew the moment it is no longer displayed as none?</p> |
39,261,796 | 0 | <p>Using <code>$unwind</code> and then <code>$group</code> with the tag as the key will give you each tag in a separate document in your result set: </p> <pre><code>db.collection_name.aggregate([ { $unwind: "$tags" }, { $match: { "tags.type": "machine" } }, { $group: { _id: "$tags.code" } }, { $project:{ _id:false code: "$_id" } } ]); </code></pre> <p>Or, if you want them put into an array within a single document, you can use <code>$push</code> within a second <code>$group</code> stage: </p> <pre><code>db.collection_name.aggregate([ { $unwind: "$tags" }, { $match: { "tags.type": "machine" } }, { $group: { _id: "$tags.code" } }, { $group:{ _id: null, codes: {$push: "$_id"} } } ]); </code></pre> <p>Another user suggested including an initial stage of <code>{ $match: { "tags.type": "machine" } }</code>. This is a good idea if your data is likely to contain a significant number of documents that do not include <strong>"machine"</strong> tags. That way you will eliminate unnecessary processing of those documents. Your pipeline would look like this:</p> <pre><code>db.collection_name.aggregate([ { $match: { "tags.type": "machine" } }, { $unwind: "$tags" }, { $match: { "tags.type": "machine" } }, { $group: { _id: "$tags.code" } }, { $group:{ _id: null, codes: {$push: "$_id"} } } ]); </code></pre> |
36,894,812 | 0 | <p>other solution for your question.</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var app = angular.module("testApp", []); app.controller('testCtrl', function($scope){ $scope.data = [{ "fleetcheckitemid": "1", "checkitemdesc": "Engine oil level", "answers": [{ "fleetcheckid": "1", "checkvaluedesc": "Ok" }, { "fleetcheckid": "2", "checkvaluedesc": "Low" }, { "fleetcheckid": "3", "checkvaluedesc": "Top-Up Required" }] }, { "fleetcheckitemid": "2", "checkitemdesc": "Water level", "answers": [{ "fleetcheckid": "1", "checkvaluedesc": "Ok" }, { "fleetcheckid": "2", "checkvaluedesc": "Low" }, { "fleetcheckid": "3", "checkvaluedesc": "Top-Up Required" }] }, { "fleetcheckitemid": "3", "checkitemdesc": "Brake fluid level", "answers": [{ "fleetcheckid": "1", "checkvaluedesc": "Ok" }, { "fleetcheckid": "2", "checkvaluedesc": "Low" }, { "fleetcheckid": "3", "checkvaluedesc": "Top-Up Required" }] }]; angular.forEach($scope.data,function(value,key){ console.log(value.fleetcheckitemid); console.log(value.checkitemdesc); angular.forEach(value.answers,function(v,k){ console.log(v.fleetcheckid); console.log(v.checkvaluedesc); }); }); });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="testApp" ng-controller="testCtrl"> </div></code></pre> </div> </div> </p> |
32,825,500 | 0 | <p>I find very strange the differences between the assembler results of the following code compiled without optimization and with -Os optimization.</p> <pre><code>#include <stdio.h> int main(){ int i; for(i=3;i>2;i++); printf("%d\n",i); return 0; } </code></pre> <p>Without optimization the code results:</p> <pre><code>000000000040052d <main>: 40052d: 55 push %rbp 40052e: 48 89 e5 mov %rsp,%rbp 400531: 48 83 ec 10 sub $0x10,%rsp 400535: c7 45 fc 03 00 00 00 movl $0x3,-0x4(%rbp) 40053c: c7 45 fc 03 00 00 00 movl $0x3,-0x4(%rbp) 400543: eb 04 jmp 400549 <main+0x1c> 400545: 83 45 fc 01 addl $0x1,-0x4(%rbp) 400549: 83 7d fc 02 cmpl $0x2,-0x4(%rbp) 40054d: 7f f6 jg 400545 <main+0x18> 40054f: 8b 45 fc mov -0x4(%rbp),%eax 400552: 89 c6 mov %eax,%esi 400554: bf f4 05 40 00 mov $0x4005f4,%edi 400559: b8 00 00 00 00 mov $0x0,%eax 40055e: e8 ad fe ff ff callq 400410 <printf@plt> 400563: b8 00 00 00 00 mov $0x0,%eax 400568: c9 leaveq 400569: c3 retq </code></pre> <p>and the output is: -2147483648 (as I expect on a PC)</p> <p>With -Os the code results:</p> <pre><code>0000000000400400 <main>: 400400: eb fe jmp 400400 <main> </code></pre> <p>I think the second result is an error!!! I think the compiler should have compiled something corresponding to the code:</p> <p>printf("%d\n",-2147483648);</p> |
8,007,594 | 0 | <p>If you have the <code>rsvp_event</code> permission for the user you can RSVP them to any event they have permission to join (i.e public events) See here: <a href="https://developers.facebook.com/docs/reference/api/event/#attending" rel="nofollow">https://developers.facebook.com/docs/reference/api/event/#attending</a></p> |
6,149,810 | 0 | Why does the iterator.hasNext not work with BlockingQueue? <p>I was trying to use the iterator methods on a BlockingQueue and discovered that hasNext() is non-blocking - i.e. it will not wait until more elements are added and will instead return false when there are no elements. </p> <p>So here are the questions :</p> <ol> <li>Is this bad design, or wrong expectation?</li> <li>Is there a way to use the blocking methods of the BLockingQueue with its parent Collection class methods (e.g. if some method were expecting a collection, can I pass a blocking queue and hope that its processing will wait until the Queue has more elements)</li> </ol> <p>Here is a sample code block </p> <pre><code>public class SomeContainer{ public static void main(String[] args){ BlockingQueue bq = new LinkedBlockingQueue(); SomeContainer h = new SomeContainer(); Producer p = new Producer(bq); Consumer c = new Consumer(bq); p.produce(); c.consume(); } static class Producer{ BlockingQueue q; public Producer(BlockingQueue q) { this.q = q; } void produce(){ new Thread(){ public void run() { for(int i=0; i<10; i++){ for(int j=0;j<10; j++){ q.add(i+" - "+j); } try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } } }; }.start(); } } static class Consumer{ BlockingQueue q; public Consumer(BlockingQueue q) { this.q = q; } void consume() { new Thread() { public void run() { Iterator itr = q.iterator(); while (itr.hasNext()) System.out.println(itr.next()); } }.start(); } } } </code></pre> <p>This Code only prints the iteration once at the most. </p> |
14,381,642 | 0 | <p>How can we tell without seeing the XML? It could be both. Depends on if the 50,000 in referring to parent nodes, which most likely it is, which would mean you have 49,999 left. But with that said, who knows.</p> <p>Edit...I just realized maybe you are talking about a google sitemap. You can have 50,000 parent nodes, the inner nodes are not counted.</p> |
3,956,421 | 0 | <p>Sorry if my vb is wrong as im a c# guy!! but I hope this should give you a guidance. I do something similar in c#. Good luck</p> <pre><code>Protected Sub dvPictureInsert_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvPictureInsert.ItemInserting Dim cancelInsert As Boolean = False Dim imageUpload As FileUpload = CType(dvPictureInsert.FindControl("imageUpload"), FileUpload) If Not imageUpload.HasFile Then cancelInsert = True Else If Not imageUpload.FileName.ToUpper().EndsWith(".JPG") Then cancelInsert = True 'Invalid image file! Else Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(imageUpload.PostedFile.InputStream) If image.Width > 600 Or image.Height > 700 Then cancelInsert = True End If End If End If //etc </code></pre> |
300,964 | 0 | <p>Users can totally handle grids. It's more intuitive than an edit button and a detail form.</p> <p>However, is this application a multiple user application? Could the underlying data be changed by more than one user at a time? If so, then you have some concurrency design decisions to make, and sometimes, that can be easier to solve when users can only edit one row at a time.</p> <p>It smells a little fishy though, and I suspect your programmer is making convenient excuses because it's easier for him to design read-only grids in a master / detail pattern.</p> <p>Stick with your gut instinct. :)</p> |
12,253,719 | 0 | Java - parsing text file - Scanner, Reader or something else? <p>I'd like to parse an UTF8 encoded text file that may contain something like this:</p> <pre><code>int 1 text " some text with \" and \\ " int list[-45,54, 435 ,-65] float list [ 4.0, 5.2,-5.2342e+4] </code></pre> <p>The numbers in the list are separated by commas. Whitespace is permitted but not required between any number and any symbol like commas and brackets here. Similarly for words and symbols, like in the case of <code>list[</code></p> <p>I've done the quoted string reading by forcing Scanner to give me single chars (setting its delimiter to an empty pattern) because I still thought it'll be useful for reading the ints and floats, but I'm not sure anymore.</p> <p>The Scanner always takes a complete token and then tries to match it. What I need is try to match as much (or as little) as possible, disregarding delimiters.</p> <p>Basically for this input</p> <pre><code>int list[-45,54, 435 ,-65] </code></pre> <p>I'd like to be able to call and get this</p> <pre><code>s.nextWord() // int s.nextWord() // list s.nextSymbol() // [ s.nextInt() // -45 s.nextSymbol() // , s.nextInt() // 54 s.nextSymbol() // , s.nextInt() // 435 s.nextSymbol() // , s.nextInt() // -65 s.nextSymbol() // ] </code></pre> <p>and so on.</p> <p>Or, if it couldn't parse doubles and other types itself, at least a method that takes a regex, returns the biggest string that matches it (or an error) and sets the stream position to just after what it matched.</p> <p>Can the Scanner somehow be used for this? Or is there another approach? I feel this must be quite a common thing to do, but I don't seem to be able to find the right tool for it.</p> |
8,537,249 | 0 | <p>You can't distinguish between identical objects.</p> |
3,315,350 | 0 | <p>Consider the following test case:</p> <pre><code>CREATE TABLE accounts (id int); CREATE TABLE emails (id int, account_id int, type_name varchar(10), order_id int); INSERT INTO accounts VALUES (1), (2), (3), (4); INSERT INTO emails VALUES (1, 1, 'name', 1); INSERT INTO emails VALUES (2, 1, 'no-name', 1); INSERT INTO emails VALUES (3, 2, 'name', 1); INSERT INTO emails VALUES (4, 2, 'no-name', 1); INSERT INTO emails VALUES (5, 3, 'name', 2); </code></pre> <p>Then this works as expected:</p> <pre><code>SELECT * FROM `accounts` LEFT OUTER JOIN `emails` ON emails.account_id = accounts.id WHERE (emails.type_name = 'name' AND emails.order_id = 1); +------+------+------------+-----------+----------+ | id | id | account_id | type_name | order_id | +------+------+------------+-----------+----------+ | 1 | 1 | 1 | name | 1 | | 2 | 3 | 2 | name | 1 | +------+------+------------+-----------+----------+ 2 rows in set (0.00 sec) </code></pre> <p>The problem with your second query is that it can return a <code>NULL</code> row if there is an account with no email, as is the case of account number 4: </p> <pre><code>SELECT * FROM `accounts` LEFT OUTER JOIN `emails` ON emails.account_id = accounts.id WHERE (!(emails.type_name = 'name' AND emails.order_id = 1) OR emails.id IS NULL); +------+------+------------+-----------+----------+ | id | id | account_id | type_name | order_id | +------+------+------------+-----------+----------+ | 1 | 2 | 1 | no-name | 1 | | 2 | 4 | 2 | no-name | 1 | | 3 | 5 | 3 | name | 2 | | 4 | NULL | NULL | NULL | NULL | +------+------+------------+-----------+----------+ 4 rows in set (0.01 sec) </code></pre> <p>Why wouldn't this be enough for a mutually exclusive result set with no <code>NULL</code> rows?:</p> <pre><code>SELECT * FROM `accounts` LEFT OUTER JOIN `emails` ON emails.account_id = accounts.id WHERE NOT (emails.type_name = 'name' AND emails.order_id = 1) +------+------+------------+-----------+----------+ | id | id | account_id | type_name | order_id | +------+------+------------+-----------+----------+ | 1 | 2 | 1 | no-name | 1 | | 2 | 4 | 2 | no-name | 1 | | 3 | 5 | 3 | name | 2 | +------+------+------------+-----------+----------+ 3 rows in set (0.00 sec) </code></pre> |
18,729,798 | 0 | SImple Drupal 7 online store (send email to clients, no online payments) <p>i want to create a simple online store using Drupal 7, and i just need to send an email for the client after choosing the item (with info about the items). no need to pay online or anything.</p> <p>is there any module that does that? if not how can i build such module?</p> |
7,168,331 | 0 | <p>Solved,</p> <pre><code>public abstract class CustomViewPage<T> : ViewPage<T> where T : class { } </code></pre> |
6,572,084 | 0 | <p>you can set the Username and tag of req.</p> <p>this is the example of imageview. req.</p> <pre><code>UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]; ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[self.arr objectAtIndex:i]]]; [req setUsername:[NSString stringWithFormat:@"%i",i]]; [req setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:imgV,@"imgV",nil]]; [req setDelegate:self]; [req startAsynchronous]; [imgV setContentMode:UIViewContentModeScaleToFill]; [imgV setClipsToBounds:YES]; [imgV setTag:kTagImageViewInScrollView]; [scr2 addSubview:imgV]; [scr2 setDelegate:self]; [imgV release]; imgV=nil; </code></pre> <p>and in requestFinished</p> <pre><code>- (void)requestFinished:(ASIHTTPRequest *)request { [(UIImageView*)[[request userInfo] valueForKey:@"imgV"] setImage:[UIImage imageWithData:[request responseData]]]; } </code></pre> |
19,443,987 | 0 | <p>Way 1:</p> <blockquote> <ul> <li>Adv : Persistent</li> <li>Disadv : More cumbersome, you'll have to manage opening file, preserving old content, closing properly, etc.</li> </ul> </blockquote> <p>Way 2:</p> <blockquote> <ul> <li>Adv : Easy to implement</li> <li>Disadv : Not persistent</li> </ul> </blockquote> <p>Console is good to track development of App and de-bugging purposes. If you're looking at logging content from multiple users and then somehow retrieving it to further process it, then go with Way 1, else, Way 2 should suffice.</p> |
19,086,518 | 0 | <p>Sorry. I got my answer for my own question.</p> <p>Here is codes</p> <pre><code>[[self tableView] setSectionIndexColor:[UIColor redColor]]; [[self tableView] setSectionIndexBackgroundColor:[UIColor clearColor]]; </code></pre> |
32,276,005 | 0 | <p>After several formatting errors and incorrect / missing inline table aliases...</p> <pre><code>SELECT * FROM ( SELECT TIME FROM table1 UNION ALL SELECT TIME FROM table2 ) B WHERE TIME = ( SELECT MAX(TIME) FROM ( SELECT TIME FROM table1 union all SELECT TIME FROM table2) a ) </code></pre> |
3,127,459 | 0 | <p>The parts of the rewrite rule break down as follows:</p> <ol> <li><p>RewriteRule <br /> Indicates this line will be a rewrite rule, as opposed to a rewrite condition or one of the other rewrite engine directives</p></li> <li><p>^(.*)$ <br /> Matches all characters <code>(.*)</code> from the beggining <code>^</code> to the end <code>$</code> of the request</p></li> <li><p>/index.php/$1 <br /> The request will be re-written with the data matched by <code>(.*)</code> in the previous example being substituted for <code>$1</code>.</p></li> <li><p>[L] <br /> This tells mod_rewrite that if the pattern in step 2 matches, apply this rule as the "Last" rule, and don't apply anymore.</p></li> </ol> <p>The <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html" rel="nofollow noreferrer">mod_rewrite documentation</a> is really comprehensive, but admittedly a lot to wade through to decode such a simple example.</p> <p>The net effect is that all requests will be routed through <code>index.php</code>, a pattern seen in many model-view-controller implementations for PHP. <code>index.php</code> can examine the requested URL segments (and potentially whether the request was made via GET or POST) and use this information to dynamically invoke a certain script, without the location of that script having to match the directory structure implied by the request URI.</p> <p>For example, <code>/users/john/files/index</code> might invoke the function <code>index('john')</code> in a file called <code>user_files.php</code> stored in a scripts directory. Without mod_rewrite, the more traditional URL would probably use an arguably less readable query string and invoke the file directly: <code>/user_files.php?action=index&user=john</code>.</p> |
32,771,927 | 0 | Why is 857 larger than 1000 and 1001? Javascript <p>I have the following problem, my function accepts an array that contains 4 arrays, each element is a number. The functions must return the largest element of each array. </p> <pre><code>function largestOfFour(arr) { var largest = []; for (var i = 0; i < arr.length; i++) { largest.push(arr[i].sort().pop()); } console.log(largest); return largest; } largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); </code></pre> <p>Results: </p> <pre><code>Array [ 5, 27, 39, 857 ] </code></pre> <p>Apparently it works, but when I tried with the last array [1000, 1001, 857, 1], in which 1000 and 1001 are larger than 857 I'm getting 857. Why does it happen?</p> |
17,477,899 | 0 | Sylius Instalation - ProductBundle is Missing <p>I'm new in sylius development and i'm getting trouble to install some sylius bundles. I want to build a small online store and i pretend to use SyliusProductBundle, SyliusCartBundle and the required SyliusResourcesBundle.</p> <p>How can i add them to my project?</p> <p>Just to test, i've downloaded and installed the sylius full stack and i've noticed that the ProductBundle isn't there. I've read the documentation of both ProductBundle and CartBundle. The ProductBundle was replaced?</p> <p>So, i have 2 problems:</p> <p>1 - Figure out what bundles should i use (i think Product and Cart but ProcuctBundle is aparently missing) 2 - How to install this standalone bundles via composer.</p> <p>I'm using symfony 2.3.1</p> <p>Can anyone help me? Thanks</p> |
32,139,557 | 1 | Pandas for large(r) datasets <p>I have a rather complex database which I deliver in CSV format to my client. The logic to arrive at that database is an intricate mix of Python processing and SQL joins done in sqlite3.</p> <p>There are ~15 source datasets ranging from a few hundreds records to as many as several million (but fairly short) records.</p> <p>Instead of having a mix of Python / sqlite3 logic, for clarity, maintainability and several other reasons I would love to move ALL logic to an efficient set of Python scripts and circumvent sqlite3 altogether.</p> <p>I understand that the answer and the path to go would be Pandas, but could you please advise if this is the right track for a rather large database like the one described above?</p> |
16,816,114 | 0 | <p>Location Manager is not reliable on some phones. You may notice that if you launch google maps all of a sudden your app works. That is because Google Maps kicked the LocationManager. Which also means that there is programmatic way to kick that dude alive. So I used </p> <pre><code>HomeScreen.getLocationManager().requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { } }); </code></pre> <p>After the above code, I called what ever I needed from LocationManager and it kinda worked. If not try out the new API's <code>LocationClient</code>. This is suppose to be much better, battery, accuracy and reliability.</p> |
25,610,938 | 0 | <p>The problem isn't that the plugin changes your structure (although it does add some <code>ins</code> elements, which I don't agree with), it's that the plugin doesn't fire a <code>change</code> event for the converted radio controls, and setting the <code>checked</code> property interactively doesn't appear to do so either.</p> <p>Since the plugin author doesn't publish an API for this use case, it's hard to know whether this is by design or oversight, but the source code definitely doesn't fire the event when the slider is clicked:</p> <pre><code>this.bearer.find('.slider-level').click( function(){ var radioId = $(this).attr('data-radio'); slider.bearer.find('#' + radioId).prop('checked', true); slider.setSlider(); }); </code></pre> <p>Your options, as I see them:</p> <ol> <li>Contact the API author and ask for a bug fix, or the intended way to support this case <ul> <li>Downside: Time: dependent on the author to respond</li> </ul></li> <li>Attach your "check" function to the <code>click</code> event of the <code>.slider-level</code> class, as the API does. <ul> <li>Downside: Brittle: future versions of the plugin may attach the behavior to different selectors</li> </ul></li> <li>Attach your function to the <code>click</code> event of your radio group, and catch click events on the bubble <ul> <li>Downside: Inefficient: It will check for every click in the radio control</li> </ul></li> </ol> <p>Here's a sample implementation of option 3. <strong><a href="http://jsbin.com/pisida/2/edit" rel="nofollow">DEMO</a></strong>.</p> <pre><code>$(document).ready(function () { $(".radios").radiosToSlider(); }); var makeIsRadioGroupChecked = function(selector) { var $radioGroup = $(selector); return function isRadioGroupChecked() { return $radioGroup.find(':checked').length > 0; }; }; var isOptionsChecked = makeIsRadioGroupChecked('#optionsRadioGroup'); var isSizeChecked = makeIsRadioGroupChecked('#sizeRadioGroup'); var areAllGroupsChecked = function() { return isOptionsChecked() && isSizeChecked(); }; var alertIfAllGroupsChecked = function() { if (areAllGroupsChecked()) { alert("all answered"); } }; $('.radios').on('click', alertIfAllGroupsChecked); </code></pre> |
31,538,589 | 0 | <p>because print format is %u is unsigned int,but the c is a unsigned char. printf parse c point as a unsigned int point, program read undefined buffer.</p> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.