EzDevInfo.com

shorthand

Shrthnd is a handy tool that converts CSS properties into shorthand, making shorter and more readable stylesheets. Welcome to nginx!

Multiline String Literal in C#

Is there an easy way to create a multiline string literal in C#?

Here's what I have now:

string query = "SELECT foo, bar"
+ " FROM table"
+ " WHERE id = 42";

I know PHP has

<<<BLOCK

BLOCK;

Does C# have something similar?


Source: (StackOverflow)

Shorthand if/else statement Javascript

I'm wondering if there's a shorter way to write this:

var x = 1;
if(y != undefined) x = y;

I initially tried x = y || 1, but that didn't work. What's the correct way to go about this?


Source: (StackOverflow)

Advertisements

Is there a good JS shorthand reference out there?

I'd like to incorporate whatever shorthand techniques there are in my regular coding habits and also be able to read them when I see them in compacted code.

Anybody know of a reference page or documentation that outlines techniques?

Edit: I had previously mentioned minifiers and it is now clear to me that minifying and efficient JS-typing techniques are two almost-totally-separate concepts.


Source: (StackOverflow)

What does "a" stand for in font: 0/0 a;

I was referring a video tutorial where the designer used font: 0/0 a; for image replacement, so I get that 0 is the font-size, another 0 is the line-height but designer skips the a part just by saying that's an hack.

So what does that a exactly do there?


Source: (StackOverflow)

Less border-radius shorthand mixin, disable variable

I am trying to write a mixin for border-radius than only outputs when the values, set by a variable, are >= 0. I set the base value in a variable as 3px, so if I enter -1 or no for example, the border-radius mixin would not create any properties in the final stylesheet. I can get this to work for if I want to have the same value for every corner. But I can't workout how to get it working if I want to use the shorthand i.e 3px 3px 0 0. I think it is an issue with the 3px being changed by a variable and 0 in both scenarios. My code at the moment is

.border-radius(@r) when not (@r = no), (@r = 0) {
    -webkit-border-radius: @r;
       -moz-border-radius: @r;
            border-radius: @r;
}
.border-radius(@r) when (@r = no), (@r = 0) {}

@baseBorderRadius: 3px;
.class1 { .border-radius(@baseBorderRadius); }
// This outputs fine: 3px 3px 3px 3px
.class2 { .border-radius(@baseBorderRadius @baseBorderRadius 0 0); }
// This outputs fine 3px 3px 0 0

@baseBorderRadius: no; // If I change the variable to try and disable/not run the mixin
.class1 { .border-radius(@baseBorderRadius); }
// This does what I want and doesn't run the mixin
.class2 { .border-radius(@baseBorderRadius @baseBorderRadius 0 0); }
// THIS IS THE PROBLEM! This outputs: no no 0 0

So I need a way to disable/not run the mixin if it contains a certain value or word defined from a global variable. I am doing this for a theme variables file where, based on the branding, companies might want rounded corners or not and I would prefer not to have loads of 0 values unnecessarily included in the final stylesheet.

I would really appreciate any help with this, even if it is just to find out that what I want to do isn't possible within LESS. Thank you


Source: (StackOverflow)

Javascript shorthand way to duplicate strings

I have this code in a function, and want to shorten it - it applies the same style to every item in an array.

document.getElementById(divsArray[0]).style.visibility='hidden'; document.getElementById(divsArray[1]).style.visibility='hidden'; document.getElementById(divsArray[2]).style.visibility='hidden'; document.getElementById(divsArray[3]).style.visibility='hidden';

NO answer to date worked (Because I am looping thru the code??)

Resolved it by setting only the previously displayed slide visibility to hidden

 x=i;
 i=i+1;

 document.getElementById(divsArray[x]).style.visibility='hidden'

Source: (StackOverflow)

PHP shorthand for isset()? [duplicate]

This question already has an answer here:

Is there a shorthand way to assign a variable to something if it doesn't exist in PHP?

