Sunday, November 15, 2015

Consuming a RESTful Web Service Video and Notes

mkdir src/main/java/hello

@JsonIgnoreProperties - any properties not bound in this type should be ignored.

gradle bootRun
or
gradle build
java -jar build/libs/gs-consuming-rest-0.1.0.jar

OR

gradle wrapper
./gradlew bootRun
or
./gradlew build
java -jar build/libs/gs-consuming-rest-0.1.0.jar

OR

mvn spring-boot:run
or
mvn clean package
java -jar target/gs-consuming-rest-0.1.0.jar

output:
2015-11-14 03:20:26.415  INFO 23613 --- [main] hello.Application  : Quote{type='success', value=Value{id=12, quote='@springboot with @springframework is pure productivity! Who said in #java one has to write double the code than in other langs? #newFavLib'}}

Thursday, November 12, 2015

Building Java Projects with Maven Video and Notes

mvn compile
mvn package
mvn install

Greeter.java
package hello;

public class Greeter{
public String sayHello(){
return "Hello world!";
}
}

HelloWorld.java
package hello;

import org.joda.time.LocalTime;

public class HelloWorld{
public static void main(String[] args){
LocalTime currentTime = new LocalTime();
System.out.println("The curent local time is " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework</groupId>
    <artifactId>gs-maven</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0</version>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer                                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>hello.HelloWorld</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Monday, November 9, 2015

Wednesday, November 4, 2015

Building Java Projects with Gradle Video and Notes

gradle tasks
gradle wrapper
gradlew build
gradlew run
jar tvf build/libs/gs-gradle-0.1.0.jar

HelloWorld.java
package hello;

import org.joda.time.LocalTime;

public class HelloWorld{
public static void main(String[] args){
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);

Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}

Greeter.java
package hello;

public class Greeter{
public String sayHello(){
return "Hello world!";
}
}

//build.gradle file starts
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = 'hello.HelloWorld'

repositories{
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile "joda-time:joda-time:2.2"
}

jar{
baseName = 'gs-gradle'
version = '0.1.0'
}

task wrapper(type: Wrapper){
gradleVersion = '2.3'
}
//build.gradle file ends

Tutorial Fly YouTube Channel


Tuesday, October 13, 2015

Wednesday, October 7, 2015

Monday, October 5, 2015

Tuesday, August 4, 2015

Enable Execution of Powershell Scripts inside Visual Studio

























PS P:\>Set-ExecutionPolicy unrestricted
PS P:\>Set-ExecutionPolicy remotesigned

Note: clear all *.licx files

Tuesday, July 21, 2015

Compressed AJAX Data

String Extension Method Zip:
public static byte[] Zip(this string str)
{
var bytes = Encoding.ASCII.GetBytes(str);
using (var memorystreaminput = new MemoryStream(bytes))
using (var memorystreamoutput = new MemoryStream())
{
using (var gs = new GZipStream(memorystreamoutput, CompressionMode.Compress))
{
memorystreaminput.CopyTo(gs);
}
return memorystreamoutput.ToArray();
}
}

Repository Save:
var showsIQueryable = GetShowsIQueryable();
var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
var data = serializer.Serialize(showsIQueryable);

var compressedDataBlob = data.Zip();

//stores compressedDataBlob

Controller ActionResult Get:
var showsJsonText = _showService.CommandRepo.GetShowsCache();
Response.Headers.Remove("Content-Encoding");
Response.AppendHeader("Content-Encoding", "gzip");

return new FileContentResult(showsJsonText, "application/javascript");

JavaScript:
$.ajax({
type: "POST",
url: serverUrl,
dataType: 'json',
cache: false,
async: true,
data: JSON.stringify(model),
contentType: "application/json; charset=utf-8"
}).done(function (data) {
....
});

HTML:
<script type="text/javascript">
var shows = @Html.Raw(new JavaScriptSerializer().Serialize(Model.Shows)
</script>

Thursday, July 16, 2015