Archive for January, 2009
Licensing Your Code the Ruby Way
Do you have an existing project you want to open-source? Does the thought of manually adding the license comment block to EVERY. SINGLE. SOURCE. FILE. sound not-so-exciting? Here’s some help, ruby style:
class Licenser
def licenseFiles(dir)
filenames = Dir[dir.chop + "**/*.java"]
for filename in filenames do
contents = ''
File.open(filename, 'r') { |file| contents = file.read }
contents = HEADER + contents
File.open(filename, 'w') { |file| file.write(contents) }
end
end
end
HEADER = <<HEAD
/*
* Copyright 2008-2009 Mike Reedell / LuckyCatLabs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
HEAD
Licenser.new.licenseFiles(ARGV[0])
This script was inspired by the the check_license_headers.rb script in the Apache SVN repo. Couldn’t get it to work on my setup, so I rewrote the parts I needed.
This can be found in the LuckyCat Labs GitHub scripts project. Look for updates to handle more source types and to check for existing license headers.
View CommentsRelease: Sunrise/Sunset Java Library
New from LuckyCat Labs is a Java library that computes the sunrise / sunset using GPS coordinates and today’s date. To use, simply download the tar or zip file from the GitHub page, or use git to pull the source:
$ git clone git://github.com/mikereedell/sunrisesunsetlib-java
Once you have the source, use the command:
$ ant all
To compile the source, build the bin, src, and test jars, execute the unit tests and generate the JavaDoc for the library.
This code snippet illustrates the main usage pattern:
// Location of sunrise/set, as latitude/longitude.
Location location = new Location("39.9937", "-75.7850");
// Create calculator object with the location and time zone identifier.
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "America/New_York");
Calendar date = Calendar.getInstance();
String dawn = calculator.getCivilSunriseForDate(date);
String dusk = calculator.getCivilSunsetForDate(date);
The list of supported time zone identifiers is given by:
//Returns String[] of supported tz identifiers. TimeZone.getAvailableIDs();
Any feedback? Comments? Features? Bugs? Comment below or add to the project wiki.
Released under the Apache License 2.0.
View Comments