Skip to content

Instantly share code, notes, and snippets.

Avatar

Ludovic Feltz ludo6577

View GitHub Profile
View Unity3D: AsymmetricFrustum
// This script should be attached to a Camera object
// in Unity. Once a Plane object is specified as the
// "projectionScreen", the script computes a suitable
// view and projection matrix for the camera.
// The code is based on Robert Kooima's publication
// "Generalized Perspective Projection," 2009,
// http://csc.lsu.edu/~kooima/pdfs/gen-perspective.pdf
// Use the following line to apply the script in the editor:
// @script ExecuteInEditMode()
View TestsCalibratePhysicalVrScene.cs
using UnityEngine;
using System.Collections;
public class CalibrationScript : MonoBehaviour
{
public Transform P1; //Physic
public Transform P2; //Physic
public Transform P3; //Physic
public Transform V1; //Virtual
@ludo6577
ludo6577 / RequestFullScreen.js
Last active Aug 29, 2015
FullScreen in Javascript
View RequestFullScreen.js
<script>
/*
* Make the body go full screen.
* see: http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen
*/
function requestFullScreen() {
var element;
var requestMethod;
var isInFullScreen = document.fullScreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msIsFullScreen;
@ludo6577
ludo6577 / CSVExportExtJsGrid.js
Last active Feb 21, 2017
ExtJs grid export to csv javascript
View CSVExportExtJsGrid.js
function exportToCSV(separator, includeHidden) {
var text = "";
//Columns
//var grid = Ext.getCmp("@Model.Id");
var columns = grid.columnManager.columns;
var columnsCount = columns.length;
for (var i = 0; i < columnsCount; i++) {
if (includeHidden || !columns[i].hidden) {
text += columns[i].text + separator;
}
View Global.asax.cs
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
HttpException httpException = exception as HttpException;
// Log the exception.
log.Info(String.Format("Application error: {0}:", exception));
log.Info(exception.StackTrace);
RouteData routeData = new RouteData();
@ludo6577
ludo6577 / HelperMethod.cs
Last active Feb 11, 2016
ASP.NET MVC: Add resources to Layout from View/Partial/HtmlHelper http://stackoverflow.com/a/8559777/2576706
View HelperMethod.cs
public static class Helper
{
public static MvcHtmlString HelperMethod(this HtmlHelper<TModel> htmlHelper)
{
htmlHelper.Resource("<link rel='stylesheet' href='/Content/bootstrap-multiselect.css' type='text/css'/>", "css");
htmlHelper.Resource("<script type='text/javascript' src='/Scripts/bootstrap-multiselect.js'></script>", "js");
//...
}
}
View Utf16 to Utf8 .js
//Simple way:
var utf8 = unescape(encodeURIComponent(utf16_str));
//Or (http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array):
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
View Base64 encode decode .js
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/javascript-base64.html
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
@ludo6577
ludo6577 / Javascript tricks .js
Created Dec 16, 2014
Tricks: Disable F5, resizing, scrollbars
View Javascript tricks .js
//Disable F5
$(document).on("keydown", function disableF5(e) {
if ((e.which || e.keyCode) == 116) e.preventDefault();
});
//Disable resizing
var size = [window.outerWidth, window.outerHeight];
$(window).resize(function () {
window.resizeTo(size[0], size[1]);
});
View Client (server close stream).cs
public void test(){
//var request = System.Net.HttpWebRequest.CreateHttp("http://localhost:8081/index/");
var request = System.Net.HttpWebRequest.Create("http://localhost:8081/index/");
request.Method = "POST";
string filename = "foo\u00A0bar.dat"; // Invalid characters in filename, the server will refuse it
request.Headers["Content-Disposition"] = string.Format("attachment; filename*=utf-8''{0}", Uri.EscapeDataString(filename));
request.ContentType = "application/octet-stream";
request.ContentLength = 100 * 1024 * 1024;
// Upload the "file" (just random data in this case)
You can’t perform that action at this time.