Skip to content

Instantly share code, notes, and snippets.

View ajokela's full-sized avatar

A.C. Jokela ajokela

View GitHub Profile
@ajokela
ajokela / imgscalr.rb
Created October 7, 2011 19:40 — forked from mchung/imgscalr.rb
imgscalr in jruby
require "imgscalr-lib" # https://github.com/thebuzzmedia/imgscalr
require "jruby"
java_import "javax.imageio.ImageIO"
ImageIO.write(
com.thebuzzmedia.imgscalr.Scalr.resize(
ImageIO.read(java.io.File.new("iss.jpg")),
250),
"jpg",
java.io.File.new("iss_new.jpg"))
@ajokela
ajokela / jruby_color_convertop.rb
Created October 10, 2011 14:03
Java ColorConvertOp in JRuby
case @data
when "GrayScale"
colorSpace = CS.getInstance(CS::CS_GRAY)
op = java.awt.image.ColorConvertOp.new(colorSpace, nil)
when "Negative"
lut = Array.new
for j in 0..255
lut[j] = 256-j
end
jlut = lut.to_java :byte
@ajokela
ajokela / apache_poi.java
Created October 11, 2011 20:53
Apache POI (Excel in Java) - Span Multiple Columns with Cell
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
@ajokela
ajokela / gist:1285103
Created October 13, 2011 18:46
UTM to Geog, Geog to UTM
<html>
<head>
<title>Convert Between Geographic and UTM Coordinates</title>
<script type="text/JavaScript" src="../jsDraw2D.js"></script>
<link rel="stylesheet" type="text/css" href="../main0.css">
<script language=javascript>
function Declarations(){
//Symbols as used in USGS PP 1395: Map Projections - A Working Manual
@ajokela
ajokela / gist:1287052
Created October 14, 2011 13:13
Ruby Time String Formatting
Format meaning:
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
@ajokela
ajokela / gist:1288322
Created October 14, 2011 21:00
Longitude and Latitude - Distance between points
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
@ajokela
ajokela / gist:1288325
Created October 14, 2011 21:00
Is Point within Polygon
GeoHelper.IsInPolygon=function(points,latlong)
{
// This code adapted from the following URL:
// http://msdn.microsoft.com/en-us/library/cc451895.aspx
var i;
var j=points.length-1;
var inPoly=false;
var lat = latlong.Latitude;
var lon = latlong.Longitude;
for (i=0; i<points.length; i++)
@ajokela
ajokela / distance.rb
Created October 16, 2011 20:53
Ruby/Rails - Distance between latitude/longitude points
GeoName.find_by_sql("SELECT ordered.* FROM (SELECT gn.*, round(distance.d * 6371.0, 2) AS distance_km, round(distance.d * 6371.0 * 0.621371192, 2) as distance_miles FROM
(SELECT (2*atan2(sqrt(calcs.a), sqrt(1-calcs.a)))::numeric d, calcs.id FROM
(SELECT (sin(consts.dlat/2) * sin(consts.dlat/2) + sin(consts.dlon/2) * sin(consts.dlon/2) * cos(consts.lat1) * cos(consts.lat2)) as a, consts.id FROM
(SELECT f.id, abs((#{self.exif_data.latitude} - f.latitude)*(#{Math::PI}/180)) AS dlat,
abs((#{self.exif_data.longitude} - f.longitude)*(#{Math::PI}/180)) AS dlon,
#{self.exif_data.latitude} * (#{Math::PI}/180) as lat1,
f.latitude * (#{Math::PI}/180) as lat2 FROM geo_names f) consts) calcs) distance,
geo_names gn WHERE gn.id = distance.id ORDER BY distance.d ASC LIMIT 10) ordered ORDER BY random() LIMIT 1")
@ajokela
ajokela / Decrypt.java
Created October 19, 2011 13:54
Recover SQLDeveloper Passwords
/**
Via: Stack Overflow
Originally from:
http://stackoverflow.com/questions/1032721/does-anybody-know-what-encrypting-technique-is-jdeveloper-sql-developer-using-to
Developed by: Adam Paynter (http://stackoverflow.com/users/41619/adam-paynter)
*/
import javax.crypto.*;
@ajokela
ajokela / gist:1309402
Created October 24, 2011 16:12
Rhino - ORM + HBase
https://github.com/sqs/rhino/