w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Optimising a big Wordpress site
With issues like this, the thing to do is take the caching out of the hands of Wordpress, and make the server to the work. Software like Wordpress and Drupal do have their own caching systems, and you should enable them, but even with them in use, there's still a certain amount of overhead for the software to load and serve the page. So I suggest you investigate a server caching engine such as Varnish. This will dramatically reduce the server load for most sites like yours; if you have a lot of requests for the same page over and over, Varnish will take over the caching and Wordpess will never even have to know that the page is being requested. No more loading PHP and the Wordpress core for every request, no more database session with every request. If your back-end CMS software is sta

Categories : PHP

Tips for optimising code in Cython
This answer is not related to Cython, but should mention some points which might be helpful. Defining vars before really knowing if they're needed might be not ideal. Move "cdef double l1, l2, A, r, g2, gs" after the "if g == 0" statement. I would ensure that from "omega = omega*M_PI/180" the M_PI/180 part is only calculated once. E.g. some Python code: import timeit from math import pi def calc1( omega ): return omega * pi / 180 SCALEDPI = pi / 180 def calc2( omega ): return omega * SCALEDPI if __name__ == '__main__': took = timeit.repeat( stmt = lambda:calc1( 5 ), number = 10000 ) print "Min. time: %.4f Max. time: %.4f" % ( min( took ), max( took ) ) took = timeit.repeat( stmt = lambda:calc2( 5 ), number = 10000 ) print "Min. time: %.4f Max. time: %.4f" % (

Categories : Python

How to Get a Specific Song From the Phone's MediaLibrary? And optimising the code
Maybe you have to store the values in a XML document after you read the directory, this can save you a lot of time if the library doesn't get changed (Check the size of the whole library). If it does then you can check the library again and update your XML.

Categories : C#

Conditional Menu in WordPress
wp_nav_menu displays a navigation menu at the spot, you are using a init hook, that runs before anything else, like you figured. Either: run that code within the template between HTML use a filter to wp_nav_menu (it has to be called somewhere) Example for the filter (not tested): add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args_filter'); function my_wp_nav_menu_args_filter($args = array()) { $args['menu'] = 'menu1'; return $args; }

Categories : Wordpress

Wordpress - Where do conditional tags go in header.php?
Note the : in the first line. http://php.net/manual/en/control-structures.alternative-syntax.php <?php if ( !is_page( 'shop' ) ) : wp_nav_menu( array( 'show_home' => 'Home', 'container' => 'false', 'theme_location' => 'main') ); endif; ?> OR: <?php if ( !is_page( 'shop' ) ) { wp_nav_menu( array( 'show_home' => 'Home', 'container' => 'false', 'theme_location' => 'main') ); } ?>

Categories : PHP

Wordpress conditional meta tag description
What if you use the strip_shortcode function try this one function metadesc($pid) { $p = get_post($pid); $description = strip_tags($p->post_content); $description = str_replace (" ","",$description); $description = str_replace (" ","",$description); $description =strip_shortcodes($description ); if(empty($description )){ return please get home page content } else{ if (strlen($description) > 135) { return htmlspecialchars(substr($description,0,135) . "..."); }else{ return htmlspecialchars($description); } } } strip_shortcodes

Categories : PHP

Wordpress Conditional Check in The Loop
You aren't using is_category correctly. Wordpress Codex Try changing $post->is_category=='Entries' to $post->is_category('Entries')

Categories : PHP

Wordpress: Conditional function (if/else) for custom tag
You can use wordpress's wp_get_post_tags($post->ID); to get all the tags of the post it will return the array and you have to loop through the array to get the tags $tags=wp_get_post_tags($post->ID); $alltags=array(); foreach($tags as $t){ $alltags[]=$t->taxonomy; } Then use inarray in you if condition if (in_array("certaintag", $alltags)) { Show something }else{ } Hope it makes sense

Categories : PHP

