Share some clever hacks , tweaks etc.
For me "the shortest and most effective code" has to be:
*{box-sizing:border-box}
My favorite one, in languages that do support it, is the discovery (it took me such a while) of the ||= operator, used to assign a value only if not already set.
For instance
myVar ||= myDefaultValue;
Which if the same as
myVar = myVar || myDefaultValue;
// OR
if (!myVar) {
myVar = myDefaultValue;
}
(Obviously, this little syntaxic gem is only useful for any variable that isn't supposed to get any falsy value). I'd really like to get this operator in more language (like JS, as many readers here are JS fluent)
A quick sort example with the functional programming way of ES6 Javascript
Array.prototype.quick_sort = function ()
{ if (this.length < 2) { return this; }
var pivot = this[Math.round(this.length / 2)];
return this.filter(x => x < pivot)
.quick_sort()
.concat(this.filter(x => x == pivot))
.concat(this.filter(x => x > pivot).quick_sort());
};
This, no doubts:
<!--[if lt IE 9]>
<div class="alert-box warning">
Update the goddamn browser or go to hell.
</div>
<![endif]-->
I recently discovered a ridiculously miraculous shortcut for horizontally centering an absoluted element that is
.element
{
position:absolute;
margin:0px auto;
left:0px;
right:0px;
}
mostly people use the calculated method of % for centering absolute elements where you have to change calculation depending on the size(width) of the element but this one works generally on all elements of any width ...
A forkbomb
:(){ :|:& };:
Above is the shortest code which has lot of BAD effects. It defines a function named ":" (colon) which just calls itself twice. Thus forking the process into two. This just goes on and on till your system runs out of memory.
For more info, read Fork bomb
style liss (styliss)
web developer
Salman Haider
Eat, Sleep and Breathe Programming
Koko E
Web | Digital Publishing
This simple line of CSS solved a ton of parity-related headaches back in the day: