Thursday, May 24, 2012
Five Fridays in July every 823 years == false
package pkg5fridaysinjuly;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Main {
private static final int NUMBER_OF_YEARS = 823;
public static void main(String[] args) {
Calendar c = new GregorianCalendar();
int firstYear = c.get(Calendar.YEAR);
int lastYear = firstYear - NUMBER_OF_YEARS;
c.set(firstYear, Calendar.JULY, 1);
System.out.println("Initial: " + firstYear);
System.out.println("Last: " + lastYear);
for (int y = firstYear; y >= lastYear; y--) {
c.set(y, Calendar.JULY, 1);
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
System.out.println(y + " Found!");
}
}
}
}
Wednesday, April 25, 2012
Configuring Logging in Glassfish
Calls to System.out.println are logged at the INFO level using the logger name javax.enterprise.system.stream.out. Calls to System.err.println are logged at the WARNING level using the logger name javax.enterprise.system.stream.err. To turn off the logs from these sources, specify the logger name with the value OFF in the Additional Properties area.
Friday, April 20, 2012
The World's Greatest Solvable Problem
The price tag for solving hunger is also less than you may realise:
- US $10: the costs to feed a boy in a Kenya refugee camp for 3 weeks, less than the cost of a lipstick bought in Manhattan
- US $50: the cost to feed a schoolgirl for one year, roughly the same price for an iPod shuffle
Taken from freerice.com site.
Monday, April 16, 2012
We Animals pictures
Stray dog in Santiago, Chile. I visited this market several times and the dog was always in the same place, lying in his box. 2005.Taken from: http://www.weanimals.org/photographs.php
Tuesday, March 27, 2012
What Week Day Is That Date in the Past?
A solution for: http://www.linuxjournal.com/content/work-shell-what-day-date-past
No AWK involved.
#!/bin/bash
# We need 3 arguments:
# DOW, Month and Day
if [ $# -ne 3 ]
then
echo "Usage: $(basename $0) weekday month day"
echo "(example: $(basename $0) 4 3 2)"
exit 1
fi
# We use the date command for checking
date -d "$2/$3" &> /dev/null
if [ "$?" == "1" ]
then
echo "$(basename $0) Error: Invalid date!"
exit 1
fi
# Month as number
M=$(date -d "$2/$3" +%m)
# The day of the month
D=$(date -d "$2/$3" +%e | sed 's/ //')
WD=$1
# The day of year is gonna help us decide which is
# the first year to test: current year or the previous one
DOY=$(date -d "$2/$3" +%j)
CDOY=$(date +%j)
Y=$(date +%Y)
if [ ${DOY} -gt ${CDOY} ]
then
Y=$(expr ${Y} - 1)
fi
echo $M $D $WD $DOY $CDOY $Y
F=''
until [ -n "${F}" ]
do
echo -n $Y $M =
# The calendar for the month and year
# Extract the line with the day of the month
# Add numbers to the lines, the number will be
# used to identify the Day of the Week
# Extract the line of the particular day
# gotta be careful cause 6 1 is the sixth line day 1
# and 1 6 is the first line day 6, so we search by the second number
# Convert the multiple spaces in front of the numbers into one space
# so the cut command always return the second field
# Extract the first number only, that's the DOW
CWD=$(cal ${M} ${Y} \
| grep "\b${D}\b" \
| sed 's/[ ][ ][ ]\|[ ][ ]\|[ ]/|/g; s/^|//; s/|/\n/g' \
| cat -n \
| grep "\b${D}\b$" \
| tr -s [:space:] ' ' \
| cut -d ' ' -f 2)
if [ ${WD} -eq ${CWD} ]
then
F=Found
fi
echo $CWD
Y=$(expr ${Y} - 1)
done
##END##
No AWK involved.
#!/bin/bash
# We need 3 arguments:
# DOW, Month and Day
if [ $# -ne 3 ]
then
echo "Usage: $(basename $0) weekday month day"
echo "(example: $(basename $0) 4 3 2)"
exit 1
fi
# We use the date command for checking
date -d "$2/$3" &> /dev/null
if [ "$?" == "1" ]
then
echo "$(basename $0) Error: Invalid date!"
exit 1
fi
# Month as number
M=$(date -d "$2/$3" +%m)
# The day of the month
D=$(date -d "$2/$3" +%e | sed 's/ //')
WD=$1
# The day of year is gonna help us decide which is
# the first year to test: current year or the previous one
DOY=$(date -d "$2/$3" +%j)
CDOY=$(date +%j)
Y=$(date +%Y)
if [ ${DOY} -gt ${CDOY} ]
then
Y=$(expr ${Y} - 1)
fi
echo $M $D $WD $DOY $CDOY $Y
F=''
until [ -n "${F}" ]
do
echo -n $Y $M =
# The calendar for the month and year
# Extract the line with the day of the month
# Add numbers to the lines, the number will be
# used to identify the Day of the Week
# Extract the line of the particular day
# gotta be careful cause 6 1 is the sixth line day 1
# and 1 6 is the first line day 6, so we search by the second number
# Convert the multiple spaces in front of the numbers into one space
# so the cut command always return the second field
# Extract the first number only, that's the DOW
CWD=$(cal ${M} ${Y} \
| grep "\b${D}\b" \
| sed 's/[ ][ ][ ]\|[ ][ ]\|[ ]/|/g; s/^|//; s/|/\n/g' \
| cat -n \
| grep "\b${D}\b$" \
| tr -s [:space:] ' ' \
| cut -d ' ' -f 2)
if [ ${WD} -eq ${CWD} ]
then
F=Found
fi
echo $CWD
Y=$(expr ${Y} - 1)
done
##END##
The output of searching the first date in the past when March 1 was Wednesday:
janeiros@harlie:~/tmp$ ./t.sh 4 3 1
03 1 4 061 087 2012
2012 03 =5
2011 03 =3
2010 03 =2
2009 03 =1
2008 03 =7
2007 03 =5
2006 03 =4
janeiros@harlie:~/tmp$ cal 3 2006
March 2006
Su Mo Tu We Th Fr Sa
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
Day of the Week in GAWK
gawk '
BEGIN {
for (d = 1; d <= 31; d++) {
t = mktime("2008 08 " d " 0 0 0")
print d, strftime("%A", t)
}
}'
The output is:
1 Friday
2 Saturday
3 Sunday
4 Monday
5 Tuesday
6 Wednesday
7 Thursday
8 Friday
9 Saturday
10 Sunday
11 Monday
12 Tuesday
13 Wednesday
14 Thursday
15 Friday
16 Saturday
17 Sunday
18 Monday
19 Tuesday
20 Wednesday
21 Thursday
22 Friday
23 Saturday
24 Sunday
25 Monday
26 Tuesday
27 Wednesday
28 Thursday
29 Friday
30 Saturday
31 Sunday
BEGIN {
for (d = 1; d <= 31; d++) {
t = mktime("2008 08 " d " 0 0 0")
print d, strftime("%A", t)
}
}'
The output is:
1 Friday
2 Saturday
3 Sunday
4 Monday
5 Tuesday
6 Wednesday
7 Thursday
8 Friday
9 Saturday
10 Sunday
11 Monday
12 Tuesday
13 Wednesday
14 Thursday
15 Friday
16 Saturday
17 Sunday
18 Monday
19 Tuesday
20 Wednesday
21 Thursday
22 Friday
23 Saturday
24 Sunday
25 Monday
26 Tuesday
27 Wednesday
28 Thursday
29 Friday
30 Saturday
31 Sunday
Compare to:
$ cal 8 2008
August 2008
Su Mo Tu We Th Fr Sa
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
Subscribe to:
Posts (Atom)