Rectangle 27 184

background-size: 100% 100%; produces the least predictable result.

You have multiple options:

background-size: 100% 100%;
  • background-size: contain; - image is stretched without cutting it while preserving aspect ratio
  • background-size: cover; - image is completely covering the element while preserving aspect ratio (image can be cut off)

thank you, @Alp and @jao! this answer and comment really helped me instead of using ugly javascript to create a separate img element and then set the height and width before putting the img back into the div instead.

html - Resize background image in div using css - Stack Overflow

html css
Rectangle 27 3

You have multiple options here.

By setting 'has_archive' => 'galleries' you can define custom post type archive slug. Check documentation. Then you can delete your page "galleries" then add & customize the archive-post_type.php

Disable the archive by setting 'has_archive' => false then keep the page for the post type archive.

function archive_to_custom_archive() {
    if( is_post_type_archive( 'post_slug' ) ) {
        wp_redirect( home_url( '/galleries/' ), 301 );
        exit();
    }
}
add_action( 'template_redirect', 'archive_to_custom_archive' );

Can you please suggest wich option would be better if I also have "custom taxonomy for this custom post type" (custom taxonomy name is 'gallery_categories', example of galery category is "auto"). And I wish myurl.com/galleries/auto would work the same as myurl.com/galleries. I wish it would have almost the same code (code would check if it is 'galleries' or 'galleries'/xxx and act in very the same way with minor differences)?

Custom post type archive and custom taxonomy archive are different. The fist option is always good but it will not work as myurl.com/galleries/auto You can not pull results from term auto. For this you will need custom page template and URL rewrite to parse the request as example.com/page-name/?mytax=auto

custom-post-types custom-post-type-archives
Rectangle 27 142

For the special date of January 1, 1970 there are multiple options.

For any other starting date you need to get the difference between the two dates in seconds. Subtracting two dates gives a timedelta object, which as of Python 2.7 has a total_seconds() function.

>>> (t-datetime.datetime(1970,1,1)).total_seconds()
1256083200.0

The starting date is usually specified in UTC, so for proper results the datetime you feed into this formula should be in UTC as well. If your datetime isn't in UTC already, you'll need to convert it before you use it, or attach a tzinfo class that has the proper offset.

As noted in the comments, if you have a tzinfo attached to your datetime then you'll need one on the starting date as well or the subtraction will fail; for the example above I would add tzinfo=pytz.utc if using Python 2 or tzinfo=timezone.utc if using Python 3.

Python now warns me: "TypeError: can't subtract offset-naive and offset-aware datetimes" What's the best solution to fix that?

datetime.datetime(1970,1,1,tzinfo=pytz.utc)

Consider using: datetime.datetime.utcfromtimestamp(0) I've used this to get the 'epoch' easily. Note that epoch is not always the same on all systems.

@D.A.: Python does not support non-POSIX epochs. All systems where python works use the same Epoch: 1970-01-01 00:00:00 UTC

@felice, there's an answer to this question that says the same, you should give it an upvote. Was there a point to your comment?

How to convert a Python datetime object to seconds - Stack Overflow

python python-2.7
Rectangle 27 15

I've come across the same problem and I have a solution. A function called ExpandSelect() that emulates mouse clicking on "select" element, it does so by creating an another <select> element that is absolutely posioned and have multiple options visible at once by setting the size attribute. Tested in all major browsers: Chrome, Opera, Firefox, Internet Explorer. Explanation of how it works, along with the code here:

I've created a project at Google Code, go for the code there:

There is a little difference in GUI when emulating click, but it does not really matter, see it for yourself:

Can you post a jsfiddle for this?

html - Can I open a dropdownlist using jQuery - Stack Overflow

jquery html drop-down-menu
Rectangle 27 15

I've come across the same problem and I have a solution. A function called ExpandSelect() that emulates mouse clicking on "select" element, it does so by creating an another <select> element that is absolutely posioned and have multiple options visible at once by setting the size attribute. Tested in all major browsers: Chrome, Opera, Firefox, Internet Explorer. Explanation of how it works, along with the code here:

I've created a project at Google Code, go for the code there:

There is a little difference in GUI when emulating click, but it does not really matter, see it for yourself:

Can you post a jsfiddle for this?

html - Can I open a dropdownlist using jQuery - Stack Overflow

jquery html drop-down-menu
Rectangle 27 43

There are multiple options to implement SSO for a .NET application.

Check out the following tutorials online:

GaryMcAllisterOnline: ASP.NET MVC 4, ADFS 2.0 and 3rd party STS integration (IdentityServer2)

The first one uses ASP.NET Web Forms, while the second one uses ASP.NET MVC4.

If your requirements allow you to use a third-party solution, also consider OpenID. There's an open source library called DotNetOpenAuth.