if(!isset($var) {
  $var = "";
}

I'd like to do something like

$var = $var | "";

Source: (StackOverflow)

C# getter and setter shorthand

If my understanding of the internal workings of this line is correct:

public int MyInt { get; set; }

Then it behind the scenes does this:

private int _MyInt { get; set; }
Public int MyInt {
    get{return _MyInt;}
    set{_MyInt = value;}
}

What I really need is:

private bool IsDirty { get; set; }

private int _MyInt { get; set; }
Public int MyInt {
    get{return _MyInt;}
    set{_MyInt = value; IsDirty = true;}
}

But I would like to write it something like:

private bool IsDirty { get; set; }

public int MyInt { get; set{this = value; IsDirty = true;} }

Which does not work. The thing is some of the objects I need to do the IsDirty on have dozens of properties and I'm hoping there is a way to use the auto getter/setter but still set IsDirty when the field is modified.

Is this possible or do I just have to resign myself to tripling the amount of code in my classes?


Source: (StackOverflow)

shorthand http:// as // for script and link tags? anyone see / use this before?

the question is as follows:

if you take a look at any site using addthis (the share button)...

once you float over the addthis button, and all of the required assets load take a look at the body of the document using firebug or chrome inspector (not the source, the actual document that is sitting on your screen... the object inspector). you will notice that the additional assets loaded automatically by addthis look something like this:

<script type="text/javascript" src="//s7.addthis.com/static/r07/menu78.js"></script>
<link rel="stylesheet" type="text/css" rel='nofollow' href="//s7.addthis.com/static/r07/widget61.css" media="all">

what is this short handing of http:// in the above tags?

has anyone used this before? does it have an 'official' name? how cross browser compatible is this method of short handing the http protocal?

yes, i understand this will break things as far as crawlers / seo go, but i am thinking about starting to use this in situations that are inaccessible (mainly, js handled stuff) to bots.

good or bad idea?


Source: (StackOverflow)

In PHP, is there a short way to compare a variable to multiple values?

Basically what I'm wondering if there is a way to shorten something like this:

if ($variable == "one" || $variable == "two" || $variable == "three")

in such a way that the variable can be tested against or compared with multiple values without repeating the variable and operator every time.

For example, something along the lines of this might help:

if ($variable == "one" or "two" or "three")

or anything that results in less typing.


Source: (StackOverflow)

Add item to an Array in Ruby, even if the variable does not exist

I have the following:

foo ||= []
foo << "bar"

And I am sure this can be done in one line, I just cannot find how.

Important is, that foo may, or may not exist. If it exists it is always an Array, if it does not exist, it must become an array and get a variable appended to it.


Source: (StackOverflow)

Other Ruby Map Shorthand Notation

I am aware of the shorthand for map that looks like:

[1, 2, 3, 4].map(&:to_s)
> ["1", "2", "3", "4"]

I was told this is shorthand for:

[1, 2, 3, 4].map{|i| i.to_s}

This makes perfect sense. My question is this: It seems there should be an easier way to write:

[1, 2, 3, 4].map{|x| f.call(x)} 

for some procedure f. I know the way I just typed isn't all that long to begin with, but I'd contend that neither is the previous example for which the shorthand exists. This example just seems like the complement to the first example: Rather than calling i's to_s method for every i, I wish to call f for every x.

Does such a shorthand exist?


Source: (StackOverflow)

Using key-value pairs as parameters

Simple. If I use:

public void Add(params int[] values)

Then I can use this as:

Add(1, 2, 3, 4);

But now I'm dealing with key-value pairs! I have a KeyValue class to link an integer to a string value. So I start with:

public void Add(params KeyValue[] values)

But I can't use this:

Add(1, "A", 2, "B", 3, "C", 4, "D");

Instead, I'm forced to use:

Add(new KeyValue(1, "A"), new KeyValue(2, "B"), new KeyValue(3, "C"), new KeyValue(4, "D"));

Ewww... Already I dislike this...

So, right now I use the Add function without the params modifier and just pass a pre-defined array to this function. Since it's just used for a quick initialization for a test, I'm not too much troubled about needing this additional code, although I want to keep the code simple to read. I would love to know a trick to use the method I can't use but is there any way to do this without using the "new KeyValue()" construction?


Source: (StackOverflow)

Is !0 and !1 something more than a shorthand for true/false?

Reading through some code, I came across the use of !0 and !1. I realize that these are shorter ways of writing true and false.

!0 === true
!1 === false

This of course save a few bytes, but is there some other reason to use it?

Is there a name for this way of writing it?


Source: (StackOverflow)

Shorthand conditional to define a variable based on the existence of another variable in PHP

Essentially, I'd love to be able to define a variable as one thing unless that thing doesn't exist. I swear that somewhere I saw a shorthand conditional that looked something like this:

$var=$_GET["var"] || "default";

But I can't find any documentation to do this right, and honestly it might have been JS or ASP or something where I saw it.

I understand that all that should be happening in the above code is just to check if either statement returns true. But I thought I saw someone do something that essentially defined a default if the first failed. Is this something anyone knows about and can help me? Am I crazy? It just seems redundant to say:

$var=($_GET["var"]) ? $_GET["var"] : "default";

or especially redundant to say:

if ($_GET["var"]) { $var=$_GET["var"]; } else { $var="default"; }

Thoughts?


Source: (StackOverflow)