Thursday, November 1, 2012

Ultimate CSS Cheat Sheet


http://www.addedbytes.com/cheat-sheets/css-cheat-sheet/

Given the number of possible selectors in CSS, it is no wonder some people often become confused. Mixing up ID and Class selectors is easy enough, without throwing sibling, child, attribute and language selectors into the mix. This section of the cheat sheet lists selectors and shows which element(s) those selectors would apply to.


Pseudo-selectors are used when defining styles for elements that either do not exist, or are in a particular state. This section lists various of the pseudo-selectors.
Please note - I have left the :before and :after pseudo-selectors off this list, as I felt generated content was too complex to add to this sheet and still define in a way that made that area of the sheet usable.

http://slodive.com/freebies/css-cheat-sheets/

How to stop Chrome from opening pdfs in the browser?

How to stop Chrome from opening pdfs in the browser?


http://superuser.com/questions/30850/stop-pdfs-from-displaying-inside-google-chrome

a probably faster way to do the same thing: go to chrome://plugins (in firefox, that would be about:plugins), and disable the acrobat reader plugin – Babu Aug 23 '10 at 13:24

chrome://plugins
Disable everything in the list that handles opening of PDF, even this
Foxit Reader Plugin for Mozilla - Version: 2, 0, 0, 1102 (Disabled)
Foxit Reader Plug-In For Firefox and Netscape







How to join strings, format strings... add variables to strings... printf?


Javascript dynamic string manipulation.

How to join strings, format strings... add variables to strings... printf?


It has nothing as neat as Python's... but you'll find a way when you need to.



How to change color/style of element in Jquery/Javascript


jQuery Learnings.

any styling you can do with CSS you can handle with jQuery.



Place the following in your jQuery mouseover event handler:
$(this).css('color', 'red');To set both color and size at the same time:
$(this).css({ 'color': 'red', 'font-size': '150%' });You can set any CSS attribute using the .css() jQuery function.



Whatever DOM element you turn into a jQuery object using this constructor $(),
you can use the .css() method on it.



2

$(document).ready(function() {
    var button = $('#specific_consultant_no');
    button.click(function() {
        button.css('color', 'FOO');
    });
});

THIS
$(this) = in the function object, 'this' refers to: the DOM element, which you need to turn into a jquery object by using $() on this.
[then only you get all the jquery object goodness as .methods on that element.]


if you want to reuse the method, you can do eg.
var colorMethod = function() {
    $(this).css('color', 'FOO');
};
$(document).ready(function() {
    var button = $('#specific_consultant_no');
    button.click(colorMethod);
});
you can also use the addClass and removeClass methods, to be more flexible!



This lets you name your functions to be reused elsewhere.

var colorMethod = function() {

Define using var and give it a name, actually is closest to Python
function_obj = lambda a, b : a+b

or def asdf(a, b): return a+b
function_obj = asdf
[In this second case, you could just pass asdf as arg to a function.]



Entire Jquery object?

You could use the css function:
$(function() {
    $('#specific_consultant_no').click(function() {
        $(this).css('color', 'red');
    });
);




How to change color/style of element in Jquery/Javascript
(just, glorified console-text formatting again.)

changing text color with jquery - Google Search


If no jquery:
http://www.ehow.com/how_5220878_change-text-color-javascript.html
document.getElementById('mySpan').style.color = '#FFFFFF';

function spanColorChange(){document.getElementById('mySpan').style.color = '#FFFFFF';}





Python functions modify whatever arguments you pass in.


Python functions modify whatever arguments you pass in,
and the changes are seen outside the function.

Example code:


dct = dict(a='a', b='b')

def modify_dct(thedct):
    thedct['a'] = 1
    thedct['b'] = 2

if __name__ == '__main__':
    print dct
    modify_dct(dct)
    print dct
    print "OK"



Output:


[Dbg]>>> 
{'a': 'a', 'b': 'b'}
{'a': 1, 'b': 2}
OK



What just happened?
Unlike C, which has pass by value, whatever you pass to a function other than primitives (int, e.g. 1, 110,)
is actually a reference to that object itself, and not a copy.

So, modifying it inside the function will see it changed outside the function, after the func has run (processed it) on it.





linux shell script how to check environment variable exist (and define a default if it doesn't)


linux shell script how to check environment variable exist - Google Search

Scenario: You have a long command line e.g.
python sth.py --asdf $asdf --qwer $qwer --zxcv $zxcv

and you're getting the $xxxx from somewhere else.. but it could be empty..
in which case all your --xxxx get --yyyy as their arguments... not good...



linux shell script how to check environment variable exist (and define a default if it doesn't)
- 2 syntax (OLD, NEW)



http://www.cyberciti.biz/faq/bash-ksh-if-variable-is-not-defined-set-default-variable/

output=${1-text}
echo $output

Common mistake:
$output=${1-text}
If you do this, errmsg is := not defined not found etc. (becoz left hand side is blank)
Correct is this
output=${asdf-text}
or
output=${output-text}
Note, without the $ sign in front


Or, Syntax 2:

OR (see my comment below):
output=${1:-text}
echo $output




Vivek Gite July 27, 2009 at 7:59 am
@Ronald,
The original Bourne shell only supported above syntax and it works with all shells to keep portability. POSIX shells (KSH and BASH) offer a slight variant (as mentioned in bash man page):
${1:-text}
I should have mentioned both syntax..
HTH




Ronald Fischer July 27, 2009 at 7:11 am
It surprises me that this works (and, at least, on bash 3, it does). I have always used the form
${VAR:-VALUE} in such a case, not ${VAR-VALUE}, but it seems that both work. The man pages of bash describe, however, ONLY the variant with a colon, so I wonder whether omitting the colon just exploits an undocumented feature, which might be gone with the next version of bash. Or did I miss here something in ‘man bash’?




Shell Scripting: If Variable Is Not Defined, Set Default Variable



If var is defined AND NOT EMPTY, use var, otherwise set a default variable under Bash. For e.g. my script needs a parameter for output variable. It can be text or html. I set it as follows in my script







2
http://stackoverflow.com/questions/2981878/bash-checking-for-environment-variables

In Bash (and ksh and zsh), if you use double square brackets you don't need to quote variables to protect against them being null or unset.
$ if [ $xyzzy == "x" ]; then echo "True"; else echo "False"; fi
-bash: [: ==: unary operator expected
False
$ if [[ $xyzzy == "x" ]]; then echo "True"; else echo "False"; fi
False
There are other advantages.






3: useful
What's the best way to check that environment variables are set in Unix shellscript
http://stackoverflow.com/questions/307503/whats-the-best-way-to-check-that-environment-variables-are-set-in-unix-shellscr

Your question is dependent on the shell that you are using.
Bourne shell leaves very little in the way of what you're after.
BUT...
It does work, just about everywhere.
Just try and stay away from csh. It was good for the bells and whistles it added, compared the Bourne shell, but it is really creaking now. If you don't believe me, just try and separate out STDERR in csh! (-:
There are two possibilities here. The example above, namely using:
${MyVariable:=SomeDefault}
for the first time you need to refer to $MyVariable. This takes the env. var MyVariable and, if it is currently not set, assigns the value of SomeDefault to the variable for later use.
You also have the possibility of:
${MyVariable:-SomeDefault}
which just substitutes SomeDefault for the variable where you are using this construct. It doesn't assign the value SomeDefault to the variable, and the value of MyVariable will still be null after this statement is encountered.
HTH.
cheers,
Rob








how do you reset CSS localized in your small Universe of your ?

Scenario:

1
What to do if you're using some CSS layout by somebody else,
and you want to style differently at certain parts, BUT...

the original CSS already styled stuff like <p> and <div> generally...

how do you reset CSS localized in your small Universe of your <block> ?


2 what is the CSS syntax actually?

Why does this work
p.opening-intro
and this doesn't
.opening-intro p


And why does this work
#opening-jqm-homeheader p
and this doesn't?
p #opening-jqm-homeheader
p#opening-jqm-homeheader

What is the space combinator, and the , (comma) combinator?





http://stackoverflow.com/questions/9515534/disinherit-reset-the-css-style-of-a-specific-element

This is a problem that is solved best by avoiding it from the beginning. I try to keep contextual (or decendeant) selectors to a minimum and I avoid using tag names as selectors. Instead I make use of classes so that my html elements (<a>, <p>, <ul>, <span>, etc) will always look like they've not been styled no matter what the context/its parent element is.
In your case, I think you can only overwrite the inherited styles as you have mentioned with the inline-style attribute or with !important or even better, create a .reset class.
.reset { with: auto; height: auto; padding: 0; /* etc */ }
All solutions mentioned above have drawbacks, so you'll need to chose your battle.


Contextual/descendent selectors =
http://reference.sitepoint.com/css/descendantselector



Q. Ok, I have a beautiful web, with its styles within a CSS and everything
But now I've found a problem, I want ONE list to be virgin, without any style inherited.
I know I can do it just giving it a style="(...)" so it overwrites the inherited style, but, is there any instruction / trick / something to do it without doing this?

Solution to #1, just make a localized css style block next to the new html block you put in, for ease of testing:

    <style type="text/css">
p.opening-intro {
    border-top: 1px solid #75AE18;
    font-size: 0.96em;
    line-height: 1.3;
    padding: 0.5em 1em 0;
color: #558E08;
}
#opening-jqm-homeheader p {
    color: #666666;
    font-size: 0.9em;
    font-weight: bold;
    line-height: 1.3;
    margin: 0.3em 1em 0;
}
#opening-jqm-homeheader {
    margin-bottom: 1em;
}
    </style>

http://stackoverflow.com/questions/8228980/reset-css-display-property-to-default-value



2
http://snipplr.com/view/7438/element-specific-css-reset/
http://perishablepress.com/a-killer-collection-of-global-css-reset-styles/
css specific reset
http://weblogs.asp.net/bleroy/archive/2009/04/14/css-isolation-there-has-got-to-be-a-better-way.aspx
how to locally reset css