Mental Jetsam

By Peter Finch

.Net Core 2.0 Command Line Configuration

Posted by pcfinch on November 24, 2017

To configure a .Net Core 2.0 MVC application from the command line you need to add the following “UseConfiguration()” line to the “BuildWebHost()” function. You can then configure the app using the command line option.

public class Program
{
  public static void Main(string[] args) {
    BuildWebHost(args).Run();
  }
  public static IWebHost BuildWebHost(string[] args) => WebHost
    .CreateDefaultBuilder(args)
    .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build())
    .UseStartup()
    .Build();
  }
}
Some example command line options are :

--server.urls http://*:80
--urls http://localhost:500;http://localhost:501

References

Advertisements

Posted in .Net Core 2.0, Uncategorized | Leave a Comment »

Changing Google cardboard IPD ( interpupillary distance)

Posted by pcfinch on June 17, 2015

I recently received a Google Cardboard viewer from Dodocase. It was fun to put together and worked really well with my Samsung S3 (even though the phone is a bit “dated” these days). However,  in some of the cardboard demos I was “seeing double” and I think this was due to the default setup of the viewer and my interpupillary distance (which is slightly different for everyone). There is no way to customize it on phone without having a QR code, but there was no QR code on the case.

I found that you can customize the cardboard viewer by generating you own QR code using the following link.

https://www.google.com/get/cardboard/viewerprofilegenerator/

I originally used the measurements that matched my case, but I found I had a “play” with the values a little to get them to work, but after a few tries it worked great! I found that using a “Inter-lens distance (mm)” or 55mm a little less that the actually measurement of 60mm and a “Tray to lens-center distance (mm)” of 35mm (1/2 my phone height width) worked well.

Good luck and I hope it works for your!

Posted in Google Cardboard | Leave a Comment »

Simple HTML5 Drag, Drop and upload JQuery plugin

Posted by pcfinch on January 21, 2013

The following code is based on an excellect description of working with HTML5’s ability to handle drag and drop and auto upload items to a server, found at HTML5 Drag and Drop Upload and File API Tutorial. The code below implements this as a very simple JQuery plugin and current this only works on Chrome and Firefox.

(function ($) {
    $.fn.html5Upload = function (options) {
        var settings = $.extend({
            'start': function () { },
            'preview': function () { },
            'url': null,
            'data': 'data',
            'filename': 'filename'
        }, options);
        this.each(function () {
            function noopHandler(evt) {
                evt.stopPropagation();
                evt.preventDefault();
            };
            $(this).bind("dragenter", noopHandler);
            $(this).bind("dragexit", noopHandler);
            $(this).bind("dragover", noopHandler);
            $(this).bind("drop", function (devt) {
                noopHandler(devt);
                var files = devt.originalEvent.dataTransfer.files;
                if (settings.start) settings.start();
                $.each(files, function (index, file) {
                    var reader = new FileReader();
                    reader.onload = function (revt) {
                        var data64 = revt.target.result;
                        if (settings.preview) settings.preview(file, data64);
                        if (settings.url && settings.filename && settings.data) {
                            var postdata = {} ;
                            postdata[settings.filename] = file.name ;
                            postdata[settings.data] = data64 ;
                            $.ajax({
                                url : settings.url,
                                type : "POST",
                                data : postdata
                            }) ; 
                        }
                    };
                    reader.readAsDataURL(file);
                });
            });
        });
    }
})(jQuery);

You can use the following javascript to start the plugin. The “upload.aspx” script will be called and the filename and data will be passed to it in the “filename” and “data” post parameters.

$(document).ready(function () {
    $("#dropbox").html5Upload({
        start: function() {
            $("#preview").empty() ;
        },
        preview: function (file, data64) {
            $("#preview").append($("<img>").attr("src", data64));
        },
        url : "upload.ashx"
    });
});

Some example HTML, just for good measure…

<div id="dropbox">
<span id="droplabel">Drop file here...</span>
</div>
<div id="preview" ></div>

Posted in Uncategorized | Leave a Comment »

Android JSON WebService Example

Posted by pcfinch on September 27, 2012

The following code, for the Android OS, will make a HTTP request to a JSON webservice at “url” and convert the response into a JSONObject.

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(url) ;
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpClient.execute(request, responseHandler);
JSONObject jsonResponse = new JSONObject(responseBody) ;

Posted in Programming | Leave a Comment »