Same Specificity, After Taking Placement into Consideration,: First-Letter Always Wins

CSS Precedence strange behaviour

I have just looked at your fiddle in Firefox, and you don't have a problem, it is working correctly. The font size of the word is 12px as asked for. But the first-letter pseudo element is all about identifying the first letter as a separate entitiy, and giving it a different style to that used for the rest of the word. As such, the specificity of the first letter is entirely separate from the specificity of the whole word; they do not override each other.
So your first letter in the fiddle is correctly 20px.

User style !important not taking precedence

You are correct that an !important declaration of origin "user" should take precedence over any declaration of origin "author", regardless of importance or specificity. However you are making an assumption that Stylish applies its styles with the "user" origin.

Since Stylish 1.4.1 for Firefox, it will apply styles with "author" origin by default. One reason for this change was compatibility with Stylish for other browsers. Their APIs only allow Stylish to add "author" origin styles, which meant that a style that worked in Firefox didn't work in Chrome. Yours is one example of where this would be the case.

The best way to fix this (and to ensure compatibility with other browsers, should you share your style on userstyles.org), is to increase the specificity of your selector to something greater than that of the site's CSS. The simplest way to do so would be to use the same selector as the site, but add a body type selector at the start:

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("jsfiddle.net") {
body #content iframe {
border: 4px solid red !important;
}
}

There are cases where this isn't feasible: a style that affects iframes on many sites that couldn't be so specific with its selector, or a style trying to override an !important declaration inside an HTML style attribute. Stylish for Firefox allows you to switch your style to the "agent" origin with a special comment: /* AGENT_SHEET */. This will have the effect of your !importants beating anything the site can do (much like the "user" origin), but it will not work in other browsers and can cause bad things like crashes, so this is only suggested if the above method is completely unworkable for you.

All of this is described on Stylish's wiki along with some info less relevant to your situation.

$fclose placement in testbench

$fopen/$fmonitor/$fclose are all procedural statements that must be placed inside procedural code.

When you had $fclose in the initial block, you closed it at time 0 before $fmonitor had a chance to produce any output. $fmonitor writes the state of its arguments at then end of current time slot when any of them change value.

You need to let your simulation run for some period of time and then have it execute a $finish. There is no need to explicitly use $fclose unless you have too many files open at one time, or some other process is blocked waiting for the file output.

Why do I have to put media queries at the bottom of the stylesheet?

Because css is read from top to bottom. The rule that is set last, is the one that will be executed.

Translating, it is like this:

@media (max-width: 600px) { //If my screen fits this size
.text {
color: red; //Paint it red
}
}

.text {
color: yellow; //Now, forget about everything and paint it yellow!
}

When you add !important is like saying:

@media (max-width: 600px) { //If my screen fits this size
.text {
color: red !important; //Paint it red, and don't change it ever!!!
}
}

.text {
color: yellow; //Ok, I'm not going to paint it yellow....
}

garble function contest

UPDATE( LATEST ): Don't think it can get any smaller.. DEMO

Latest compressed (332):

var e=document.body.getElementsByTagName('*'),j,i,l,x,t,b;for(i=0;e[i];i++)for(j=0;b=e[i].childNodes[j];j++)if(b.nodeType==3)b.data=b.data.replace(/\w{4,}/g,function(w){if(/(^.)(\1)+$/.test(x=w.substring(1,l=w.length-1)))return w;t=w;while(t==w)t=w[0]+x.split('').sort(function(){return 0.5-Math.random()}).join('')+w[l];return t}); 

code:

var e = document.body.getElementsByTagName('*'),
j, i, l, x, t, b;
for (i = 0; e[i]; i++)
for (j = 0; b = e[i].childNodes[j]; j++)
if (b.nodeType == 3) b.data = b.data.replace(/\w{4,}/g, function(w) {
if (/(^.)(\1)+$/.test(x = w.substring(1, l = w.length - 1))) return w;
t = w;
while (t == w)
t = w[0] + x.split('').sort(function() {
return 0.5 - Math.random();
}).join('') + w[l];
return t;
});

UPDATE even.. smaller..

Even smaller version
I dont know the minifier your using, but this must be at least (EDIT 108) bytes smaller.

compressed version (365 bytes):

var e=document.body.getElementsByTagName('*'),a=[],c,j,i,l,x,t,b;for(i=0;c=e[i];i++)for(j=0;b=c.childNodes[j];j++)if(b.nodeType==3){b.data=b.data.replace(/\b[a-z0-9]{4,}\b/gi,function(w){if(/(^.)(\1)+$/.test(x=w.substring(1,l=w.length-1)))return w;t=w;while(t==w)t=w[0]+x.split('').sort(function(){return Math.floor(Math.random()*2)?1:-1}).join('')+w[l];return t})}  

Code:

var e = document.body.getElementsByTagName('*'),
a = [],
c, j, i, l, x, t, b;
for (i = 0; c = e[i]; i++)
for (j = 0; b = c.childNodes[j]; j++)
if (b.nodeType == 3) {
b.data = b.data.replace(/\b[a-z0-9]{4,}\b/gi, function(w) {
if (/(^.)(\1)+$/.test(x = w.substring(1, l = w.length - 1))) return w;
t = w;
while (t == w)
t = w[0] + x.split('').sort(function() {
return Math.floor(Math.random() * 2) ? 1 : -1;
}).join('') + w[l];
return t;
});
}

EDIT
NEW RULES DEMO
CODE:

var fn = function(e) {
var ret = [],c;
for (var i = 0; i < e.length; i++) {
c = e[i].childNodes;
for (var j = 0; j < c.length; j++)
if (c[j].nodeType === 3) ret.push(c[j]);
}
return ret;
};
var es = fn(document.body.getElementsByTagName('*'));
for (var i = 0; i < es.length; i++) {
var e = es[i],len,x;
e.data = e.data.replace(/\b[a-z0-9]{4,}\b/gi, function(w) {
if (/(^.)(\1)+$/.test(x = w.substring(1, len = w.length - 1))) return w;
var tmp = w;
while (tmp === w) {
tmp = w[0] + x.split('').sort(function() {
return Math.floor(Math.random() * 2) ? 1 : -1;
}).join('') + w[len];
}
return tmp;
});
}

This should respect all the rules, and keep format and punctuation. DEMO

//select all nodes in document and perform map on it to filter out
//non text node types, then each one of those elements is processed.
$('*').contents().map(function(i, elem) {
if (elem.nodeType !== 3) return null;
else return elem;
}).each(function(i, elem) {
//call strip funciton defined down to get an object, with a word array, and
//charecters which was stripped along with there index in the orginal string
var str1 = '',
tmp = strip(elem.data),
words = tmp.words,
sentence;
// shuffle all words
words = $.map(words, function(x, i) {
return shuffle(x);
});
//construct raw sentence (non alphanumeric charecters)
sentence = words.join('');
//reinsert spaces and punctiouation
$.each(tmp.chars, function(i, elem) {
sentence = sentence.substring(0, elem.index) + elem.char + sentence.substring(elem.index - 1 + elem.char.length);
});
//set the element text
elem.data = sentence;
});

//shuffle funciton takes a word and shuffle the charecters between the last and the firt
function shuffle(txt) {
//if the word is smaller than 4 charecters or it has repeated charecters in
//its middle (i.e. loop, 'oo' cannot be shuffled!) then return it;
if (txt.length < 4 || /(^.)(\1)+$/.test(txt.substring(1, txt.length - 1)))
return txt;
var str = txt.split(''),
ret = [],
rand, x = 0,
tmp = txt;
//while the txt hasn't changed in the first randomization cycle then repeated
while (txt === tmp) {
ret = [];
$.each(str, function(i, c) {
if (i === str.length - 1 || i === 0) {
ret[i] = c;
return;
}
while (true) {
rand = Math.floor(Math.random() * (str.length - 2) + 1);
if (!ret[rand]) {
ret[rand] = c;
break;
}
}
});
tmp = ret.join('');
}
return ret.join('');
}

function strip(txt) {
var punc = /[^A-Za-z0-9]/g,
res, nonAlphaNum = [],
arr;
//punc regex is all non-alphanumeric charecters which will act on the string
//to point out unwanted charecters and store them in an array along with
//their index
while ((res = punc.exec(txt)) != null) {
nonAlphaNum.push({
index: res.index,
char: res[0]
});
}
//split into words
arr = txt.split(/\s/);
//remove punctiuation and other unwanted chars
arr = $.map(arr, function(x, i) {
return x.replace(punc, '');
});
return {
words: arr, //words array
chars: nonAlphaNum //array of stripped charecter objects (chars, index in orginal)
};
}

btw nice choice of the article, WWiWieikikb!!

Switch statement: must default be the last case?

The C99 standard is not explicit about this, but taking all facts together, it is perfectly valid.

A case and default label are equivalent to a goto label. See 6.8.1 Labeled statements. Especially interesting is 6.8.1.4, which enables the already mentioned Duff's Device:

Any statement may be preceded by a
prefix that declares an identifier as
a label name. Labels in themselves do
not alter the flow of control, which
continues unimpeded across them.

Edit: The code within a switch is nothing special; it is a normal block of code as in an if-statement, with additional jump labels. This explains the fall-through behaviour and why break is necessary.

6.8.4.2.7 even gives an example:

switch (expr) 
{
int i = 4;
f(i);
case 0:
i=17;
/*falls through into default code */
default:
printf("%d\n", i);
}

In the artificial program fragment the
object whose identifier is i exists
with automatic storage duration
(within the block) but is never
initialized, and thus if the
controlling expression has a nonzero
value, the call to the printf function
will access an indeterminate value.
Similarly, the call to the function f
cannot be reached.

The case constants must be unique within a switch statement:

6.8.4.2.3 The expression of each case label shall be an integer constant
expression and no two of the case
constant expressions in the same
switch statement shall have the same
value after conversion. There may be
at most one default label in a switch
statement.

All cases are evaluated, then it jumps to the default label, if given:

6.8.4.2.5 The integer promotions are performed on the controlling
expression. The constant expression in
each case label is converted to the
promoted type of the controlling
expression. If a converted value
matches that of the promoted
controlling expression, control jumps
to the statement following the matched
case label. Otherwise, if there is a
default label, control jumps to the
labeled statement. If no converted
case constant expression matches and
there is no default label, no part of
the switch body is executed.

How to modify Levenshteins Edit Distance to count adjacent letter exchanges as 1 edit

You need one more case in the algorithm from Wikipedia:

if s[i] = t[j] then 
d[i, j] := d[i-1, j-1]
else if i > 0 and j > 0 and s[i] = t[j - 1] and s[i - 1] = t[j] then
d[i, j] := minimum
(
d[i-2, j-2] + 1 // transpose
d[i-1, j] + 1, // deletion
d[i, j-1] + 1, // insertion
d[i-1, j-1] + 1 // substitution
)
else
d[i, j] := minimum
(
d[i-1, j] + 1, // deletion
d[i, j-1] + 1, // insertion
d[i-1, j-1] + 1 // substitution
)


Related Topics



Leave a reply



Submit