Entwicklung - Unity3D - Web

Online-Gedächtnis - Stichpunkte zur Erinnerungshilfe

NAVIGATION - SEARCH

Linux Backup Rotation

  1. Ordnerstruktur anlegen
    drwxr-xr-x 15 root root 4096 Apr 23 06:44 backup.daily
    drwxr-xr-x  4 root root 4096 Apr  1 06:29 backup.monthly
    -rwxr-x---  1 root root 1386 Feb 21 11:53 backup.sh
    drwxr-xr-x 10 root root 4096 Apr 20 06:38 backup.weekly
    drwxr-xr-x  2 root root 4096 Apr 23 06:44 incoming
     
  2. Rotationsskript
    #!/bin/bash
    # Julius Zaromskis
    # Backup rotation
    
    # Storage folder where to move backup files
    # Must contain backup.monthly backup.weekly backup.daily folders
    storage=/home/backups/your_website_name
    
    # Source folder where files are backed
    source=$storage/incoming
    
    # Destination file names
    date_daily=`date +"%d-%m-%Y"`
    #date_weekly=`date +"%V sav. %m-%Y"`
    #date_monthly=`date +"%m-%Y"`
    
    # Get current month and week day number
    month_day=`date +"%d"`
    week_day=`date +"%u"`
    
    # Optional check if source files exist. Email if failed.
    if [ ! -f $source/archive.tgz ]; then
    ls -l $source/ | mail [email protected] -s "[backup script] Daily backup failed! Please check for missing files."
    fi
    
    # It is logical to run this script daily. We take files from source folder and move them to
    # appropriate destination folder
    
    # On first month day do
    if [ "$month_day" -eq 1 ] ; then
      destination=backup.monthly/$date_daily
    else
      # On saturdays do
      if [ "$week_day" -eq 6 ] ; then
        destination=backup.weekly/$date_daily
      else
        # On any regular day do
        destination=backup.daily/$date_daily
      fi
    fi
    
    # Move the files
    mkdir $destination
    mv -v $source/* $destination
    
    # daily - keep for 14 days
    find $storage/backup.daily/ -maxdepth 1 -mtime +14 -type d -exec rm -rv {} \;
    
    # weekly - keep for 60 days
    find $storage/backup.weekly/ -maxdepth 1 -mtime +60 -type d -exec rm -rv {} \;
    
    # monthly - keep for 300 days
    find $storage/backup.monthly/ -maxdepth 1 -mtime +300 -type d -exec rm -rv {} \;


  3. Durch cronjob anstoßen
    #!/bin/bash
    #@author Julius Zaromskis
    #@description Backup script for your website
    
    BACKUP_DIR=/home/backups/your_website_name
    FILES_DIR=/var/www/your_website_name
    
    # Dump MySQL tables
    mysqldump -h 127.0.0.1 -u admin -pyourpassword database > $BACKUP_DIR/incoming/mysql_dump.sql
    
    # Compress tables and files
    tar -cvzf $BACKUP_DIR/incoming/archive.tgz $BACKUP_DIR/incoming/mysql_dump.sql $FILES_DIR
    
    # Cleanup
    rm $BACKUP_DIR/incoming/mysql_dump.sql
    
    # Run backup rotate
    cd $BACKUP_DIR
    bash backup.sh


Quelle

Multipart MIME Mail Aufbau

 

// Mail-Header
From: [email protected]
To: [email protected]
Subject: blabla
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="=_abgrenzung1"

// Mail-Body
// Textteil der Mail
–=_abgrenzung1
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

// Hier der kodierte Text der Mail.

// HTML-Teil der Mail
–=_abgrenzung1
Content-Type: multipart/related; boundary=“=_abgrenzung2″

// der eigentliche HTML-Teil
–=_abgrenzung2
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: base64

// Hier der kodierte HTML-Quelltext der Mail.

// ein Bild, das in den HTML-Teil eingebettet wird
–=_abgrenzung2
Content-Type: image/gif; name=“bild.gif“
Content-Transfer-Encoding: base64
Content-ID: bild
Content-Disposition: inline; filename=“bild.gif“

// Hier das base64-kodierte Bild.

–=_abgrenzung2–
–=_abgrenzung1–



Quelle

Android-Anwendung mit Visual Studio debuggen

You can attach the MonoDevelop debugger to an Android device with ADB via TCP/IP. The process is described below.

  • Enable “USB debugging” on your device and connect the device to your development machine via USB cable. Ensure your device is on the same subnet mask and gateway as your development machine. Also, make sure there are no other active network connections on the device, i.e. disable data access over mobile/cellular network.

  • On your development machine, open up your terminal/cmd and navigate to the location of the ADB. You can find the ADB tool in <sdk>/platform-tools/

  • Restart host ADB in TCP/IP mode with the following command:

adb tcpip 5555

This will have enabled ADB over TCP/IP using port 5555. If port 5555 is unavailable, you should use a different port (see ADB.) The following output should be produced:

restarting in TCP mode port: 5555
  • Find out the IP address of your Android device (Settings -> About -> Status) and input the following command:
adb connect DEVICEIPADDRESS

DEVICEIPADDRESS is the actual IP address of your Android device. This should produce the following output:

connected to DEVICEIPADDRESS:5555
  • Ensure that your device is recognised by inputting the following command:
adb devices

This should produce the following output:

List of devices attached
DEVICEIPADDRESS:5555 device
  • Build and run your Unity application to the device. Ensure you build your application with Development Build flag enabled and Script Debugging turned on.

  • Disconnect the USB cable as the device no longer needs to be connected to your development machine.

  • Finally, while the application is running on your device, open your script in MonoDevelop, add a breakpoint, select “Run” -> “Attach to Process” and select your device from the list. (It might take a few seconds for the device to appear in the list. It may not appear in the list if the application is not running or if the device’s display goes to sleep).

For some more details and for troubleshooting, see the Wireless Usage section in the Android developers guide for the ADB.

Note: The device sends multicast messages and the editor and MonoDevelop subscribe/listen for them. For the process to work, your network will need to be setup correctly for Multicasting. 


Blur - UI - Shader

  • Neuen Shader anlegen - "SimpleGrabPassBlur"
    • Shader "Custom/SimpleGrabPassBlur" {
          Properties {
              _Color ("Main Color", Color) = (1,1,1,1)
              _BumpAmt  ("Distortion", Range (0,128)) = 10
              _MainTex ("Tint Color (RGB)", 2D) = "white" {}
              _BumpMap ("Normalmap", 2D) = "bump" {}
              _Size ("Size", Range(0, 20)) = 1
          }
       
          Category {
       
              // We must be transparent, so other objects are drawn before this one.
              Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque" }
       
       
              SubShader {
           
                  // Horizontal blur
                  GrabPass {                    
                      Tags { "LightMode" = "Always" }
                  }
                  Pass {
                      Tags { "LightMode" = "Always" }
                   
                      CGPROGRAM
                      #pragma vertex vert
                      #pragma fragment frag
                      #pragma fragmentoption ARB_precision_hint_fastest
                      #include "UnityCG.cginc"
                   
                      struct appdata_t {
                          float4 vertex : POSITION;
                          float2 texcoord: TEXCOORD0;
                      };
                   
                      struct v2f {
                          float4 vertex : POSITION;
                          float4 uvgrab : TEXCOORD0;
                      };
                   
                      v2f vert (appdata_t v) {
                          v2f o;
                          o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                          #if UNITY_UV_STARTS_AT_TOP
                          float scale = -1.0;
                          #else
                          float scale = 1.0;
                          #endif
                          o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                          o.uvgrab.zw = o.vertex.zw;
                          return o;
                      }
                   
                      sampler2D _GrabTexture;
                      float4 _GrabTexture_TexelSize;
                      float _Size;
                   
                      half4 frag( v2f i ) : COLOR {
      //                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
      //                  return col;
                       
                          half4 sum = half4(0,0,0,0);
                          #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
                          sum += GRABPIXEL(0.05, -4.0);
                          sum += GRABPIXEL(0.09, -3.0);
                          sum += GRABPIXEL(0.12, -2.0);
                          sum += GRABPIXEL(0.15, -1.0);
                          sum += GRABPIXEL(0.18,  0.0);
                          sum += GRABPIXEL(0.15, +1.0);
                          sum += GRABPIXEL(0.12, +2.0);
                          sum += GRABPIXEL(0.09, +3.0);
                          sum += GRABPIXEL(0.05, +4.0);
                       
                          return sum;
                      }
                      ENDCG
                  }
                  // Vertical blur
                  GrabPass {                        
                      Tags { "LightMode" = "Always" }
                  }
                  Pass {
                      Tags { "LightMode" = "Always" }
                   
                      CGPROGRAM
                      #pragma vertex vert
                      #pragma fragment frag
                      #pragma fragmentoption ARB_precision_hint_fastest
                      #include "UnityCG.cginc"
                   
                      struct appdata_t {
                          float4 vertex : POSITION;
                          float2 texcoord: TEXCOORD0;
                      };
                   
                      struct v2f {
                          float4 vertex : POSITION;
                          float4 uvgrab : TEXCOORD0;
                      };
                   
                      v2f vert (appdata_t v) {
                          v2f o;
                          o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                          #if UNITY_UV_STARTS_AT_TOP
                          float scale = -1.0;
                          #else
                          float scale = 1.0;
                          #endif
                          o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                          o.uvgrab.zw = o.vertex.zw;
                          return o;
                      }
                   
                      sampler2D _GrabTexture;
                      float4 _GrabTexture_TexelSize;
                      float _Size;
                   
                      half4 frag( v2f i ) : COLOR {
      //                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
      //                  return col;
                       
                          half4 sum = half4(0,0,0,0);
                          #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely*_Size, i.uvgrab.z, i.uvgrab.w))) * weight
                          //G(X) = (1/(sqrt(2*PI*deviation*deviation))) * exp(-(x*x / (2*deviation*deviation)))
                       
                          sum += GRABPIXEL(0.05, -4.0);
                          sum += GRABPIXEL(0.09, -3.0);
                          sum += GRABPIXEL(0.12, -2.0);
                          sum += GRABPIXEL(0.15, -1.0);
                          sum += GRABPIXEL(0.18,  0.0);
                          sum += GRABPIXEL(0.15, +1.0);
                          sum += GRABPIXEL(0.12, +2.0);
                          sum += GRABPIXEL(0.09, +3.0);
                          sum += GRABPIXEL(0.05, +4.0);
                       
                          return sum;
                      }
                      ENDCG
                  }
               
                  // Distortion
                  GrabPass {                        
                      Tags { "LightMode" = "Always" }
                  }
                  Pass {
                      Tags { "LightMode" = "Always" }
                   
                      CGPROGRAM
                      #pragma vertex vert
                      #pragma fragment frag
                      #pragma fragmentoption ARB_precision_hint_fastest
                      #include "UnityCG.cginc"
                   
                      struct appdata_t {
                          float4 vertex : POSITION;
                          float2 texcoord: TEXCOORD0;
                      };
                   
                      struct v2f {
                          float4 vertex : POSITION;
                          float4 uvgrab : TEXCOORD0;
                          float2 uvbump : TEXCOORD1;
                          float2 uvmain : TEXCOORD2;
                      };
                   
                      float _BumpAmt;
                      float4 _BumpMap_ST;
                      float4 _MainTex_ST;
                   
                      v2f vert (appdata_t v) {
                          v2f o;
                          o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                          #if UNITY_UV_STARTS_AT_TOP
                          float scale = -1.0;
                          #else
                          float scale = 1.0;
                          #endif
                          o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                          o.uvgrab.zw = o.vertex.zw;
                          o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
                          o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
                          return o;
                      }
                   
                      fixed4 _Color;
                      sampler2D _GrabTexture;
                      float4 _GrabTexture_TexelSize;
                      sampler2D _BumpMap;
                      sampler2D _MainTex;
                   
                      half4 frag( v2f i ) : COLOR {
                          // calculate perturbed coordinates
                          half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg; // we could optimize this by just reading the x  y without reconstructing the Z
                          float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
                          i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
                       
                          half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
                          half4 tint = tex2D( _MainTex, i.uvmain ) * _Color;
                       
                          return col * tint;
                      }
                      ENDCG
                  }
              }
          }
      }
  • Material anlegen
  • Shader zuweisen
  • UI Element (z.B. Panel) dieses Material zuweisen
  • Via Imagezweisung Helligkeit einstellen (weiß = transparent)

Razor functions und helpers

Helper ermöglichen die Verwendung und Rückgabe von direktem HTML:
@helper OrderedList(IEnumerable<string> items){
    <ol>
        @foreach(var item in items){
            <li>@item</li>
        }
    </ol>
}
@OrderedList(new[] { "Blue", "Red", "Green" })

Bei functions kann man kein HTML verwenden:
@using System.Web.Mvc;
@using System.Text;
@functions {
    
    public static HtmlString OrderedList(IEnumerable<string> items)
    {
        var sb = new StringBuilder();
        var orderedList = new TagBuilder("ol");
        foreach(var item in items){
            var listItem = new TagBuilder("li");
            listItem.SetInnerText(item);
            sb.AppendLine(listItem.ToString(TagRenderMode.Normal));
        }
        orderedList.InnerHtml = sb.ToString();
        return new HtmlString(orderedList.ToString(TagRenderMode.Normal));
    }
}
@OrderedList(new[] { "Blue", "Red", "Green" })

Quelle

Zen Coding und weitere HTML-Hilfen

In VisualStudio, HTML-Editor:
div#head>nav.menu>ul>li#item$$*10
und Tab, erzeugt komplettes HTML-Gerüst.

div.container>(header>nav)+(div.row>div.col-md-4*3)


Alt+1 hinter einem HTML-Element markiert weitere Ebenen, kann wiederholt gedrückt werden.

Anschließend Shift+Alt+W erzeugt Wrapper-HTML-Element.