Wordpress & Enquire.js - conditional loading philosophy
IMO, the logic is flawed. For one, there's no way to detect the screen width with PHP. Secondly, if you were to generate a PHP -> JS file (my-script.js.php), you'd have to load WordPress engine two times. The Answer in this link is super-pro. You'll find easier methods that use wp-load.php and WP_USE_THEMES. Thirdly, the way you're trying to load a theme template would require the "load two times" approach. Or solving it with AJAX and wp_localize_script. If I understood the Question correctly, I think the best bet would be to use WordPress user-agent detection and enqueue your scripts and styles accordingly. Study the core function to adapt to your needs. [update] Still not sure if all this complexity is really needed. Would something like this work in a generic header.php? if( wp_is

Categories : PHP

Wordpress conditional statement for body to onload javascript
You seem to be missing the closing ">" after the "?>" i.e. You have: <body <?php body_class($class); ?> But you should have: <body <?php body_class($class); ?>> If that doesn't work, make sure you're not using query_posts before the call to is_home as this may be affecting the main loop, see here for more information: http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts

Categories : Javascript

Wordpress conditional slider (Advanced Custom Fields)
I think you might have answered your own question! If you currently have 2 images, and when you view the returned array and it comes back with 2 results, then to check if you only have 1 image you would do something like this : if( count($images) == 1 ) Edit: added full code <?php /* Create the Markup for a slider */ $images = get_field('hero_image_gallery'); if( $images && count($images) == 1 ) { ?> <!-- there is only 1 image --> <?php } else if ( $images && count($images) > 1 ) { ?> <!-- there is more than 1 image --> <div id="slider" class="flexslider"> <ul class="slides"> <?php foreach( $images as $image ): ?> <li> <img src="<?php echo $imag

Categories : PHP

Conditional stament for custom template page in WordPress
is_page_template returns true when the specified template is being used: if( is_page_template( 'custom-home.php' ) ) { // do home stuff } elseif( is_page_template( 'custom-gallery.php' ) ) { // do gallery stuff }

Categories : Wordpress

wordpress conditional change login logout link
Your conditional should look like this: <?php if ( is_user_logged_in() ): ?> <a href="<?php echo wp_logout_url( $_SERVER['REQUEST_URI'] ); ?>">Logout</a> <!-- This redirects the user to the current page after logout. --> <?php else: ?> <a href="<?php echo wp_login_url( $_SERVER['REQUEST_URI'] ); ?>">Login</a> <!-- This redirects the user to the current page after login. --> <?php endif; ?>

Categories : Wordpress

Running a long conditional on the wordpress loop to display certain posts
I would suggest using WP_Query to fine tune the query http://codex.wordpress.org/Class_Reference/WP_Query rather than using if statements and outputting the default wordpress loop.

Categories : PHP

Bash conditional on command exit code
Yes there is: if grep --quiet ..... then # If grep finds something fi or if the grep fails if ! grep --quiet ..... then # If grep doesn't find something fi

Categories : Bash

Conditional Formatting Code Crashing Program
I assume you intend to look explicitly in colums A to O, so you should use dollar-signs to fix the references: =COUNTIF($A:$O,A3) = 2 =COUNTIF($A:$O,A3) > 2 Without these it will check from the current column, 14 columns to the right. Added If your range that has the conditional formatting can be limited to a specific area then, assuming you first highlight the area A3:O50, then: =COUNTIF($A$3:$O$50,A3) = 2 =COUNTIF($A$3:$O$50,A3) > 2

Categories : Excel

Spree template - deface conditional code
You can try using the set attributes property of deface to change the property of the class for that div. From the deface docs: :set_attributes - Sets attributes on all elements that match the supplied selector, replacing existing attribute value if present or adding if not. Expects :attributes option to be passed Also for a slightly different solution, you could try a CSS selector to set the width: div.twelve[data-hook="checkout_form_wrapper"] { width: something_less_than_what_you_had_before }

Categories : Ruby On Rails

'If then Else' loops with Conditional Operators from Java code to XML or something else
XML will be hard to update every day. Maybe harder then recompiling and deploying. This is the moment when you want to do some scripting. There are lots of scripting languages out here. Pick one that will suite your needs. I don't have any experience with scripting (yet), but I heard Lua is used sometimes. Wikipedia has a demo list of some applications/games that use Lua for quickly changing logic here. Another approach might be to use a Java interpreter like Beanshell. Beanshell will compile at runtime Java code in string form to real executable byte code in RAM. This will allow you to write a little Java script apart from the code. Always be careful with evil script injections.

Categories : Java

Optimising Apache
As long as you don't mind getting a dsp parameter that is blank, you can do this: RewriteRule ^help(?:/([A-Za-z0-9-]+)|)$ help.php?dsp=$1 [NC] The (?:) is a conditional capture group. So it is either /([A-Za-z0-9-]+) or nothing at all. Thus the backreference $1 is either [A-Za-z0-9-]+ or nothing at all (giving you a blank dsp parameter).

Categories : Apache

Ruby: Clean code for checking nil /false conditional statement?
if a && a.value!=false puts "a value is true" else puts "a value is not available" end or just puts a && a.value!=false ? "a value is true" : "a value is not available"

Categories : Ruby

Can ProGuard remove conditional code from a method that ALWAYS returns a constant?
Why not add a constant DEV to your BuildConfig interface, like boolean DEBUG = ... boolean QA = ... boolean DEV = DEBUG | QA; It will be a compile-time constant (given that DEBUG and QA are defined at compile-time) and so ProGuard will be able to do code elimination based on just if (BuildConfig.DEV) { ...

Categories : Android

C/C++ (Other Languages Too?) Conditional Early Return Good Code Practice
The else would only add clarity if the else clause is short, a few lines of code at best. And if you have several initial conditions you want to check, the source gets cluttered very quickly. The only time I would use an else if it is a small function with a small else, meaning less than about 10 source lines, and there are no other initial checks to make. In some cases I have used a single loop so that a series of initial checks can use a break to leave. do { ... } while (0); I am loathe to use a goto which is practically guaranteed to get at least one true believer of goto less programming up in arms. So much would depend on any code standards of your organization. I tend to like minimalism so I use the first version you provide without the else. I might also do something li

Categories : C++

Optimising iterative loop
Not specifically about the loop, you're doing a ton of extra work in calls that look like: np.array(zeros((nh,nt))) Just use: np.zeros((nh,nt)) in its place. Additionally, you could replace: h = np.array(range(nh)) with: h = np.arange(nh) Other comments: You're calling np.sin(sl.T)*np.cos(sl.T) in every loop although, sl does not appear to be changing at all. Just calculate it once and assign it to a variable that you use in the loop. You do this in a bunch of your trig calls.

Categories : Python

Python: optimising loops
The best way of writing loops in numpy is not writing loops and instead using vectorized operations. For example: c = 0 for i in range(len(a)): c += a[i] + b[i] becomes c = np.sum(a + b, axis=0) For a and b with a shape of (100000, 100) this takes 0.344 seconds in the first variant, and 0.062 seconds in the second. In the case presented in your question the following does what you want: sol['ems'][naxis:] = numpy.ravel( numpy.repeat( data['ems'][naxis:,ispec,numpy.newaxis] * ems_mod, nplanes, axis=1 ), order='F' ) This could be further optimized with some tricks, but that would reduce clarity and is probably premature optimization because: plain python: 0.064 seconds numpy: 0.002 seconds The solution works as follows: Your origi

Categories : Python

Optimising bitwise operations in C
To make an n bit mask: mask_y = (1U << n) - 1; To start it at bit p: mask_x = mask_y << p; Clear the appropriate bits in x: x &= ~mask_x; Extract the bits from y: y &= mask_y; Upshift them to position p: y <<= p; Put it all together: result = x | y; Or in a more compact form: mask = (1U << n) - 1; result = x & ~(mask << p); result |= (y & mask) << p;

Categories : C

can JIT be prevented from optimising method?
There are two answers to this Question: AFAIK, there is no way of "turning off" optimization for a method without turning it off for everything. You can do things that are likely to inhibit the particular optimization you are worried about for current generation Java compilers. For instance: private static char[] password; public static String dummy; public static void clearArraySafely() { // Overwritting array for (int i = 0 ; i <= password.length; i++) { password[i] = 0; } dummy = new String(password); password = null; } The JIT compiler cannot optimize away the zero assignments. If it did, then the dummy String would be created with the "wrong" contents. And since dummy can be accessed by reflection without b

Categories : Java

Optimising away function table in C(++)
So I would like some way to tell the compiler that the function table will never change (...) Well, declare all const (BTW, you should rather interleave the first const between static and struct): #ifndef TEST # define CONST const #else # define CONST #endif static CONST struct { void (*CONST reportTargets)(size_t targetc, const char **targetv); [...] } interfaceToOutside #ifndef TEST = { reportTargetsLive, [...] } #endif ; #undef CONST (the macro name is bad, I know). Now, Is this likely to do the trick (...)? I think so, but you should still check the generated assembler code (-S option for gcc/g++).

Categories : C++

What is the easiest way to generate code files based on conditional compilation symbols in C#?
One option is to move all version-dependent code into separate classes with common interface. And then use conditional compilation once - to create an instance of required class. That way, you can write something like versionAdapter.RegisterProvider() instead of this.For<System.Web.Mvc.IFilterProvider>() .Singleton() .Use<FilterProvider>()

Categories : C#

Optimising and lowering GPU Overdraw - Android
The RelativeLayout and children for your rows would not appear to be the problem. Instead, it's stuff behind them. You should read Romain Guy's epic blog post on diagnosing jank (or similar coverage in ::cough:: well-regarded Android developer books). Specifically, use Hierarchy View to determine what is layered upon what, and try to get rid of unnecessary layers outright, or at least make them transparent if their color is completely overlapped by something higher in the Z-axis. Some of it may require changes in your design, or perhaps significant complexities in achieving your current look. For example, your 5dip of padding is causing the ListView to be inset within the page, meaning that whatever is behind it peeks through on the edges. Hence, you cannot get rid of the stuff behind i

Categories : Android

Optimising conways game of life
I believe that the Hashlife algorithm could help you. It gives the idea of using a quadtree (tree data structure in which each internal node has exactly four children) to keep the data, and then it uses hash tables to store the nodes of the quadtree. For further reading, this post, written by Eric Burnett, gives a great insight about how Hashlife works, it's performance and implementation (although in Python). It's worth a read.

Categories : Java

how does the compiler decides whether the operand of an instruction is signed or unsigned and then set the conditional code registers accordingly
It extracts such information from the type of the variable. The compiler does that in the semantic analysis phase where it adds semantic information to the parse tree and builds the symbol table. Some more information. A good book to understand a compiler is this one

Categories : Assembly

Optimising Python QT apps on retina displays
I basically found out the solution: be sure you have QT >= 5 installed, since it has been introduced in that version, secondly I am now running python3.3. Enjoy your retina

Categories : Python

Optimising 2D array indexing for cache line
I do not see justification for maximizing consecutive use of one cache line. The cache does not operate “one line at a time”, and there is generally no advantage to using one cache line repeatedly versus using any of the lines that are in cache. A better goal is to maximize the number of accesses that are served from a line in L1 cache, instead of needing to be fetched from slower cache or memory. As long as an access “hits” a line currently in cache, we do not care which cache line it is. The i5-2500K is a Sandy Bridge processor. The Sandy Bridge L1 data cache is 32 KiB and is eight-way associative, with 64-byte cache lines. This means the 32,768-byte cache has 512 lines, and they are organized into 64 sets of eight lines each. Each memory address maps to exactly one set, as sho

Categories : C

Optimising Canny Edge Detector for Android
Some suggestions for you to do image processing on Android: Do not implement per-element operations on large arrays in Java code. It is very inefficient. Instead do it in RenderScript or in C/C++ using JNI. This suggestion is not directly related to your question, but it makes huge difference in your program's performance. To avoid memory issue, do not operate directly on large images. Usually Android devices have far less memory (RAM) than traditional computing devices. Instead, break the image into small chunks and operate on them one by one. This technique should work on all the operations in your program above. When this is not possible (e.g. some algorithms whose inputs are not all nearby pixels), you can scale down the image and operate on the scaled image, and then scale the

Categories : Android

Conditional VBA code for PowerPoint 2003 & 2007/2010/2013 object model compatibility
After developing/debugging in 2007 or later, change this: Sub FillShape(oShp as Shape) to this: Sub FillShape(oShp as Object) Since the compiler doesn't know what properties an Object has or doesn't have, it will no longer bark at you. Of course it's up to you to make sure you don't try to push 2003 through any hoops it doesn't understand or trap the error if you do.

Categories : Misc

Optimising memory consumption for Grails applications deployed on Raspberry Pi
I would not recommend running any non-"Hello World" style Grails application on Raspberry Pi. In general, 512MB of RAM would be a minimum, in order to have a decent performance on a medium to smaller application. Tomcat memory usage + your app memory usage on 512MB of RAM doesn't look good on Raspberry Pi to me... See the second answer from Igor on this related SO question. Please consider other alternatives Spring MVC or something more lightweight(Not too many proxies, low amount of reflection in the Web Framework, etc.).

Categories : Grails

Conditional updating of matrix elements based on conditional statement
for is not your friend in R, here's a solution using apply and conditional indexing ## create some toy data matrix( ncol=5, nrow = 100, c( runif(300), sample(c('A','G','C','T','a','c','g','t'), replace=T, 200))) -> data flip_allele_freqs <- function(x) { ## function will return 1-x on any x that looks like a number less than 1 n = as.numeric(x) if ( is.na(n) ) { ## cant convert to numeric, must be str return(x) } if (n < 1) { return( 1 - n ) } else { return x } } ## apply the flip alleles function to the rows where the two last columns are equal ##fold the new data back into the old matrix data[toupper(data[,5]) == toupper(data[,4]),] <- apply(data[toupper(data[,5]) == toupper(data[,4]),], c(1,2), flip_allele_freqs)

Categories : R

Is it possible to make conditional includes and conditional function calls?
You can have 2 activities (for a single activity extending 2 different classes) and can launch the activities conditionally. if (MODE == MODE.ANDROID) startActivity(A) else startActivity(B) But your launcher activity has to be one, that cannot be designed in this way. I was wondering why are you trying to do this ??

Categories : Java

Can conditional and combinatorial conditional relationships be designed in Neo4j?
This question really seems oriented toward your app domain logic, not about Neo4j itself. With Neo4j, it's entirely possible to dynamically add/remove nodes, add/remove relationships, etc. For function 1, you'd just need to add or remove the relationship between E1 and S1/S2 (via your app logic; there's no automatic conditional-relationship mechanism to rely upon). And for function 2, again you'd add or remove a relationship between E1/E2 and S1-S5 (or just leave E1 & E2 without any relationship). You'll be able to do any of the query+add or query+remove via Cypher (latest documentation is here).

Categories : Neo4j

where to put php code for wordpress login
WordPress authentication is a lot more complex than a .php file that handles all this stuff. There's no one file. Also, changing any core file is highly discouraged as it makes updating WordPress impossible or very difficult. If you decide on implementing your own plugin that adds Google OAuth login then a good starting point is the codex. I would recommend against this though. The functionality you are looking after is already implemented by other people in free, open-source plugins. You could also have a look at those for a starting point.

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.