Youtube embed video html code without branding and controls (seekbar, play/pause and volume)

Youtube embedded player can be adjusted a lot using the parameters available here https://developers.google.com/youtube/player_parameters. Some parameters are available on both HTML5 and flash players and some are not.

Check out https://developers.google.com/youtube/youtube_player_demo, for all availabel configuration and play with it.

For example you can hide the controllers in embedded video, by setting parameter controls to 0

1
2
3
4
<iframe
src="http://www.youtube.com/embed/p09QlQQazo0?controls=0"
width="640" height="360">
</iframe>


Default video quality can be set using vq.
1
2
3
<iframe src="http://www.youtube.com/embed/p09QlQQazo0?vq=hd720" style="border: 5px solid #cccccc; overflow: hidden;" width="640" height="360" frameborder="0"
allowfullscreen></iframe>


Youtube allows you to have its logo to be modest, by setting modestbranding to 1.
1
2
<iframe src="http://www.youtube.com/embed/p09QlQQazo0?modestbranding=1" width="640" height="360" frameborder="0" allowfullscreen></iframe>


We can also set all of these values together
1
2
3
4
<iframe src="http://www.youtube.com/embed/p09QlQQazo0?rel=0&amp;autoplay=0&amp;showinfo=0&amp;modestbranding=1&amp;controls=0&amp;vq=hd720"
style="border: 5px solid #cccccc; overflow: hidden;" width="640" height="360"
frameborder="0" allowfullscreen></iframe>

Get last date of a month

Java Calendar

In Java, we can use the Calendar class to get day_of_month, day_of_week etc.
Last day of a month varies depending on the Month and on leap year we have extra day in February.
So to figure out the last day of any given month in a year, we write some code which is apparently simple.
Calendar object allows us to manipulate days, go forward or backward on the Calendar, add days, hours, minutes or seconds to any given time etc.

We will use these capabilities of Calendar class to get our last_of_month.


The idea here is to get the first day of next month and then reduce one day from it, which gives us the last day of the month relative to input date.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* The trick is to add a month, set the date as 1st and then reduce a date.
*
* @param calendar
*/
private static void setCalendarToLastDayOfMonth(Calendar calendar) {
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, -1);
}

But, Java Calendar has a better way of doing this, by using getActualMaximum() method which is far more convenient.

1
2
3
4
5
6
7
8
private static void setCalendarToLastDayOfMonth(Calendar calendar) {
int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, lastDay);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
}

Sample Util class code

A sample calendar util class which gives you few convenient methods is given below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Copyright (C) 2013 Deepu Mohan Puthrote. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class CalendarUtil {
public static void main(String[] args) throws Exception {
String string = "January 2, 2010";
CalendarUtil calendarUtil = new CalendarUtil();
System.out.println(calendarUtil.getLastDateOfMonth(string));
System.out.println(calendarUtil.getLastDateOfMonth());
}
public Date getLastDateOfMonth() {
return getLastDateOfMonth(new Date());
}
public Date getLastDateOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return getLastDateOfMonth(calendar);
}
public Date getLastDateOfMonth(Calendar calendar) {
setCalendarToLastDayOfMonth(calendar);
return calendar.getTime();
}
public Date getLastDateOfMonth(String date) throws ParseException {
return getLastDateOfMonth(date, "MMMM d, yyyy");
}
public Date getLastDateOfMonth(String date, String format) throws ParseException {
return getLastDateOfMonth(date, format, Locale.US);
}
public Date getLastDateOfMonth(String stringDate, String format, Locale locale) throws ParseException {
Date date = new SimpleDateFormat(format, locale).parse(stringDate);
return getLastDateOfMonth(date);
}
private static void setCalendarToLastDayOfMonth(Calendar calendar) {
int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, lastDay);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
}
}

References

How to change extension of multiple files (bash script)

The following is the script I use in Macbook (Mountain Lion). It should work on most /*nix shell like bash, csh, ksh etc.
However, I have tested it only in bash.

Script to change extension for multiple filesview raw
1
2
3
4
5
##!/usr/bin/env bash
for f in *.$1; do
[[ -f "$f" ]] && mv -v "$f" "${f%$1}$2"
done

Save this file as “chext”, make it executable chmod +x chext and add to your $PATH.

Now you can use it like this:

Usage
1
2
cd path-to-dir
chext oldextension newextension
Example
1
chext JPG jpg

Reference:

JavaMail api - javax.mail.NoSuchProviderException: smtp

Problem

When you are using Java’s mailapi.jar, it also expects supporting libraries like smtp.jar, imap.jar, pop3.jar, gimap.jar, dsn.jar. If you are using Java EE platform, then it is already included. But if you are getting the following error, you might have to include additional libraries, from Java mail API.

1
2
3
4
5
6
7
8
Exception in thread "main" javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:746)
at javax.mail.Session.getTransport(Session.java:685)
at javax.mail.Session.getTransport(Session.java:628)
at javax.mail.Session.getTransport(Session.java:608)
at javax.mail.Session.getTransport(Session.java:663)
at javax.mail.Transport.send0(Transport.java:154)
at javax.mail.Transport.send(Transport.java:80)

There are several forums and discussions happening on this same issue. Surprisingly, this is a small class path issue.

Solution

To solve this error, make sure you have both mailapi.jar and smtp.jar in your classpath. Also, make sure you don’t have duplicate jar files in your class path.

Reading the FAQ on Oracle’s documentation will give you a better idea. http://www.oracle.com/technetwork/java/javamail/faq/index.html

References

Javascript :: Ace Editor Positioning with Bootstrap3

Ace editor is a fantastic option for live source code editor on the web. One problem you come across when using Ace Editor is with the default absolute positioning. Also it doesn’t fit inside a container div by default. Here is how I overcame these issues.

The example from ace website uses absolute positioning by default, as show below. But luckily, ace can work perfectly with relative positioning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html lang="en">
<head>
<title>ACE in Action</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<div id="editor">function foo(items) {
var x = "All this is syntax highlighted";
return x;
}
</div>
<script src="/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
</script>
</body>
</html>

In order to put ace-editor inside a container div, we can give relative positioning to the editor and remove the positioning attribs, like top, right, bottom and left.

1
2
3
#editor {
position: relative;
}

We also need to give height, otherwise editor won’t show up.

1
2
3
4
#editor {
position: relative;
height: 300px;
}

That said, when using Twitter Bootstrap, you can absolutely forget about relative positioning of ace. But we still need to set height, as ace does not fill. In the following jsfiddle, I have used Bootstrap’s panel component for showing the editor.

Full Screen Result is available here. http://jsfiddle.net/deepumohanp/U5JtP/embedded/result/

Fiddle here: http://jsfiddle.net/deepumohanp/U5JtP/

References

  1. How do I make a textarea an ace editor?
  2. Ace doesn’t fit inside a container div

Blog Update :: Bootstrap awesomeness

Yesterday, I spend some to change the blog template using Bootstrap.

Thanks to Blogger’s new template editor. Now it is much easier to understand the templates.

The template was built on top of my older template Simple by Joshua Peterson. The process was simple and straight forward.

Blogger templates are mostly collection of widgets. I introduced few new divs with Bootstrap classes and removed few divs from older template. Bootstrap documentation has everything clearly explained along with examples.

I haven’t tested this new template on all screens yet.