Skip to content

Instantly share code, notes, and snippets.

@osdrv
osdrv / i18n.js.coffee
Created August 3, 2011 09:39
tiny JS i18n support
window.i18n = (() ->
__def_loc = "en_US"
{
locale: (loc) ->
if loc != undefined
__def_loc = loc
else
__def_loc
, bind: (o) ->
if o.i18ze == undefined
@osdrv
osdrv / processing_json.java
Created December 19, 2011 18:01
Processing + json
import org.json.*;
import simpleML.*;
XMLRequest xmlRequest;
String apiHost = "http://example.com";
void setup() {
HTMLRequest req = new HTMLRequest( this, apiHost + "/data.json" );
req.makeRequest();
}
@osdrv
osdrv / mercator.cpp
Created December 30, 2011 08:38
c++ libcinder mercator coordinates mapper
#include "Mercator.h"
#include "cinder/app/AppBasic.h"
#include "cinder/Vector.h"
using namespace ci;
using namespace std;
/* static method to map latitude and longitude to mercator 2d coords */
Vec2f Mercator::mapLatLon( const Vec2f lat_lon ) {
/* mercator projection center was screen centered */
Vec2f offset = Vec2f( app::getWindowWidth() / 2, app::getWindowHeight() / 2 );
@osdrv
osdrv / mercator_route.cpp
Created December 30, 2011 10:04
c++ mercator projection route approximation
current_point = this->from;
/* just a direction */
this->sign = ( ( this->from.y - this->to.y ) > 0 ) ? -1 : 1;
for ( int j = 0; j < this->steps; ++j ) {
float lon = ( current_point.y + this->sign * this->step_lon ) * M_PI / 180;
float lat = atan( ( tan( this->lat1 ) * sin( this->lon2 - lon ) / sin( this->lon2 - this->lon1 ) ) + ( tan( this->lat2 ) * sin( lon - this->lon1 ) / sin( this->lon2 - this->lon1 ) ) );
Vec2f next_point = Vec2f( lat * 180 / M_PI, lon * 180 / M_PI );
/* draw line */
current_point = next_point;
@osdrv
osdrv / mercator_if_pacific.cpp
Created December 30, 2011 10:12
mercator pacific-placed route condition
if ( ( ( this->lon_range ) > ( 360 - this->lon_range ) ) && ( this->from.y * this->to.y < 0 ) ) {
/* ... */
}
@osdrv
osdrv / mercator_if_pacific_changes.cpp
Created December 30, 2011 10:20
mercator pacific-placed route maping transformation
Vec2f next_point = Vec2f( lat * 180 / M_PI, lon * 180 / M_PI );
Vec2f tmp_next_point = next_point;
if ( this->via_pacific ) {
if ( next_point.y * current_point.y < 0 ) {
this->shape.moveTo( Mercator::mapLatLon( Vec2f( next_point.x, ( next_point.y > 0 ) ? ( next_point.y - 180 ) : ( next_point.y + 180 ) ) ) );
}
tmp_next_point = Vec2f( next_point.x, ( next_point.y > 0 ) ? ( next_point.y - 180 ) : ( next_point.y + 180 ) );
}
@osdrv
osdrv / http_request_initializing.java
Created January 4, 2012 21:50
just a processing app part
/* this == current PApplet instance */
HTMLRequest req1 = new HTMLRequest(this,"http://url1.com/req1");
HTMLRequest req2 = new HTMLRequest(this,"http://url2.com/req2");
@osdrv
osdrv / HTTPLoader.java
Created January 4, 2012 22:00
simple Java http loader with labmda-handlers
import java.net.*;
import java.io.*;
interface LambdaHandler {
public void success( String response );
}
class XMLLoader implements Runnable {
LambdaHandler handler;
@osdrv
osdrv / my_class.java
Created January 4, 2012 22:02
async http request handler with lambda handler
class MyClass {
void loadData() {
String data_url = "http://4pcbr.com";
HTTPLoader loader = new HTTPLoader();
try {
loader.load( data_url, new LambdaHandler() {
public void success( String res ) {
handleResponse( res );
}
} );
@osdrv
osdrv / DocumentObjectSketch.pde
Created January 11, 2012 13:10
processing document object model
import processing.opengl.*;
import document_object.*;
Window window;
void setup() {
this.window = new Window( this, 640, 480, OPENGL );
background( 0 );
MyDocumentObject o = new MyDocumentObject( this );
window.appendChild( o );