Thanks for the help! I'm wondering though, aren't there already pre-existing single sign-on servers that I might use to do this instead of writing my own implementation? Like Yale's CAS or something?

I don't have any experience with Yale CAS, but I found another StackOverflow question that covers it: stackoverflow.com/questions/173704/which-sso-framework-to-use It mentions the flowing presentation: slideshare.net/craigsdickson/ You'll find mentions of both JOSSO and CAS.

Perhaps I'm missing something, but the first link seems fairly useless. You can just hack the query string to bypass authentication?

C# ASP.NET Single Sign-On Implementation - Stack Overflow

c# asp.net single-sign-on
Rectangle 27 61

I would answer this with multiple options actually, the some of which actually render in the body.

  • Place library script such as the jQuery library in the head section.
  • Place normal script in the head unless it becomes a performance/page load issue.
  • Place script associated with includes, within and at the end of that include. One example of this is .ascx user controls in asp.net pages - place the script at the end of that markup.
  • Place script that impacts the render of the page at the end of the body (before the body closure).
  • do NOT place script in the markup such as <input onclick="myfunction()"/> - better to put it in event handlers in your script body instead.
  • If you cannot decide, put it in the head until you have a reason not to such as page blocking issues.

Footnote: "When you need it and not prior" applies to the last item when page blocking (perceptual loading speed) - the users perception IS thier reality, if it is percieved to load faster, it does load faster (even though stuff might still be occuring in code).

  • the other answers on this question present valid information as well.
  • use www.google.com and www.bing.com to search for related information (there are a lot of references)

Side note: IF you place script blocks within markup, it may effect layout in certain browsers by taking up space (ie7 and opera 9.2 are known to have this issue) so place them in a hidden div (use a css class like: .hide { display: none; visibility: hidden; } on the div)

EDIT2: Note that whenever possible (always?) you should put the actual Javascript in external files and reference those - this does not change the pertinent sequence validity.

Do you have a source that have more information about this page blocking issue or how browser download resources?

@Khoi - the page render blocking is a commonly documented issue. Editing the answer to provide some other references as it depends somewhat on the environment (platform and browser/version)

@Andrew $().on("error", function(){}); is one example or if you want to avoid multiple errors (on the backup image) try $().one("error", function(){}); with the one function - jQuery specific but you can reverse the source if you want pure JavaScript

javascript - Should I write script in the body or the head of the html...

javascript html
Rectangle 27 61

I would answer this with multiple options actually, the some of which actually render in the body.

  • Place library script such as the jQuery library in the head section.
  • Place normal script in the head unless it becomes a performance/page load issue.
  • Place script associated with includes, within and at the end of that include. One example of this is .ascx user controls in asp.net pages - place the script at the end of that markup.
  • Place script that impacts the render of the page at the end of the body (before the body closure).
  • do NOT place script in the markup such as <input onclick="myfunction()"/> - better to put it in event handlers in your script body instead.
  • If you cannot decide, put it in the head until you have a reason not to such as page blocking issues.

Footnote: "When you need it and not prior" applies to the last item when page blocking (perceptual loading speed) - the users perception IS thier reality, if it is percieved to load faster, it does load faster (even though stuff might still be occuring in code).

  • the other answers on this question present valid information as well.
  • use www.google.com and www.bing.com to search for related information (there are a lot of references)

Side note: IF you place script blocks within markup, it may effect layout in certain browsers by taking up space (ie7 and opera 9.2 are known to have this issue) so place them in a hidden div (use a css class like: .hide { display: none; visibility: hidden; } on the div)

EDIT2: Note that whenever possible (always?) you should put the actual Javascript in external files and reference those - this does not change the pertinent sequence validity.

Do you have a source that have more information about this page blocking issue or how browser download resources?

@Khoi - the page render blocking is a commonly documented issue. Editing the answer to provide some other references as it depends somewhat on the environment (platform and browser/version)

@Andrew $().on("error", function(){}); is one example or if you want to avoid multiple errors (on the backup image) try $().one("error", function(){}); with the one function - jQuery specific but you can reverse the source if you want pure JavaScript

javascript - Should I write script in the body or the head of the html...

javascript html
Rectangle 27 1

There are multiple options here:

Any decent framework should allow you to use annotations to use a different name within the JSON representation and the actual field names!

