Saturday, October 13, 2012
ImageMagick: Save for web (JPG)
convert input.jpg -profile AdobeRGB1998.icc -colorspace sRGB -auto-orient output.jpg
Notice that in above input.jpg need not to be jpg, it can be BMP/PNG... any format that imagemagick reads, it's perfect way to convert anything user uploads to the JPG.
I got a gaping wound as group of users had managed to upload bunch of JPG images with CMYK profiles! As a programmer it would be far easier if there were command like convertweb or something that would just converted any image to PNG or JPG that just works in browsers.
Friday, June 22, 2012
Scala cast if possible when getting from Map
object MyAsDefaultTest extends App {
implicit def anyDefaultVal(theoption : Option[Any]) = { new { def asDefault[A](default: A) : A = try { default.getClass.cast(theoption.getOrElse(default)) } catch { case _ => default } } }
override def main(args: Array[String]) { val numbers = Map(1 -> 123, 2 -> 321.123, 3 -> "fail")
println(numbers.get(1).asDefault(-1) * 3) // Returns 123 println(numbers.get(2).asDefault(-1) * 3) // Returns -3 println(numbers.get(3).asDefault(-1) * 3) // Returns -3 println(numbers.get(999).asDefault(-1) * 3) // Returns -3
println(numbers.get(3).asDefault("") + "test") // Returns "failtest" println(numbers.get(2).asDefault(0.0) + 100) // Returns 421.123 }}Friday, January 13, 2012
iPad & iPhone targetting
/* iPad [portrait + landscape] */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
.selector-01 { margin: 10px; }
.selector-02 { margin: 10px; }
.selector-03 { margin: 10px; }
}
/* iPhone [portrait + landscape] */
@media only screen and (max-device-width: 480px) {
.selector-01 { margin: 10px; }
.selector-02 { margin: 10px; }
.selector-03 { margin: 10px; }
}
/* == iPad/iPhone [portrait + landscape] == */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px),
@media only screen and (max-device-width: 480px) {
.selector-01 { margin: 10px; }
.selector-02 { margin: 10px; }
.selector-03 { margin: 10px; }
}
Stolen from PreishablepressFriday, October 21, 2011
Sticky Footer & Variable Height - modern CSS
-- paste --Step 3: All we have to do now is to put our CSS and HTML code together. Fortunately we can use the
bodyelement as .Frame, so there is no need for an extradivtag or so.<!DOCTYPE HTML> <html> <head> <style type="text/css"> html, body { height: 100%; margin: 0pt; } .Frame { display: table; height: 100%; width: 100%; } .Row { display: table-row; } .Row.Expand { height: 100%; } </style> </head> <body class="Frame"> <header class="Row"><h1>Catchy header</h1></header> <section class="Row Expand"><h2>Awesome content</h2></section> <footer class="Row"><h3>Sticky footer</h3></footer> </body> </html>Note: Remember to include the html5shiv workaround in your page (and define appropriate CSS styles) if you want to use HTML5 tags in IE8 and below. Or simply use
divtags instead ofheader,sectionandfooter.A word on older browsers
The code above will work even with older versions of Firefox, Opera and Safari, so there is nothing to worry about here, but unfortunately Internet Explorer 7 and below don’t know anything about
display:tableordisplay:table-row, so we go the way of graceful degradation here.The first thing we have to to is, to prevent the margins of elements inside the row from being outside of it, by adding
overflow:hiddento the.Rowstyle.That gives us quite acceptable results, but the footer will always be outside of the window due to the 100% height of the
.Frameand the.Row. The solution is to setheight:100%in a way that all Internet Explorer versions below 8 won’t recognize. I’m using the (valid)html>/**/bodyCSS hack to accomplish this, but you might also use conditional comments if you feel better that way. However, here is the fixed CSS:.Frame { display: table; width: 100%; } html>/**/body .Frame { height: 100%; } .Row { display: table-row; overflow: hidden; } html>/**/body .Row.Expand { height: 100%; }I guess it shouldn’t be too complicated to create a sticky footer by adjusting the height of
.Row.Expandwith some little Javascript.
Tuesday, September 27, 2011
WP: Turn Off Comments / Ping Backs by Default from Pages
Themes functions.php or yourplugin.php:
// This is valid hack as long as "wp-admin/includes/post.php" // `get_default_post_to_edit()` keeps calling `apply_filter()` for // `default_content` *after* `comment_status` and `ping_status` setting.
function my_disable_pages_default_commenting($content, $post) {
if ($post->post_type == 'page') {
$post->comment_status = "closed";
$post->ping_status = "closed";
}
return $content;
}
add_filter('default_content', 'my_disable_pages_default_commenting', 1, 2);
Snippet above turns off the check boxes only from New Pages, any existing pages must be unchecked manually.
Friday, September 23, 2011
Duplicate All Pages (in-place) in Acrobat X
First elevate privileges of the JavaScript programs:
- Right click on document, and choose "Page Display Preferences"
- Choose "JavaScript" from the left.
- Check the "Enable menu items JavaScript execution privileges".
%appdata%\Adobe\Acrobat\10.0\JavaScripts folder:app.addMenuItem({
cExec: "duplicatePagesInPlace();",
cParent: "Edit",
cName: "Duplicate all pages (in-place)"
});
function duplicatePagesInPlace() {
var doc = this,
pages = this.numPages;
for (var i = pages - 1; i >= 0; i--) {
doc.insertPages({
cPath: doc.path,
nStart : i,
nEnd : i,
nPage : i
});
}
}
Now you should be able to access the "Duplicate all pages (in-place)" under "Edit" menu item. If you can't see the item remember to restart Acrobat.
Saturday, July 30, 2011
Windows 7 - Photo Viewer was really slow
- Go to Color management (Desktop -> Screen Resolution -> Advanced Settings -> Color Management -> Color Management -> Advanced (tab) -> Change System Defaults)
- Remove all profiles from all screens, and add single profile per display. (I chose sRGB virtual device mode profile.)
- Check the colors in Photo Viewer if the colors are fine then you chose good profile.
That did the trick.