id
int64
4
73.8M
title
stringlengths
10
150
body
stringlengths
17
50.8k
accepted_answer_id
int64
7
73.8M
answer_count
int64
1
182
comment_count
int64
0
89
community_owned_date
stringlengths
23
27
creation_date
stringlengths
23
27
favorite_count
int64
0
11.6k
last_activity_date
stringlengths
23
27
last_edit_date
stringlengths
23
27
last_editor_display_name
stringlengths
2
29
last_editor_user_id
int64
-1
20M
owner_display_name
stringlengths
1
29
owner_user_id
int64
1
20M
parent_id
null
post_type_id
int64
1
1
score
int64
-146
26.6k
tags
stringlengths
1
125
view_count
int64
122
11.6M
answer_body
stringlengths
19
51k
3,068,168
How to read a key pressed by the user and display it on the console?
<p>I am trying to ask user "enter any key" and when that key is pressed it shows that "You Pressed 'Key'". Can you help what's wrong in this code?</p> <p>This is what I have written:</p> <pre><code>using System; class Program { public static void Main(string[] args) { Console.Write("Enter any Key: "); char name = Console.Read(); Console.WriteLine("You pressed {0}", name); } } </code></pre>
3,068,195
7
1
null
2010-06-18 08:34:36.62 UTC
0
2022-08-23 15:37:25.407 UTC
2016-10-15 18:54:16.997 UTC
null
6,400,526
null
370,090
null
1
16
c#|console|keyboard
52,745
<p>Try</p> <pre><code>Console.WriteLine("Enter any Key: "); ConsoleKeyInfo name = Console.ReadKey(); Console.WriteLine("You pressed {0}", name.KeyChar); </code></pre>
2,635,086
MIPS processors : Are they still in use? Which other architecture should I learn?
<p>I've been programming for x86 &amp; x86-64 in assembly language for few months. Now, I want to move on to some different kind of processors. </p> <p>MIPS, SPARC, PowerPC, Itanium, ARM of these I found ARM is being <strong>widely</strong> use. But the books I see that tutorials &amp; books teach about MIPS more than all these other architectures.</p> <p>Why is MIPS so popular? Are MIPS processors still in use? Which architecture should I go for?</p> <p>My background:</p> <p>I'm a student in Electronics dept. I'm also a high level programmer.</p>
2,653,951
7
4
null
2010-04-14 05:28:35.25 UTC
10
2019-09-20 04:13:26.433 UTC
2010-04-14 05:33:48.467 UTC
null
193,653
null
193,653
null
1
26
assembly|x86|arm|mips
29,976
<p><a href="http://www.cavium.com" rel="noreferrer">Cavium Networks</a> and <s><a href="http://www.rmicorp.com/" rel="noreferrer">Raza Microelectronics</a></s> <a href="http://www.broadcom.com/products/Processors" rel="noreferrer">Broadcom</a> are two large MIPS chipmakers. See <a href="http://mips.com/" rel="noreferrer"><s>MIPS</s> Imagination Technologies' website</a> for more info.</p> <p><s>One thing that MIPS does and ARM doesn't is 64-bit.</s></p> <p>Update as of 2013: Broadcom does not appear to have introduced new MIPS products since 2006, and Cavium appears to be transitioning to 64-bit ARM v8. Imagination Technologies acquired MIPS in late 2012. (Ironically, Apple, their #1 customer, were the first to market with ARM v8.)</p> <p>The writing is on the wall for MIPS.</p> <hr> <p>MIPS is the cleanest successful RISC. PowerPC and (32-bit) ARM have so many extra instructions (even a few operating modes, 32-bit ARM especially) that you could almost call them CISC. SPARC has a few odd features and Itanium is composed entirely of odd features. The latter two are more dead than MIPS.</p> <p>So if you learn MIPS, you will be able to transfer 100% of that knowledge to other RISCs (give or take delay slots), but you still have to learn about lots of odd instructions on PPC, a whole ton-o-junk on 32-bit ARM, and register windows on SPARC. Itanium isn't RISC so it's hard to say anything, besides don't learn Itanium.</p> <p>I have not studied 64-bit ARM yet but it is likely to have most of the positive qualities of MIPS, being essentially a clean-slate design.</p>
2,959,820
Convert existing project into Android project in Eclipse?
<p>How do you convert an existing project into an Android project in Eclipse?</p> <p>In particular, I want to convert a plain old Java project into an Android Library project.</p> <p>Thanks.</p>
2,959,849
7
1
null
2010-06-02 16:58:33.99 UTC
20
2018-09-06 20:13:11.667 UTC
null
null
null
null
143,378
null
1
51
android|eclipse
39,841
<p>What subsystem/plugin are you using for Eclipse Android development?</p> <p>Generally speaking, the process is called "changing the project nature" e.g.,</p> <p><a href="http://enarion.net/programming/tools/eclipse/changing-general-project-to-java-project/" rel="noreferrer">http://enarion.net/programming/tools/eclipse/changing-general-project-to-java-project/</a></p>
2,461,667
Centering strings with printf()
<p>By default, <code>printf()</code> seems to align strings to the right.</p> <pre><code>printf("%10s %20s %20s\n", "col1", "col2", "col3"); /* col1 col2 col3 */ </code></pre> <p>I can also align text to the left like this:</p> <pre><code>printf("%-10s %-20s %-20s", "col1", "col2", "col3"); </code></pre> <p>Is there a quick way to center text? Or do I have to write a function that turns a string like <code>test</code> into <code>(space)(space)test(space)(space)</code> if the text width for that column is 8?</p>
2,461,825
9
0
null
2010-03-17 11:06:24.553 UTC
10
2021-08-13 20:52:34.327 UTC
null
null
null
null
217,649
null
1
31
c|printf
94,673
<p>printf by itself can't do the trick, but you could play with the "indirect" width, which specifies the width by reading it from an argument. Lets' try this (ok, not perfect)</p> <pre><code>void f(char *s) { printf("---%*s%*s---\n",10+strlen(s)/2,s,10-strlen(s)/2,""); } int main(int argc, char **argv) { f("uno"); f("quattro"); return 0; } </code></pre>
2,883,373
Simple CSS: Text won't center in a button
<p>In Firefox 'A' shows in the middle, on Chrome/IE it doesn't:</p> <pre><code>&lt;button type="button" style="width:24px; text-align:center; vertical-align:middle"&gt;A&lt;/button&gt; </code></pre> <p>Note the following has the same results:</p> <pre><code>&lt;button type="button" style="width:24px;"&gt;A&lt;/button&gt; </code></pre> <p>Edit: Now seems to be fixed in Chrome 5.0</p>
2,883,407
9
2
null
2010-05-21 15:22:14.54 UTC
6
2022-07-27 17:20:32.473 UTC
2017-04-26 16:14:31.6 UTC
null
1,033,581
null
333,733
null
1
52
css
167,305
<p>Testing this in Chrome, you need to add</p> <pre><code>padding: 0px; </code></pre> <p>To the CSS. </p>
2,879,473
How to fix "failed codesign verification" of an iPhone project?
<p>Last night, the iPhone project was built perfectly.</p> <p>This morning, I installed <code>XCode 3.2.3</code> in a <em>separate</em> folder. When I open the same project in the old <code>XCode 3.2.2</code> and re-built the project. I got this warning:</p> <blockquote> <p>Application failed codesign verification. The signature was invalid, or it was not signed with an Apple submission certificate. (-19011)</p> </blockquote> <p>How can I fix it? Thanks!</p>
2,890,706
13
3
null
2010-05-21 03:58:01.697 UTC
10
2012-01-04 23:18:01.973 UTC
null
null
null
null
88,597
null
1
31
iphone|xcode
36,303
<p>I had the same problem, seems 3.2.3 messes with codesigning. I fixed it by re-running the 3.2.2 installer, no need to uninstall anything.</p>
23,682,511
How to store user session in AngularJS?
<p>I have just started using AngularJS and I'm trying to store user session on my AngularApp.</p> <p>First step to submit username and password works. After that, I store the <code>username</code> retrieved from the service in the <code>$rootScope</code>. The next page can display the <code>username</code> stored. </p> <p>But after a refresh, the <code>$rootScope</code> is empty.</p> <p>I'm trying to do an authentication system as simple as possible. </p> <pre><code>myApp.controller('loginController', ['$scope', '$rootScope', '$location', 'AuthService', '$route', function ($scope, $rootScope, $location, AuthService, $route) { $scope.login = function (credentials) { AuthService.login(credentials).then(function (response) { if(response.data == "0"){ alert("Identifiant ou mot de passe incorrect"); } else { // response.data is the JSON below $rootScope.credentials = response.data; $location.path("/"); } }); }; }]); </code></pre> <p><code>AuthService.login()</code> makes a <code>$http</code> request.</p> <p>JSON </p> <pre><code> {user_id: 1, user_name: "u1", user_display_name: "Steffi"} </code></pre> <p>HTML : </p> <pre><code> &lt;div&gt;Welcome {{ credentials.user_display_name }}!&lt;/div&gt; </code></pre> <p>I tried a lot of tutorials, but I can't make session work. I already used UserApp but it's not ok to me. I would like to create my own <strong>simple</strong> authentication.</p>
23,682,835
3
1
null
2014-05-15 15:23:59.553 UTC
8
2020-05-09 19:33:11.86 UTC
2020-05-09 19:33:11.86 UTC
null
21,926
null
387,912
null
1
11
javascript|angularjs|authentication|session|cookies
84,228
<p><code>$rootScope</code> will always reset when the page refreshes, since it's a single-page app.</p> <p>You need to use something that persists client-side, such as a cookie or sessionStorage (as they both have an expiration time). Take a look at the documentation for <code>$cookieStore</code>: <a href="https://docs.angularjs.org/api/ngCookies/service/$cookieStore" rel="nofollow noreferrer">https://docs.angularjs.org/api/ngCookies/service/$cookieStore</a></p> <p>Remember, sensitive session information should be encrypted.</p>
40,104,350
React.js, Is `DOMContentLoaded` equal with `componentDidMount`?
<p>People always say that you can get the <code>dom</code> in <code>componentDidMount</code>.</p> <p>Is that mean <code>componentDidMount</code> and <code>DOMContentLoaded</code> are synchronous, or does it mean when <code>componentDidMount</code>, the <code>dom</code> is always ready?</p>
40,105,151
2
0
null
2016-10-18 09:23:02.343 UTC
9
2020-11-03 03:22:24.953 UTC
2020-11-03 03:22:24.953 UTC
null
6,463,558
null
6,463,558
null
1
22
reactjs|dom
22,941
<p>The <code>DOMContentLoaded</code> event is <em>exclusive</em> to when the <a href="https://developer.mozilla.org/en/docs/Web/Events/DOMContentLoaded" rel="noreferrer">entire HTML page loads</a>. Therefore, this event is only fired once and only once, throughout the entirety of the web page's lifetime. <code>componentDidMount</code>, on the other hand, is called when a React component is rendered. Therefore, it is entirely possible for <code>componentDidMount</code> to be called several times, albeit for entirely different instances of the same component's class.</p> <p>And yes, the browser's DOM is always in the "ready state", at the time when a <code>componentDidMount</code> event is called.</p>
10,741,311
MATLAB graph plotting: assigning legend labels during plot
<p>I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command 'hold on;', and then plot each of the data, followed by this to get my legend:</p> <pre><code>legend('DataSet1', 'DataSet2') % etcetera </code></pre> <p>However, the (multiple) datasets I am plotting on the same axes are not necessarily the same datasets each time. I am plotting up to six different sets of data on the same axes, and there could be any combination of these shown (depending on what the user chooses to display). Obviously that would be a lot of elseif's if I wanted to setup the legend the traditional way.</p> <p>What I really would like to do is assign each DataSet a name <em>as it is plotted</em> so that afterwards I can just call up a legend of all the data being shown.</p> <p>...Or, any other solution to this problem that anyone can think of..?</p>
10,741,633
5
0
null
2012-05-24 16:13:30.087 UTC
6
2015-02-08 07:59:03.05 UTC
null
null
null
null
741,739
null
1
10
matlab|legend
42,154
<p>One option is to take advantage of the <code>'UserData'</code> property like so:</p> <pre><code>figure; hold on plot([0 1], [1 0], '-b', 'userdata', 'blue line') plot([1 0], [1 0], '--r', 'userdata', 'red dashes') % legend(get(get(gca, 'children'), 'userdata')) % wrong legend(get(gca, 'children'), get(get(gca, 'children'), 'userdata')) % correct </code></pre> <p>Edit: As the questioner pointed out, the original version could get out of order. To fix this, specify which handle goes with which label (in the fixed version, it is in the correct order).</p>
10,279,116
Conditional JOIN different tables
<p>I want to know if a user has an entry in <strong>any</strong> of 2 related tables.</p> <p><strong>Tables</strong></p> <pre><code>USER (user_id) EMPLOYEE (id, user_id) STUDENT (id, user_id) </code></pre> <p>A User may have an employee and/or student entry. How can I get that info in one query? I tried:</p> <pre><code>select * from [user] u inner join employee e on e.user_id = case when e.user_id is not NULL then u.user_id else null end inner join student s on s.user_id = case when s.user_id is not NULL then u.user_id else null end </code></pre> <p>But it will return only users with entries in <strong>both</strong> tables.</p> <h3><a href="http://sqlfiddle.com/#!3/90216/2" rel="noreferrer">SQL Fiddle example</a></h3>
10,279,231
7
0
null
2012-04-23 10:49:13.463 UTC
8
2021-08-27 17:25:03.123 UTC
2020-06-20 09:12:55.06 UTC
null
-1
null
575,376
null
1
29
sql|sql-server-2008|join|conditional
82,736
<p>You could use an outer join:</p> <pre><code>select * from USER u left outer join EMPLOYEE e ON u.user_id = e.user_id left outer join STUDENT s ON u.user_id = s.user_id where s.user_id is not null or e.user_id is not null </code></pre> <p>alternatively (if you're not interested in the data from the EMPLOYEE or STUDENT table)</p> <pre><code>select * from USER u where exists (select 1 from EMPLOYEE e where e.user_id = u.user_id) or exists (select 1 from STUDENT s where s.user_id = u.user_id) </code></pre>
10,326,729
Don't drop zero count: dodged barplot
<p>I am making a dodged barplot in ggplot2 and one grouping has a zero count that I want to display. I remembered seeing this on <a href="http://groups.google.com/group/ggplot2/browse_thread/thread/b520e0be08f5d100" rel="noreferrer">HERE</a> a while back and figured the <code>scale_x_discrete(drop=F)</code> would work. It does not appear to work with dodged bars. How can I make the zero counts show?</p> <p>For instance, (code below) in the plot below, type8~group4 has no examples. I would still like the plot to display the empty space for the zero count instead of eliminating the bar. How can I do this?</p> <p><img src="https://i.stack.imgur.com/uuvcJ.png" alt="enter image description here"></p> <pre><code>mtcars2 &lt;- data.frame(type=factor(mtcars$cyl), group=factor(mtcars$gear)) m2 &lt;- ggplot(mtcars2, aes(x=type , fill=group)) p2 &lt;- m2 + geom_bar(colour="black", position="dodge") + scale_x_discrete(drop=F) p2 </code></pre>
10,326,906
6
0
null
2012-04-26 03:14:39.57 UTC
13
2018-05-16 14:26:24.39 UTC
2015-11-24 20:28:06.487 UTC
null
2,966,110
null
1,000,343
null
1
46
r|ggplot2
24,220
<p>The only way I know of is to pre-compute the counts and add a dummy row:</p> <pre><code>dat &lt;- rbind(ddply(mtcars2,.(type,group),summarise,count = length(group)),c(8,4,NA)) ggplot(dat,aes(x = type,y = count,fill = group)) + geom_bar(colour = "black",position = "dodge",stat = "identity") </code></pre> <p><img src="https://i.stack.imgur.com/D767u.png" alt="enter image description here"></p> <p>I thought that using <code>stat_bin(drop = FALSE,geom = "bar",...)</code> instead would work, but apparently it does not.</p>
18,346,849
How to get CMake to use existing Makefile?
<p>I have an existing project (<code>wvdial</code>) that has a working makefile. I'm trying to integrate it into our main build process which uses CMake. Can anyone advise on how to do this? I made an attempt below based on some of the other projects we build but the makefile is never called. All I want to do is call the makefile for wvdial and include the binary in the <code>.deb</code> package we build.</p> <pre> cmake_minimum_required(VERSION 2.6) SET(COMPONENT_NAME roots-vendor-wvdial) SET(DEBIAN_PACKAGE_VERSION 1.6.1) SET(WVDIAL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) SET(WVDIAL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(WVDIAL_INSTALLED ${CMAKE_CURRENT_BINARY_DIR}) ADD_CUSTOM_TARGET( wvdial ALL DEPENDS ${WVDIAL_INSTALLED} ) IF (${ROOTS_TARGET_ARCHITECTURE} STREQUAL "armhf") SET(TARGET_FLAG "--host=arm-linux-gnueabihf") ENDIF() ADD_CUSTOM_COMMAND( WORKING_DIRECTORY ${WVDIAL_BINARY_DIR} OUTPUT ${WVDIAL_INSTALLED} COMMAND env CXXFLAGS=${ROOTS_COMPILER_FLAGS} ./configure ${TARGET_FLAG} ${ROOTS_HOST_OPTION} COMMAND make COMMENT "Building wvdial" VERBATIM ) INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/wvdial DESTINATION usr/local/bin COMPONENT ${COMPONENT_NAME} PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ ) DEFINE_DEBIAN_PACKAGE( NAME ${COMPONENT_NAME} CONTROL_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/debian/control CHANGELOG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/debian/changelog ) </pre>
18,352,528
1
0
null
2013-08-21 00:03:35.303 UTC
4
2021-07-24 09:40:49.62 UTC
2021-07-24 09:40:49.62 UTC
null
1,414,496
null
411,180
null
1
33
makefile|cmake
28,832
<p>Take a look at the <a href="http://www.cmake.org/cmake/help/v2.8.11/cmake.html#module:ExternalProject" rel="noreferrer"><code>ExternalProject</code></a> module.</p> <p>This will add a dummy target to your CMake project that is responsible for building the dependency. The command is quite complex and supports a lot of stuff that you probably won't need in your case. Kitware (the company behind CMake) did a <a href="https://blog.kitware.com/wp-content/uploads/2016/01/kitware_quarterly1009.pdf" rel="noreferrer">nice post called <em>Building External Projects with CMake 2.8</em></a> a while back explaining the basic use of that command.</p>
22,994,810
How do I desaturate and saturate an image using CSS?
<p><strong>Update</strong> </p> <p>I just realized that the desaturation is only working in Chrome. How do I make it work in FF, IE and other browsers? (Headline changed)</p> <hr> <p>I'm converting a color picture to greyscale by following the suggestions here: <a href="https://stackoverflow.com/questions/609273/convert-an-image-to-grayscale-in-html-css">Convert an image to grayscale in HTML/CSS</a></p> <p>And it works great (in Chrome): <a href="http://jsfiddle.net/7mNEC/" rel="noreferrer">http://jsfiddle.net/7mNEC/</a></p> <pre><code>&lt;img src="https://imagizer.imageshack.us/v2/350x496q90/822/z7ds.jpg" /&gt; // CSSS img { filter: url(~"data:image/svg+xml;utf8,&lt;svg xmlns=\'http://www.w3.org/2000/svg\'&gt;&lt;filter id=\'grayscale\'&gt;&lt;feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/&gt;&lt;/filter&gt;&lt;/svg&gt;#grayscale"); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter: gray; } img:hover { filter: none; cursor: pointer; } </code></pre> <p>But I'm not able to remove the desaturation on e.g. mouse over. </p> <p>Any ideas to what I'm doing wrong?</p>
22,994,891
3
0
null
2014-04-10 17:20:32.68 UTC
3
2020-04-24 21:47:22.41 UTC
2017-05-23 10:29:52.607 UTC
null
-1
null
91,612
null
1
26
html|image|css|grayscale
47,075
<p>You just have to reverse the grayscale for each browser prefix CSS property:</p> <pre><code>img:hover { filter: none; -webkit-filter: grayscale(0%); -moz-filter: grayscale(0%); -ms-filter: grayscale(0%); -o-filter: grayscale(0%); cursor: pointer; } </code></pre> <p><a href="http://jsfiddle.net/7mNEC/1/">http://jsfiddle.net/7mNEC/1/</a></p>
32,395,988
Highlight Menu Item when Scrolling Down to Section
<p>I know this question have been asked a million times on this forum, but none of the articles helped me reach a solution.</p> <p>I made a little piece of jquery code that highlights the hash-link when you scroll down to the section with the same id as in the hash-link.</p> <pre><code>$(window).scroll(function() { var position = $(this).scrollTop(); $('.section').each(function() { var target = $(this).offset().top; var id = $(this).attr('id'); if (position &gt;= target) { $('#navigation &gt; ul &gt; li &gt; a').attr('href', id).addClass('active'); } }); }); </code></pre> <p>The problem now is that it highlights all of the hash-links instead of just the one that the section has a relation to. Can anyone point out the mistake, or is it something that I forgot?</p>
32,396,543
5
0
null
2015-09-04 10:37:11.817 UTC
18
2019-12-09 15:46:32.743 UTC
null
null
null
null
2,487,453
null
1
21
javascript|jquery|hash|hyperlink|sections
44,024
<h2>EDIT:</h2> <p>I have modified my answer to talk a little about performance and some particular cases.</p> <p>If you are here just looking for code, there is a commented snippet at the bottom.</p> <hr> <h2>Original answer</h2> <p>Instead of adding the <code>.active</code> <em>class</em> to all the links, you should identify the one which attribute <em>href</em> is the same as the section's <em>id</em>.</p> <p>Then you can add the <code>.active</code> <em>class</em> to that link and remove it from the rest.</p> <pre><code> if (position &gt;= target) { $('#navigation &gt; ul &gt; li &gt; a').removeClass('active'); $('#navigation &gt; ul &gt; li &gt; a[href=#' + id + ']').addClass('active'); } </code></pre> <p>With the above modification your code will correctly highlight the corresponding link. Hope it helps!</p> <hr> <h2>Improving performance</h2> <p>Even when this code will do its job, is far from being optimal. Anyway, remember: </p> <blockquote> <p>We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. (<em>Donald Knuth</em>)</p> </blockquote> <p>So if, event testing in a slow device, you experience no performance issues, the best you can do is to stop reading and to think about the next amazing feature for your project!</p> <p>There are, basically, three steps to improve the performance:</p> <p><strong>Make as much previous work as possible:</strong></p> <p>In order to avoid searching the DOM once and again (each time the event is triggered), you can cache your jQuery objects beforehand (e.g. on <code>document.ready</code>):</p> <pre><code>var $navigationLinks = $('#navigation &gt; ul &gt; li &gt; a'); var $sections = $(".section"); </code></pre> <p>Then, you can map each section to the corresponding navigation link:</p> <pre><code>var sectionIdTonavigationLink = {}; $sections.each( function(){ sectionIdTonavigationLink[ $(this).attr('id') ] = $('#navigation &gt; ul &gt; li &gt; a[href=\\#' + $(this).attr('id') + ']'); }); </code></pre> <p>Note the two backslashes in the anchor selector: the hash '<em>#</em>' has a special meaning in CSS so <a href="https://api.jquery.com/category/selectors/" rel="noreferrer">it must be escaped</a> (thanks <a href="https://stackoverflow.com/a/46554013/5247200">@Johnnie</a>).</p> <p>Also, you could cache the position of each section (Bootstrap's <a href="http://v4-alpha.getbootstrap.com/components/scrollspy/" rel="noreferrer">Scrollspy</a> does it). But, if you do it, you need to remember to update them every time they change (the user resizes the window, new content is added via ajax, a subsection is expanded, etc).</p> <p><strong>Optimize the event handler:</strong></p> <p>Imagine that the user is scrolling <em>inside</em> one section: the active navigation link doesn't need to change. But if you look at the code above you will see that actually it changes several times. Before the correct link get highlighted, all the previous links will do it as well (because their corresponding sections also validate the condition <code>position &gt;= target</code>).</p> <p>One solution is to iterate the sections for the bottom to the top, the first one whose <code>.offset().top</code> is equal or smaller than <code>$(window).scrollTop</code> is the correct one. And yes, <a href="https://stackoverflow.com/a/25165306/5247200">you can rely on jQuery returning the objects in the order of the DOM</a> (since <a href="http://blog.jquery.com/2009/02/20/jquery-1-3-2-released/" rel="noreferrer">version 1.3.2</a>). To iterate from bottom to top just select them in inverse order:</p> <pre><code>var $sections = $( $(".section").get().reverse() ); $sections.each( ... ); </code></pre> <p>The double <code>$()</code> is necessary because <code>get()</code> returns DOM elements, not jQuery objects.</p> <p>Once you have found the correct section, you should <code>return false</code> to exit the loop and avoid to check further sections.</p> <p>Finally, you shouldn't do anything if the correct navigation link is already highlighted, so check it out:</p> <pre><code>if ( !$navigationLink.hasClass( 'active' ) ) { $navigationLinks.removeClass('active'); $navigationLink.addClass('active'); } </code></pre> <p><strong>Trigger the event as less as possible:</strong></p> <p>The most definitive way to prevent high-rated events (scroll, resize...) from making your site slow or unresponsive is to control how often the event handler is called: sure you don't need to check which link needs to be highlighted 100 times per second! If, besides the link highlighting, you add some fancy parallax effect you can ran fast intro troubles. </p> <p>At this point, sure you want to read about throttle, debounce and requestAnimationFrame. <a href="https://css-tricks.com/debouncing-throttling-explained-examples/" rel="noreferrer">This article</a> is a nice lecture and give you a very good overview about three of them. For our case, throttling fits best our needs.</p> <p>Basically, throttling enforces a minimum time interval between two function executions.</p> <p>I have implemented a throttle function in the snippet. From there you can get more sophisticated, or even better, use a library like <a href="http://underscorejs.org/" rel="noreferrer">underscore.js</a> or <a href="https://lodash.com/" rel="noreferrer">lodash</a> (if you don't need the whole library you can always extract from there the throttle function).</p> <p>Note: if you look around, you will find more simple throttle functions. Beware of them because they can miss the last event trigger (and that is the most important one!).</p> <h2>Particular cases:</h2> <p>I will not include these cases in the snippet, to not complicate it any further.</p> <p>In the snippet below, the links will get highlighted when the section reaches the very top of the page. If you want them highlighted before, you can add a small offset in this way:</p> <pre><code>if (position + offset &gt;= target) { </code></pre> <p>This is particullary useful when you have a top navigation bar.</p> <p>And if your last section is too small to reach the top of the page, you can hightlight its corresponding link when the scrollbar is in its bottom-most position:</p> <pre><code>if ( $(window).scrollTop() &gt;= $(document).height() - $(window).height() ) { // highlight the last link </code></pre> <p>There are some browser support issues thought. You can read more about it <a href="https://stackoverflow.com/q/3898130/5247200">here</a> and <a href="https://stackoverflow.com/q/9439725/5247200">here</a>.</p> <h2>Snippet and test</h2> <p>Finally, here you have a commented snippet. Please note that I have changed the name of some variables to make them more descriptive.</p> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>// cache the navigation links var $navigationLinks = $('#navigation &gt; ul &gt; li &gt; a'); // cache (in reversed order) the sections var $sections = $($(".section").get().reverse()); // map each section id to their corresponding navigation link var sectionIdTonavigationLink = {}; $sections.each(function() { var id = $(this).attr('id'); sectionIdTonavigationLink[id] = $('#navigation &gt; ul &gt; li &gt; a[href=\\#' + id + ']'); }); // throttle function, enforces a minimum time interval function throttle(fn, interval) { var lastCall, timeoutId; return function () { var now = new Date().getTime(); if (lastCall &amp;&amp; now &lt; (lastCall + interval) ) { // if we are inside the interval we wait clearTimeout(timeoutId); timeoutId = setTimeout(function () { lastCall = now; fn.call(); }, interval - (now - lastCall) ); } else { // otherwise, we directly call the function lastCall = now; fn.call(); } }; } function highlightNavigation() { // get the current vertical position of the scroll bar var scrollPosition = $(window).scrollTop(); // iterate the sections $sections.each(function() { var currentSection = $(this); // get the position of the section var sectionTop = currentSection.offset().top; // if the user has scrolled over the top of the section if (scrollPosition &gt;= sectionTop) { // get the section id var id = currentSection.attr('id'); // get the corresponding navigation link var $navigationLink = sectionIdTonavigationLink[id]; // if the link is not active if (!$navigationLink.hasClass('active')) { // remove .active class from all the links $navigationLinks.removeClass('active'); // add .active class to the current link $navigationLink.addClass('active'); } // we have found our section, so we return false to exit the each loop return false; } }); } $(window).scroll( throttle(highlightNavigation,100) ); // if you don't want to throttle the function use this instead: // $(window).scroll( highlightNavigation );</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>#navigation { position: fixed; } #sections { position: absolute; left: 150px; } .section { height: 200px; margin: 10px; padding: 10px; border: 1px dashed black; } #section5 { height: 1000px; } .active { background: red; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="navigation"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#section1"&gt;Section 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#section2"&gt;Section 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#section3"&gt;Section 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#section4"&gt;Section 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#section5"&gt;Section 5&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="sections"&gt; &lt;div id="section1" class="section"&gt; I'm section 1 &lt;/div&gt; &lt;div id="section2" class="section"&gt; I'm section 2 &lt;/div&gt; &lt;div id="section3" class="section"&gt; I'm section 3 &lt;/div&gt; &lt;div id="section4" class="section"&gt; I'm section 4 &lt;/div&gt; &lt;div id="section5" class="section"&gt; I'm section 5 &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>And in case you are interested, <a href="https://jsfiddle.net/upqwhou2/" rel="noreferrer">this fiddle</a> tests the different improvements we have talked about. </p> <p>Happy coding!</p>
47,455,960
"Safari cannot open the page because the address is invalid" appearing when accessing Branch link with app uninstalled
<p>I'm integrating an app with Branch.io and encountered an issue in Safari (I've tested this on iOS 11, but the issue might be appearing on other versions as well).</p> <p>Basically, if I have my app installed and open a quick link in either Safari or Chrome, everything works fine and I get a prompt to open the link in the app. However, if I <strong>uninstall the app</strong> and tap on the link in Safari I get the following message:</p> <p><a href="https://i.stack.imgur.com/xRyAw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xRyAw.png" alt="error message on Safar"></a></p> <p>When I tap the OK button, I get a prompt to open the Appstore which is the desired behaviour. Is there any way to prevent the "Safari cannot open the page because the address is invalid" message from appearing? I've tried opening the link in Chrome without the app installed and everything works fine there.</p> <p>I've used the official setup guide and entered my URI Scheme but disabled Universal Links because I'm handling those myself. Could this be causing the issue?</p>
47,519,321
4
0
null
2017-11-23 12:49:07.953 UTC
8
2021-01-08 02:51:18.863 UTC
null
null
null
null
5,465,959
null
1
25
ios|branch.io
21,141
<p>Aaron from <a href="https://branch.io/" rel="noreferrer">Branch.io</a> here</p> <p>You are probably getting this error because Branch is attempting to launch your app via URI schemes when the app is not installed. Starting from iOS 9.2, Apple no longer officially supports URI schemes for deep linking, and developers are strongly advised to implement Universal Links in order to get equivalent functionality on iOS.</p> <p>Specifically, there are significant drawbacks to custom URI schemes, most notably the inability to easily handle these two situations:</p> <ul> <li>When the app isn’t installed.</li> <li>When more than one app tries to claim myapp://.</li> </ul> <p>For this reason, we recommend you enable Universal links in your Branch Dashboard. All you need to do is provide your bundle ID and app prefix, and Branch will host the AASA file for you.</p>
34,340,450
How to get a Kotlin KClass from a package class name string?
<p>If I have a string like <code>"mypackage.MyClass"</code>, how can I get the corresponding <code>KClass</code> at runtime (from the JVM)?</p>
34,340,492
1
0
null
2015-12-17 17:12:51.407 UTC
2
2017-09-19 20:19:13.493 UTC
2017-09-19 20:18:28.127 UTC
null
3,533,380
null
1,028,906
null
1
47
kotlin
21,982
<p>You can use Java's method of getting a <code>Class</code> instance <code>Class.forName</code> and then convert it to a <code>KClass</code> using the <code>.kotlin</code> extension property. The code then looks like this:</p> <pre><code>val kClass = Class.forName("mypackage.MyClass").kotlin </code></pre> <p>A more direct way may be added at some point. The issue is located <a href="https://youtrack.jetbrains.com/issue/KT-10440" rel="noreferrer">here</a></p>
17,842,667
I need a VBA code to count the number rows, which varies from ss to ss, return that number and copy and paste that row and all other columns
<p>I have vba question I have been trying to find the answer for for a long time. I have numerous spreadsheets from numerous clients that I run macro's on, I'm new to coding and have been able to mostly figure out what I need to do. My clients send us data monthly and every month the number of rows change. The columns don't change but the amount of data does. My previous macro's I have just chosen the entire column to copy and paste onto our companies template. This worked fine for must things but has created some really long code and macros take a long time. I would like to write a code that counts how many rows are in a certain column and then from there copies and pastes that however many rows it counted in each column. Only a few columns contain data in every row, so I need it to count the rows in one specific column and apply to that every column. Any help would be appreciated. Thanks Tony </p> <p>Hi Guys, Still having issues with this, below I pasted the code I'm using if anyone can see why it won't run please help.</p> <pre><code>Windows("mmuworking2.xlsx").Activate Workbooks.Open Filename:= _ "C:\Users\I53014\Desktop\QC DOCS\Sample_Data_Import_Template.xlsx" Windows("mmuworking2.xlsx").Activate Dim COL As Integer COL = Range("A:DB").Columns.Select **Range(Cells(2, COL), Cells(Range("E" &amp; Rows.Count).End(xlUp).Row, COL)).Copy Destination:=Windows("Sample_Data_Import_Template.xlsx").Range("A2")** Range("A2").Paste Range("A5000").Formula = "='C:\Users\I53014\Desktop\[Import_Creator.xlsm]sheet1'!$B$2" ActiveWorkbook.SaveAs Filename:="Range (A5000)", _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False </code></pre> <p>I bolded where it keeps stopping.</p>
17,843,168
1
0
null
2013-07-24 19:02:19.547 UTC
null
2013-07-29 17:07:53.327 UTC
2018-07-09 19:34:03.733 UTC
null
-1
null
2,615,922
null
1
1
vba|variables|excel
82,806
<p>This should give you the last row containing data:</p> <pre><code>ActiveSheet.UsedRange.Rows.Count </code></pre> <p>This will give you the last row in a specific column:</p> <pre><code>Range("B" &amp; Rows.Count).End(xlUp).Row </code></pre> <p>here is an example of how I can copy every row in the first three columns of a worksheet</p> <pre><code>Sub Example() Dim LastRow As Long LastRow = ActiveSheet.UsedRange.Rows.Count Range(Cells(1, 1), Cells(LastRow, 3)).Copy Destination:=Sheet2.Range("A1") End Sub </code></pre> <p>You have to be careful as there are some caveats to both methods. </p> <p><code>ActiveSheet.UsedRange</code> may include cells that do not have any data if the cells were not cleaned up properly.</p> <p><code>Range("A" &amp; Rows.Count).End(xlUp).Row</code> will only return the number of rows in the specified column.</p> <p><code>Rows(Rows.Count).End(xlUp).Row</code> will only return the number of rows in the first column.</p> <p><strong>Edit</strong> Added an example<br> <strong>Edit2</strong> Changed the example to be a bit more clear</p> <p>For this example lets say we have this data<br> <img src="https://i.stack.imgur.com/s4lr5.jpg" alt="enter image description here"></p> <p>You could copy any other column down to the number of rows in column A using this method: </p> <pre><code>Sub Example() Dim Col as Integer Col = Columns("C:C").Column 'This would copy all data from C1 to C5 'Cells(1, Col) = Cell C1, because C1 is row 1 column 3 Range(Cells(1, Col), Cells(Range("A" &amp; Rows.Count).End(xlUp).Row, Col)).Copy Destination:=Sheet2.Range("A1") End Sub </code></pre> <p>The end result would be this:<br> <img src="https://i.stack.imgur.com/n7ulY.jpg" alt="enter image description here"></p>
52,396,724
TypeError: axios.get is not a function?
<p>Not sure why I'm getting the following error:</p> <pre><code>TypeError: axios.get is not a function 4 | 5 | export const getTotalPayout = async (userId: string) =&gt; { &gt; 6 | const response = await axios.get(`${endpoint}get-total-payout`, { params: userId }); 7 | return response.data; 8 | }; 9 | </code></pre> <p><strong>My service:</strong></p> <pre><code>import * as axios from 'axios'; const endpoint = '/api/pool/'; export const getTotalPayout = async (userId: string) =&gt; { const response = await axios.get(`${endpoint}get-total-payout`, { params: userId }); return response.data; }; </code></pre> <p><strong>My jest test:</strong></p> <pre><code>// import mockAxios from 'axios'; import { getTotalPayout } from './LiquidityPool'; const userId = 'foo'; describe('Pool API', () =&gt; { it('getTotalPayout is called and returns the total_payout for the user', async () =&gt; { // mockAxios.get.mockImplementationOnce(() =&gt; { // Promise.resolve({ // data: { // total_payout: 100.21, // }, // }); // }); const response = await getTotalPayout(userId); console.log('response', response); }); }); </code></pre> <p><strong>In the src/__mocks__/axios.js I have this:</strong></p> <pre><code>// tslint:disable-next-line:no-empty const mockNoop = () =&gt; new Promise(() =&gt; {}); export default { get: jest.fn(() =&gt; Promise.resolve({ data: { total_payout: 100.21 }})), default: mockNoop, post: mockNoop, put: mockNoop, delete: mockNoop, patch: mockNoop }; </code></pre>
52,397,838
3
0
null
2018-09-19 01:29:01.873 UTC
3
2022-01-27 09:48:48.067 UTC
2018-11-05 14:34:20.487 UTC
null
2,071,697
null
168,738
null
1
7
javascript|typescript|axios|jestjs
40,663
<p>Please look at: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Syntax" rel="noreferrer">MDN</a></p> <p>As mentoined there, you need a value to collect the <code>default export</code> and the rest as <code>X</code>. In this case you could:</p> <pre><code>import axios, * as others from 'axios'; </code></pre> <p>X being <code>others</code> here.</p> <p>Instead of</p> <pre><code>import * as axios from 'axios'; </code></pre> <p>Assumption: <code>... from 'axios'</code> is referring to your jest mock.</p>
21,536,627
What's the difference between transform and reduce in lodash
<p>Other than stating "transform is a more powerful alternative to reduce", I can find no documentation of what the differences are. What are the differences between transform and reduce in lodash (Other than it being <a href="http://jsperf.com/transform-vs-reduce">25% slower</a>)?</p>
21,536,978
2
0
null
2014-02-03 20:03:37.95 UTC
13
2017-12-22 01:43:31.463 UTC
2014-07-28 15:27:18.433 UTC
null
1,517,919
null
3,798
null
1
59
javascript|lodash
32,709
<p>I like to dive into the source code before I pull in utilities. For lo-dash this can be difficult as there is a ton of abstracted internal functionality in all the utilities.</p> <ul> <li><a href="https://github.com/lodash/lodash/blob/2.4.1/dist/lodash.js#L2870-L2889">transform source</a></li> <li><a href="https://github.com/lodash/lodash/blob/2.4.1/dist/lodash.js#L3721-L3744">reduce source</a></li> </ul> <p>So the obvious differences are:</p> <ul> <li>If you dont specify the <em>accumulator</em> (commonly referred to as <em>memo</em> if you're used to underscore), <code>_.transform</code> will guess if you want an array or object while reduce will make the accumulator the initial item of the collection. </li> </ul> <p>Example, array or object map via <code>transform</code>:</p> <pre><code>_.transform([1, 2, 3], function(memo, val, idx) { memo[idx] = val + 5; }); // =&gt; [6, 7, 8] </code></pre> <p>Versus reduce (note, you have to know the input type!)</p> <pre><code>_.reduce([1, 2, 3], function(memo, val, idx) { memo[idx] = val + 5; return memo; }, []); </code></pre> <p>So while with reduce the below will compute the sum of an array, this wouldn't be possible with transform as <code>a</code> will be an array.</p> <pre><code>var sum = _.reduce([1, 2, 3, 4], function(a, b) { return a + b; }); </code></pre> <ul> <li>Another big difference is you don't have to return the accumulator with <code>transform</code> and the accumulator can't change value (ie it will always be the same array). I'd say this is the biggest advantage of the function as I've often forgotten to return the accumulator using reduce.</li> </ul> <p>For example if you wanted to convert an array to dictionary of values with reduce you would write code like the following: </p> <pre><code>_.reduce([1, 2, 3, 4, 5], function(memo, idx) { memo[idx] = true; return memo; }, {}); </code></pre> <p>Whereas with transform we can write this very nicely without needing to return the accumulator like in reduce</p> <pre><code>_.transform([1, 2, 3, 4, 5], function(memo, idx) { memo[idx] = true; }, {}); </code></pre> <ul> <li>Another distinction is we can exit the transform iteration by returning false.</li> </ul> <p>Overall, I'd say reduce is a more flexible method, as you have more control over the accumulator, but transform can be used to write equivalent code for some cases in a simpler style.</p>
29,868,724
Gradle not running tests
<p>For some reason gradle is not running my tests. When i execute <code>gradle cleanTest test -i</code> i get:</p> <pre><code>Skipping task ':compileJava' as it is up-to-date (took 0.262 secs). :compileJava UP-TO-DATE :compileJava (Thread[main,5,main]) completed. Took 0.266 secs. :processResources (Thread[main,5,main]) started. :processResources Skipping task ':processResources' as it has no source files. :processResources UP-TO-DATE :processResources (Thread[main,5,main]) completed. Took 0.001 secs. :classes (Thread[main,5,main]) started. :classes Skipping task ':classes' as it has no actions. :classes UP-TO-DATE :classes (Thread[main,5,main]) completed. Took 0.0 secs. :compileTestJava (Thread[main,5,main]) started. :compileTestJava Skipping task ':compileTestJava' as it has no source files. :compileTestJava UP-TO-DATE :compileTestJava (Thread[main,5,main]) completed. Took 0.001 secs. :processTestResources (Thread[main,5,main]) started. :processTestResources Skipping task ':processTestResources' as it is up-to-date (took 0.004 secs). :processTestResources UP-TO-DATE :processTestResources (Thread[main,5,main]) completed. Took 0.007 secs. :testClasses (Thread[main,5,main]) started. :testClasses Skipping task ':testClasses' as it has no actions. :testClasses UP-TO-DATE :testClasses (Thread[main,5,main]) completed. Took 0.001 secs. :test (Thread[main,5,main]) started. :test file or directory '/Users/jan/2014-2015-groep-05/VoPro/build/classes/test', not found Skipping task ':test' as it has no source files. </code></pre> <p>My test are in the folder <code>./test/</code>. And this is my gradle config:</p> <pre><code>apply plugin: 'java' apply plugin: 'eclipse' test { testLogging { events "passed", "skipped", "failed", "standardOut", "standardError" } dependsOn 'cleanTest' } repositories { mavenCentral() } dependencies { testCompile("junit:junit") } sourceSets { main { java { srcDir 'src' srcDir 'test' } } } </code></pre> <p>I can't seem to find what the problem is. Gradle does not recognize any tests, since both test and cleanTest are always up to date, however i did add test/ to my sourceSets. </p>
29,868,790
3
1
null
2015-04-25 17:57:45.243 UTC
1
2021-09-26 21:33:26.73 UTC
null
null
null
null
1,790,040
null
1
21
java|junit|gradle
38,286
<p>You're saying that the <strong>main</strong> SourceSet should contain the test directory. This directory should be set in the <strong>test</strong> SourceSet.</p>
25,512,527
Emacs: Symbol's value as variable is void
<p>This is my <code>~/.emacs</code> file:</p> <pre><code>(setq-default c-basic-offset 4 c-default-style "linux") (setq-default tab-width 4 indent-tabs-mode t) (define-key c-mode-base-map (kbd "RET") 'newline-and-indent) </code></pre> <p>I'm getting a warning when I open up emacs:</p> <blockquote> <p>Warning (initialization): An error occurred while loading <code>c:/home/.emacs</code>:</p> <p>Symbol's value as variable is void: <code>c-mode-base-map</code></p> <p>To ensure normal operations, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the <code>--debug-init</code> option to view a complete error backtrace.</p> </blockquote> <p>I ran <code>--debug-init</code> and this is what it returned. I don't know what I means:</p> <blockquote> <p>Debugger entered--Lisp error: (void-variable <code>c-mode-base-map</code>) </p> <pre><code>(define-key c-mode-base-map (kbd "RET") (quote newline-and-indent)) eval-buffer(#&lt;buffer *load*&gt; nil "c:/home/.emacs" nil t) ; Reading at buffer position 311 load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t) load("~/.emacs" t t) </code></pre> </blockquote>
25,512,676
1
0
null
2014-08-26 18:15:58.76 UTC
4
2018-01-19 15:25:52.5 UTC
2018-01-19 15:25:52.5 UTC
null
729,907
null
2,030,677
null
1
29
emacs
40,841
<p>What this means is that, at the point at which you invoke <code>define-key</code>, <code>c-mode-base-map</code> is not yet defined by anything.</p> <p>The usual fix is to find out where this is defined and require that module. In this case:</p> <pre><code>(require 'cc-mode) </code></pre> <p>However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using <code>eval-after-load</code>. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.</p>
28,202,158
postgresql migrating JSON to JSONB
<p>In postgresql 9.4 the new JSONB was incorporated. </p> <p>On a live DB in postgresql 9.3 I have a JSON column. </p> <p>I want to migrate it to JSONB. </p> <p>Assuming I migrated the DB first to 9.4 (using pg_upgrade). What do I do next?</p>
28,202,449
2
0
null
2015-01-28 20:51:50.57 UTC
14
2021-02-27 21:29:02.007 UTC
2021-02-27 21:29:02.007 UTC
null
5,841,306
null
429,249
null
1
58
postgresql|ddl|jsonb
29,130
<pre><code>ALTER TABLE table_with_json ALTER COLUMN my_json SET DATA TYPE jsonb USING my_json::jsonb; </code></pre>
8,643,780
Get text written in Anchor tag
<pre><code>&lt;td class="td1"&gt; &lt;input name="CheckBox" id="c1" type="checkbox" CHECKED="" value="on"/&gt; &lt;a class="a_c" id="a1"&gt; &lt;/td&gt; </code></pre> <p>If I know ID of Check box <code>$(#c1)</code> then how can I get text of Anchor tag?</p>
8,643,926
7
0
null
2011-12-27 10:46:40.87 UTC
2
2022-01-19 03:59:51.773 UTC
2017-11-07 03:11:49.68 UTC
null
4,758,494
null
888,181
null
1
4
javascript|jquery
40,414
<p>First you have to write a close this tag</p> <pre><code>&lt;input name="CheckBox" id="c1" type="checkbox" CHECKED="" value="on"/&gt; &lt;a class="a_c" id="a1"&gt; Something &lt;/a&gt; </code></pre> <p>Anchor has id assigned yet therefore you can get access directly:</p> <pre><code>$("#a1").text() </code></pre> <p>If anchor did not have id and will be always after checkbox ( can be separated by other tags)</p> <pre><code>$('#c1').next("a").text(); </code></pre> <p>otherwise if will be checkbox's sibling and in this branch is one anchor ( not necessarily just after checkbox)</p> <pre><code> $('#c1').parent().find("a").text(); </code></pre>
8,497,160
using predict with a list of lm() objects
<p>I have data which I regularly run regressions on. Each "chunk" of data gets fit a different regression. Each state, for example, might have a different function that explains the dependent value. This seems like a typical "split-apply-combine" type of problem so I'm using the plyr package. I can easily create a list of <code>lm()</code> objects which works well. However I can't quite wrap my head around how I use those objects later to predict values in a separate data.frame. </p> <p>Here's a totally contrived example illustrating what I'm trying to do:</p> <pre><code># setting up some fake data set.seed(1) funct &lt;- function(myState, myYear){ rnorm(1, 100, 500) + myState + (100 * myYear) } state &lt;- 50:60 year &lt;- 10:40 myData &lt;- expand.grid( year, state) names(myData) &lt;- c("year","state") myData$value &lt;- apply(myData, 1, function(x) funct(x[2], x[1])) ## ok, done with the fake data generation. require(plyr) modelList &lt;- dlply(myData, "state", function(x) lm(value ~ year, data=x)) ## if you want to see the summaries of the lm() do this: # lapply(modelList, summary) state &lt;- 50:60 year &lt;- 50:60 newData &lt;- expand.grid( year, state) names(newData) &lt;- c("year","state") ## now how do I predict the values for newData$value # using the regressions in modelList? </code></pre> <p>So how do I use the <code>lm()</code> objects contained in <code>modelList</code> to predict values using the year and state independent values from <code>newData</code>?</p>
8,497,539
6
0
null
2011-12-13 22:31:22.317 UTC
14
2014-07-23 12:59:36.81 UTC
2011-12-13 22:52:34.723 UTC
null
358,506
null
37,751
null
1
18
r|plyr|lm|predict
8,067
<p>Here's my attempt:</p> <pre><code>predNaughty &lt;- ddply(newData, "state", transform, value=predict(modelList[[paste(piece$state[1])]], newdata=piece)) head(predNaughty) # year state value # 1 50 50 5176.326 # 2 51 50 5274.907 # 3 52 50 5373.487 # 4 53 50 5472.068 # 5 54 50 5570.649 # 6 55 50 5669.229 predDiggsApproved &lt;- ddply(newData, "state", function(x) transform(x, value=predict(modelList[[paste(x$state[1])]], newdata=x))) head(predDiggsApproved) # year state value # 1 50 50 5176.326 # 2 51 50 5274.907 # 3 52 50 5373.487 # 4 53 50 5472.068 # 5 54 50 5570.649 # 6 55 50 5669.229 </code></pre> <p><strong>JD Long edit</strong></p> <p>I was inspired enough to work out an <code>adply()</code> option:</p> <pre><code>pred3 &lt;- adply(newData, 1, function(x) predict(modelList[[paste(x$state)]], newdata=x)) head(pred3) # year state 1 # 1 50 50 5176.326 # 2 51 50 5274.907 # 3 52 50 5373.487 # 4 53 50 5472.068 # 5 54 50 5570.649 # 6 55 50 5669.229 </code></pre>
8,956,577
How can I correct the correlation names on this sql join?
<p>I need a join that yields three fields with the same name from two different tables. When I try to run my sql query, VS gives me the following error.</p> <blockquote> <p>The objects "PoliticalFigures" and "PoliticalFigures" in the FROM clause have the same exposed names. Use correlation names to distinguish them.</p> </blockquote> <p>I've been trying to use "AS" to distinguish these fields, but I haven't found a working solution. This is the sql query I'm running:</p> <pre><code>SELECT Countries.Name AS Country, PoliticalFigures.Name AS President, PoliticalFigures.Name AS VicePresident FROM Countries LEFT OUTER JOIN PoliticalFigures ON Countries.President_Id = PoliticalFigures.Id LEFT OUTER JOIN PoliticalFigures ON Countries.VicePresident_Id = PoliticalFigures.Id </code></pre> <p>If it's not obvious from the code, these are the tables.</p> <ul> <li>Countries: Id, Name, President_Id, VicePresident_Id.</li> <li>PoliticalFigures: Id, Name.</li> <li>Joined table: Country, President, VicePresident</li> </ul> <p>(Note, the tables and fields in my application have different names. I am generalizing them to make this example clearer and <em>hopefully</em> more relevant to others.)</p> <p>(The tools I'm using are Visual Web Developer 2010 Express and SQL Server 2008 Express.)</p>
8,956,604
4
0
null
2012-01-21 20:50:30.52 UTC
6
2012-01-23 08:25:13.047 UTC
null
null
null
null
921,739
null
1
33
sql|sql-server|database
90,098
<p>Use table aliases for each reference to <code>PoliticalFigures</code> instead:</p> <pre><code>SELECT Countries.Name AS Country, P.Name AS President, VP.Name AS VicePresident FROM Countries LEFT OUTER JOIN PoliticalFigures AS P ON Countries.President_Id = P.Id LEFT OUTER JOIN PoliticalFigures AS VP ON Countries.VicePresident_Id = VP.Id </code></pre>
8,611,815
Determine if char is a num or letter
<p>How do I determine if a <code>char</code> in C such as <code>a</code> or <code>9</code> is a number or a letter?</p> <p>Is it better to use:</p> <pre><code>int a = Asc(theChar); </code></pre> <p>or this?</p> <pre><code>int a = (int)theChar </code></pre>
8,611,823
7
0
null
2011-12-23 02:56:53.25 UTC
14
2020-04-02 09:36:22.857 UTC
2016-06-04 20:00:56.75 UTC
null
5,183,619
null
1,103,257
null
1
61
c|char|alphanumeric
286,980
<p>You'll want to use the <code>isalpha()</code> and <code>isdigit()</code> standard functions in <code>&lt;ctype.h&gt;</code>.</p> <pre><code>char c = 'a'; // or whatever if (isalpha(c)) { puts("it's a letter"); } else if (isdigit(c)) { puts("it's a digit"); } else { puts("something else?"); } </code></pre>
55,463,849
How can I escape double curly braces in jinja2?
<p>I need to escape double curly braces in a code I'm working on using Ansible. The thing is I have all those parameters that needs to be transformed in variables. Basically I'm working on a template creator.</p> <p>I've tried using {% raw %}{{ name-of-variable }}{% endraw %} but it did not worked. When I tried /{/{ name-of-variable }} I almost got it, but I am trying to get rid of the backslashes too.</p> <p>Here's a bit of the code:</p> <pre><code>local_action: module: replace path: "/tmp/{{ ambiance }}/{{ seed }}DEFAULT.j2" regexp: "{{ item.regexp1 }}" replace: "{{ item.replace }}" with_items: - { regexp1: '^DBHOST.*$', replace: 'DBHOST = {% raw %}{{ databasehost }}{% endraw %}' } - { regexp1: '^GLOBALHOST.*$', replace: 'GLOBALHOST = {% raw %}{{ global_hostname }}{% endraw %}' } </code></pre> <p>I expect the result as it follows:</p> <pre><code>DBHOST = {{ satabasehost }} GLOBALHOST = {{ global_hostname }} </code></pre> <p>Any suggestions/ideas?</p>
55,464,045
1
0
null
2019-04-01 21:30:32.98 UTC
3
2021-01-14 21:18:24.59 UTC
null
null
null
null
10,394,770
null
1
29
ansible|jinja2
21,246
<p><code>{% raw %}{{ databasehost }}{% endraw %}</code> should work.</p> <p>You can also use <code>{{ '{{ databasehost }}' }}</code> as an alternative.</p>
27,094,544
Android (Java) HttpURLConnection silent retry on 'read' timeout
<p>So I'm using <code>Google Volley</code> for HTTP request, which basically uses <code>Java</code>'s <code>HttpURLConnection</code>.</p> <p>According to my tests, the <strong>problem is this</strong>:<br> When the 'read' timeout on the <code>HttpURLConnection</code> reaches, a silent retry is executed before the connection is closed and the relevant exception thrown (<code>SocketTimeoutException</code>).</p> <p><strong>Note</strong> that:<br> - I noticed this error when using <code>HTTP POST</code> request.<br> - 'read' timeout is different than 'connect' timeout.<br> - If the 'read' timeout (set by calling <code>connection.setReadTimeout(int)</code>) is NOT set (0), or set to a greater value than <code>connection.setConnectTimeout(int)</code>, this error does not occur.<br> - This issue has been discussed, <a href="https://stackoverflow.com/questions/24417817/stopping-silent-retries-in-httpurlconnection">here</a> for example, but I haven't found any satisfying solution.<br> - A somewhat related issue can be found <a href="http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest" rel="noreferrer">here</a>, but I'm not sure it is relevant (is it?)</p> <p><strong>More Background</strong><br> My app is used for paying money, so not retrying a request is crucial (yes, I know it can be handled by the server, I want my client to be "correct" anyway).</p> <p>When the 'read' timeout is set, in case the server connection is established, but the server waits/sleeps/delays-response that 'timeout' time before answering (thus raising the 'read' exception and not the 'connect' exception), another (silent) request is sent just before that exception is raised, resulting in 2 similar requests, which is not acceptable. </p> <p><strong>What kind of solution am I looking for?</strong><br> Well, a one that will nicely solve this problem/bug, just like the fix explained <a href="http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest" rel="noreferrer">here</a> (but I again, I think it's irrelevant in this case).<br> Also, I would want to keep the original flow as is, meaning not forcing the connection to close or anything like that. </p> <p>What I'm gonna do for now, is set the 'read' timeout to twice the 'connection' timeout (they start counting at the same time), to make sure the 'connection' exception is raised first. I will also try to overcome this issue on the server side. The problem is, this 'read' timeout is there for a reason, and my current implementation practically just ignores it, and handles only 'connection' timeouts. </p> <p><strong>EDIT</strong> The <code>Volley</code> library's <code>RetryPolicy</code> has not affect on this issue, as this is a silent retry. I looked as deep as possible inside the library. Logs/breakpoints everywhere, cancelled the calls to retry. That how I know it is 99.99% a <code>HttpURLConnection</code> issue.</p>
37,675,253
4
2
null
2014-11-23 21:29:28.51 UTC
12
2016-06-09 08:28:15.443 UTC
2017-05-23 10:29:37.043 UTC
null
-1
null
2,774,781
null
1
12
java|android|httpurlconnection|android-volley
10,513
<p>This bad decision was made by a developer in the year 2006. Here is a nice citation from someone that explains the whole situation from java perspective:</p> <blockquote> <p>"As you probably guessed by now it's a bug (<a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6382788" rel="noreferrer">http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6382788</a>). Not the retry mechanism, of course, that's just crap. The bug is that it also happens for a POST (which is by default not idempotent per HTTP RFC). But don't worry, Bill fixed that bug a long time ago. Bill fixed it by introducing a toggle. Bill learned about backward compatibility. Bill decided it's better to leave the toggle 'on' by default because that would make it bug-backward-compatible. Bill smiles. He can already see the faces of surprised developers around the globe running into this. Please don't be like Bill?"<br> <a href="https://dzone.com/articles/pola-and-httpurlconnection" rel="noreferrer">Source</a></p> </blockquote> <p>Well the proposed solution is:</p> <pre><code>System.setProperty("sun.net.http.retryPost", "false") </code></pre> <p>But we cannot do this on android! The only remaining solution then is:</p> <pre><code>httpURLConnection.setChunkedStreamingMode(0); </code></pre> <p><a href="https://code.google.com/p/android/issues/detail?id=163595" rel="noreferrer">Which seems to be working, but isn't very effective from a requesting-time perspektive.</a></p> <p>EDIT: I could not use this implementation so i looked for an alternative library. I found out that the implementation of HttpUrlConnection uses <a href="https://github.com/square/okhttp" rel="noreferrer">OkHttp</a> since Android 4.4. As OkHttp is opensource i could search if they have also problems with silent retries. And yep they <a href="https://github.com/square/okhttp/issues/2394" rel="noreferrer">had problems with it</a> and fixed it in April, 2016. <a href="https://stackoverflow.com/questions/34168030/which-implementation-of-httpurlconnection-is-used-for-android#comment56083913_34168030">CommonsWare</a> (a real <a href="https://stackoverflow.com/users/115145/commonsware">android expert</a>) explains that every manufacturer can decide which implementation they can use. As a consequence of this there must be a lot of devices out there that do silent retries on POST requests and as a developer we only can try some workarrounds. </p> <p>My solution will be to change the library</p> <p>EDIT 2: To give you a final answer: <a href="https://gist.github.com/JakeWharton/5616899" rel="noreferrer">You can now use OkHttp as the transport layer for Volley with minimal code.</a></p> <p><a href="https://stackoverflow.com/a/30245868/2061089">Another helpful solution</a></p>
43,744,156
Error calling Appregistry.runApplication in react-native
<p>I am trying to run a react-native app on android emulator, but I am getting an error like </p> <blockquote> <p>Error calling Appregistry.runApplication</p> </blockquote> <p>AVD: 'Nexus_5X_API_23(AVD) - 6.0 OS:Windows 10</p> <p><a href="https://i.stack.imgur.com/BwwHX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BwwHX.png" alt="enter image description here"></a></p> <p>Please help on this?</p>
43,790,213
13
0
null
2017-05-02 17:46:39.24 UTC
10
2020-10-08 05:11:29.607 UTC
2017-05-04 20:06:56.837 UTC
null
1,718,174
null
1,043,102
null
1
50
javascript|android|reactjs|react-native
24,221
<p>Finally, I got it working.I created a new AVD </p> <blockquote> <p>Nexus6 API 23</p> </blockquote> <p>.Earlier I was trying with <em>Nexus5x API 23</em>.Thanks all</p>
22,149,982
Find id of element on already made google form?
<p>I have a form made on google docs, and I have a script that I've just created (that isn't complete) that will analyze the responses on the form, and validate them based on info from a different google doc. Through trial and error I have figured out the id's for all of the elements on said form. I used:</p> <pre><code>var body = "" var bodyTitle = "" for (var i = 1; i &lt; its.length; i ++) { body = body + " " +its[i].getId() bodyTitle = bodyTitle + " " + its[i].getTitle() } </code></pre> <p>and then by logging that out and basically just counting, the 5th id matches the 5th title, I have all of the id's. I'm just wondering for next time, is there a way I can look at the form and find it'd ID without doing this?</p> <p>With HTML forms (I use chrome fyi) you can right click, inspect element, and you can see the id for page elements, and refer to them by that id in javascript. Is there a way to do this in Google Forms? that way I don't have to screw with just logging out all the id's and titles and matching them up. </p> <p>Keep in mind: these are all forms created in Google Forms by users, they insist on making them. None of them are code made so I haven't been able to code the id's myself.</p>
22,210,591
3
0
null
2014-03-03 14:57:43.707 UTC
13
2021-04-22 21:58:49.443 UTC
2017-10-18 20:44:13.56 UTC
null
1,595,451
null
1,759,942
null
1
9
google-apps-script|google-forms
35,687
<p>Something like this will show you the ids in the logger...</p> <pre><code>var form = FormApp.getActiveForm(); var items = form.getItems(); for (var i in items) { Logger.log(items[i].getTitle() + ': ' + items[i].getId()); } </code></pre> <p>To see the IDs manually in Chrome >> View Form >> right-click on the question <strong>Label</strong> >> Inspect element >> look for the <code>for="entry_XXXXXXX"</code> attribute. That 'xxxxxxx' will be the id.</p>
22,008,822
How to get the size of single document in Mongodb?
<p> I encountered a strange behavior of mongo and I would like to clarify it a bit...<br> My request is simple as that: I would like to get a size of single document in collection. I found two possible solutions:<br> </p> <ul> <li>Object.bsonsize - some javascript method that should return a size in bytes</li> <li>db.collection.stats() - where there is a line 'avgObjSize' that produce some "aggregated"(average) size view on the data. It simply represents average size of single document.</li> <br> When I create test collection with only one document, both functions returns different values. How is it possible? <br> Does it exist some other method to get a size of a mongo document?</li> </ul> <p>Here, I provide some code I perform testing on:</p> <ol> <li><p>I created new database 'test' and input simple document with only one attribute: type:"auto"</p> <pre><code>db.test.insert({type:"auto"}) </code></pre></li> <li><p>output from stats() function call: <em>db.test.stats()</em>:</p> <pre><code>{ "ns" : "test.test", "count" : 1, "size" : 40, "avgObjSize" : 40, "storageSize" : 4096, "numExtents" : 1, "nindexes" : 1, "lastExtentSize" : 4096, "paddingFactor" : 1, "systemFlags" : 1, "userFlags" : 0, "totalIndexSize" : 8176, "indexSizes" : { "_id_" : 8176 }, "ok" : 1 </code></pre> <p>}</p></li> <li><p>output from bsonsize function call: <em>Object.bsonsize(db.test.find({test:"auto"}))</em></p> <pre><code>481 </code></pre></li> </ol>
22,166,477
6
0
null
2014-02-25 08:45:06.55 UTC
34
2022-01-17 09:53:37.677 UTC
2020-05-28 20:01:31.117 UTC
null
5,780,109
null
1,949,763
null
1
112
javascript|mongodb|document|objectid|objectsize
113,770
<p>In the previous call of <code>Object.bsonsize()</code>, Mongodb returned the size of the cursor, rather than the document. </p> <p>Correct way is to use this command:</p> <pre><code>Object.bsonsize(db.test.findOne()) </code></pre> <p>With <code>findOne()</code>, you can define your query for a specific document:</p> <pre><code>Object.bsonsize(db.test.findOne({type:"auto"})) </code></pre> <p>This will return the correct size (in bytes) of the particular document.</p>
35,292,836
Input byte array has incorrect ending byte at 40
<p>I have a string that is base64 encoded. It looks like this:</p> <pre><code>eyJibGExIjoiYmxhMSIsImJsYTIiOiJibGEyIn0= </code></pre> <p>Any online tool can decode this to the proper string which is <code>{"bla1":"bla1","bla2":"bla2"}</code>. However, my Java implementation fails:</p> <pre><code>import java.util.Base64; System.out.println("payload = " + payload); String json = new String(Base64.getDecoder().decode(payload)); </code></pre> <p>I'm getting the following error:</p> <pre><code>payload = eyJibGExIjoiYmxhMSIsImJsYTIiOiJibGEyIn0= java.lang.IllegalArgumentException: Input byte array has incorrect ending byte at 40 </code></pre> <p>What is wrong with my code?</p>
35,293,091
3
2
null
2016-02-09 13:04:28.207 UTC
2
2020-02-29 15:46:15.327 UTC
2018-04-27 12:43:16.813 UTC
null
1,685,157
null
1,020,704
null
1
20
java|base64|illegalargumentexception
41,929
<p>Okay, I found out. The original String is encoded on an Android device using <code>android.util.Base64</code> by <code>Base64.encodeToString(json.getBytes("UTF-8"), Base64.DEFAULT);</code>. It uses <code>android.util.Base64.DEFAULT</code> encoding scheme.</p> <p>Then on the server side when using <code>java.util.Base64</code> this has to be decoded with <code>Base64.getMimeDecoder().decode(payload)</code> <em>not</em> with <code>Base64.getDecoder().decode(payload)</code></p>
24,334,761
MVC 5.1 Razor DisplayFor not working with Enum DisplayName
<p>I have the following entity (domain) object and model that contain an enum. The display name appears correctly and works for a EnumDropdownList but for some reason not for the DisplayFor helper, all that is shown is the actual enum name.</p> <p>Not sure what I am missing, asp.net MVC 5.1 added display name support for this so I shouldn't need to create my own helper methods. See: <a href="https://aspnet.codeplex.com/SourceControl/latest#Samples/MVC/EnumSample/EnumSample/Models/Enums.cs">https://aspnet.codeplex.com/SourceControl/latest#Samples/MVC/EnumSample/EnumSample/Models/Enums.cs</a></p> <pre><code>public class Addon { public int Id { get; set; } public AddonType AddonType { get; set; } public string Name { get; set; } public decimal Price { get; set; } public bool IsActive { get; set; } } public enum AddonType : byte { [Display(Name = "Cake Theme")] CakeTheme, [Display(Name = "Cake Flavour")] CakeFlavour, [Display(Name = "Cupcake Icing")] CupcakeIcing, [Display(Name = "Party Addon")] AddOn } </code></pre> <p>MODEL</p> <pre><code>public class AddonModel { public int Id { get; set; } public AddonType AddonType { get; set; } public string Name { get; set; } public decimal Price { get; set; } public int Quantity { get; set; } public bool IsActive { get; set; } } </code></pre> <p>VIEW</p> <pre><code>&lt;h2&gt;Index&lt;/h2&gt; &lt;p&gt; @Html.ActionLink("Create New", "Create") &lt;/p&gt; &lt;table class="table"&gt; &lt;tr&gt; &lt;th&gt;Type&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; @foreach (var item in Model) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(model =&gt; item.AddonType) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(model =&gt; item.Name) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(model =&gt; item.Price) &lt;/td&gt; &lt;td&gt; @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | @Html.ActionLink("Details", "Details", new { id=item.Id }) | @Html.ActionLink("Delete", "Delete", new { id=item.Id }) &lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; </code></pre>
24,406,117
1
0
null
2014-06-20 19:58:50.293 UTC
11
2018-01-08 16:54:33.263 UTC
null
null
null
null
1,112,819
null
1
37
c#|razor|enums|asp.net-mvc-5.1
27,052
<p>Create new folder Views/Shared/DisplayTemplates<br/> Add empty Partial View named Enum, to the folder<br/> Replace Enum View code with:</p> <pre><code>@model Enum @if (EnumHelper.IsValidForEnumHelper(ViewData.ModelMetadata)) { // Display Enum using same names (from [Display] attributes) as in editors string displayName = null; foreach (SelectListItem item in EnumHelper.GetSelectList(ViewData.ModelMetadata, (Enum)Model)) { if (item.Selected) { displayName = item.Text ?? item.Value; } } // Handle the unexpected case that nothing is selected if (String.IsNullOrEmpty(displayName)) { if (Model == null) { displayName = String.Empty; } else { displayName = Model.ToString(); } } @Html.DisplayTextFor(model =&gt; displayName) } else { // This Enum type is not supported. Fall back to the text. @Html.DisplayTextFor(model =&gt; model) } </code></pre> <p>Here is the <a href="http://www.codeproject.com/Articles/776908/Dealing-with-Enum-in-MVC" rel="noreferrer">link to detailed article by Shahriar Hossain</a></p>
24,019,820
Today App Extension Widget Tap To Open Containing App
<p>I've implemented a Today widget for my application +Quotes which displays the day's quote within the notification center with the help of these <a href="https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214-CH20-SW1" rel="noreferrer" title="Apple&#39;s Docs">Apple Docs</a>. What I'd like to accomplish is opening the Containing App, in this case +Quotes, when the user taps the +Quotes widget within their Today notification view, not entirely sure what to call this, as Calendar would if you tapped it in the Today view. I've tried overlaying a button over the label which would call <code>-(void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL success))completionHandler</code> upon it being tapped, then open the Custom URL Scheme I have declared to open the Containing App. The issue is it doesn't open the Containing App.</p> <p><img src="https://i.stack.imgur.com/NGmcr.png" alt="+Quotes Today App Extension Widget"></p> <pre><code>-(IBAction)myButton:(id)sender { NSURL *customURL = [NSURL URLWithString:@"PositiveQuotes://"]; [self openURL:customURL completionHandler:nil]; } </code></pre>
24,038,704
5
0
null
2014-06-03 16:04:37.833 UTC
13
2017-05-15 03:06:29.12 UTC
2017-05-15 03:06:29.12 UTC
null
2,108,547
null
2,108,547
null
1
59
ios|ios8|ios-app-extension|today-extension
40,654
<p>EDIT: Ok, just a little correction here. I got it working with placing a button over the label just like suggested above and the following code: </p> <pre><code>- (IBAction) goToApp: (id)sender { NSURL *url = [NSURL URLWithString:@"floblog://"]; [self.extensionContext openURL:url completionHandler:nil]; } </code></pre> <p>I linked it to a "Touch Up Inside" event. However, this also causes the app to launch when the user scrolls the Today view.</p> <p>=======================================</p> <p>I ran into the same issue. However, it seems that there is no solution for now since the <a href="https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-8.0/index.html">release notes</a> for the first beta of iOS 8 mention:</p> <blockquote> <p>Known Issues: openURL does not work from an extension.</p> </blockquote> <p>So I guess we will at least have to wait until beta 2.</p>
19,861,373
Powershell - Get-ADOrganizationalUnit Groups
<p>I'm starting to get my head around powershell. But then again maybe not! Can someone please tell me how to list all security groups within a OU? </p> <p>I am able to list all the members within a group, for example:</p> <pre><code>get-adgroupmember "groupName" | select-object name </code></pre> <p>In the following, I am trying to list all security groups within an OU:</p> <pre><code>Import-Module ActiveDirectory Get-ADOrganizationalUnit -Identity 'ou=OUName' ERROR: Cannot find object with identity: ...... </code></pre> <p>I would like to remove all members from all security groups in a particular OU. Then I would like to add group members from a text file.</p>
19,862,082
2
0
null
2013-11-08 14:26:43.457 UTC
null
2013-11-08 16:04:54.99 UTC
2013-11-08 15:01:46.59 UTC
null
260,545
null
2,606,804
null
1
5
powershell|powershell-2.0
59,762
<p>From <a href="http://technet.microsoft.com/en-us/library/hh852298" rel="noreferrer">Get-ADOrganizationalUnit</a></p> <p>Here is how you're supposed to use -Identity (from the examples at the bottom of the above document):</p> <pre><code>Get-ADOrganizationalUnit -Identity 'OU=AsiaPacific,OU=Sales,OU=UserAccounts,DC=FABRIKAM,DC=COM' </code></pre> <p>So I suspect your 'ou=OUName' needs the relevant DC=domain,DC=com information on the end.</p> <p>To remove users I'd go about doing it this way:</p> <pre><code>Get-ADGroup -SearchBase "OU=AsiaPacific,OU=Sales,OU=UserAccounts,DC=FABRIKAM,DC=COM" -filter {GroupCategory -eq "Security"} | Get-ADGroupMember | Remove-ADGroupMember -WhatIf </code></pre> <p>Replace -WhatIf with -Confirm:$false if you're happy this does what you need.</p>
5,823,375
How to learn Fortran. Problems?
<p>I have just got a job, starting in a months time which requires me to use fortran.</p> <p>I have brought a couple of books, but they seem to lack any questions or problems and that is how i learn best.</p> <p>I would like to know if you could recommend and books or websites that offer problems that i could practise with.</p> <p>Thanks</p>
5,825,624
4
7
null
2011-04-28 18:36:20.567 UTC
10
2011-09-22 15:39:29.857 UTC
2011-09-22 15:39:29.857 UTC
null
764,846
null
729,905
null
1
3
fortran
9,870
<p>I can recommend several, depending on your previous programming in general knowledge and Fortran specific knowledge.</p> <p>For an <a href="http://www.youtube.com/watch?v=9hca-yvFUPk" rel="nofollow noreferrer">absolute beginner</a> (and don't take this in a negative context; it just means you're starting anew, and unlike someone who has a habit of some bad Fortran77 practices, you'll start with a clean mindset) I would definitely go with <a href="https://rads.stackoverflow.com/amzn/click/com/0073191574" rel="nofollow noreferrer" rel="nofollow noreferrer">Chapman's Fortran 95/2003 for Scientists &amp; Engineers</a>. It is an <strong><em>excellent learning book</em></strong>, and although it has some drawbacks they're not important at this stage. It also has a plethora of examples useful in real life. It also emphasises good modern Fortran concepts and ideas (Fortran 90 and newer).</p> <p>After it, or maybe instead of it, if you're looking for more of a reference book one cannot recommend enough one of the following:<br> - <a href="https://rads.stackoverflow.com/amzn/click/com/0198526938" rel="nofollow noreferrer" rel="nofollow noreferrer">Metcalf, Reid and Cohen's Fortran 95/2003 Explained</a> (btw, a new edition covering the latest Fortran standard is coming up in a few days) - a classical reference book. Some swear by it instead of Chapman's.<br> - <a href="https://rads.stackoverflow.com/amzn/click/com/1846283787" rel="nofollow noreferrer" rel="nofollow noreferrer">The Fortran 2003 Handbook: The Complete Syntax, Features and Procedures</a> by several authors; a standard reference book, dealing with the finer aspects of the language. Not important at this stage but just so you know it's there.</p> <p>Apart from these, which I like to call "the big three", there are numerous tutorials, scriptas and handbooks all over the web (free) and on Amazon. Some links were given in <a href="https://stackoverflow.com/questions/723851/fortran-90-resources">here</a> as well, so I won't repeat those. Also, your compiler is bound to have a good reference manual I don't know about the free g* ones, but all commercial ones do.)</p> <p>Apart from that, you know you can always ask any question that comes to your mind in here, and on comp.lang.fortran (usenet group; google for a "Usenet client" or "newsclient" and check it out.). Some very(!) knowledgeable people lurk in there.</p>
34,486,832
Objects.equals and Object.equals
<p>I try to create a tuple class that allows a tuple-like structure in Java. The general type for two elements in tuple are X and Y respectively. I try to override a correct equals for this class.</p> <p>Thing is, I know Object.equals falls into default that it still compares based on references like "==", so I am not so sure I can use that. I looked into Objects and there is an equals() in it. Does this one still compare on references, or it compares on contents? </p> <p>Quickly imagined the return statement as something like:</p> <pre><code>return Objects.equals(compared.prev, this.prev) &amp;&amp; Objects.equals(compared.next, this.next); </code></pre> <p>where prev and next are elements of tuple. Would this work?</p>
34,486,950
4
1
null
2015-12-28 01:56:59.23 UTC
4
2021-10-25 14:57:53.953 UTC
null
null
null
null
4,206,075
null
1
42
java|equals
54,229
<p>The difference is the <code>Objects.equals()</code> considers two nulls to be "equal". The pseudo code is:</p> <ol> <li>if both parameters are <code>null</code> or the same object, return <code>true</code></li> <li>if the first parameter is <code>null</code> return <code>false</code></li> <li>return the result of passing the second parameter to the <code>equals()</code> method of the first parameter </li> </ol> <p>This means it is "null safe" (non null safe implementation of the first parameter’s <code>equals()</code> method notwithstanding).</p>
1,662,038
Retrieve ADO Recordset Field names (Classic ASP)
<p>I wonder if someone can help:</p> <p>Long story short, I'm using MSSQL2005 to build a Pivot table. The data being examined is limited by date range (All data for 1 week starting from the nearest Monday to the date selected)</p> <p>When I run the Stored Proc and pass it a date, I get The correct table back eg:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th><strong>Time</strong></th> <th><strong>1 Jan 09</strong></th> <th><strong>2 Jan 09</strong></th> <th><strong>3 Jan 09</strong></th> <th><strong>...</strong></th> </tr> </thead> <tbody> <tr> <td>09:00</td> <td>0</td> <td>9</td> <td>25</td> <td>...</td> </tr> <tr> <td>09:30</td> <td>8</td> <td>27</td> <td>65</td> <td>...</td> </tr> <tr> <td>10:00</td> <td>20</td> <td>44</td> <td>112</td> <td>...</td> </tr> </tbody> </table> </div> <p>The only problem I have is that the column headers will vary based on both the date passed in to the SP (The desired view date) and the logic inside the SP (which forces the left-hand column to be the nearest Monday to the date specified).</p> <p>This means that when I display the results to the user, I (currently) need to duplicate the date-checking logic in classic ASP [easy but a maintainability fail]</p> <p>What I really need is a way of retrieving the column names from the recordset itself.</p> <p>Can someone please point me in the right direction?</p> <p>I've Googled but all the results I get seem to relate to reading a Table Schema - which doesn't help in this case as my table is being generated on the fly in memory.</p> <p>Many thanks in advance for any help you can provide</p>
1,662,082
2
0
null
2009-11-02 15:42:11.067 UTC
2
2021-04-27 20:19:41.813 UTC
2021-04-27 20:19:41.813 UTC
null
156,755
null
156,755
null
1
9
asp-classic|ado|pivot|recordset
42,058
<p>Given an ado record set you could do roughly the following (This is in psuedo code):</p> <pre><code>foreach (field in rs.Fields) { alert(field.Name); } </code></pre> <p>This will give you the name of the field check out this <a href="http://www.w3schools.com/ADO/prop_field_name.asp" rel="noreferrer">documentation</a>. </p>
2,156,482
Why does adding a new value to list<> overwrite previous values in the list<>
<p>I'm essentially trying to add multiple items to a list but at the end all items have the same value equal to last item.</p> <pre><code>public class Tag { public string TagName { get; set; } } List&lt;Tag&gt; tags = new List&lt;Tag&gt;(); Tag _tag = new Tag(); string[] tagList = new[]{"Foo", "Bar"}; foreach (string t in tagList) { _tag.tagName = t; // set all properties //Add class to collection, this is where all previously added rows are overwritten tags.Add(_tag); } </code></pre> <p>The code above produces list of two items with <code>TagName</code> set to "Bar" when I expect one for <code>"Foo"</code> and one with <code>"Bar"</code>. <strong>Why all items have the same properties in the resulting list?</strong></p> <p>Bonus point for explanation why changing <code>public class Tag</code> to <code>public struct Tag</code> makes this code work as expected (different items have different values).</p> <hr> <p>If that matter my actual goal is to create derived collection class, but since issue happens with just list it likely optional, still showing what my goal is below. </p> <p>Following a few tutorials and such I was able to successfully create a collection class which inherits the functionality needed to create a DataTable which can be passed to a Sql Server's stored procedure as a table value parameter. Everything seems to be working well; I can get all of the rows added and it looks beautiful. However, upon closer inspection I notice that when I add a new row, the data for all of the previous rows is overwritten with the value for the new row. So if I have a row with a string value of "foo" and I add a second row with the value "bar", the second row will be inserted (making a DataTable with two rows) but both rows will have the value "bar". Can anyone see why this would be? Here is some of the code, which works but has been a bit simplified (the Tag class has been reduced for ease of explanation).</p> <p>The following is the Collection class's:</p> <pre><code>using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using Microsoft.SqlServer.Server; namespace TagTableBuilder { public class TagCollection : List&lt;Tag&gt;, IEnumerable&lt;SqlDataRecord&gt; { IEnumerator&lt;SqlDataRecord&gt; IEnumerable&lt;SqlDataRecord&gt;.GetEnumerator() { var sdr = new SqlDataRecord( new SqlMetaData("Tag", SqlDbType.NVarChar) ); foreach (Tag t in this) { sdr.SetSqlString(0, t.tagName); yield return sdr; } } } public class Tag { public string tagName { get; set; } } } </code></pre> <p>These are called as follows:</p> <pre><code>//Create instance of collection TagCollection tags = new TagCollection(); //Create instance of object Tag _tag = new Tag(); foreach (string t in tagList) { //Add value to class propety _tag.tagName = t; //Add class to collection, this is where all previously added rows are overwritten tags.Add(_tag); } </code></pre>
2,163,355
2
0
null
2010-01-28 17:21:44.773 UTC
5
2019-02-25 01:53:38.967 UTC
2019-02-25 01:17:51.917 UTC
null
477,420
null
261,191
null
1
26
c#
44,072
<p>You're using the same instance of the <code>Tag</code> object inside the loop, so each update to the <code>TagName</code> is to the same reference. Move the declaration inside the loop to get a fresh object on each pass of the loop:</p> <pre><code>foreach (string t in tagList) { Tag _tag = new Tag(); // create new instance for every iteration _tag.tagName = t; tags.Add(_tag); } </code></pre> <p>For bonus part - when you change <code>Tag</code> from <code>class</code> to <code>struct</code> copy operation (that happens when you call <code>tags.Add(_tag)</code>) copies whole instance (essentially creating new one) unlike in original <code>class</code> case when only reference to the same single instance is copied into the parameter of the call and then to the list's element (see <a href="https://stackoverflow.com/questions/29606475/c-sharp-pass-by-value-vs-pass-by-reference">C# pass by value vs. pass by reference</a> for explanation on how <code>struct</code> passed to method calls).</p>
1,597,930
Architecture of a PHP app on Amazon EC2
<p>I recently experienced a flood of traffic on a Facebook app I created (mostly for the sake of education, not with any intention of marketing)</p> <p>Needless to say, I did not think about scalability when I created the app. I'm now in a position where my meager virtual server hosted by MediaTemple isn't cutting it at all, and it's really coming down to raw I/O of the machine. Since this project has been so educating to me so far, I figured I'd take this as an opportunity to understand the Amazon EC2 platform. </p> <p>The app itself is created in PHP (using Zend Framework) with a MySQL backend. I use application caching wherever possible with memcached. I've spent the weekend playing around with EC2, spinning up instances, installing the packages I want, and mounting an EBS volume to an instance.</p> <p>But what's the next logical step that is going to yield good results for scalability? Do I fire up an AMI instance for the MySQL and one for the Apache service? Or do I just replicate the instances out as many times as I need them and then do some sort of load balancing on the front end? Ideally, I'd like to have a centralized database because I do aggregate statistics across all database rows, however, this is not a hard requirement (there are probably some application specific solutions I could come up with to work around this)</p> <p>I know this is probably not a straight forward answer, so opinions and suggestions are welcome.</p>
1,600,564
2
0
null
2009-10-20 23:40:09.51 UTC
23
2009-10-21 14:52:54.313 UTC
null
null
null
null
5,865
null
1
30
php|zend-framework|amazon-ec2
9,430
<p>So many questions - all of them good though.</p> <p>In terms of scaling, you've a few options.</p> <p>The first is to start with a single box. You can scale upwards - with a more powerful box. EC2 have various sized instances. This involves a server migration each time you want a bigger box.</p> <p>Easier is to add servers. You can start with a single instance for Apache &amp; MySQL. Then when traffic increases, create a separate instance for MySQL and point your application to this new instance. This creates a nice layer between application and database. It sounds like this is a good starting point based on your traffic.</p> <p>Next you'll probably need more application power (web servers) or more database power (MySQL cluster etc.). You can have your DNS records pointing to a couple of front boxes running some load balancing software (try <a href="http://www.apsis.ch/pound/" rel="noreferrer">Pound</a>). These load balancing servers distribute requests to your webservers. EC2 has <a href="http://aws.amazon.com/ec2/#pricing" rel="noreferrer">Elastic Load Balancing</a> which is an alternative to managing this yourself, and is probably easier - I haven't used it personally.</p> <p>Something else to be aware of - <strong>EC2 has no persistent storage</strong>. You have to manage persistent data yourself using the Elastic Block Store. <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1663" rel="noreferrer">This guide</a> is an excellent tutorial on how to do this, with automated backups.</p> <p>I recommend that you purchase some reserved instances if you decide EC2 is the way forward. You'll save yourself about 50% over 3 years!</p> <p>Finally, you may be interested in services like <a href="http://www.rightscale.com/" rel="noreferrer">RightScale</a> which offer management services at a cost. There are other providers available.</p>
1,567,134
How can I get a writable path on the iPhone?
<p><em>I am posting this question because I had a complete answer for this written out for another post, when I found it did not apply to the original but I thought was too useful to waste. Thus I have also made this a community wiki, so that others may flesh out question and answer(s). If you find the answer useful, please vote up the question - being a community wiki I should not get points for this voting but it will help others find it</em></p> <p>How can I get a path into which file writes are allowed on the iPhone? You can (misleadingly) write anywhere you like on the Simulator, but on the iPhone you are only allowed to write into specific locations.</p>
1,567,147
2
0
2009-10-14 15:37:55.243 UTC
2009-10-14 15:37:55.243 UTC
62
2012-01-13 08:46:44.75 UTC
2009-10-14 15:45:00.313 UTC
null
6,330
null
6,330
null
1
74
iphone|filesystems
43,005
<p>There are three kinds of writable paths to consider - the first is Documents, where you store things you want to keep and make available to the user through iTunes (as of 3.2):</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; </code></pre> <p>Secondly, and very similar to the Documents directory, there is the Library folder, where you store configuration files and writable databases that you also want to keep around, but you don't want the user to be able to mess with through iTunes:</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *libraryDirectory = [paths objectAtIndex:0]; </code></pre> <p>Note that even though the user cannot see files in iTunes using a device older than 3.2 (the iPad), the NSLibraryDirectory constant has been available since iPhoneOS 2.0, and so can be used for builds targeting 3.0 (or even earlier if you are still doing that). Also the user will not be able to see anything unless you flag an app as allowing users to modify documents, so if you are using Documents today you are fine as long as you change location when updating for support of user documents.</p> <p>Last there is a cache directory, where you can put images that you don't care exist for the long term or not (the phone may delete them at some point):</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachePath = [paths objectAtIndex:0]; BOOL isDir = NO; NSError *error; if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&amp;isDir] &amp;&amp; isDir == NO) { [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&amp;error]; } </code></pre> <p>Note that you have to actually create the Caches directory there, so when writing you have to check and create every time! Kind of a pain, but that's how it is.</p> <p>Then when you have a writable path, you just append a file name onto it like so:</p> <pre><code>NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"SomeDirectory/SomeFile.txt"]; </code></pre> <p>or </p> <pre><code>NSString *filePath = [cachePath stringByAppendingPathComponent:@"SomeTmpFile.png"]; </code></pre> <p>Use that path for reading or writing.</p> <p>Note that you can make subdirectories in either of those writable paths, which one of the example string above is using (assuming one has been created).</p> <p>If you are trying to write an image into the photo library, you cannot use file system calls to do this - instead, you have to have a UIImage in memory, and use the <code>UIImageWriteToSavedPhotosAlbum()</code> function call defined by UIKit. You have no control over the destination format or compression levels, and cannot attach any EXIF in this way.</p>
29,206,067
Understanding Chrome network log "Stalled" state
<p>I've a following network log in chrome:</p> <p><img src="https://i.stack.imgur.com/IJXd5.png" alt="network log"></p> <p>I don't understand one thing in it: what's the difference between filled gray bars and transparent gray bars.</p>
29,564,247
5
1
null
2015-03-23 08:42:02.31 UTC
39
2020-02-26 09:51:11.367 UTC
2015-04-10 14:42:37.237 UTC
null
3,155,639
null
753,621
null
1
213
google-chrome|http|httprequest|google-chrome-devtools
193,186
<p>Google gives a breakdown of these fields in the <a href="https://developer.chrome.com/devtools/docs/network" rel="noreferrer">Evaluating network performance</a> section of their DevTools documentation.</p> <h3>Excerpt from <a href="https://developer.chrome.com/devtools/docs/network#resource-network-timing" rel="noreferrer">Resource network timing</a>:</h3> <blockquote> <h3>Stalled/Blocking</h3> <p>Time the request spent waiting before it could be sent. This time is inclusive of any time spent in proxy negotiation. Additionally, this time will include when the browser is waiting for an already established connection to become available for re-use, obeying Chrome's <a href="https://code.google.com/p/chromium/issues/detail?id=12066" rel="noreferrer">maximum six</a> TCP connection per origin rule.</p> </blockquote> <p>(If you forget, Chrome has an &quot;Explanation&quot; link in the hover tooltip and under the &quot;Timing&quot; panel.)</p> <p>Basically, the primary reason you will see this is because Chrome will only download 6 files per-server at a time and other requests will be stalled until a connection slot becomes available.</p> <p>This isn't necessarily something that needs fixing, but one way to avoid the stalled state would be to distribute the files across multiple domain names and/or servers, keeping <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS" rel="noreferrer">CORS</a> in mind if applicable to your needs, however HTTP2 is probably a better option going forward. Resource bundling (like JS and CSS concatenation) can also help to reduce amount of stalled connections.</p>
6,098,685
Running multiple threads concurrently
<p>Good day all, for running multiple threads concurrently is it advisable to create different thread objects from a class or create two classes where one implements runnable and one extends a thread and then create thread objects from both of them as needed assuming we are trying to run 7- 10 tasks concurrently. </p> <ol> <li>whats are the best solutions?..</li> <li>Are there any pitfalls or performance hit, if one creates different thread objects from a single class?. </li> </ol> <p>Thank you. Tips appreciated as always.</p>
6,098,724
5
2
null
2011-05-23 14:34:53.577 UTC
1
2011-05-24 06:49:14.753 UTC
2011-05-23 14:45:09.783 UTC
null
447,570
null
447,570
null
1
14
java|multithreading
39,177
<p>I would personally go for <strong>option(1)</strong> (Creating 2 different threads of the same class). </p> <p>I don't feel there's need to create 2 different classes for the job that can be done by 2 different threads of the same class.</p>
6,270,440
Simple logical operators in Bash
<p>I have a couple of variables and I want to check the following condition (written out in words, then my failed attempt at bash scripting):</p> <pre><code>if varA EQUALS 1 AND ( varB EQUALS "t1" OR varB EQUALS "t2" ) then do something done. </code></pre> <p>And in my failed attempt, I came up with:</p> <pre><code>if (($varA == 1)) &amp;&amp; ( (($varB == "t1")) || (($varC == "t2")) ); then scale=0.05 fi </code></pre>
6,270,803
5
0
null
2011-06-07 19:18:05.683 UTC
280
2020-06-15 08:44:48.587 UTC
2017-02-04 06:43:11.217 UTC
null
6,862,601
null
381,798
null
1
313
bash|logical-operators
371,088
<p>What you've written actually almost works (it would work if all the variables were numbers), but it's not an idiomatic way at all.</p> <ul> <li><code>(…)</code> parentheses indicate a <a href="http://www.gnu.org/software/bash/manual/bash.html#Command-Grouping" rel="noreferrer">subshell</a>. What's inside them isn't an expression like in many other languages. It's a list of commands (just like outside parentheses). These commands are executed in a separate subprocess, so any redirection, assignment, etc. performed inside the parentheses has no effect outside the parentheses. <ul> <li>With a leading dollar sign, <code>$(…)</code> is a <a href="http://www.gnu.org/software/bash/manual/bash.html#Command-Substitution" rel="noreferrer">command substitution</a>: there is a command inside the parentheses, and the output from the command is used as part of the command line (after extra expansions unless the substitution is between double quotes, but that's <a href="https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters">another story</a>).</li> </ul></li> <li><code>{ … }</code> braces are like parentheses in that they group commands, but they only influence parsing, not grouping. The program <code>x=2; { x=4; }; echo $x</code> prints 4, whereas <code>x=2; (x=4); echo $x</code> prints 2. (Also braces require spaces around them and a semicolon before closing, whereas parentheses don't. That's just a syntax quirk.) <ul> <li>With a leading dollar sign, <code>${VAR}</code> is a <a href="http://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion" rel="noreferrer">parameter expansion</a>, expanding to the value of a variable, with possible extra transformations.</li> </ul></li> <li><code>((…))</code> double parentheses surround an <a href="http://www.gnu.org/software/bash/manual/bash.html#Shell-Arithmetic" rel="noreferrer">arithmetic instruction</a>, that is, a computation on integers, with a syntax resembling other programming languages. This syntax is mostly used for assignments and in conditionals. <ul> <li>The same syntax is used in arithmetic expressions <code>$((…))</code>, which expand to the integer value of the expression.</li> </ul></li> <li><code>[[ … ]]</code> double brackets surround <a href="http://www.gnu.org/software/bash/manual/bash.html#index-_005b_005b" rel="noreferrer">conditional expressions</a>. Conditional expressions are mostly built on <a href="http://www.gnu.org/software/bash/manual/bash.html#Bash-Conditional-Expressions" rel="noreferrer">operators</a> such as <code>-n $variable</code> to test if a variable is empty and <code>-e $file</code> to test if a file exists. There are also string equality operators: <code>"$string1" == "$string2"</code> (beware that the right-hand side is a pattern, e.g. <code>[[ $foo == a* ]]</code> tests if <code>$foo</code> starts with <code>a</code> while <code>[[ $foo == "a*" ]]</code> tests if <code>$foo</code> is exactly <code>a*</code>), and the familiar <code>!</code>, <code>&amp;&amp;</code> and <code>||</code> operators for negation, conjunction and disjunction as well as parentheses for grouping. Note that you need a space around each operator (e.g. <code>[[ "$x" == "$y" ]]</code>, not <s><code>[[ "$x"=="$y" ]]</code></s>), and a space or a character like <code>;</code> both inside and outside the brackets (e.g. <code>[[ -n $foo ]]</code>, not <s><code>[[-n $foo]]</code></s>).</li> <li><code>[ … ]</code> single brackets are an alternate form of conditional expressions with more quirks (but older and more portable). Don't write any for now; start worrying about them when you find scripts that contain them.</li> </ul> <p>This is the idiomatic way to write your test in bash:</p> <pre><code>if [[ $varA == 1 &amp;&amp; ($varB == "t1" || $varC == "t2") ]]; then </code></pre> <p>If you need portability to other shells, this would be the way (note the additional quoting and the separate sets of brackets around each individual test, and the use of the traditional <code>=</code> operator rather than the ksh/bash/zsh <code>==</code> variant):</p> <pre><code>if [ "$varA" = 1 ] &amp;&amp; { [ "$varB" = "t1" ] || [ "$varC" = "t2" ]; }; then </code></pre>
5,776,660
Export from sqlite to csv using shell script
<p>I'm making a shell script to export a sqlite query to a csv file, just like this:</p> <pre><code> #!/bin/bash ./bin/sqlite3 ./sys/xserve_sqlite.db ".headers on" ./bin/sqlite3 ./sys/xserve_sqlite.db ".mode csv" ./bin/sqlite3 ./sys/xserve_sqlite.db ".output out.csv" ./bin/sqlite3 ./sys/xserve_sqlite.db "select * from eS1100_sensor_results;" ./bin/sqlite3 ./sys/xserve_sqlite.db ".exit" </code></pre> <p>When executing the script, the output apears on the screen, instead of being saved to "out.csv". It's working doing the same method with the command line, but I don't know why the shell script fails to export data to the file.</p> <p>What am I doing wrong?</p>
5,776,785
7
0
null
2011-04-25 08:35:15.983 UTC
48
2021-04-07 20:24:54.573 UTC
2013-09-04 01:01:30.833 UTC
null
2,683
null
704,178
null
1
95
sqlite|shell|csv
97,559
<h3>sqlite3</h3> <p>You have a separate call to <code>sqlite3</code> for each line; by the time your <code>select</code> runs, your <code>.out out.csv</code> has been forgotten.</p> <p>Try:</p> <pre><code>#!/bin/bash ./bin/sqlite3 ./sys/xserve_sqlite.db &lt;&lt;! .headers on .mode csv .output out.csv select * from eS1100_sensor_results; ! </code></pre> <p>instead.</p> <h3>sh/bash methods</h3> <p>You can either call your script with a redirection:</p> <pre><code>$ your_script &gt;out.csv </code></pre> <p>or you can insert the following as a first line in your script:</p> <pre><code>exec &gt;out.csv </code></pre> <p>The former method allows you to specify different filenames, while the latter outputs to a specific filename. In both cases the line <code>.output out.csv</code> can be ignored.</p>
5,849,192
Spring's overriding bean
<p>Can we have duplicate names for the same bean id that is mentioned in the XML? If not, then how do we override the bean in Spring?</p>
5,849,483
8
1
null
2011-05-01 15:08:41.333 UTC
16
2020-07-19 09:50:07.75 UTC
2015-06-15 09:08:55.08 UTC
null
81,520
null
507,134
null
1
42
spring
120,364
<p>Any given Spring context can only have one bean for any given id or name. In the case of the XML <code>id</code> attribute, this is enforced by the schema validation. In the case of the <code>name</code> attribute, this is enforced by Spring's logic.</p> <p>However, if a context is constructed from two different XML descriptor files, and an <code>id</code> is used by both files, then one will "override" the other. The exact behaviour depends on the ordering of the files when they get loaded by the context.</p> <p>So while it's possible, it's not recommended. It's error-prone and fragile, and you'll get no help from Spring if you change the ID of one but not the other.</p>
6,237,455
Chrome renders colours differently from Safari and Firefox
<p>Chrome renders #FF3A00 as #FF0000 for some reason. I included a screenshot from <a href="http://jsfiddle.net/L9xy4/" rel="noreferrer">jsfiddle</a> to illustrate the point. The colour that the Color Meter reports (and what I see) differs from what CSS says.</p> <p>This happens to other colours too. For example, #FFAF00 is rendered as #FFA400 according to the Color Meter.</p> <p>However, the colours are rendered without problems on Safari and Firefox. I'm on a Mac using Chrome 11, Safari 5 and Firefox 5.</p> <p>I'm sure there's a logical explanation. Any ideas?</p> <p>Update: I'm attaching a screenshot of Chrome next to Safari showing the very same page. I checked this image in Photoshop: the colours are #F00 in Chrome and #FF3A00 in Safari.<img src="https://i.stack.imgur.com/R5QvN.png" alt="Chrome vs Safari"></p> <p><img src="https://i.stack.imgur.com/La5WR.png" alt="Chrome renders #FF3A00 as #F00"></p>
6,338,124
8
10
null
2011-06-04 14:59:54.147 UTC
13
2021-01-27 18:14:59.783 UTC
2011-06-04 15:35:02.567 UTC
null
219,977
null
219,977
null
1
85
css|google-chrome|colors|rendering
68,303
<p>I recently posted a similar question: <a href="https://stackoverflow.com/questions/6338077/google-chrome-for-mac-css-colors-and-display-profiles">https://stackoverflow.com/questions/6338077/google-chrome-for-mac-css-colors-and-display-profiles</a></p> <p>As Andrew Marshall answered there, this is a known issue: <a href="http://code.google.com/p/chromium/issues/detail?id=44872" rel="noreferrer">http://code.google.com/p/chromium/issues/detail?id=44872</a></p>
5,612,602
Improving regex for parsing YouTube / Vimeo URLs
<p>I've made a function (in JavaScript) that takes an URL from either YouTube or Vimeo. It figures out the provider and ID for that particular video (demo: <a href="http://jsfiddle.net/csjwf/" rel="noreferrer">http://jsfiddle.net/csjwf/</a>). </p> <pre><code>function parseVideoURL(url) { var provider = url.match(/http:\/\/(:?www.)?(\w*)/)[2], id; if(provider == "youtube") { id = url.match(/http:\/\/(?:www.)?(\w*).com\/.*v=(\w*)/)[2]; } else if (provider == "vimeo") { id = url.match(/http:\/\/(?:www.)?(\w*).com\/(\d*)/)[2]; } else { throw new Error("parseVideoURL() takes a YouTube or Vimeo URL"); } return { provider : provider, id : id } } </code></pre> <p>It works, however as a regex Novice, I'm looking for ways to improve it. The input I'm dealing with, typically looks like this:</p> <pre><code>http://vimeo.com/(id) http://youtube.com/watch?v=(id)&amp;blahblahblah..... </code></pre> <p>1) Right now I'm doing three separate matches, would it make sense to try and do everything in one single expression? If so, how?</p> <p>2) Could the existing matches be more concise? Are they unnecessarily complex? or perhaps insufficient?</p> <p>3) Are there any YouTube or Vimeo URL's that would fail being parsed? I've tried quite a few and so far it seems to work pretty well.</p> <p><strong>To summarize:</strong> I'm simply looking for ways improve the above function. Any advice is greatly appreciated.</p>
5,613,414
12
0
null
2011-04-10 15:01:19.943 UTC
9
2022-09-23 07:27:30.637 UTC
null
null
null
null
50,841
null
1
18
javascript|regex|youtube|vimeo
26,835
<p>I am not sure about your question 3), but provided that your induction on the url forms is correct, the regexes can be combined into one as follows: </p> <pre><code>/http:\/\/(?:www.)?(?:(vimeo).com\/(.*)|(youtube).com\/watch\?v=(.*?)&amp;)/ </code></pre> <p>You will get the match under different positions (1st and 2nd matches if vimeo, 3rd and 4th matches if youtube), so you just need to handle that.</p> <p>Or, if you are quite sure that vimeo's id only includes numbers, then you can do:</p> <pre><code>/http:\/\/(?:www.)?(vimeo|youtube).com\/(?:watch\?v=)?(.*?)(?:\z|&amp;)/ </code></pre> <p>and the provider and the id will apprear under 1st and 2nd match, respcetively.</p>
46,584,175
RestSharp Timeout not working
<p>I have a restsharp client and request set up like this:</p> <pre><code>var request = new RestRequest(); request.Method = Method.POST; request.AddParameter("application/json", jsonBody, ParameterType.RequestBody); request.OnBeforeDeserialization = resp =&gt; { resp.ContentType = "application/json"; }; request.Timeout = -1; request.ReadWriteTimeout = -1; var url = $"http://{ipAddress}/api/calculate"; var client = new RestClient(); client.BaseUrl = new Uri(url); client.Timeout = -1; client.ReadWriteTimeout = -1; var response = client.Execute(request); </code></pre> <p>This request is going to take a while to finish, around 30 minutes. Now, I know that there are more elegant ways of doing this, but, for this request, I need to do it like this.</p> <p>This RestSharp client and request are executed inside Windows service. When service executes request, it throws TimoutException and request maximum timeout is around 40 seconds.</p> <p>For some reason, timeout that I set is not working for this case.</p> <p>Anybody has a solution for this?</p>
46,584,483
3
2
null
2017-10-05 11:08:46.657 UTC
3
2022-09-01 22:17:15.733 UTC
2017-10-05 11:47:01.897 UTC
null
1,849,024
null
4,966,197
null
1
26
c#|.net|windows-services|timeout|restsharp
61,187
<p>You may not be doing what you think by setting the <code>ReadWriteTimeout</code> value. Your value is ignored so you get the default.</p> <p>According to this answer <a href="https://stackoverflow.com/questions/28829524/what-is-default-timeout-value-of-restsharp-restclient">What is default timeout value of RestSharp RestClient?</a> RestSharp uses <code>HttpWebRequest</code> in its implementation.</p> <p>The timeout property for <code>HttpWebRequest</code> cannot be negative <a href="https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout" rel="noreferrer">HttpWebRequest.Timeout Property</a>.</p> <p>If you look in the RestSharp client code you see this: <a href="https://github.com/restsharp/RestSharp/blob/70de357b0b9dfc3926c95d1e69967c7a7cbe874c/RestSharp/RestClient.cs#L452" rel="noreferrer">https://github.com/restsharp/RestSharp/blob/70de357b0b9dfc3926c95d1e69967c7a7cbe874c/RestSharp/RestClient.cs#L452</a></p> <pre><code> int readWriteTimeout = request.ReadWriteTimeout &gt; 0 ? request.ReadWriteTimeout : this.ReadWriteTimeout; if (readWriteTimeout &gt; 0) { http.ReadWriteTimeout = readWriteTimeout; } </code></pre>
39,257,740
How to access state inside Redux reducer?
<p>I have a reducer, and in order to calculate the new state I need data from the action and also data from a part of the state not managed by this reducer. Specifically, in the reducer I will show below, I need access to the <code>accountDetails.stateOfResidenceId</code> field.</p> <p><strong>initialState.js:</strong></p> <pre><code>export default { accountDetails: { stateOfResidenceId: '', accountType: '', accountNumber: '', product: '' }, forms: { blueprints: [ ] } }; </code></pre> <p><strong>formsReducer.js:</strong></p> <pre><code>import * as types from '../constants/actionTypes'; import objectAssign from 'object-assign'; import initialState from './initialState'; import formsHelper from '../utils/FormsHelper'; export default function formsReducer(state = initialState.forms, action) { switch (action.type) { case types.UPDATE_PRODUCT: { //I NEED accountDetails.stateOfResidenceId HERE console.log(state); const formBlueprints = formsHelper.getFormsByProductId(action.product.id); return objectAssign({}, state, {blueprints: formBlueprints}); } default: return state; } } </code></pre> <p><strong>index.js (root reducer):</strong></p> <pre><code>import { combineReducers } from 'redux'; import accountDetails from './accountDetailsReducer'; import forms from './formsReducer'; const rootReducer = combineReducers({ accountDetails, forms }); export default rootReducer; </code></pre> <p>How can I access this field?</p>
39,260,147
9
2
null
2016-08-31 19:40:49.497 UTC
20
2021-01-26 16:04:47.287 UTC
null
null
null
null
2,421,349
null
1
97
javascript|reactjs|redux
71,753
<p>I would use <a href="https://github.com/gaearon/redux-thunk" rel="noreferrer">thunk</a> for this, here's an example:</p> <pre><code>export function updateProduct(product) { return (dispatch, getState) =&gt; { const { accountDetails } = getState(); dispatch({ type: UPDATE_PRODUCT, stateOfResidenceId: accountDetails.stateOfResidenceId, product, }); }; } </code></pre> <p>Basically you get all the data you need on the action, then you can send that data to your reducer.</p>
44,086,009
Path to bundle of iOS framework
<p>I am working on a framework for iOS, which comes with some datafiles. To load them into a <code>Dictionary</code> I do something like this:</p> <pre><code>public func loadPListFromBundle(filename: String, type: String) -&gt; [String : AnyObject]? { guard let bundle = Bundle(for: "com.myframework") let path = bundle.main.path(forResource: filename, ofType: type), let plistDict = NSDictionary(contentsOfFile: path) as? [String : AnyObject] else { print("plist not found") return nil } return plistDict } </code></pre> <p>If I use this in a playground with the framework, it works as intended.</p> <p>But if I use the framework embedded in an app, it doesn't work anymore, the "path" now points to the bundle of the app, not of the framework.</p> <p>How do I make sure that the bundle of the framework is accessed?</p> <p><strong>EDIT:</strong> the code above resides in the framework, not in the app.</p> <p><strong>EDIT2:</strong> the code above is a utility function, and is not part of a struct or class.</p>
44,088,602
5
1
null
2017-05-20 12:43:04.29 UTC
6
2021-10-01 13:20:30.153 UTC
2020-04-17 13:29:32.8 UTC
null
1,015,258
null
1,015,258
null
1
44
ios|swift|frameworks|bundle
30,516
<p>Use <code>Bundle(for:Type)</code>:</p> <pre><code>let bundle = Bundle(for: type(of: self)) let path = bundle.path(forResource: filename, ofType: type) </code></pre> <p>or search the bundle by <code>identifier</code> (the frameworks bundle ID):</p> <pre><code>let bundle = Bundle(identifier: &quot;com.myframework&quot;) </code></pre>
14,275,493
How to create text file using sql script with text "|"
<p>if i run below script without char "|" it working but when i am adding char "|" it is not working how to add char "|" using sql script to text file ?</p> <pre><code>DECLARE @Text AS VARCHAR(100) DECLARE @Cmd AS VARCHAR(100) SET @Text = 'Hello world| ' SET @Cmd ='echo ' + @Text + ' &gt; C:\AppTextFile.txt' EXECUTE Master.dbo.xp_CmdShell @Cmd </code></pre> <p>thanks </p>
14,283,954
3
4
null
2013-01-11 09:49:35.15 UTC
1
2018-04-09 12:32:21.827 UTC
2013-01-11 09:57:12.237 UTC
null
592,111
null
1,538,219
null
1
2
sql|sql-server|sql-scripts
72,929
<p>The pipe character has a special meaning in batch commands, so it must be <a href="https://stackoverflow.com/questions/1855009/batch-echo-pipe-symbol-causing-unexpected-behaviour">escaped</a> using the caret character. This should work:</p> <pre><code>DECLARE @Text AS VARCHAR(100) DECLARE @Cmd AS VARCHAR(100) SET @Text = 'Hello world^| ' SET @Cmd ='echo ' + @Text + ' &gt; C:\AppTextFile.txt' EXECUTE Master.dbo.xp_CmdShell @Cmd </code></pre> <p>Although this is really not a good way to write data to a text file: usually SQL Server should not have permission to write to the root of the C: drive, and <code>xp_cmdshell</code> is disabled by default. I suggest you look at alternatives like <code>sqlcmd.exe</code>, <code>bcp.exe</code> or a small script in your preferred language (PowerShell, Perl, Python, whatever).</p> <p>It is generally much easier, safer and more flexible to query data from SQL Server than it is to push it out from the server side. In your specific case, it looks like you want to write out a delimited file, and <a href="http://msdn.microsoft.com/en-us/library/ms162802.aspx" rel="nofollow noreferrer"><code>bcp.exe</code> is intended for that purpose</a>.</p>
19,572,154
how many times is System.Web.HttpApplication is initialised per process
<p>I have the <code>global.asax</code> which extends from a custom class I created, called <code>MvcApplication</code> which extends from <code>System.Web.HttpApplication</code>.</p> <p>In it's constructor, it logs application start as per below:</p> <pre><code>protected MvcApplicationGeneral() { _log.Info("logApplicationStartToTextFile"); } </code></pre> <p>When I went to look in the log file, this seems to be called A LOT of times, not just once per application start. I placed another log entry in <code>Application_Start</code> and that seems to be called only once. Is the <code>Global.asax</code> class instantiated per request, or much more frequently than just once per application?</p>
19,572,451
1
0
null
2013-10-24 17:02:59.667 UTC
8
2013-10-24 17:19:43.243 UTC
null
null
null
null
571,668
null
1
15
c#|asp.net|global-asax
7,170
<p>Multiple intances of HttpAppliction objects are created and pooled to process the requests.in the lifecycle of an asp.net application. yes Application_Start will be called only once.</p> <p>refer <a href="http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle" rel="noreferrer">http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle</a></p> <p>excerpt: Once all the core ASP.NET objects are created, ‘HttpApplication’ object is created to serve the request. In case you have a ‘global.asax’ file in your system, then the object of the ‘global.asax’ file will be created. Please note global.asax file inherits from ‘HttpApplication’ class. Note: The first time an ASP.NET page is attached to an application, a new instance of ‘HttpApplication’ is created. Said and done to maximize performance, HttpApplication instances might be reused for multiple requests.</p> <p><img src="https://i.stack.imgur.com/NJgj1.jpg" alt="enter image description here"></p>
19,596,135
Reading JSON files with C# and JSON.net
<p>Im having some trouble to understand how to use JSON.net to read a json file.</p> <p>The file is looking like this:</p> <pre><code>"version": { "files": [ { "url": "http://www.url.com/", "name": "someName" }, { "name": "someOtherName" "url": "http://www.url.com/" "clientreq": true }, .... </code></pre> <p>I really do not have much idea how i can read this file .. What i need to do is to read the lines and download the file via the "url".. I know how to download files and so on, but i dont know how i can use JSON.net to read the json file and loop through each section, and download the file.. </p> <p>Can you assist ?</p>
19,596,194
2
0
null
2013-10-25 17:35:03.197 UTC
4
2013-12-05 14:16:30.693 UTC
null
null
null
null
2,840,111
null
1
6
c#|json|json.net
38,693
<p>The easiest way is to deserialize your json into a dynamic object like this</p> <p>Then you can access its properties an loop for getting the urls</p> <pre><code>dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString); var urls = new List&lt;string&gt;(); foreach(var file in result.version.files) { urls.Add(file.url); } </code></pre>
44,381,358
Error: Cannot find module '@ionic/app-scripts'
<p>I'm new to Ionic. I was following the Ionic documentation "get started", created a project sample named "super". The problem is that when I run the command line <code>ionic serve</code> in the project directory, it threw an error <code>Error: Cannot find module '@ionic/app-scripts'</code></p>
44,749,860
18
0
null
2017-06-06 04:20:54.12 UTC
14
2022-02-08 15:29:24.723 UTC
2017-06-06 04:27:06.54 UTC
null
8,111,827
null
8,117,436
null
1
38
angularjs|ionic-framework|hybrid-mobile-app
84,359
<p>app-scripts currently compatible with node 6 and 7. İf you installed node 8, then please uninstall and install node 6 stable version. This solved error and now i can use ionic 3, angular 4 . Take care!</p>
42,460,039
Promise reject() causes "Uncaught (in promise)" warning
<p>Once a promise <code>reject()</code> callback is called, a warning message <em>"Uncaught (in promise)"</em> appears in the Chrome console. I can't wrap my head around the reason behind it, nor how to get rid of it.</p> <pre><code>var p = new Promise((resolve, reject) =&gt; { setTimeout(() =&gt; { var isItFulfilled = false isItFulfilled ? resolve('!Resolved') : reject('!Rejected') }, 1000) }) p.then(result =&gt; console.log(result)) p.catch(error =&gt; console.log(error)) </code></pre> <p>Warning:</p> <p><img src="https://i.stack.imgur.com/fB3nJ.png" alt="enter image description here"></p> <p><strong>Edit:</strong></p> <p>I found out that if the <code>onRejected</code> handler is not explicitly provided to the <code>.then(onResolved, onRejected)</code> method, JS will automatically provide an implicit one. It looks like this: <code>(err) =&gt; throw err</code>. The auto generated handler will throw in its turn.</p> <p>Reference:</p> <blockquote> <p>If IsCallable(<em>onRejected</em>)` is <strong>false</strong>, then<br> &nbsp; &nbsp; &nbsp;Let <em>onRejected</em> be "<strong>Thrower</strong>". </p> </blockquote> <p><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performpromisethen" rel="noreferrer">http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performpromisethen</a></p>
42,460,094
5
1
null
2017-02-25 18:35:33.263 UTC
11
2022-03-31 10:15:08.05 UTC
2018-03-05 20:31:47.747 UTC
null
5,459,839
null
5,464,660
null
1
62
javascript|promise|es6-promise|catch-block
55,415
<p>This happens because you do not attach a catch handler to the promise returned by the first <code>then</code> method, which therefore is without handler for when the promise rejects. You <em>do</em> have one for the promise <code>p</code> in the last line, but not for the <em>chained</em> promise, returned by the <code>then</code> method, in the line before it.</p> <p>As you correctly added in comments below, when a catch handler is not provided (or it's not a function), the <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performpromisethen" rel="noreferrer">default one will throw</a> the error. Within a promise chain this error can be caught down the line with a <code>catch</code> method callback, but if none is there, the JavaScript engine will deal with the error like with any other uncaught error, and apply the default handler in such circumstances, which results in the output you see in the console.</p> <p>To avoid this, chain the <code>.catch</code> method to the promise returned by the first <code>then</code>, like this:</p> <pre><code>p.then( result =&gt; console.log('Fulfilled')) .catch( error =&gt; console.log(error) ); </code></pre>
51,439,843
'unknown' vs. 'any'
<p>TypeScript 3.0 introduces <code>unknown</code> type, according to their wiki:</p> <blockquote> <p>unknown is now a reserved type name, as it is now a built-in type. Depending on your intended use of unknown, you may want to remove the declaration entirely (favoring the newly introduced unknown type), or rename it to something else.</p> </blockquote> <p>What is difference between <code>unknown</code> and <code>any</code>? When should we use <code>unknown</code> over <code>any</code>?</p>
51,439,876
8
2
null
2018-07-20 09:50:26.32 UTC
84
2022-08-19 15:45:09.157 UTC
2019-02-25 15:12:22.28 UTC
null
3,345,644
null
4,492,194
null
1
563
typescript|typescript3.0
165,055
<p>You can read more about <code>unknown</code> in the <a href="https://github.com/Microsoft/TypeScript/pull/24439" rel="noreferrer">PR</a> or the <a href="https://blogs.msdn.microsoft.com/typescript/2018/07/12/announcing-typescript-3-0-rc/" rel="noreferrer">RC announcement</a>, but the gist of it is:</p> <blockquote> <p>[..] unknown which is the type-safe counterpart of any. Anything is assignable to unknown, but unknown isn't assignable to anything but itself and any without a type assertion or a control flow based narrowing. Likewise, no operations are permitted on an unknown without first asserting or narrowing to a more specific type.</p> </blockquote> <p>A few examples:</p> <pre><code>let vAny: any = 10; // We can assign anything to any let vUnknown: unknown = 10; // We can assign anything to unknown just like any let s1: string = vAny; // Any is assignable to anything let s2: string = vUnknown; // Invalid; we can't assign vUnknown to any other type (without an explicit assertion) vAny.method(); // Ok; anything goes with any vUnknown.method(); // Not ok; we don't know anything about this variable </code></pre> <p>The suggested usage is:</p> <blockquote> <p>There are often times where we want to describe the least-capable type in TypeScript. This is useful for APIs that want to signal “this can be any value, so you must perform some type of checking before you use it”. This forces users to safely introspect returned values.</p> </blockquote>
9,071,316
Iphone simulator screen rotation
<p>How can I rotate the iPhone simulator to landscape? I have read many items of information, and none of them has helped me yet. I am using xcode 4, and am developing an iphone application. Thanks!</p>
9,071,343
5
0
null
2012-01-30 21:51:16.473 UTC
4
2022-08-11 05:33:12.05 UTC
2012-01-30 22:06:05.423 UTC
null
544,050
null
1,139,348
null
1
34
iphone|xcode4|ios-simulator
33,206
<p>Option 1: Use the left/right arrow keys while holding down command.</p> <p>Option 2: Under the Hardware tab at the top, select "Rotate Left" or "Rotate Right".</p>
9,550,297
Faster alternative to glReadPixels in iPhone OpenGL ES 2.0
<p>Is there any faster way to access the frame buffer than using glReadPixels? I would need read-only access to a small rectangular rendering area in the frame buffer to process the data further in CPU. Performance is important because I have to perform this operation repeatedly. I have searched the web and found some approach like using Pixel Buffer Object and glMapBuffer but it seems that OpenGL ES 2.0 does not support them. </p>
9,704,392
2
0
null
2012-03-03 22:07:23.86 UTC
95
2016-02-07 01:35:37.85 UTC
2012-03-14 14:57:18.84 UTC
null
19,679
null
1,179,521
null
1
67
iphone|ios|opengl-es|opengl-es-2.0
36,439
<p>As of iOS 5.0, there is now a faster way to grab data from OpenGL ES. It isn't readily apparent, but it turns out that the texture cache support added in iOS 5.0 doesn't just work for fast upload of camera frames to OpenGL ES, but it can be used in reverse to get quick access to the raw pixels within an OpenGL ES texture.</p> <p>You can take advantage of this to grab the pixels for an OpenGL ES rendering by using a framebuffer object (FBO) with an attached texture, with that texture having been supplied from the texture cache. Once you render your scene into that FBO, the BGRA pixels for that scene will be contained within your CVPixelBufferRef, so there will be no need to pull them down using <code>glReadPixels()</code>.</p> <p>This is much, much faster than using <code>glReadPixels()</code> in my benchmarks. I found that on my iPhone 4, <code>glReadPixels()</code> was the bottleneck in reading 720p video frames for encoding to disk. It limited the encoding from taking place at anything more than 8-9 FPS. Replacing this with the fast texture cache reads allows me to encode 720p video at 20 FPS now, and the bottleneck has moved from the pixel reading to the OpenGL ES processing and actual movie encoding parts of the pipeline. On an iPhone 4S, this allows you to write 1080p video at a full 30 FPS.</p> <p>My implementation can be found within the GPUImageMovieWriter class within my open source <a href="https://github.com/BradLarson/GPUImage" rel="noreferrer">GPUImage</a> framework, but it was inspired by <a href="http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/" rel="noreferrer">Dennis Muhlestein's article on the subject</a> and Apple's ChromaKey sample application (which was only made available at WWDC 2011).</p> <p>I start by configuring my AVAssetWriter, adding an input, and configuring a pixel buffer input. The following code is used to set up the pixel buffer input:</p> <pre><code>NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, [NSNumber numberWithInt:videoSize.width], kCVPixelBufferWidthKey, [NSNumber numberWithInt:videoSize.height], kCVPixelBufferHeightKey, nil]; assetWriterPixelBufferInput = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:assetWriterVideoInput sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary]; </code></pre> <p>Once I have that, I configure the FBO that I'll be rendering my video frames to, using the following code:</p> <pre><code>if ([GPUImageOpenGLESContext supportsFastTextureUpload]) { CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)[[GPUImageOpenGLESContext sharedImageProcessingOpenGLESContext] context], NULL, &amp;coreVideoTextureCache); if (err) { NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d"); } CVPixelBufferPoolCreatePixelBuffer (NULL, [assetWriterPixelBufferInput pixelBufferPool], &amp;renderTarget); CVOpenGLESTextureRef renderTexture; CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, coreVideoTextureCache, renderTarget, NULL, // texture attributes GL_TEXTURE_2D, GL_RGBA, // opengl format (int)videoSize.width, (int)videoSize.height, GL_BGRA, // native iOS format GL_UNSIGNED_BYTE, 0, &amp;renderTexture); glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture)); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0); } </code></pre> <p>This pulls a pixel buffer from the pool associated with my asset writer input, creates and associates a texture with it, and uses that texture as a target for my FBO.</p> <p>Once I've rendered a frame, I lock the base address of the pixel buffer:</p> <pre><code>CVPixelBufferLockBaseAddress(pixel_buffer, 0); </code></pre> <p>and then simply feed it into my asset writer to be encoded:</p> <pre><code>CMTime currentTime = CMTimeMakeWithSeconds([[NSDate date] timeIntervalSinceDate:startTime],120); if(![assetWriterPixelBufferInput appendPixelBuffer:pixel_buffer withPresentationTime:currentTime]) { NSLog(@"Problem appending pixel buffer at time: %lld", currentTime.value); } else { // NSLog(@"Recorded pixel buffer at time: %lld", currentTime.value); } CVPixelBufferUnlockBaseAddress(pixel_buffer, 0); if (![GPUImageOpenGLESContext supportsFastTextureUpload]) { CVPixelBufferRelease(pixel_buffer); } </code></pre> <p>Note that at no point here am I reading anything manually. Also, the textures are natively in BGRA format, which is what AVAssetWriters are optimized to use when encoding video, so there's no need to do any color swizzling here. The raw BGRA pixels are just fed into the encoder to make the movie.</p> <p>Aside from the use of this in an AVAssetWriter, I have some code in <a href="https://stackoverflow.com/a/10455622/19679">this answer</a> that I've used for raw pixel extraction. It also experiences a significant speedup in practice when compared to using <code>glReadPixels()</code>, although less than I see with the pixel buffer pool I use with AVAssetWriter. </p> <p>It's a shame that none of this is documented anywhere, because it provides a huge boost to video capture performance.</p>
10,606,558
How to attach PDF to email using PHP mail function
<p>I am sending an email using PHP mail function, but I would like to add a specified PDF file as a file attachment to the email. How would I do that?</p> <p>Here is my current code:</p> <pre><code>$to = "me@myemail.com"; $subject = "My message subject"; $message = "Hello,\n\nThis is sending a text only email, but I would like to add a PDF attachment if possible."; $from = "Jane Doe &lt;janedoe@myemail.com&gt;"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent!"; </code></pre>
10,606,615
3
1
null
2012-05-15 18:19:28.07 UTC
6
2018-03-26 09:38:48.42 UTC
null
null
null
null
1,279,133
null
1
14
email|email-attachments|php
63,158
<p>You should consider using a PHP mail library such as <a href="https://github.com/PHPMailer/PHPMailer" rel="noreferrer">PHPMailer</a> which would make the procedure to send mail much simpler and better.</p> <p>Here's an example of how to use PHPMailer, it's really simple!</p> <pre><code>&lt;?php require_once('../class.phpmailer.php'); $mail = new PHPMailer(); // defaults to using php "mail()" $body = file_get_contents('contents.html'); $body = eregi_replace("[\]",'',$body); $mail-&gt;AddReplyTo("name@yourdomain.com","First Last"); $mail-&gt;SetFrom('name@yourdomain.com', 'First Last'); $mail-&gt;AddReplyTo("name@yourdomain.com","First Last"); $address = "whoto@otherdomain.com"; $mail-&gt;AddAddress($address, "John Doe"); $mail-&gt;Subject = "PHPMailer Test Subject via mail(), basic"; $mail-&gt;AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail-&gt;MsgHTML($body); $mail-&gt;AddAttachment("images/phpmailer.gif"); // attachment $mail-&gt;AddAttachment("images/phpmailer_mini.gif"); // attachment if(!$mail-&gt;Send()) { echo "Mailer Error: " . $mail-&gt;ErrorInfo; } else { echo "Message sent!"; } ?&gt; </code></pre> <p>An alternative to PHPMailer is <a href="http://swiftmailer.org/" rel="noreferrer">http://swiftmailer.org/</a></p>
7,487,551
No argument names in abstract declaration?
<p>This is the typical declaration of an abstract member in F#:</p> <pre><code>abstract member createEmployee : string -&gt; string -&gt; Employee </code></pre> <p>You define the argument types but not their names. Without names, how do you tell what each parameter is when you implement the interface? In other words, how do you know if the interface expects to be implemented as 1- or 2-?</p> <pre><code>1- member this.createEmployee firstName lastName = ... 2- member this.createEmployee lastName firstName = ... </code></pre> <p>Am I looking the problem from a wrong perspective (being used to C#)?</p>
7,487,595
2
0
null
2011-09-20 15:15:59.757 UTC
5
2016-03-05 22:37:33.543 UTC
null
null
null
null
209,538
null
1
31
f#|c#-to-f#
1,694
<p>What about:</p> <pre><code>abstract member createEmployee : firstName:string -&gt; lastName:string -&gt; Employee </code></pre> <p>?</p>
23,156,780
How can I get all the plain text from a website with Scrapy?
<p>I would like to have all the text visible from a website, after the HTML is rendered. I'm working in Python with Scrapy framework. With <code>xpath('//body//text()')</code> I'm able to get it, but with the HTML tags, and I only want the text. Any solution for this? </p>
23,157,062
3
0
null
2014-04-18 15:03:05.24 UTC
12
2019-03-26 15:30:55.217 UTC
2019-03-26 15:30:55.217 UTC
null
1,245,190
null
3,516,028
null
1
23
python|html|xpath|web-scraping|scrapy
28,399
<p>The easiest option would be to <a href="http://doc.scrapy.org/en/latest/topics/selectors.html#scrapy.selector.Selector.extract"><code>extract</code></a> <code>//body//text()</code> and <a href="https://docs.python.org/2/library/string.html#string.join"><code>join</code></a> everything found:</p> <pre><code>''.join(sel.select("//body//text()").extract()).strip() </code></pre> <p>where <code>sel</code> is a <a href="http://doc.scrapy.org/en/latest/topics/selectors.html#scrapy.selector.Selector"><code>Selector</code></a> instance.</p> <p>Another option is to use <a href="https://pypi.python.org/pypi/nltk"><code>nltk</code></a>'s <code>clean_html()</code>:</p> <pre><code>&gt;&gt;&gt; import nltk &gt;&gt;&gt; html = """ ... &lt;div class="post-text" itemprop="description"&gt; ... ... &lt;p&gt;I would like to have all the text visible from a website, after the HTML is rendered. I'm working in Python with Scrapy framework. ... With &lt;code&gt;xpath('//body//text()')&lt;/code&gt; I'm able to get it, but with the HTML tags, and I only want the text. Any solution for this? Thanks !&lt;/p&gt; ... ... &lt;/div&gt;""" &gt;&gt;&gt; nltk.clean_html(html) "I would like to have all the text visible from a website, after the HTML is rendered. I'm working in Python with Scrapy framework.\nWith xpath('//body//text()') I'm able to get it, but with the HTML tags, and I only want the text. Any solution for this? Thanks !" </code></pre> <p>Another option is to use <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/#get-text"><code>BeautifulSoup</code></a>'s <code>get_text()</code>:</p> <blockquote> <p><code>get_text()</code></p> <p>If you only want the text part of a document or tag, you can use the <code>get_text()</code> method. It returns all the text in a document or beneath a tag, as a single Unicode string.</p> </blockquote> <pre><code>&gt;&gt;&gt; from bs4 import BeautifulSoup &gt;&gt;&gt; soup = BeautifulSoup(html) &gt;&gt;&gt; print soup.get_text().strip() I would like to have all the text visible from a website, after the HTML is rendered. I'm working in Python with Scrapy framework. With xpath('//body//text()') I'm able to get it, but with the HTML tags, and I only want the text. Any solution for this? Thanks ! </code></pre> <p>Another option is to use <a href="http://lxml.de/lxmlhtml.html"><code>lxml.html</code></a>'s <code>text_content()</code>:</p> <blockquote> <p><code>.text_content()</code></p> <p>Returns the text content of the element, including the text content of its children, with no markup.</p> </blockquote> <pre><code>&gt;&gt;&gt; import lxml.html &gt;&gt;&gt; tree = lxml.html.fromstring(html) &gt;&gt;&gt; print tree.text_content().strip() I would like to have all the text visible from a website, after the HTML is rendered. I'm working in Python with Scrapy framework. With xpath('//body//text()') I'm able to get it, but with the HTML tags, and I only want the text. Any solution for this? Thanks ! </code></pre>
17,836,956
I have three font type -Gotham-bold, Gotham-medium, Gotham-thin, so do I need to use three times @font-face?
<p>Actually I have three files in the fonts folder. These are <code>Gotham-Bold.ttf</code>, <code>Gotham-Medium.ttf</code>, <code>Gotham-Thin.ttf</code>..... So do I need to use the <code>@font-face</code> three times for those three types. Please anybody help me.</p> <p>I have currently used the code like the following:</p> <pre><code> @font-face { font-family: 'Gotham'; src: url('fonts/Gotham-Bold.eot'); /* IE9 Compat Modes */ src: url('fonts/Gotham-Bold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('fonts/Gotham-Bold.woff') format('woff'), /* Modern Browsers */ url('fonts/Gotham-Bold.ttf') format('truetype'), /* Safari, Android, iOS */ url('fonts/Gotham-Bold.svg#svgFontName') format('svg'); /* Legacy iOS */ font-weight: normal; font-style: normal; } @font-face { font-family: 'Gotham'; src: url("/fonts/Gotham-Bold.eot"); } @font-face { font-family: 'Gotham'; src: url("/fonts/Gotham-Bold.woff") format("woff"); } </code></pre> <p>Thanks.</p>
17,837,450
2
0
null
2013-07-24 14:29:07.133 UTC
4
2018-04-13 10:22:56.337 UTC
2017-01-04 14:01:42.163 UTC
null
1,331,432
null
2,361,994
null
1
2
css|font-face
63,142
<p>That is correct, you'll need an <code>@font-face</code> for each weight of the font you want to use. </p> <pre><code>@font-face { font-family: 'Gotham'; src: url('fonts/Gotham-Bold.eot'); /* IE9 Compat Modes */ src: url('fonts/Gotham-Bold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('fonts/Gotham-Bold.woff') format('woff'), /* Modern Browsers */ url('fonts/Gotham-Bold.ttf') format('truetype'), /* Safari, Android, iOS */ url('fonts/Gotham-Bold.svg#svgFontName') format('svg'); /* Legacy iOS */ font-weight: 700; font-style: normal; } @font-face { font-family: 'Gotham'; src: url('fonts/Gotham-Medium.eot'); /* IE9 Compat Modes */ src: url('fonts/Gotham-Medium.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('fonts/Gotham-Medium.woff') format('woff'), /* Modern Browsers */ url('fonts/Gotham-Medium.ttf') format('truetype'), /* Safari, Android, iOS */ url('fonts/Gotham-Medium.svg#svgFontName') format('svg'); /* Legacy iOS */ font-weight: 400; font-style: normal; } @font-face { font-family: 'Gotham'; src: url('fonts/Gotham-Thin.eot'); /* IE9 Compat Modes */ src: url('fonts/Gotham-Thin.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('fonts/Gotham-Thin.woff') format('woff'), /* Modern Browsers */ url('fonts/Gotham-Thin.ttf') format('truetype'), /* Safari, Android, iOS */ url('fonts/Gotham-Thin.svg#svgFontName') format('svg'); /* Legacy iOS */ font-weight: 300; font-style: normal; } </code></pre> <p>Then you can use your fonts as so:</p> <pre><code>body { font-family: 'Gotham'; } // For normal .normal { font-weight: 400; } // For bold .bold, strong { font-weight: 700; } // For thin .light { font-weight: 300; } </code></pre>
3,277,792
How can I use Git with multiple remote repositories?
<p>I use currently use Heroku for rails hosting which uses a Git repository for deployment. I also have a hosted Git repository that I use as my main source control for history/backup purposes. I would like to have 1 local folder that has my working copy of my application, then be able to commit my changes to either the Heroku repository, or my hosted repository when needed. </p> <p>How do I do this? (note that I am familiar with how Team System does source control and am very new to Git)</p>
3,277,800
1
0
null
2010-07-19 00:26:36.773 UTC
10
2010-07-19 02:34:06.723 UTC
null
null
null
null
3,291
null
1
15
git|heroku
8,749
<p>Add them both as remotes:</p> <pre><code>git remote add origin ssh://myserver.example.com/var/git/myapp.git git remote add hosted ssh://myotherserver.example.com/var/git/myapp.git </code></pre> <p>[1] <a href="http://toolmantim.com/thoughts/setting_up_a_new_remote_git_repository" rel="noreferrer">http://toolmantim.com/thoughts/setting_up_a_new_remote_git_repository</a></p> <p>[2] <a href="http://www.kernel.org/pub/software/scm/git/docs/git-remote.html" rel="noreferrer">http://www.kernel.org/pub/software/scm/git/docs/git-remote.html</a></p>
1,600,260
How do I plot confidence intervals in MATLAB?
<p>I want to plot some confidence interval graphs in MATLAB but I don't have any idea at all how to do it. I have the data in a .xls file.</p> <p>Can someone give me a hint, or does anyone know commands for plotting CIs?</p>
1,603,464
3
1
null
2009-10-21 11:32:32.447 UTC
2
2016-04-01 17:07:46.333 UTC
2009-10-26 01:45:54 UTC
null
52,738
null
193,738
null
1
3
matlab|plot|confidence-interval
44,656
<p>I'm not sure what you meant by confidence intervals graph, but this is an example of how to plot a two-sided 95% CI of a normal distribution:</p> <pre><code>alpha = 0.05; % significance level mu = 10; % mean sigma = 2; % std cutoff1 = norminv(alpha, mu, sigma); cutoff2 = norminv(1-alpha, mu, sigma); x = [linspace(mu-4*sigma,cutoff1), ... linspace(cutoff1,cutoff2), ... linspace(cutoff2,mu+4*sigma)]; y = normpdf(x, mu, sigma); plot(x,y) xlo = [x(x&lt;=cutoff1) cutoff1]; ylo = [y(x&lt;=cutoff1) 0]; patch(xlo, ylo, 'b') xhi = [cutoff2 x(x&gt;=cutoff2)]; yhi = [0 y(x&gt;=cutoff2)]; patch(xhi, yhi, 'b') </code></pre> <p><img src="https://i.stack.imgur.com/N9OUn.png" alt="plot"></p>
2,244,773
Set max-height using javascript
<p>I have a div, and the maximum width for this div is user defined. I know I can get it done using element.style.height but this doesn't work in IE.</p> <p>Any ideas on how to implement the max-height equivalent of Firefox by using javascript?</p>
2,244,798
3
0
null
2010-02-11 13:44:20.14 UTC
3
2020-05-01 17:34:45.97 UTC
2013-01-22 17:39:23.547 UTC
null
104,223
null
87,956
null
1
15
javascript|css
43,663
<p>Usually style attribute names are translated into javascript property names by removing the hyphens and camelcase the name instead.</p> <p>So <code>background-color</code> becomes <code>backgroundColor</code>, <code>text-align</code> becomes <code>textAlign</code> and <code>max-height</code> becomes <code>maxHeight</code>.</p> <p>You can set an element <code>el</code>'s maximum height to <code>mHeight</code> by:</p> <p><code>el.style.maxHeight=mHeight;</code></p> <p>Remember to use a valid value for <code>mHeight</code>.</p>
8,902,674
Manually map column names with class properties
<p>I am new to the Dapper micro ORM. So far I am able to use it for simple ORM related stuff but I am not able to map the database column names with the class properties.</p> <p>For example, I have the following database table:</p> <pre><code>Table Name: Person person_id int first_name varchar(50) last_name varchar(50) </code></pre> <p>and I have a class called Person:</p> <pre><code>public class Person { public int PersonId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } </code></pre> <p>Please note that my column names in the table are different from the property name of the class to which I am trying to map the data which I got from the query result.</p> <pre><code>var sql = @"select top 1 PersonId,FirstName,LastName from Person"; using (var conn = ConnectionFactory.GetConnection()) { var person = conn.Query&lt;Person&gt;(sql).ToList(); return person; } </code></pre> <p>The above code won't work as the column names don't match the object's (Person) properties. In this scenario, is there anything i can do in Dapper to manually map (e.g <code>person_id =&gt; PersonId</code>) the column names with object properties?</p>
8,904,096
16
1
null
2012-01-17 22:35:21.483 UTC
105
2021-01-06 01:03:18.99 UTC
2019-05-13 15:51:44.04 UTC
null
133
null
1,154,985
null
1
212
dapper
180,441
<p>This works fine:</p> <pre><code>var sql = @"select top 1 person_id PersonId, first_name FirstName, last_name LastName from Person"; using (var conn = ConnectionFactory.GetConnection()) { var person = conn.Query&lt;Person&gt;(sql).ToList(); return person; } </code></pre> <p>Dapper has no facility that allows you to specify a <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.columnattribute.aspx" rel="noreferrer">Column Attribute</a>, I am not against adding support for it, providing we do not pull in the dependency. </p>
1,098,503
How to unsupress local echo
<p>I am trying to suppress the local echo of a password in a telnet session by sending 0xFF 0xFD 0x2D (IAC DO SUPPRESS_LOCAL_ECHO). This works fine. </p> <p>My trouble is enabling the local echo after the password. I am sending 0xFF 0xFE 0x2D (IAC DONT SUPPRESS_LOCAL_ECHO). But I don't see any of my commands that I type afterwards.</p> <p>I am using the MS Telnet program to connect.</p> <p>The IAC is describe <a href="http://www.faqs.org/rfcs/rfc854.html" rel="noreferrer">here</a>.</p> <p>The Suppress Local Echo is defined <a href="http://www.iana.org/assignments/telnet-options" rel="noreferrer">here</a></p>
1,125,766
4
2
null
2009-07-08 14:36:14.203 UTC
1
2015-02-17 22:16:06.37 UTC
null
null
null
null
9,516
null
1
13
telnet|echo
47,983
<p>Send a backspace and then a *. This will backup the cursor and then print a * over the character they just printed. If it is a slow connection the character may be there for some amount of time. Also look for the '\n' and don't try to over write that.</p>
562,802
Cache Expire Control with Last Modification
<p>In Apache's <code>mod_expires</code> module, there is the <code>Expires</code> directive with two base time periods, <strong>access</strong>, and <strong>modification</strong>.</p> <pre><code>ExpiresByType text/html "access plus 30 days" </code></pre> <p>understandably means that the cache will request for fresh content after 30 days.</p> <p>However,</p> <pre><code>ExpiresByType text/html "modification plus 2 hours" </code></pre> <p>doesn't make intuitive sense. </p> <p>How does the browser cache know that the file has been modified unless it makes a request to the server? And if it is making a call to the server, what is the use of caching this directive? It seems to me that I am not understanding some crucial part of caching. Please enlighten me.</p>
562,989
4
0
null
2009-02-18 20:55:34.187 UTC
9
2019-05-17 19:47:37.717 UTC
2011-03-25 01:27:14.643 UTC
null
143,804
bushman
null
null
1
15
apache|caching|browser|mod-expires
20,725
<p>An <code>Expires*</code> directive with "modification" as its base refers to the modification time of the file on the server. So if you set, say, "modification plus 2 hours", any browser that requests content within 2 hours after the file is modified (on the server) will cache that content until 2 hours after the file's modification time. And the browser knows when that time is because the server sends an <code>Expires</code> header with the proper expiration time.</p> <p>Let me explain with an example: say your Apache configuration includes the line</p> <pre><code>ExpiresDefault modification plus 2 hours </code></pre> <p>and you have a file <code>index.html</code>, which the <code>ExpiresDefault</code> directive applies to, on the server. Suppose you upload a version of <code>index.html</code> at 9:53 GMT, overwriting the previous existing <code>index.html</code> (if there was one). So now the modification time of <code>index.html</code> is 9:53 GMT. If you were running <code>ls -l</code> on the server (or <code>dir</code> on Windows), you would see it in the listing:</p> <pre><code>-rw-r--r-- 1 apache apache 4096 Feb 18 09:53 index.html </code></pre> <p>Now, with every request, Apache sends the <code>Last-Modified</code> header with the last modification time of the file. Since you have that <code>ExpiresDefault</code> directive, it will also send the <code>Expires</code> header with a time equal to the modification time of the file (9:53) plus two hours. So here is part of what the browser sees:</p> <pre><code>Last-Modified: Wed, 18 Feb 2009 09:53:00 GMT Expires: Wed, 18 Feb 2009 11:53:00 GMT </code></pre> <p>If the time at which the browser makes this request is before 11:53 GMT, the browser will cache the page, because it has not yet expired. So if the user first visits the page at 11:00 GMT, and then goes to the same page again at 11:30 GMT, the browser will see that its cached version is still valid and will not (or rather, is allowed not to) make a new HTTP request.</p> <p>If the user goes to the page a third time at 12:00 GMT, the browser sees that its cached version has now expired (it's after 11:53) so it attempts to validate the page, sending a request to the server with a If-Modified-Since header. A 304 (not modified) response with no body will be returned since the page's date has not been altered since it was first served. Since the expiry date has passed -- the page is 'stale' -- a validation request will be made every subsequent time the page is visited until validation fails.</p> <p>Now, let's pretend instead that you uploaded a new version of the page at 11:57. In this case, the browser's attempt to validate the old version of the page at 12:00 fails and it receives in the response, along with the new page, these two new headers:</p> <pre><code>Last-Modified: Wed, 18 Feb 2009 11:57:00 GMT Expires: Wed, 18 Feb 2009 13:57:00 GMT </code></pre> <p>(The last modification time of the file becomes 11:57 upon upload of the new version, and Apache calculates the expiration time as 11:57 + 2:00 = 13:57 GMT.) </p> <p>Validation (using the more recent date) will not be required now until 13:57. </p> <p>(Note of course that many other things are sent along with the two headers I listed above, I just trimmed out all the rest for simplicity)</p>
148,130
How do I peek at the first two bytes in an InputStream?
<p>Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this?</p> <p><strong>Answer</strong> - As I had suspected, the solution was to wrap it in a BufferedInputStream which offers markability. Thanks Rasmus.</p>
148,135
4
0
null
2008-09-29 09:48:05.627 UTC
4
2012-03-27 16:46:44.077 UTC
2008-09-29 10:34:31.537 UTC
Epaga
6,583
Epaga
6,583
null
1
33
java|inputstream|bufferedinputstream
21,079
<p>For a general InputStream, I would wrap it in a BufferedInputStream and do something like this:</p> <pre><code>BufferedInputStream bis = new BufferedInputStream(inputStream); bis.mark(2); int byte1 = bis.read(); int byte2 = bis.read(); bis.reset(); // note: you must continue using the BufferedInputStream instead of the inputStream </code></pre>
50,524
What is a regex "independent non-capturing group"?
<p>From the Java 6 <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html" rel="noreferrer">Pattern</a> documentation:</p> <blockquote> <p>Special constructs (non-capturing)</p> <p><code>(?:</code><i>X</i><code>)</code>&nbsp;&nbsp;&nbsp;<i>X</i>, as a non-capturing group</p> <p>…</p> <p><code>(?></code><i>X</i><code>)</code>&nbsp;&nbsp;&nbsp;<i>X</i>, as an independent, non-capturing group</p> </blockquote> <p>Between <code>(?:X)</code> and <code>(?&gt;X)</code> what is the difference? What does the <strong>independent</strong> mean in this context?</p>
50,567
4
0
null
2008-09-08 19:57:03.767 UTC
9
2022-06-02 04:41:10.42 UTC
2021-10-18 21:42:24.723 UTC
erickson
16,320,675
null
4,265
null
1
65
java|regex
7,381
<p>It means that the grouping is <a href="http://www.regular-expressions.info/atomic.html" rel="noreferrer">atomic</a>, and it throws away backtracking information for a matched group. So, this expression is possessive; it won't back off even if doing so is the only way for the regex as a whole to succeed. It's "independent" in the sense that it doesn't cooperate, via backtracking, with other elements of the regex to ensure a match.</p>
1,067,531
Are there any log file about Windows Services Status?
<p>I want to figure out when the services was start up and terminated. Are there any kind log file about it?</p>
1,067,663
4
2
null
2009-07-01 06:15:28.273 UTC
18
2017-05-17 13:39:31.503 UTC
2009-07-01 07:04:29.73 UTC
null
116,371
null
1,145,208
null
1
74
windows-services|logging
237,630
<p>Take a look at the <code>System</code> log in Windows EventViewer (<code>eventvwr</code> from the command line).<br> You should see entries with source as 'Service Control Manager'. e.g. on my WinXP machine,</p> <pre><code>Event Type: Information Event Source: Service Control Manager Event Category: None Event ID: 7036 Date: 7/1/2009 Time: 12:09:43 PM User: N/A Computer: MyMachine Description: The Background Intelligent Transfer Service service entered the running state. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp. </code></pre>
23,872,902
Chrome Download Attribute not working
<p>I've experienced some unexpected behavior of Chrome since the newest version: While in Firefox this Code is working Perfectly fine:</p> <pre><code>&lt;a id="playlist" class="button" download="Name.xspf" href="data:application/octet-stream;base64,PD94ANDSOON" style="display: inline;"&gt;Download Me&lt;/a&gt; </code></pre> <p>It isn't working in Chrome (Simply downloading a file named "Download"), but has worked pretty fine before. What do I have to change that it is working again?</p>
23,873,370
11
1
null
2014-05-26 14:57:36.497 UTC
25
2021-12-14 11:16:08.537 UTC
null
null
null
null
3,144,499
null
1
81
html|google-chrome
146,619
<p>After some research I have finally found your problem.</p> <p>&lt;a&gt; download attribute:</p> <p>If the HTTP header Content-Disposition: is present and gives a different filename than this attribute, the HTTP header has priority over this attribute.</p> <p>If this attribute is present and Content-Disposition: is set to inline, Firefox gives priority to Content-Disposition, like for the filename case, while Chrome gives priority to the download attribute.</p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a">Source</a></p> <p>HTTP-Header <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1">Content-Disposition</a></p>
30,638,739
Transparent overlay in React Native
<p>I'm trying to get a transparent overlay sliding down in an app, pretty much like this here (all/filter-by):</p> <p><img src="https://i.stack.imgur.com/lJdpZ.gif" alt="transparent slider"></p> <p>So far I found react-native-slider and react-native-overlay. I modified the slider to work from top to bottom, but it always moves down the ListView as well. If using react-native-overlay, the overlay is static and I can't move it.</p> <p>I added some demo code from the original react-native tutorial <a href="https://gist.github.com/PatrickHeneise/24c400226fc80df2749e" rel="noreferrer">in this gist</a>. When clicking the button, the content should stick, and the menu should overlay. The transparency is not that important right now but would be awesome.</p> <p>What would be the smartest solution?</p>
30,870,639
6
1
null
2015-06-04 08:27:58.883 UTC
15
2019-05-13 09:40:44.117 UTC
2017-03-16 07:05:25.74 UTC
null
407,213
null
459,329
null
1
59
javascript|reactjs|react-native
130,613
<p>The key to your ListView not moving down, is to set the positioning of the overlay to <code>absolute</code>. By doing so, you can set the position and the width/height of the view manually and it doesn't follow the flexbox layout anymore. Check out the following short example. The height of the overlay is fixed to 360, but you can easily animate this or make it dynamic.</p> <pre class="lang-js prettyprint-override"><code>'use strict'; var React = require('react-native'); var Dimensions = require('Dimensions'); // We can use this to make the overlay fill the entire width var { width, height } = Dimensions.get('window'); var { AppRegistry, StyleSheet, Text, View, } = React; var SampleApp = React.createClass({ render: function() { return ( &lt;View style={styles.container}&gt; &lt;Text style={styles.welcome}&gt; Welcome to the React Native Playground! &lt;/Text&gt; &lt;View style={[styles.overlay, { height: 360}]} /&gt; &lt;/View&gt; ); } }); var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, // Flex to fill, position absolute, // Fixed left/top, and the width set to the window width overlay: { flex: 1, position: 'absolute', left: 0, top: 0, opacity: 0.5, backgroundColor: 'black', width: width } }); AppRegistry.registerComponent('SampleApp', () =&gt; SampleApp); module.exports = SampleApp; </code></pre>
26,441,735
Radio box, get the checked value [iCheck]
<p>Basic radio box</p> <pre><code>&lt;div class="adv_filter"&gt; &lt;li&gt; &lt;input type="radio" name="letter_type" data-custom="Text" value="0"&gt; Text&lt;/li&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="radio" name="letter_type" data-custom="Text" value="0"&gt; Text&lt;/li&gt; &lt;/li&gt; &lt;/div&gt; </code></pre> <p>iCheck transformation</p> <pre><code>&lt;!-- iCheck output format &lt;div class="adv_filter"&gt; &lt;li&gt; &lt;div class="iradio_square-orange checked" aria-checked="true" aria-disabled="false" style="position: relative;"&gt;&lt;input type="radio" name="letter_type" data-custom="Text" value="0" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"&gt;&lt;ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"&gt;&lt;/ins&gt;&lt;/div&gt; Text&lt;/li&gt; &lt;li&gt; &lt;div class="iradio_square-orange" aria-checked="false" aria-disabled="false" style="position: relative;"&gt;&lt;input type="radio" name="letter_type" data-custom="Text" value="0" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"&gt;&lt;ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"&gt;&lt;/ins&gt;&lt;/div&gt; Text&lt;/li&gt; &lt;/div&gt; --&gt; </code></pre> <p><strong><em>As you see the checked is attached to the div..</em></strong></p> <pre><code> $(document).ready(function () { $('input').iCheck({ checkboxClass: 'icheckbox_square-orange', radioClass: 'iradio_square-orange', increaseArea: '20%' // optional }); $("li").on("click", "input", function () { var val = $(this).val(); //updateDataGrid(val); alert(val); }); }); </code></pre> <p><strong>Question and description</strong> </p> <p>Provided javascript code worked properly before adding the icheck plugin, <em>I am wondering how to get the same result in the icheck plugin. Its simple, on radio click it stores the value in variable later its passed further to functions.</em> </p> <p>Live example : <a href="http://jsfiddle.net/9ypwjvt4/">http://jsfiddle.net/9ypwjvt4/</a></p> <p>iCheck : <a href="http://fronteed.com/iCheck/">http://fronteed.com/iCheck/</a></p>
26,441,864
4
1
null
2014-10-18 16:03:02.377 UTC
2
2016-07-21 13:30:15.797 UTC
2014-10-18 16:17:31.703 UTC
null
1,420,197
null
3,793,639
null
1
13
jquery|icheck
38,306
<p>Attach a handler to <code>ifChanged</code> event:</p> <pre><code>$('input').on('ifChecked', function(event){ alert($(this).val()); // alert value }); </code></pre> <p>There are <a href="http://fronteed.com/iCheck/#callbacks">11 ways to listen for changes</a>:</p> <ul> <li><code>ifClicked</code> - user clicked on a customized input or an assigned label</li> <li><code>ifChanged</code> - input's checked, disabled or indeterminate state is changed</li> <li><code>ifChecked</code> - input's state is changed to checked</li> <li><code>ifUnchecked</code> - checked state is removed</li> <li><code>ifToggled</code> - input's checked state is changed</li> <li><code>ifDisabled</code> -input's state is changed to disabled</li> <li><code>ifEnabled</code> - disabled state is removed</li> <li><code>ifIndeterminate</code> - input's state is changed to indeterminate</li> <li><code>ifDeterminate</code> - indeterminate state is removed</li> <li><code>ifCreatedinput</code> - is just customized</li> <li><code>ifDestroyed</code> - customization is just removed</li> </ul> <p><a href="http://jsfiddle.net/9ypwjvt4/1/"><strong>JSFIDDLE</strong></a></p>
20,166,847
Faster version of find for sorted vectors (MATLAB)
<p>I have code of the following kind in MATLAB:</p> <pre><code>indices = find([1 2 2 3 3 3 4 5 6 7 7] == 3) </code></pre> <p>This returns 4,5,6 - the indices of elements in the array equal to 3. Now. my code does this sort of thing with very long vectors. The vectors are <em>always sorted</em>.</p> <p>Therefore, I would like a function which replaces the O(n) complexity of find with O(log n), at the expense that the array has to be sorted.</p> <p>I am aware of ismember, but for what I know it does not return the indices of all items, just the last one (I need all of them).</p> <p>For reasons of portability, I need the solution to be MATLAB-only (no compiled mex files etc.)</p>
20,167,257
5
1
null
2013-11-23 19:29:09.747 UTC
9
2021-10-20 17:54:17.383 UTC
null
null
null
null
2,236,746
null
1
24
algorithm|matlab|sorting|optimization
12,661
<p>Here is a fast implementation using binary search. This file is also available on <a href="https://github.com/danielroeske/danielsmatlabtools/blob/master/matlab/data/findinsorted.m" rel="noreferrer">github</a></p> <pre><code>function [b,c]=findInSorted(x,range) %findInSorted fast binary search replacement for ismember(A,B) for the %special case where the first input argument is sorted. % % [a,b] = findInSorted(x,s) returns the range which is equal to s. % r=a:b and r=find(x == s) produce the same result % % [a,b] = findInSorted(x,[from,to]) returns the range which is between from and to % r=a:b and r=find(x &gt;= from &amp; x &lt;= to) return the same result % % For any sorted list x you can replace % [lia] = ismember(x,from:to) % with % [a,b] = findInSorted(x,[from,to]) % lia=a:b % % Examples: % % x = 1:99 % s = 42 % r1 = find(x == s) % [a,b] = myFind(x,s) % r2 = a:b % %r1 and r2 are equal % % See also FIND, ISMEMBER. % % Author Daniel Roeske &lt;danielroeske.de&gt; A=range(1); B=range(end); a=1; b=numel(x); c=1; d=numel(x); if A&lt;=x(1) b=a; end if B&gt;=x(end) c=d; end while (a+1&lt;b) lw=(floor((a+b)/2)); if (x(lw)&lt;A) a=lw; else b=lw; end end while (c+1&lt;d) lw=(floor((c+d)/2)); if (x(lw)&lt;=B) c=lw; else d=lw; end end end </code></pre>
6,675,373
bundle command not found in linux debian
<p>When i enter <code>bundle install</code> I get the error '-bash: bundle: command not found'.</p> <p>How do I find whether bundler is installed ? </p> <p>gem environment returns the following</p> <pre><code>RubyGems Environment: - RUBYGEMS VERSION: 1.2.0 - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] - INSTALLATION DIRECTORY: /var/lib/gems/1.8 - RUBY EXECUTABLE: /usr/bin/ruby1.8 - EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /var/lib/gems/1.8 - GEM CONFIGURATION: - :update_sources =&gt; true - :verbose =&gt; true - :benchmark =&gt; false - :backtrace =&gt; false - :bulk_threshold =&gt; 1000 - REMOTE SOURCES: - http://gems.rubyforge.org/ </code></pre> <p>Can somebody explains me how to get the bundler command working ? I am a novice to this subject..</p>
6,675,410
2
0
null
2011-07-13 07:16:29.827 UTC
7
2015-08-26 16:16:42.173 UTC
2015-08-26 16:16:42.173 UTC
null
1,300,194
null
396,734
null
1
24
ruby|rubygems
54,446
<pre><code>gem install bundler </code></pre> <p>or probably, since there is an executable</p> <pre><code>sudo gem install bundler </code></pre>
6,390,375
using regular expressions in if statement conditions
<p>i am trying to get a php if statement to have the rule where if a set variable equals "view-##" where the # signifies any number. what would be the correct syntax for setting up an if statement with that condition?</p> <pre><code>if($variable == &lt;&lt;regular expression&gt;&gt;){ $variable2 = 1; } else{ $variable2 = 2; } </code></pre>
6,390,400
2
0
null
2011-06-17 18:48:03.243 UTC
2
2011-06-17 19:01:21.573 UTC
null
null
null
null
635,867
null
1
29
php|regex|if-statement
45,023
<p>Use the <code>preg_match()</code> function:</p> <pre><code>if(preg_match("/^view-\d\d$/",$variable)) { .... } </code></pre> <p>[EDIT] OP asks additionally if he can isolate the numbers.</p> <p>In this case, you need to (a) put brackets around the digits in the regex, and (b) add a third parameter to <code>preg_match()</code>.</p> <p>The third parameter returns the matches found by the regex. It will return an array of matches: element zero of the array will be the whole matched string (in your case, the same as the input), the remaining elements of the array will match any sets of brackets in the expression. Therefore <code>$matches[1]</code> will be your two digits:</p> <pre><code>if(preg_match("/^view-(\d\d)$/",$variable,$matches)) { $result = $matches[1]; } </code></pre>
6,766,551
Strip new lines in PHP
<p>I've been working with phrases the past couple of days and the only problem I seem to be facing is stripping new lines in the html before printing it.</p> <p>Anybody have any idea how to remove <strong>every</strong> new lines from HTML using PHP?</p>
6,766,580
2
1
null
2011-07-20 18:21:04.493 UTC
2
2016-03-14 23:19:19.763 UTC
2015-04-29 13:23:56.517 UTC
null
1,347,953
user580523
null
null
1
31
php
39,149
<pre><code>str_replace(array("\r", "\n"), '', $string) </code></pre>
8,071,174
Android WebView safe font family?
<p>No, like others, I don't want to use custom fonts. I am looking for <strong>list of WebView safe fonts</strong> that can be used without using CSS3's custom @font-face, which loads ttf/wof/eot font from web/local storage.</p> <p>More refined question would be: <strong>What are the list font's that are included with Android Operating System which can be used inside WebView?</strong></p> <p>For example, Arial, Verdana, sans-serif, etc font can be used (not sure), so where exactly to look for to be 100% sure?</p> <p>Thanks</p>
8,133,357
1
4
null
2011-11-09 20:26:44.05 UTC
10
2011-11-15 08:22:05.39 UTC
null
null
null
null
132,121
null
1
27
android|fonts|webview|font-family
14,174
<p><em><strong>Webview</em></strong>: <code>It uses the WebKit rendering engine to display web pages</code></p> <p>According to the source code, <code>android.webkit.WebSettings</code> contains the following fields:</p> <pre><code>private String mStandardFontFamily = "sans-serif"; private String mFixedFontFamily = "monospace"; private String mSansSerifFontFamily = "sans-serif"; private String mSerifFontFamily = "serif"; private String mCursiveFontFamily = "cursive"; private String mFantasyFontFamily = "fantasy"; </code></pre> <p>Accordingly, these are the fonts.</p> <p>There is probably more fonts buried somewhere in the WebKit. However, they do not appear to be accessible.</p> <hr> <p>This complies with the default fonts of Linux:</p> <ul> <li><strong>Sans-serif fonts</strong>: Arial Black, Arial, Comic Sans MS, Trebuchet MS, and Verdana</li> <li><strong>Serif fonts</strong>: Georgia and Times New Roman</li> <li><strong>Monospace fonts</strong>: Andale Mono and Courier New</li> <li><strong>Fantasy fonts</strong>: Impact and Webdings</li> </ul> <hr> <p>Bottom line, there is no comprehensive list of fonts for the Android WebKit.</p>
7,933,882
Setting preferences for all Eclipse workspaces
<p>How can I apply Eclipse preferences to all Eclipse workspaces?</p> <p>For example if I go:</p> <pre><code>Window -&gt; Preferences -&gt; General -&gt; Keys -&gt; Add a Shortcut </code></pre> <p>I would like to use that shortcut in all of my Eclipse workspaces (different projects). Is there a way to apply preferences to all workspaces?</p> <p>I would also like to configure what perspectives come up by default when I start a new workspace.</p>
7,933,921
1
0
null
2011-10-28 19:26:10.373 UTC
13
2020-08-01 17:20:39.84 UTC
2020-08-01 17:20:39.84 UTC
null
2,088,053
null
251,589
null
1
46
eclipse
42,758
<p>If you want preserve all your settings, simply copy the </p> <pre><code>.metadata/.plugins/org.eclipse.core.runtime/.settings </code></pre> <p>directory into your desired workspace directory</p> <p>You can also export the preferences you set in the template workspace and then import them into other workspaces. This is the preferred method supported by Eclipse.</p> <p>Go to </p> <pre><code>File-&gt;Export then choose General-&gt;Preferences </code></pre> <p>click Next then select the “Export all” radio button and fill in or browse to a file path where you want to save the preferences . Click Finish and your preferences are exported to that file.</p> <p>Select </p> <pre><code>File-&gt;Switch Workspace,&gt;… to switch to a different workspace. </code></pre> <p>When Eclipse restarts in the new workspace select File->Import then General->Preferences click Next and browse to your saved preferences file and click Finish to import your preferences into the current workspace.</p>
21,523,267
How to convert pptx files to jpg or png (for each slide) on linux?
<p>I want to convert a powerpoint presentation to multiple images. I already installed LibreOffice on my server and converting docx to pdf is no problem. pptx to pdf conversion does not work. I used following command line:</p> <pre><code>libreoffice --headless --convert-to pdf filename.pptx </code></pre> <p>Is there es way to convert pptx to pngs immediately or do I have to convert it to pdf first and then use ghostscript or something?</p> <p>And what about the quality settings? Is there a way to choose the resolution of the resulting images?</p> <p>Thanks in advance! </p> <p><strong>EDIT:</strong> According to <a href="https://superuser.com/questions/388350/convert-ppt-to-jpg">this link</a> I was able to convert a pdf to images with the simple command line: </p> <pre><code>convert &lt;filename&gt;.pdf &lt;filename&gt;.jpg </code></pre> <p>(I guess you need LibreOffice and ImageMagick for it but not sure about it - worked on my server)</p> <p>But there are still the problems with the pptx-to-pdf convert. </p> <p>Thanks to googling and Sebastian Heyn's help I was able to create some high quality images with this line:</p> <pre><code>convert -density 400 my_filename.pdf -resize 2000x1500 my_filename%d.jpg </code></pre> <p>Please be patient after using it - you still can type soemthing into the unix console but it's processing. Just wait a few minutes and the jpg files will be created.</p> <p>For further information about the options check out this <a href="http://www.imagemagick.org/script/convert.php" rel="noreferrer">link</a></p> <p>P.S.: The aspect ratio of a pptx file doesn't seem to be exactly 4:3 because the resulting image size is 1950x1500</p>
21,528,510
3
2
null
2014-02-03 09:06:38.21 UTC
11
2019-04-05 15:47:09.483 UTC
2017-03-20 10:18:27.643 UTC
null
-1
null
2,718,671
null
1
10
linux|jpeg|converter|powerpoint|libreoffice
20,669
<p>After Installing unoconv and LibreOffice you can use:</p> <pre><code>unoconv --export Quality=100 filename.pptx filename.pdf </code></pre> <p>to convert your presentation to a pdf. For further options look <a href="https://github.com/dagwieers/unoconv/blob/master/doc/filters.txt" rel="noreferrer">here</a>.</p> <p>Afterwards you can - as already said above - use:</p> <pre><code>convert -density 400 my_filename.pdf -resize 2000x1500 my_filename%d.jpg </code></pre> <p>to receive the images.</p>
21,893,401
Big data visualization using "search, show context, and expand on demand" concept
<p>I'm trying to visualize a really huge network (3M nodes and 13M edges) stored in a database. For real-time interactivity, I plan to show only a portion of the graph based on user queries and expand it on demand. For instance, when a user clicks a node, I expand its neighborhood. (This is called "Search, Show Context, Expand on Demand" on <a href="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=5290699" rel="nofollow noreferrer">this paper</a>).</p> <p>I have looked into several visualization tools, including <a href="https://gephi.org/" rel="nofollow noreferrer">Gephi</a>, <a href="http://d3js.org/" rel="nofollow noreferrer">D3</a>, etc. They take a text file as input, but I don't have any idea how they can connect a database and update the graph based on users' interaction.</p> <p>The linked paper implemented a system like that, but they didn't describe the tools they were using.</p> <p>How can I visualize such data with above criteria?</p>
21,907,330
1
3
null
2014-02-19 21:58:18.807 UTC
30
2017-07-17 01:35:15.387 UTC
2017-07-17 01:35:15.387 UTC
null
4,157,124
null
1,275,165
null
1
32
visualization|graph-visualization
32,890
<p>There are several solutions out there, but basically every one is using the same approach:</p> <ol> <li>create layer on top of your source to let you query at high level</li> <li>create a front end layer to talk with the level explained above</li> <li>use the visualization tool you want</li> </ol> <p>As <a href="https://stackoverflow.com/users/1993041/miro-marchi">miro marchi</a> pointed, there are several solutions to achieve this goal, some of them locked to particular data sources others with much more freedom but that would require some coding skills.</p> <h2>Datasource</h2> <p>I would start with the choice of the source type: from the type of data probably I would choice either Neo4J, Titan or OrientDB (if you fancy something more exotic with some sort of flexibility). All of them offer a JSON REST API, the former with a proprietary system and language (Cypher) and the other two using the Blueprint / Rexster system. Neo4J supports the Blueprint stack as well if you like Gremlin over Cypher.</p> <p>For other solutions, such other NoSQL or SQL db probably you have to code a layer above with the relative REST API, but it will work as well - I wouldn't recommend that for the kind of data you have though.</p> <p>Now, only the third point is left and here you have several choices.</p> <h2>Generic Viz tools</h2> <ul> <li><p><a href="http://sigmajs.org/" rel="nofollow noreferrer">Sigma.js</a> it's a free and open source tool for graph visualization quite nice. Linkurious is using a fork version of it as far as I know in their product.</p></li> <li><p><a href="http://keylines.com/" rel="nofollow noreferrer">Keylines</a> it's a commercial graph visualization tool, with advanced stylings, analytics and layouts, and they provide copy/paste demos if you are using <a href="http://keylines.com/graph-databases-data-visualization" rel="nofollow noreferrer">Neo4J or Titan</a>. It is not free, but it does support even older browsers - IE7 onwards...</p></li> <li><p><a href="https://github.com/anvaka/VivaGraphJS" rel="nofollow noreferrer">VivaGraph</a> it's another free and open source tool for graph visualization tool - but it has a smaller community compared to SigmaJS.</p></li> <li><p><a href="http://d3js.org/" rel="nofollow noreferrer">D3.js</a> it's the factotum for data visualization, you can do basically every kind of visualization based on that, but the learning curve is quite steep.</p></li> <li><p><a href="https://gephi.org/" rel="nofollow noreferrer">Gephi</a> is another free and open source desktop solution, you have to use an external plugin with that probably but it does support most of the formats out there - graphML, CSV, <a href="https://stackoverflow.com/questions/21905230/neo4j-2-0-1-doesnt-work-with-gephi-0-8-2-and-neo4j-graph-database-support-plu">Neo4J</a>, etc...</p></li> </ul> <h2>Vendor specific</h2> <ul> <li><p><a href="http://linkurio.us/" rel="nofollow noreferrer">Linkurious</a> it's a commercial Neo4J specific complete tool to search/investigate data.</p></li> <li><p><a href="https://lh5.googleusercontent.com/WDyMOC36iEoftuZeQWstZJXHIX48HiDi0eU9t2MrI506AwQnYS_2zLyt14aDDMeTOX0teYMQvEn6QRo7dwi95MuqWA1yPohx7pSH_-AzIqrR3twyd1IgmzPO-Q" rel="nofollow noreferrer">Neo4J web-admin</a> console - even if it's basic they've improved a lot with the newer version <code>2.x.x</code>, based on D3.js.</p></li> </ul> <p>There are also other solutions that I probably forgot to mention, but the ones above should offer a good variety.</p> <h3>Other nodes</h3> <p>The JS tools above will visualize well up to 1500/2000 nodes at once, due to JS limits.<br> If you want to visualize bigger stuff - while expanding - I would to recommend desktop solutions such Gephi.</p> <h3>Disclaimer</h3> <p>I'm part of the the <a href="http://keylines.com/" rel="nofollow noreferrer">Keylines</a> dev team.</p>
2,264,157
Library to render Directed Graphs (similar to graphviz) on Google App Engine
<p>I am looking for a Java or Python library that can render graphs in the Dot language as image file. The problem is that I need a library that I can use on Google App Engine. Basically I am looking for a library that can convert the text description of a directed graph into an image of the graph.</p> <p>For example:</p> <p>Covert this edge list:</p> <pre><code>[A,B] [B,C] [A,C] [C,D] </code></pre> <p>Into this image:</p> <p><img src="https://i.imgur.com/TrAjJ.png" alt="example image"></p> <p>I used <a href="http://www.graphviz.org/" rel="noreferrer">Graphviz</a> for this example, but I know it is not possible for me to use it with Google App Engine.</p>
2,295,775
4
0
null
2010-02-15 05:23:31.313 UTC
12
2016-07-26 22:25:48.803 UTC
2010-02-15 11:41:42.873 UTC
null
230,513
null
272,321
null
1
19
java|python|google-app-engine|graph|graphviz
7,910
<p><a href="http://code.google.com/p/canviz/" rel="noreferrer">Canviz</a> is what you are looking for: it is a JavaScript library for drawing Graphviz graphs to a web browser canvas. It works with <a href="http://code.google.com/p/canviz/wiki/Browsers" rel="noreferrer">most browsers</a>.</p> <blockquote> <p>Using Canviz has advantages for your web application over generating and sending bitmapped images and imagemaps to the browser:</p> <ul> <li>The server only needs to have Graphviz generate xdot text; this is faster than generating bitmapped images.</li> <li>Only the xdot text needs to be transferred to the browser; this is smaller than binary image data, and, if the browser supports it (which most do), the text can be gzip- or bzip2-compressed.</li> <li>The web browser performs the drawing, not the server; this reduces server load.</li> <li>The user can resize the graph without needing to involve the server; this is faster than having the server draw and send the graph in a different size.</li> </ul> </blockquote> <p>To see it in action, <a href="http://www.ryandesign.com/canviz/" rel="noreferrer">look here</a>.</p>
2,092,526
Difference between [NSThread detachNewThreadSelector:] and -performSelectorInBackground
<p>I've been using <code>-performSelectorInBackground</code> in many of my apps, sort of oblivious to <code>-detachNewThreadSelector</code>. Now I am wondering what the differences are between the two. Are they pretty much interchangeable, or are there differences and places where one is superior to the other? Thanks!</p>
2,095,100
4
0
null
2010-01-19 09:46:41.187 UTC
10
2016-03-29 18:45:07.113 UTC
null
null
null
null
86,020
null
1
26
iphone|cocoa-touch
18,616
<p>They're identical. See <a href="http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW13" rel="noreferrer">documentation</a>.</p> <p><strong>performSelectorInBackground:withObject:</strong> The effect of calling this method is the same as if you called the detachNewThreadSelector:toTarget:withObject: method of NSThread with the current object, selector, and parameter object as parameters.</p>
1,803,528
Disable CodeRush
<p>I do not want to uninstall code rush. I just want to have the chance to turn it off when I don't want it.</p> <p>Is this possible? (express version)... </p>
1,803,676
4
3
null
2009-11-26 12:56:47.65 UTC
7
2018-04-20 19:11:47.063 UTC
2012-06-26 07:50:54.197 UTC
null
529,310
null
64,226
null
1
40
.net|visual-studio|coderush|coderush-xpress|dxcore
16,484
<p>First you should turn on the "DevExpress" menu. This is hidden by default in CodeRush Xpress.</p> <p>See this blogpost <a href="http://www.coderjournal.com/2009/08/show-coderush-xpress-9-2-menu-in-visual-studio/" rel="noreferrer">http://www.coderjournal.com/2009/08/show-coderush-xpress-9-2-menu-in-visual-studio/</a></p> <p>Once this is done you should be able to use the <strong>Unload/Load</strong> menu option (Last item on DevExpress menu)</p> <p>Additionally you can set CodeRush Xpress to not load fully by default..</p> <hr> <p>Follow these steps to get to the <strong>Startup</strong> options page:</p> <ol> <li>From the DevExpress menu, select "Options...".</li> <li><p>In the tree view on the left, navigate to this folder:</p> <p>Core</p></li> <li><p>Select the "Startup" options page. This page level is Expert, and will only be visible if the Level combo on the lower-left of the Options dialog is set to Expert.</p></li> </ol> <hr> <p>Once on this page, you can toggle the "<strong>Load Manually</strong>" setting to dictate how CodeRush starts.</p>
36,515,937
How to detect EOF in Java?
<p>I've tried some ways to detect EOF in my code, but it still not working. I've tried using BufferedReader, Scanner, and using char u001a to flag the EOF, but still not make any sense to my code. Here is my last code :</p> <pre><code> Scanner n=new Scanner(System.in); String input; int counter=0; while(n.hasNextLine()) { input=n.nextLine(); char[] charInput=input.toCharArray(); for (int i = 0; i &lt; input.length(); i++) { if(charInput[i]=='"') { if(counter%2==0) { System.out.print("``"); } else { System.out.print("''"); } counter++; } else { System.out.print(charInput[i]); } } System.out.print("\n"); } </code></pre> <p>The program supposed to stopped when it's already reached the EOF, but I don't know why, for some reasons it keeps running and result a runtime error. Please help. By the way I'm new here, sorry if my question is not really clear to be understood, Thank you before :)</p>
36,516,401
4
6
null
2016-04-09 11:06:10.777 UTC
6
2021-08-26 21:58:40.997 UTC
null
null
null
null
6,180,692
null
1
12
java|eof
60,343
<p>It keeps running because it hasn't encountered EOF. At end of stream:</p> <ol> <li><code>read()</code> returns -1.</li> <li><code>read(byte[])</code> returns -1.</li> <li><code>read(byte[], int, int)</code> returns -1.</li> <li><code>readLine()</code> returns null.</li> <li><code>readXXX()</code> for any other X throws <code>EOFException</code>.</li> <li><code>Scanner.hasNextXXX()</code> returns false for any X.</li> <li><code>Scanner.nextXXX()</code> throws <code>NoSuchElementException</code> for any X.</li> </ol> <p>Unless you've encountered one of these, your program hasn't encountered end of stream. NB <code>\u001a</code> is a Ctrl/z. Not EOF. EOF is not a character value.</p>
7,013,640
how to disable dates before today in jQuery datepicker
<p>How do I disable dates before today in jQuery datepicker <strong>WITHOUT using <code>minDate: 0</code></strong>?</p> <p>I would like to enable navigation of the calendar as per usual before today while making sure that user do NOT pick dates before today.</p> <p>(i.e. say today's date is 11Aug11 and I would like all the dates before this disabled but still enabling user to go to previous months, years, etc.)</p>
7,014,137
6
2
null
2011-08-10 15:40:56.83 UTC
null
2019-09-16 12:57:50.663 UTC
2011-08-10 16:00:37.793 UTC
null
305
null
864,600
null
1
7
javascript|jquery|datepicker
39,850
<p>While I agree that it's weird behavior, you might be able to fake it using the <a href="http://jqueryui.com/demos/datepicker/#event-onSelect" rel="noreferrer"><code>onSelect</code> </a> event of the datepicker.</p> <pre><code>$(document).ready(function() { $('#Date').datepicker({ onSelect: function(dateText, inst) { //Get today's date at midnight var today = new Date(); today = Date.parse(today.getMonth()+1+'/'+today.getDate()+'/'+today.getFullYear()); //Get the selected date (also at midnight) var selDate = Date.parse(dateText); if(selDate &lt; today) { //If the selected date was before today, continue to show the datepicker $('#Date').val(''); $(inst).datepicker('show'); } } }); }); </code></pre> <p>Basically, you handle the <code>onSelect</code> event. </p> <p>When a date is selected, check to see if it's before today's date. </p> <p>If it <em>is</em>, then you immediately <a href="http://jqueryui.com/demos/datepicker/#method-show" rel="noreferrer">show</a> the datepicker again and clear out the input box attached to it.</p> <hr> <p><strong>Updated</strong> Code sample is now completely functional. Here's a <a href="http://jsfiddle.net/antelopelovefan/ZW7cs/34/" rel="noreferrer">jsfiddle</a> to demonstrate.</p>
7,378,773
How to add comment block to methods in Eclipse?
<p>Is there an easy of adding a comment block (Javadoc style) to every method in an Eclipse project and possibly classes so I can fill in them later?</p>
7,378,866
7
2
null
2011-09-11 14:14:11.467 UTC
6
2017-09-28 05:52:31.983 UTC
2016-09-28 06:46:08.98 UTC
null
746,285
null
529,024
null
1
24
java|eclipse|javadoc
82,824
<p>As suggested you can do it method-per-method (Source -> Generate element comment) or <code>ALT+SHIFT+J</code> but I find it a very bad idea. Comments are only useful when they give an additional information. When you feel more information is needed add it.</p> <p>Having comments on setters like "<em>sets the value</em>" or worse automatically generated comments it not useful at all.</p>
7,619,955
mapping private property entity framework code first
<p>I am using EF 4.1 and was look for a nice workaround for the lack of enum support. A backing property of int seems logical. </p> <pre><code> [Required] public VenueType Type { get { return (VenueType) TypeId; } set { TypeId = (int) value; } } private int TypeId { get; set; } </code></pre> <p>But how can I make this property private and still map it. In other words:</p> <p>How can I map a private property using EF 4.1 code first?</p>
7,621,029
8
1
null
2011-10-01 11:32:35.75 UTC
13
2021-01-19 01:12:30.4 UTC
null
null
null
null
104,002
null
1
25
entity-framework|ef-code-first|private-members
36,135
<p><em>you can't map private properties in EF code first. You can try it changing it in to <code>protected</code> and configuring it in a class inherited from <code>EntityConfiguration</code> .</em><br> <strong>Edit</strong><br> Now it is changed , See this <a href="https://stackoverflow.com/a/13810766/861716">https://stackoverflow.com/a/13810766/861716</a></p>
14,045,131
What does View method getId() return?
<p>What is the co-relation between View's getId() method and the id defined in the XML file? Is there any? My IDs look like this: "field1", "field2"... This digits at the end are very important for my application and I need to retrieve them. Is there any way to do it?</p>
14,045,226
4
0
null
2012-12-26 19:18:41.6 UTC
3
2018-06-14 07:50:12.33 UTC
null
null
null
null
1,928,115
null
1
11
android
39,342
<blockquote> <p>What is the co-relation between View's getId() method and the id defined in the XML file?</p> </blockquote> <p><code>getId()</code> returns the <code>android:id</code> value, or the value you set via <code>setId()</code>.</p> <blockquote> <p>My IDs look like this: "field1", "field2"</p> </blockquote> <p>In your XML, they may look like <code>@+id/field1</code> and <code>@+id/field2</code>. Those are allocating ID resources, which are turned into numbers at compile time. These are the numbers you refer to in Java code as <code>R.id.field1</code> and <code>R.id.field2</code>.</p> <blockquote> <p>This digits at the end are very important for my application and I need to retrieve them. Is there any way to do it?</p> </blockquote> <p>Have a big switch statement comparing the ID to <code>R.id.field1</code>, etc. Or, set up a <code>HashMap</code> to map between the <code>getId()</code> values and your "very important" numbers. Or, find some other solution that does not involve magic names on your ID values.</p>
14,149,984
For each loop on Java HashMap
<p>A basic chat program I wrote has several key words that generate special actions, images, messages, etc. I store all of the key words and special functions in a HashMap. Key words are the keys and functions are the values. I want to compare user input to the keys with some type of loop. I have tried everything I can think of and nothing works. This is what I can figure out:</p> <pre><code>myHashMap = &lt;File Input&gt; for(String currentKey : &lt;List of HashMap Keys&gt;){ if(user.getInput().equalsIgnoreCase(currentKey)){ //Do related Value action } } ... </code></pre> <p>I would appreciate any help. Forgive me if I overlooked a similar question or if the answer is obvious.</p>
14,150,018
4
3
null
2013-01-04 01:47:21.97 UTC
5
2016-10-19 07:38:09.46 UTC
null
null
null
null
1,130,454
null
1
19
java|loops|hashmap
92,326
<p>Well, you can write:</p> <pre><code>for(String currentKey : myHashMap.keySet()){ </code></pre> <p>but this isn't really the best way to use a hash-map.</p> <p>A better approach is to populate <code>myHashMap</code> with all-lowercase keys, and then write:</p> <pre><code>theFunction = myHashMap.get(user.getInput().toLowerCase()); </code></pre> <p>to retrieve the function (or <code>null</code> if the user-input does not appear in the map).</p>
14,019,964
How to Group By Year and Month in MySQL
<p>I would like to measure the count of ID and ATTRIBUTE from the source table and present the data as shown in the "Desired Report" below. I am using MySQL.</p> <p><strong>Source:</strong></p> <pre><code>ID | DATE | ATTRIBUTE -------------------------------- 1 | 2012-01-14 | XYZ 2 | 2012-03-14 | 3 | 2012-03-15 | XYZ 4 | 2012-04-24 | ABC 5 | 2012-04-10 | 6 | 2012-05-11 | ABC </code></pre> <p><strong>Desired Reports:</strong></p> <blockquote> <p><strong>Count of Attribute</strong></p> </blockquote> <pre><code> YEAR | JAN | FEB | MAR | APR | MAY | JUN | JUL | AUG | SEP | OCT | NOV | DEC --------------------------------------------------------------------------- 2010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2012 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 </code></pre> <blockquote> <p><strong>Count of ID</strong></p> </blockquote> <pre><code> YEAR | JAN | FEB | MAR | APR | MAY | JUN | JUL | AUG | SEP | OCT | NOV | DEC --------------------------------------------------------------------------- 2010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2012 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 </code></pre> <blockquote> <p><strong>Percentage Complete ( Count of Attribute / Count of ID )</strong></p> </blockquote> <pre><code> YEAR | JAN | FEB | MAR | APR | MAY | JUN | JUL | AUG | SEP | OCT | NOV | DEC --------------------------------------------------------------------------- 2010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2012 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 </code></pre> <p>Here's the code I have so far. Thanks! And Also keep in mind, I need to extract the Month from the date field in my data but not sure how. Thanks.</p> <pre><code>SELECT YEAR(document_filing_date),MONTH(document_filing_date),COUNT(aif_id) FROM (a_aif_remaining) GROUP BY YEAR(document_filing_date),MONTH(document_filing_date); </code></pre> <p>Suggested answer doesn't work!! Not sure why, here is the error I get:</p> <pre><code>"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' COUNT(CASE WHEN MONTH(document_filing_date) = 1 THEN aif_id END) AS Jan, CO' at line 1" SELECT YEAR(document_filing_date, COUNT(CASE WHEN MONTH(document_filing_date) = 1 THEN aif_id END) AS Jan, COUNT(CASE WHEN MONTH(document_filing_date) = 2 THEN aif_id END) AS Feb, COUNT(CASE WHEN MONTH(document_filing_date) = 3 THEN aif_id END) AS Mar, COUNT(CASE WHEN MONTH(document_filing_date) = 4 THEN aif_id END) AS Apr, COUNT(CASE WHEN MONTH(document_filing_date) = 5 THEN aif_id END) AS May, COUNT(CASE WHEN MONTH(document_filing_date) = 6 THEN aif_id END) AS Jun, COUNT(CASE WHEN MONTH(document_filing_date) = 7 THEN aif_id END) AS Jul, COUNT(CASE WHEN MONTH(document_filing_date) = 8 THEN aif_id END) AS Aug, COUNT(CASE WHEN MONTH(document_filing_date) = 9 THEN aif_id END) AS Sep, COUNT(CASE WHEN MONTH(document_filing_date) = 10 THEN aif_id END) AS Oct, COUNT(CASE WHEN MONTH(document_filing_date) = 11 THEN aif_id END) AS Nov, COUNT(CASE WHEN MONTH(document_filing_date) = 12 THEN aif_id END) AS Dec, FROM a_aif_remaining GROUP BY YEAR(document_filing_date); </code></pre>
14,020,037
2
5
null
2012-12-24 10:17:49.243 UTC
9
2012-12-25 15:46:27.257 UTC
2012-12-24 12:57:03.037 UTC
null
1,788,087
null
1,788,087
null
1
22
mysql|group-by
54,145
<p>This query will count all the rows, and will also count just the rows where <code>Attribute</code> is not null, grouping by year and month in rows:</p> <pre><code>SELECT Year(`date`), Month(`date`), Count(*) As Total_Rows, Count(`Attribute`) As Rows_With_Attribute FROM your_table GROUP BY Year(`date`), Month(`date`) </code></pre> <p>(this because Count(*) counts all the rows, Count(Attibute) counts all the rows where Attribute is not null)</p> <p>If you need your table in PIVOT, you can use this to count only the rows where Attribute is not null:</p> <pre><code>SELECT Year(`date`), Count(case when month(`date`)=1 then `Attribute` end) As Jan, Count(case when month(`date`)=2 then `Attribute` end) As Feb, Count(case when month(`date`)=3 then `Attribute` end) As Mar, ... FROM your_table GROUP BY Year(`date`) </code></pre> <p>And this to count all the rows:</p> <pre><code>SELECT Year(`date`), Count(case when month(`date`)=1 then id end) As Jan, Count(case when month(`date`)=2 then id end) As Feb, Count(case when month(`date`)=3 then id end) As Mar, ... FROM your_table GROUP BY Year(`date`) </code></pre> <p>(or, instead of counting id, you can use <code>Sum(Month(</code>date<code>)=1)</code> like in kander's answer). Of course you can combine both queries into this:</p> <pre><code>SELECT Year(`date`), Count(case when month(`date`)=1 then id end) As Jan_Tot, Count(case when month(`date`)=1 then `Attribute` end) As Jan_Attr, Count(case when month(`date`)=2 then id end) As Feb_Tot, Count(case when month(`date`)=2 then `Attribute` end) As Feb_Attr, Count(case when month(`date`)=3 then id end) As Mar_Tot, Count(case when month(`date`)=3 then `Attribute` end) As Mar_Attr, ... FROM your_table GROUP BY Year(`date`) </code></pre>
14,035,698
Fatal error: Call to undefined function mb_substr()
<p>I wanted to see your input on this concern I'm currently experiencing. It turns out that:</p> <pre><code> &lt;?php $disc_t=$name; if(strlen($disc_t)&lt;=15) { $name_now=mb_substr( strip_tags($disc_t), 0, 10 ).''; } else { $name_now=mb_substr( strip_tags($disc_t), 0, 10).'...'; } ?&gt; </code></pre> <p>is somehow giving me an error on the site, the error shows:</p> <pre><code>Fatal error: Call to undefined function mb_substr() in /home/(website)/public_html/index.php on line 308 </code></pre> <p>I don't quite understand what they mean by <code>mb_substr</code>, is this a PHP version error? I am currently using PHP 5.3.19</p>
14,035,744
4
8
null
2012-12-26 03:30:32.67 UTC
3
2020-05-29 03:03:05.593 UTC
2013-07-29 17:57:42.733 UTC
null
104,223
null
1,862,192
null
1
23
php|string
65,440
<p>Throw this into a terminal:</p> <pre><code>php -m | grep mb </code></pre> <p>If <code>mbstring</code> shows up then it should work.</p>
14,068,253
EDSAC - 17-bit and 35-bit integers
<p>I'm trying to write a program for <a href="http://en.wikipedia.org/wiki/EDSAC" rel="nofollow noreferrer">EDSAC</a> and am stuck on understanding the short and long integer stuff - sometimes I enter something and get a zero, and at others I get a one.</p> <p>So, for example:</p> <p>If I enter <code>P0F</code>, 0 is stored.</p> <p>If I enter <code>P0D</code>, 1 is stored.</p> <p>If I enter <code>P1F</code>, 2 is stored</p> <p>If I enter <code>P2D</code>, 3 is stored.</p> <p><code>F</code> means use a 17-bit integer, and <code>D</code> means a full length 35-bit integer.</p> <p>Can someone explain why P0F and P0D don't have the same integer value, just a different bit length?</p>
14,293,654
1
1
null
2012-12-28 10:40:28.417 UTC
1
2017-08-10 22:38:04.983 UTC
2017-08-10 22:38:04.983 UTC
null
63,550
null
997,280
null
1
28
integer|bit|obsolete
914
<p>I am currently doing an assignment on EDSAC, and from messing around trying to work out how to store constants, I have found that it appears to work as follows:</p> <ul> <li><code>PNF</code> where <code>N</code> is an integer stores the value 2N</li> <li><code>PND</code> where <code>N</code> is an integer stores the value 2N+1</li> </ul>
14,322,299
C++ std::find with a custom comparator
<p>This is basically what I want to do:</p> <pre><code>bool special_compare(const string&amp; s1, const string&amp; s2) { // match with wild card } std::vector&lt;string&gt; strings; strings.push_back("Hello"); strings.push_back("World"); // I want this to find "Hello" find(strings.begin(), strings.end(), "hell*", special_compare); // And I want this to find "World" find(strings.begin(), strings.end(), "**rld", special_compare); </code></pre> <p>But <code>std::find</code> doesn't work like that unfortunately. So using only the STL, how can I do something like this?</p>
14,322,617
6
1
null
2013-01-14 16:19:19.943 UTC
3
2021-07-10 15:59:47.26 UTC
2013-01-14 16:30:00.74 UTC
null
468,130
null
468,130
null
1
34
c++|stl
38,881
<p>Based on your comments, you're probably looking for this:</p> <pre><code>struct special_compare : public std::unary_function&lt;std::string, bool&gt; { explicit special_compare(const std::string &amp;baseline) : baseline(baseline) {} bool operator() (const std::string &amp;arg) { return somehow_compare(arg, baseline); } std::string baseline; } std::find_if(strings.begin(), strings.end(), special_compare("hell*")); </code></pre>
14,088,294
Multithreaded web server in python
<p>I'm trying to create multithreaded web server in python, but it only responds to one request at a time and I can't figure out why. Can you help me, please?</p> <pre><code>#!/usr/bin/env python2 # -*- coding: utf-8 -*- from SocketServer import ThreadingMixIn from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler from time import sleep class ThreadingServer(ThreadingMixIn, HTTPServer): pass class RequestHandler(SimpleHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/plain') sleep(5) response = 'Slept for 5 seconds..' self.send_header('Content-length', len(response)) self.end_headers() self.wfile.write(response) ThreadingServer(('', 8000), RequestHandler).serve_forever() </code></pre>
14,089,457
5
7
null
2012-12-30 04:20:10.13 UTC
28
2019-12-03 15:05:06.487 UTC
null
null
null
null
1,937,459
null
1
62
python|multithreading|http|webserver
99,650
<p>Check <a href="http://pymotw.com/2/BaseHTTPServer/index.html#module-BaseHTTPServer" rel="noreferrer">this</a> post from Doug Hellmann's blog.</p> <pre><code>from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from SocketServer import ThreadingMixIn import threading class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() message = threading.currentThread().getName() self.wfile.write(message) self.wfile.write('\n') return class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" if __name__ == '__main__': server = ThreadedHTTPServer(('localhost', 8080), Handler) print 'Starting server, use &lt;Ctrl-C&gt; to stop' server.serve_forever() </code></pre>
32,764,981
PHP Warning: Module already loaded in Unknown on line 0
<p>On Mac OSX Mavericks using homebrew php55 whenever I run a a php command I get the following error message (everything runs fine it's just annoying)</p> <pre><code>PHP Warning: Module 'intl' already loaded in Unknown on line 0 </code></pre> <p>I ran</p> <pre><code>php --ini </code></pre> <p>and the output was</p> <pre><code>php --ini PHP Warning: Module 'intl' already loaded in Unknown on line 0 Warning: Module 'intl' already loaded in Unknown on line 0 Configuration File (php.ini) Path: /usr/local/etc/php/5.5 Loaded Configuration File: /usr/local/etc/php/5.5/php.ini Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d Additional .ini files parsed: /usr/local/etc/php/5.5/conf.d/ext-apcu.ini, /usr/local/etc/php/5.5/conf.d/ext-igbinary.ini, /usr/local/etc/php/5.5/conf.d/ext-intl.ini, /usr/local/etc/php/5.5/conf.d/ext-memcached.ini, /usr/local/etc/php/5.5/conf.d/ext-mongo.ini, /usr/local/etc/php/5.5/conf.d/ext-uuid.ini, /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini </code></pre> <p>Checked in the php.ini file and the only place intl is loaded is at the top and it's commented out. The other files contents look something like:</p> <pre><code>extension="/usr/local/Cellar/php55/5.5.23/lib/php/extensions/no-debug-non-zts-20121212/intl.so" </code></pre> <p>where the contents after the last slash is the extension.</p> <p>I'm not sure where else to look.</p> <p>Any help is appreciated</p>
36,455,035
21
3
null
2015-09-24 15:13:28.843 UTC
12
2022-07-17 03:16:28.793 UTC
2020-10-12 14:27:01.703 UTC
null
9,431,571
null
1,549,086
null
1
93
php|configuration|centos7|ini|intl
274,177
<p>I think you have loaded <a href="https://xdebug.org/" rel="noreferrer">Xdebug</a> probably twice in <a href="http://php.net/manual/en/configuration.file.php" rel="noreferrer"><code>php.ini</code></a>.</p> <ol> <li><p>check the <code>php.ini</code>, that not have set <code>xdebug.so</code> for the values <code>extension=</code> and <code>zend_extension=</code>.</p> </li> <li><p>Check also <code>/etc/php5/apache2</code> and <code>/etc/php5/cli/</code>. You should not load in each <code>php.ini</code> in these directories the extension <code>xdebug.so</code>. Only one file, <code>php.ini</code> should load it.</p> <p>Note: Inside the path is the string <code>/etc/php5</code>. The 5 is the version of PHP. So if you use another version, you always get a different path, like <code>php7</code>.</p> </li> </ol>
24,520,656
Android: Why does getDimension and getDimensionPixelSize both return the same?
<p>I find the methods getDimension and getDimensionPixelSize confusing.</p> <p>It would look to me as though getDimension would return the actual value stored in the dimension, for example 10dp and getDimensionPixelSize would return it converted to px.</p> <p>But both seem to do the same thing...</p>
24,525,144
2
2
null
2014-07-01 23:23:29.98 UTC
3
2022-08-09 11:12:52.633 UTC
null
null
null
null
3,591,115
null
1
29
android|android-resources
19,627
<p><a href="http://developer.android.com/reference/android/content/res/Resources.html#getDimension(int)" rel="noreferrer"><code>getDimension()</code></a> returns a floating point number which is the dimen value adjusted with current display metrics:</p> <p><a href="http://developer.android.com/reference/android/content/res/Resources.html#getDimensionPixelSize(int)" rel="noreferrer"><code>getDimensionPixelSize()</code></a> returns an integer. It is the same as <code>getDimension()</code> rounded to an <code>int</code> with any non-zero dimension ensured to be at least one pixel in size.</p> <p>For integer dimension values they both return the same numeric value.</p>
35,066,871
how to put all labels in bold with css
<p>how do I make all labels such as : first name, last name, etc in bold, by using header only? thank you</p> <pre><code> &lt;form&gt; &lt;fieldset class="set1"&gt; &lt;legend class="set1"&gt;Music Lover's Personal information&lt;/legend&gt; First Name &lt;input type="text" name="firstname" value=""&gt;&lt;br&gt;&lt;br&gt; Family Name &lt;input type="text" name="lastname" value=""&gt;&lt;br&gt;&lt;br&gt; Gender: &lt;input type="radio" name="gender" value="Female"&gt;Female &lt;input type="radio" name="gender" value="male"&gt;Male&lt;br&gt;&lt;br&gt; What age category are you from? </code></pre>
35,067,059
3
3
null
2016-01-28 16:32:14.657 UTC
null
2016-01-28 17:17:22.023 UTC
null
null
null
null
5,827,451
null
1
8
html|css|fonts|colors
47,235
<p>I would wrap each label in a <code>label</code> tag and then in CSS, with this code, you can get it:</p> <pre><code>form label {font-weight:bold} </code></pre> <p>Hope this helps you.</p>