public class Example {
  @SerializedName("lisp-style-name")
  private String someField....

In other words: make sure that all JSON "field names" follow such a convention - then you are independent of the underlying programming language.

The big downside is of course that have to annotate each field - maybe even on both sides. On the other hand, the above is really explicit - you understand what is supposed to happen just by looking into your "data" class declaration.

Both libraries, gson and NewtonJson support policies. So instead of doing the mapping manually, you can instruct the framework to transform field names.

that other suggestion is pretty lame

this is ugly, Newtonsoft lets you set a policy for casing rather than manually try and spec it

Writing good answers on the mobile isn't exactly easy; I have further enhanced my answer, and hope it is good enough now to at least undo the the downvote (not sure if that was you or @JerryGoyal)

java - How bad it will be if using camelCasing instead of PascalCasing...

java c# json
Rectangle 27 1

There are multiple options here:

Any decent framework should allow you to use annotations to use a different name within the JSON representation and the actual field names!

public class Example {
  @SerializedName("lisp-style-name")
  private String someField....

In other words: make sure that all JSON "field names" follow such a convention - then you are independent of the underlying programming language.

The big downside is of course that have to annotate each field - maybe even on both sides. On the other hand, the above is really explicit - you understand what is supposed to happen just by looking into your "data" class declaration.

Both libraries, gson and NewtonJson support policies. So instead of doing the mapping manually, you can instruct the framework to transform field names.

that other suggestion is pretty lame

this is ugly, Newtonsoft lets you set a policy for casing rather than manually try and spec it

Writing good answers on the mobile isn't exactly easy; I have further enhanced my answer, and hope it is good enough now to at least undo the the downvote (not sure if that was you or @JerryGoyal)

java - How bad it will be if using camelCasing instead of PascalCasing...

java c# json
Rectangle 27 1

You have multiple options to do so:

sessionStorage.setItem('key', 'value');//to set value
 sessionStorage.getItem('key');//to get the value
localStorage.setItem('key', 'value');//to set value
localStorage.getItem('key');//to get the value
var createCookie = function(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
http://www.example.com?myKey=myVal

can run the code in jsfiddle

i can understand sir but i don't know javascript. what can i do sir

JSFiddle cannot easily show how this works over two pages

javascript - how to pass value one page to another page using html - S...

javascript jquery html asp.net
Rectangle 27 1

There are multiple options:

<p class ="BasicP">Datum: <?php echo $Datum;?></p>
<p class ="BasicP">Betreft: <?php echo $Betreft;?></p>
<p class ="BasicP">Offertenr: <?php echo $Offertenr;?></p>
<p class ="BasicP">
    Datum: <?php echo $Datum;?><br/>
    Betreft: <?php echo $Betreft;?><br/>
    Offertenr: <?php echo $Offertenr;?>
<p>

Or print it as code:

<pre>
    Datum: <?php echo $Datum;?>
    Betreft: <?php echo $Betreft;?>
    Offertenr: <?php echo $Offertenr;?>
</pre>

Sure, but the question is off-topic; it's a parse error.

The Line break solution did the trick, thank you. I must've done something a tiny bit wrong.

,,, or set whitespace: pre; in the BasicP class in the stylesheet.

Newline in php not working - Stack Overflow

php newline
Rectangle 27 1

You have multiple options to do it.

$('.question .visitor li:first-child a').click(function () { // First li of it's parent
            $('.opt1').fadeToggle();
        });
$('.question .visitor li:eq(0) a').click(function () { // 0 is the first of all relevant elements criteria 
            $('.opt1').fadeToggle();
        });
$('#opt1').click(function () { // Select by ID
            $('.opt1').fadeToggle();
        });

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

javascript - Use Twitter Bootstrap Dropdown toggle to trigger another ...

javascript jquery twitter-bootstrap drop-down-menu
Rectangle 27 4

There are multiple options, but the simplest one might be:

>>> mlist = [0] + range(5,10)
>>> mlist
[0, 5, 6, 7, 8, 9]
list.insert
>>> mlist = range(5,10)
>>> mlist.insert(0, 0) # the first 0: index, the second 0: the item to insert
>>> mlist
[0, 5, 6, 7, 8, 9]

Most methods that change the sequence/maping in place return None. So just call the method, and do not reassign the return value to the variable.

python - Appending to range function - Stack Overflow

python python-2.x
Rectangle 27 47

If statement is used for checking just one condition quickly. When you have multiple options, use <xsl:choose> as illustrated below:

Also, you can use multiple <xsl:when> tags to express If .. Else If or Switch patterns as illustrated below:

<xsl:choose>
     <xsl:when test="$CreatedDate > $IDAppendedDate">
       <h2>mooooooooooooo</h2>
     </xsl:when>
     <xsl:when test="$CreatedDate = $IDAppendedDate">
       <h2>booooooooooooo</h2>
     </xsl:when>
     <xsl:otherwise>
      <h2>dooooooooooooo</h2>
     </xsl:otherwise>
   </xsl:choose>

The previous example would be equivalent to the pseudocode below:

if ($CreatedDate > $IDAppendedDate)
   {
       output: <h2>mooooooooooooo</h2>
   }
   else if ($CreatedDate = $IDAppendedDate)
   {
       output: <h2>booooooooooooo</h2>
   }
   else
   {
       output: <h2>dooooooooooooo</h2>
   }

Could you please correct the statement below, we all know that if(case > x ) without following {} will only execute 1 following line, i have seen this on many beginners that they write exactly what you have posted here, probably many of them copied 1:1

By the way, the if else condition was just an example or Rather a pseudocode. Well, I consider your concern and I've edited it ..

Hey thats cool, thanks for making me happy ;-)! (I guess you have seen this Issue in productive software too, otherwise you wouldn't have edited it) :-)!

xml - How to implement if-else statement in XSLT? - Stack Overflow

xml xslt if-statement
Rectangle 27 85

To keep your options open, if you're using .NET 3.5 or later, here is a wrapped up example you can use straight from the framework using Generics. As others have mentioned, if it's not just simple objects you should really use JSON.net.

public static string Serialize<T>(T obj)
{
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
    MemoryStream ms = new MemoryStream();
    serializer.WriteObject(ms, obj);
    string retVal = Encoding.UTF8.GetString(ms.ToArray());
    return retVal;
}

public static T Deserialize<T>(string json)
{
    T obj = Activator.CreateInstance<T>();
    MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
    obj = (T)serializer.ReadObject(ms);
    ms.Close();
    return obj;
}
using System.Runtime.Serialization;

using System.Runtime.Serialization.Json;

+1 for adding the using statements...

If DataContractJsonSerializer class is not visible, you have to add a reference to System.Runtime.Serialization by right clicking on the References in the solution, select the .NET tab and select System.Runtime.Serialization

One scenario where this one breaks. If your JSON object represents properties with single quotes, this function fails. e.g. it was not able to parse {'Subject': 'Emailing: Web User Activity Log11', 'EmbedAsImage': true} but it was able to parse {"Subject": "Emailing: Web User Activity Log11", "EmbedAsImage": true}

Plus I needed to decorate my simple class with DataContract and DataMember attributes. It won't parse without it.

asp.net - How to Convert JSON object to Custom C# object? - Stack Over...

c# asp.net .net ajax json
Rectangle 27 83

To keep your options open, if you're using .NET 3.5 or later, here is a wrapped up example you can use straight from the framework using Generics. As others have mentioned, if it's not just simple objects you should really use JSON.net.

public static string Serialize<T>(T obj)
{
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
    MemoryStream ms = new MemoryStream();
    serializer.WriteObject(ms, obj);
    string retVal = Encoding.UTF8.GetString(ms.ToArray());
    return retVal;
}

public static T Deserialize<T>(string json)
{
    T obj = Activator.CreateInstance<T>();
    MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
    obj = (T)serializer.ReadObject(ms);
    ms.Close();
    return obj;
}
using System.Runtime.Serialization;

using System.Runtime.Serialization.Json;

+1 for adding the using statements...

If DataContractJsonSerializer class is not visible, you have to add a reference to System.Runtime.Serialization by right clicking on the References in the solution, select the .NET tab and select System.Runtime.Serialization

One scenario where this one breaks. If your JSON object represents properties with single quotes, this function fails. e.g. it was not able to parse {'Subject': 'Emailing: Web User Activity Log11', 'EmbedAsImage': true} but it was able to parse {"Subject": "Emailing: Web User Activity Log11", "EmbedAsImage": true}

Plus I needed to decorate my simple class with DataContract and DataMember attributes. It won't parse without it.

asp.net - How to Convert JSON object to Custom C# object? - Stack Over...

c# asp.net .net ajax json
Rectangle 27 8

There is no consensus as in the Silver Bullet sense. For established patterns, you have multiple options like

to name a few.

@Gordon What do you think about decorating the main 'application' object (like silex has), doing your modifications to it, then returning it? Then you could repeatedly decorate these, adding more decorators for each new application modification, and being able to remove each one any time without affecting the rest?

@Jimbo Sure, if that's what you want to do. But keep in mind that a Decorator usually only operates on the existing API of the decorated class. You could also use Silex before() and after() hooks.

oop - Design pattern for implementing plugins in PHP applications - St...

php oop design-patterns plugins observer-pattern
Rectangle 27 9

See here for details on the various options open to you but you now have to iterate through the markers and remove them individually. Your code should look something like this:

var markers = [];

function clearOverlays() {
 while(markers.length) { markers.pop().setMap(null); }
  markers.length = 0;
}

markers.push(marker);
google.maps.event.addListener(marker,"click",function(){});

Google Maps API v3 - How to clear overlays? - Stack Overflow

api google-maps google-maps-api-3
Rectangle 27 9

See here for details on the various options open to you but you now have to iterate through the markers and remove them individually. Your code should look something like this:

var markers = [];

function clearOverlays() {
 while(markers.length) { markers.pop().setMap(null); }
  markers.length = 0;
}

markers.push(marker);
google.maps.event.addListener(marker,"click",function(){});

Google Maps API v3 - How to clear overlays? - Stack Overflow

api google-maps google-maps-api-3