How to update gradle for Android

To update Android Plugin for Gradle:
You can find the list of available plugin versions in:
Android Studio\gradle\m2repository\com\android\tools\build\gradle\ directory. In my case I have:

  • 1.3.0
  • 1.5.0
  • 2.1.0-alpha3
  • 2.1.0-alpha4

Use the desired version by editing your project build.gradle file.
Example of build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0-alpha4'
}

To update Gradle:
In your project directory navigate to \gradle\wrapper\ directory and edit:
gradle-wrapper.properties file.
Example: To change from version 2.8 to version 2.10
before: distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
after: distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
At the end in Android Studio select: ToolsAndroidSync Project with Gradle files

References
http://stackoverflow.com/questions/17727645/how-to-update-gradle-in-android-studio

Setting Weights And Styles With The @font-face Declaration

 

@font-face {
   font-family: 'UbuntuItalic';
      src: url('Ubuntu-RI-webfont.eot');
      src: url('Ubuntu-RI-webfont.eot?#iefix') format('embedded-opentype'),
           url('Ubuntu-RI-webfont.woff') format('woff'),
           url('Ubuntu-RI-webfont.ttf') format('truetype'),
           url('Ubuntu-RI-webfont.svg#UbuntuItalic') format('svg');
   font-weight: normal;
   font-style: normal;
}

@font-face {
   font-family: 'UbuntuBold';
      src: url('Ubuntu-B-webfont.eot');
      src: url('Ubuntu-B-webfont.eot?#iefix') format('embedded-opentype'),
           url('Ubuntu-B-webfont.woff') format('woff'),
           url('Ubuntu-B-webfont.ttf') format('truetype'),
           url('Ubuntu-B-webfont.svg#UbuntuBold') format('svg');
   font-weight: normal;
   font-style: normal;
}
.u400 {
   font-family: 'UbuntuRegular', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u400i {
   font-family: 'UbuntuRegularItalic', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u700 {
   font-family: 'UbuntuBold', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u700i {
   font-family: 'UbuntuBoldItalic', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

References
https://www.smashingmagazine.com/2013/02/setting-weights-and-styles-at-font-face-declaration/

Getting Started with SignalR 2 and MVC 5

Server
Right-click the Hubs folder, click Add | New Item, select the Visual C# | Web | SignalR node in the Installed pane, select SignalR Hub Class (v2) from the center pane, and create a new hub named ChatHub.cs. You will use this class as a SignalR server hub that sends messages to all clients

using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChat
{
    public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            // Call the addNewMessageToPage method to update clients.
            Clients.All.addNewMessageToPage(name, message);
        }
    }
}

Create a new class called Startup.cs. Change the contents of the file to the following

using Owin;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            app.MapSignalR();
        }
    }
}

Client

<!--Script references. -->
    <!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
    <!--Reference the SignalR library. -->
    <script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="~/signalr/hubs"></script>
    <!--SignalR script to update the chat page and send messages.--> 
    <script>
        $(function () {
            // Reference the auto-generated proxy for the hub.  
            var chat = $.connection.chatHub;
            // Create a function that the hub can call back to display messages.
            chat.client.addNewMessageToPage = function (name, message) {
                // Add the message to the page. 
                $('#discussion').append('<li><strong>' + htmlEncode(name) 
                    + '</strong>: ' + htmlEncode(message) + '</li>');
            };
            // Get the user name and store it to prepend to messages.
            $('#displayname').val(prompt('Enter your name:', ''));
            // Set initial focus to message input box.  
            $('#message').focus();
            // Start the connection.
            $.connection.hub.start().done(function () {
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub. 
                    chat.server.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment. 
                    $('#message').val('').focus();
                });
            });
        });
        // This optional function html-encodes messages for display in the page.
        function htmlEncode(value) {
            var encodedValue = $('<div />').text(value).html();
            return encodedValue;
        }
    </script>

References
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc

How to connect to a SignalR hub from PhoneGap or Apache Cordova

<script type="text/javascript">
    $(function () {
        $.connection.hub.url = "http://jgough/SignalR/signalr";

        // Grab the hub by name, the same name as specified on the server
        var chat = $.connection.chat;

        chat.addMessage = function (message) {
            $('#chatMessages').append('<li>' + message + '</li>');
        };

        $.connection.hub.start({ jsonp: true });

        $("#sendChatMessage").click(function () {
            var message = $("#chatMessage").val();
            console.log("Message: " + message);
            chat.send(message);
        });
    });
</script>

References
http://stackoverflow.com/questions/16501590/how-to-connect-to-a-signalr-hub-from-phonegap-app-on-ios

Access an IIS Express site from a remote computer

1 – FOR VISUAL STUDIO 2015: As was pointed out to me in a comment by Søren Nielsen, in Visual Studio 2015 the IIS Express configuration files have moved. They are now separate per project, and stored in /{project folder}/.vs/config/applicationhost.config. Which is much better, in my opinion, just don’t forget to add .vs/ to your .gitignore/.hgignore files!

You will find something like this:

<site name="Alpha.Web" id="2">
    <application path="/">
        <virtualDirectory path="/" physicalPath="C:\Users\Johan\HgReps\Alpha\Alpha.Web" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:58938:localhost" />
    </bindings>
</site>

In , add another row:

<binding protocol="http" bindingInformation="*:58938:192.168.1.42" />

(But with your IP, and port number, of course)

2 – Allow incoming connections
If you’re running Windows 7, pretty much all incoming connections are locked down, so you need to specifically allow incoming connections to your application. First, start an administrative command prompt. Second, run these commands, replacing 192.168.1.42:58938 with whatever IP and port you are using:

netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone

This just tells http.sys that it’s ok to talk to this url.

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=private remoteip=localsubnet action=allow

This adds a rule in the Windows Firewall, allowing incoming connections to port 58938 for computers on your local subnet.

To delete the rules you can do this:

netsh http show urlacl
netsh http delete urlacl url=http://192.168.1.42:58938/

References
http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

How to install Gradle on Windows

  1. Unzip the Gradle download to the folder to which you would like to install Gradle, eg. “C:\Program Files”. The subdirectory gradle-x.x will be created from the archive, where x.x is the version.
  2. Add location of your Gradle “bin” folder to your path. Open the system properties (WinKey + Pause), select the “Advanced” tab, and the “Environment Variables” button, then add “C:\Program Files\gradle-x.x\bin” (or wherever you unzipped Gradle) to the end of your “Path” variable under System Properties. Be sure to omit any quotation marks around the path even if it contains spaces. Also make sure you separated from previous PATH entries with a semicolon “;”.
  3. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_06 and that %JAVA_HOME%\bin is in your Path environment variable.
  4. Open a new command prompt (type cmd in Start menu) and run gradle –version to verify that it is correctly installed.

References
http://bryanlor.com/blog/gradle-tutorial-how-install-gradle-windows
https://www.javacodegeeks.com/2013/04/how-to-install-gradle-2.html