tag:blogger.com,1999:blog-4270107728793818462024-03-13T02:56:05.658+02:00Jviaches BlogAnonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-427010772879381846.post-81517413665999193092015-10-09T21:09:00.000+03:002015-10-09T21:09:00.146+03:003 WAYS TO IMPLEMENT FIBONACCI SERIES IN GOLANG<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Since we working with Go, it’s good time to play a bit with <a href="https://en.wikipedia.org/wiki/Fibonacci_number" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Fibonacci numbers.</a> First of all it’s great in case of learning a new programming language and second, we will try to analyze a bit recurrent function and write it’s short iterative implementation. As a bonus we will write function that return function that return int .<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
But let’s starts from a theory. The definition of Fibonacci numbers state : F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n</span> = F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n-1</span> + F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n-2 .</span> The whole idea is find number by given its index.</div>
<ol style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em; margin-top: 0px;">
<li style="box-sizing: border-box;">Recursive implementation</li>
</ol>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibbRecc(numIndex int) (numValue int){
if numIndex == 0 || numIndex == 1 {
return numIndex
}
return fibbRecc(numIndex - 2) + fibbRecc(numIndex -1)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
<strong style="box-sizing: border-box;">Note</strong>: Simple well known recursive approach. The first problem is possibility of stack overflow. The second one it’s exponential time of execution. Third problem is repetitive calculations. For example if we will calculate value at index 4 -> f(3) + f(2), it mean that f(2) will be calculated twice. And if we will calculate value at index 5 -> f(4) + f(3), it mean that f(3) will be calculated 3 times. And so on..</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
So suitable solution for third problem may be using some data structure (slice for instance) to store data and avoid unnecessary calculations.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
2. Iterative function.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
There are a short mathematical representation developed by <a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Binet</a> based on<a href="http://mathworld.wolfram.com/GoldenRatio.html" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">golden ratio</a>:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibShortIterative(numIndex float64) (float64){
Phi := (1 + math.Sqrt(5)) / 2
phi := (1 - math.Sqrt(5)) / 2
return (math.Pow(Phi, numIndex) - math.Pow(phi, numIndex)) / math.Sqrt(5)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
3. There is another way to write iterative Fibonacci function in Golang. Actually its a function that return function. And last one return int !</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibIterFunc() func() int{
x:=0
y:=1
return func() int{
x,y = y,x+y
return x
}
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Usage:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">f:=fibIterFunc()
for i := 0; i < 10; i++ {
fmt.Print(f() )
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px;">
Code (as always) can be found and downloaded from <a href="https://github.com/jviaches/Golang-playground/tree/master/Fibbonachi" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Github</a></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-75993492175198115082015-10-08T21:17:00.000+03:002015-10-08T21:22:19.719+03:003 ways to implement Fibonacci series in Golang<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Since we working with Go, it’s good time to play a bit with <a href="https://en.wikipedia.org/wiki/Fibonacci_number" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Fibonacci numbers.</a> First of all it’s great in case of learning a new programming language and second, we will try to analyze a bit recurrent function and write it’s short iterative implementation. As a bonus we will write function that return function that return int<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
But let’s starts from a theory. The definition of Fibonacci numbers state : F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n</span> = F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n-1</span> + F<span style="bottom: -0.25em; box-sizing: border-box; font-size: 14.25px; line-height: 0; position: relative; vertical-align: baseline;">n-2 .</span> The whole idea is find number by given its index.</div>
<ol style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em; margin-top: 0px;">
<li style="box-sizing: border-box;">Recursive implementation</li>
</ol>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibbRecc(numIndex int) (numValue int){
if numIndex == 0 || numIndex == 1 {
return numIndex
}
return fibbRecc(numIndex - 2) + fibbRecc(numIndex -1)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
<strong style="box-sizing: border-box;">Note</strong>: Simple well known recursive approach. The first problem is possibility of stack overflow. The second one it’s exponential time of execution. Third problem is repetitive calculations. For example if we will calculate value at index 4 -> f(3) + f(2), it mean that f(2) will be calculated twice. And if we will calculate value at index 5 -> f(4) + f(3), it mean that f(3) will be calculated 3 times. And so on..</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
So suitable solution for third problem may be using some data structure (slice for instance) to store data and avoid unnecessary calculations.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
2. Iterative function.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
There are a short mathematical representation developed by <a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Binet</a> based on<a href="http://mathworld.wolfram.com/GoldenRatio.html" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">golden ratio</a>:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibShortIterative(numIndex float64) (float64){
Phi := (1 + math.Sqrt(5)) / 2
phi := (1 - math.Sqrt(5)) / 2
return (math.Pow(Phi, numIndex) - math.Pow(phi, numIndex)) / math.Sqrt(5)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
3. There is another way to write iterative Fibonacci function in Golang. Actually its a function that return function. And last one return int !</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func fibIterFunc() func() int{
x:=0
y:=1
return func() int{
x,y = y,x+y
return x
}
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Usage:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">f:=fibIterFunc()
for i := 0; i < 10; i++ {
fmt.Print(f() )
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px;">
Code (as always) can be found and downloaded from <a href="https://github.com/jviaches/Golang-playground/tree/master/Fibbonachi" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">Github</a></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com1tag:blogger.com,1999:blog-427010772879381846.post-10620978497253430432015-10-08T21:13:00.000+03:002015-10-08T21:22:44.742+03:00Simple TODO list in Go [Tutorial]<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
In this post i will introduce some basic (real basic) web development in go. We will start to implement TODO list and at the end of this topic it would’t be perfect but it will compile and show us proper results. May be in following topics we will continue to develop and expend this project. Sources will be available at the bottom of this post.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
main.gtpl file (html based view) going to be like following:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">< html>
< head>
< title>all items< /title>
< /head>
< body>
< h1>List of todo items:< /h1>
< div>
< ul>
{{ range $item := .}}
< li>< input type="checkbox" id="{{ $item.Id }}" value="{{ $item.IsFinished }}" /> < label for="{{ $item.Id }}">{{ $item.Caption }} < /label>< /li>
{{ end }}
< /ul>
< /div>
< /body>
< /html></pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
addItem.gtpl (another html based view) is looking as following:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">< html>
< head>
< title>Add new todo item< /title>
< /head>
< body>
< form action="/" method="POST">
Caption: < input type="text" name="caption">
< input type="submit" value="add">
< /form>
< /body>
< /html></pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Controller will looks like following:</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">package main
import (
"fmt"
"log"
"net/http"
"html/template"
)
type ToDoItem struct {
Id int
Caption string
IsFinished bool
}
var TodoItemsSlice = []ToDoItem{
}
func main() {
fmt.Println("Initializing...")
TodoItemsSlice = make([]ToDoItem,0)
runServer()
}
func runServer(){
fmt.Println("Starting sever...")
// public views
http.HandleFunc("/additem", addItemHandler )
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
captionFormValue := r.PostFormValue("caption")
if captionFormValue!= "" {
fmt.Println("caption:", captionFormValue)
newId := len(TodoItemsMap) + 1
p := &ToDoItem{Id:newId, Caption: captionFormValue, IsFinished:false}
TodoItemsSlice = append(TodoItemsSlice, *p)
}
t, err := template.ParseFiles("views/main.gtpl")
if err != nil {
log.Fatal("Can not parse views/main.gtpl "+ err.Error())
}
t.Execute(w, TodoItemsMap)
}
func addItemHandler(w http.ResponseWriter, r *http.Request) {
log.Print("addItemHandler")
t, _ := template.ParseFiles("views/additem.gtpl")
t.Execute(w, t)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Firs of all lets start from Controller.</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">import (
"fmt"
"log"
"net/http"
"html/template"
)</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Here we declare all packages we going to use. It right time to mention that code will not compile when you try to declare some package you are not going to use. By the way the same approach with defining unused variables.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Next we define ToDo item as <a href="https://gobyexample.com/structs" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">struct</a> (since i go there is no classes) and some TodoItemsSlice as <a href="https://gobyexample.com/slices" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">slice</a>. In short, slices are collections : it has an ability to add and remove items.</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">type ToDoItem struct {
Id int
Caption string
IsFinished bool
}
var TodoItemsSlice = []ToDoItem{
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Lets take a look in main andrunServer functions: In main function nothing special: printing to console regarding server initialization and creating new instance of empty slice. The running runServer function</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
It’s easy to see that server starting listening on port 8080 (browser port). In addition we can find two handlers: one for entering for the “localhost” and the second one when entering to “localhost:8080/additem” (in order to add more items in ToDo list).</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func main() {
fmt.Println("Initializing...")
TodoItemsSlice = make([]ToDoItem,0)
runServer()
}
func runServer(){
fmt.Println("Starting sever...")
// public views
http.HandleFunc("/additem", addItemHandler )
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Now let’s skip default handler and talk about addHandler. In general handlers are functions that will executed when user will enter to specific URL. More about Go handlers you can find <a href="https://golang.org/pkg/net/http/" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;">here</a>.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Method addItemHandler gets two parameters: reponce and request. When use will enter to “localhost:8080/additem”, this handler will be executed. So first line is printing in console (by using log) and the we parse our view file by usage of<a href="https://golang.org/pkg/html/template/" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">template</a>. Usually view file can be represented as html but n this case it represented by gtpl which very similar to aspx file in APS.NET.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Interesting point here is that template.ParseFiles function returns two values (yes, it’s possible in go ) – result and error. Result represented by “t” variable, but we not going to use error at this point. If we define it (error variable) we have to use it, otherwise it will not compile. In order to avoid usage of returned variable we just using “_” telling Go that we are not interesting in it.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Another interesting point here is defining variables. In go there are two ways to define variable: by using “var” and by using “:=”. You can read about it <a href="https://gobyexample.com/variables" style="background-color: transparent; border-bottom-color: rgba(0, 0, 0, 0.14902); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #2d2f30; font-weight: bold; text-decoration: none; transition: all 0.35s ease-in-out;" target="_blank">here</a>.</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func addItemHandler(w http.ResponseWriter, r *http.Request) {
log.Print("addItemHandler")
t, _ := template.ParseFiles("views/additem.gtpl")
t.Execute(w, t)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
Let’s move on and take a look at our main handler.</div>
<pre style="background: rgb(41, 46, 57); border-radius: 0px; border: none; box-sizing: border-box; color: #ebedf0; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.6; margin-bottom: 30px; max-width: 100%; overflow: auto; padding: 26.3906px 39.5938px; text-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; word-break: break-all; word-wrap: break-word;">func handler(w http.ResponseWriter, r *http.Request) {
captionFormValue := r.PostFormValue("caption")
if captionFormValue!= "" {
fmt.Println("caption:", captionFormValue)
newId := len(TodoItemsMap) + 1
p := &ToDoItem{Id:newId, Caption:captionFormValue, IsFinished:false}
TodoItemsSlice = append(TodoItemsSlice, *p)
}
t, err := template.ParseFiles("views/main.gtpl")
if err != nil {
log.Fatal("Can not parse views/main.gtpl "+ err.Error())
}
t.Execute(w, TodoItemsMap)
}</pre>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
At the beginning we trying to get caption value which we read from form. If found one, we create new todo item and populate it with proper data and append it to the slice. And the simply returning to the main.gtpl and showing results.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
At this point i was encountered with this specific issue and it took me some time to get to the point and make it work. Since i spent some time on it, i suppose there are other who will encounter in the same issue. So let me show you how i resolved it.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
<strong style="box-sizing: border-box;">Goal</strong>: output dynamically changed slice on the main.gtpl page.</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
<strong style="box-sizing: border-box;">Approach</strong>: within main handler we pass to the Execute function our slice which actually will be a context of main.gtpl. That’s it!</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px; margin-bottom: 1.632em;">
* Please let me know about any issue you encountered with (not compiling, not clear some point or untipattern, etc..)</div>
<div style="background-color: white; box-sizing: border-box; color: rgba(26, 26, 26, 0.8); font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 19px; line-height: 30.4px;">
Source code is available at GitHub.</div>
</div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-69953023145441341892015-10-08T20:57:00.000+03:002015-10-08T20:57:20.004+03:00Customize gmail experience<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
Most of the day we spend answering and sending emails. Therefore, correctly configured email box can increase your productivity and free up the time for other aspects of the work. There are couple options to make our work with <a data-mce-href="http://gmail.com" href="http://gmail.com/" target="_blank">Gmail </a>with maximum convenience:</div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li><strong>Undo send</strong>. It gives us ability to cancel almost send email in specified cancellation period of time, which in some cases might be useful.</li>
</ul>
<div class="mceTemp" style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<dl class="wp-caption aligncenter" data-mce-style="width: 627px;" id="attachment_207" style="-webkit-user-drag: none; margin: 0px auto; max-width: 100%; width: 627px;">
<dt class="wp-caption-dt" style="-webkit-user-drag: none;"><a data-mce-href="http://techflask.com/wp-content/uploads/2015/09/UndoSendGmail.png" href="http://techflask.com/wp-content/uploads/2015/09/UndoSendGmail.png" style="-webkit-user-drag: none;"><img alt="Undo Send email in gmail" class="wp-image-207 size-full" data-mce-src="http://techflask.com/wp-content/uploads/2015/09/UndoSendGmail.png" height="51" src="http://techflask.com/wp-content/uploads/2015/09/UndoSendGmail.png" style="-webkit-user-drag: none; display: block; height: auto; max-width: 100%;" width="627" /></a></dt>
<dd class="wp-caption-dd" style="-webkit-user-drag: none; font-size: 14px; margin: 0px; padding-top: 0.5em;">Undo Send email in gmail</dd></dl>
</div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li><strong>Stars</strong>. By adding more stars we can get more control over our email discussion. Short glance, quicker response.</li>
</ul>
<div class="mceTemp" style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<dl class="wp-caption aligncenter" data-mce-style="width: 1403px;" id="attachment_212" style="-webkit-user-drag: none; margin: 0px auto; max-width: 100%; width: 1403px;">
<dt class="wp-caption-dt" style="-webkit-user-drag: none;"><a data-mce-href="http://techflask.com/wp-content/uploads/2015/09/GmailStars.png" href="http://techflask.com/wp-content/uploads/2015/09/GmailStars.png" style="-webkit-user-drag: none;"><img alt="Adding more stars in gmail allow you to get more control over you email conversations" class="wp-image-212 size-full" data-mce-src="http://techflask.com/wp-content/uploads/2015/09/GmailStars.png" height="110" src="http://techflask.com/wp-content/uploads/2015/09/GmailStars.png" style="-webkit-user-drag: none; display: block; height: auto; max-width: 100%;" width="1403" /></a></dt>
<dd class="wp-caption-dd" style="-webkit-user-drag: none; font-size: 14px; margin: 0px; padding-top: 0.5em;">Adding more stars in gmail allow you to get more control over you email conversations</dd></dl>
</div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li><strong>Signature</strong>. Allow us to complete email without reentering "regards" manually</li>
</ul>
<div class="mceTemp" style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<dl class="wp-caption aligncenter" data-mce-style="width: 984px;" id="attachment_215" style="-webkit-user-drag: none; margin: 0px auto; max-width: 100%; width: 984px;">
<dt class="wp-caption-dt" style="-webkit-user-drag: none;"><a data-mce-href="http://techflask.com/wp-content/uploads/2015/09/GmailSignature.png" href="http://techflask.com/wp-content/uploads/2015/09/GmailSignature.png" style="-webkit-user-drag: none;"><img alt="Gmail signature" class="wp-image-215 size-full" data-mce-src="http://techflask.com/wp-content/uploads/2015/09/GmailSignature.png" height="219" src="http://techflask.com/wp-content/uploads/2015/09/GmailSignature.png" style="-webkit-user-drag: none; display: block; height: auto; max-width: 100%;" width="984" /></a></dt>
<dd class="wp-caption-dd" style="-webkit-user-drag: none; font-size: 14px; margin: 0px; padding-top: 0.5em;">Gmail signature</dd></dl>
</div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li><strong>Labels</strong>. Free you visual space by hiding unnecessary items.<ul>
<li>Show - default option. Label will be shown</li>
<li>Hide - label will be hide even if it contains unread emails</li>
<li>Show if unread - means hide by default, but if it contains unread emails, it will be shown.</li>
</ul>
</li>
</ul>
<div class="mceTemp" style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<dl class="wp-caption aligncenter" data-mce-style="width: 451px;" id="attachment_216" style="-webkit-user-drag: none; margin: 0px auto; max-width: 100%; width: 451px;">
<dt class="wp-caption-dt" style="-webkit-user-drag: none;"><a data-mce-href="http://techflask.com/wp-content/uploads/2015/09/GmailLables.png" href="http://techflask.com/wp-content/uploads/2015/09/GmailLables.png" style="-webkit-user-drag: none;"><img alt="Control gmail lables" class="size-full wp-image-216" data-mce-src="http://techflask.com/wp-content/uploads/2015/09/GmailLables.png" height="128" src="http://techflask.com/wp-content/uploads/2015/09/GmailLables.png" style="-webkit-user-drag: none; display: block; height: auto; max-width: 100%;" width="451" /></a></dt>
<dd class="wp-caption-dd" style="-webkit-user-drag: none; font-size: 14px; margin: 0px; padding-top: 0.5em;">Control gmail lables</dd></dl>
</div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-40946453764654192992015-09-22T10:29:00.001+03:002015-09-22T10:30:57.045+03:00Motivation videoA large part of my nature is to constantly move forward in spite of everything: of failure, ups and downs, joy or sorrow. I constantly learning from anything i experience. I look at it the same way as the natural process of breathing or a natural smile on face of a standing smiling man.<br />
<br />
Since the constant movement always creates friction, I always have to look for new inspiration that will give me energy in my travels for constantly movement forward.<br />
<br />
And this time I discovered a new direction – a motivational video. And here is the first one.<br />
<br />
Disclaimer: This video found at <a href="https://www.youtube.com/user/TheMiro0r" target="_blank">Mateusz M </a>channel. But you may find it at the <a href="https://www.youtube.com/playlist?list=PLhnqxEORNfJyb10NPKNtn9zF1C4mkIQtI" target="_blank">techflask youtube channel</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/26U_seo0a1g/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/26U_seo0a1g?feature=player_embedded" width="320"></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
I hope this series of posts will not only help me. Leave your comments to this post. may the force be with us :)Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-63584383608103770342015-09-19T17:40:00.000+03:002015-09-19T17:40:13.768+03:00HI GOLANG<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
I think I falling in love for the first time after years of software development. I believe it should happen at least once to each software engineer, who truly loves what he does.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
It wasn't love from the first sight. I felt something strange, something completely different from knowledge i gain till this point. But sometimes people prefer their warm and very familiar comfort zone. And this was the case why our date was over then.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<br /></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
Since i remember my career, I always have been developed in OOP: C#, Java/Android. And any other approach felt like i have to leave cozy comfort zone of mine for something unfamiliar and risky, something questionable to invest my free time. I have a wife and lovely twins after all.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<br /></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
After almost half a year i was encountered "by accident" in "<a data-mce-href="http://www.pluralsight.com/courses/go" href="http://www.pluralsight.com/courses/go" target="_blank">The Go Programming Language</a>" course at <a data-mce-href="http://www.pluralsight.com/" href="http://www.pluralsight.com/" target="_blank">PluralSight</a>.</div>
<blockquote style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
By the way i really encourage starting from there, since it's the best overview to get familiar with Go concepts and approaches. Clear explanation along with great code examples will provide you great starting point.</blockquote>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
Anyway i was amazed by Go's different paradigms, its approaches and most of all from idea of language that was created with taking concurrency in mind. Actually its the right time to explain little bit what i have discovered:</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<br /></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<strong>Some Facts:</strong></div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li>Language was developed in 2007 by Google engineers.</li>
<li>Was announced by Google in November 2009</li>
<li>It is complete opensource.</li>
<li>Go supported by Google Cloud</li>
</ul>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<strong>Pros:</strong></div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li>Great build-in documentation and lot of libraries out-of-the-box</li>
<li>Garbage collection, type safety and some dynamic capabilities</li>
<li>Avoid stop-the-world GC pauses with no delays</li>
<li>Have no classes at all</li>
<li>Intentionally designed without any inheritance at all. Use composition instead.</li>
<li>Function may return more then one value. Such ability does not exist in C# or Java.</li>
<li>Working with Go routines (represent thread) is really easy and have ability to exchange data between them by using channels.</li>
<li>There is no possibility to use undefined variables.</li>
<li>Interesting idea of visibility : function or member starting with capital letter become visible to other packages (public modifier in C#). Small letter indicate no visibility from outside (private modifier in C#)</li>
</ul>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<strong>Some thoughts at this moment:</strong></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
It looks to me Go has a lot of potential. Language itself do efforts you write cleaner and understandable code by applying it's rules. For example there is no possibility to use undefined variables, what is possible in C# and leads to less readability and message.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
Since Go become part of Google's infrastructure it smells like relative stability to me. Besides, company has a lot of experiences in enterprise software development as well as in concurrency fields, meaning they try to implement their extensive knowledge in Golang.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
Although it feels different from what i used to, but looks like going to invest a lot of time with this language.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<strong>Sources:</strong></div>
<ul style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 16px; line-height: 24px;">
<li><a data-mce-href="https://en.wikipedia.org/wiki/Go_(programming_language)" href="https://en.wikipedia.org/wiki/Go_(programming_language)" target="_blank">Wikkipedia</a></li>
<li><a data-mce-href="https://golang.org/" href="https://golang.org/" target="_blank">GO Official project site</a></li>
</ul>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-7237805284220008022015-07-21T08:00:00.000+03:002015-08-05T10:58:30.246+03:00Update UI from task (Task schedulers)Sometime we need to update UI from a task. In order to update UI we should run or return result in UI thread. But it seems to impossible since all tasks run on threads provided by ThreadPool.<br />
<div>
<br /></div>
<div>
But still, we can achieve updating UI from the task by using synchronization context Task Scheduler. First we will see an approach and then we will discuss about it and explain what we just saw.</div>
<div>
<br /></div>
<div>
<b>Example:</b></div>
<div>
<br /></div>
<div>
<div>
private static void taskContinueWithExploration()</div>
<div>
{</div>
<div>
TaskScheduler mTaskSceduler = TaskScheduler.FromCurrentSynchronizationContext();</div>
<div>
<br /></div>
<div>
Task.Factory.StartNew<string>(() =></string></div>
<div>
{</div>
<div>
Console.WriteLine(makeCalculations);</div>
<div>
}).ContinueWith(tsk => txtRaiting.Content = tsk.Result, mTaskSceduler);</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
<b>Explanation:</b></div>
<div>
<br /></div>
<div>
Task Scheduler is a an abstract class that providing thread to the task via Thread Pool. There are two concrete implementations of Task Scheduler:</div>
<div>
<br /></div>
<div>
<ul>
<li>Default Task Scheduler (the regular one)</li>
<li>Synchronization Context Task Scheduler (give us ability work with UI)</li>
<li><br /></li>
</ul>
<div>
<b>Regarding the example:</b></div>
</div>
<div>
<b><br /></b></div>
<div>
<ul>
<li>This example update WPF text box with result of makeCalculations() method</li>
<li>First task (StartNew) making calculations (some long algorithm calculations, working with web service,..)</li>
<li>The second task (ContinueWith) will be able to print to the UI thread.</li>
</ul>
<div>
<br /></div>
</div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-52848206668078086822015-07-19T09:55:00.000+03:002015-07-19T09:55:00.532+03:00C# Task.ContinueWith() method<span style="background-color: white;">We all worked with ContinueWith() method but there are some interesting and useful facts we should be aware of.</span><br />
<span style="background-color: white;"><br />
</span> <span style="background-color: white;">First of all lets remember what is Continuation regarding the Tasks. When we looking for this definition in <a href="https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.continuewith(v=vs.110).aspx" target="_blank">MSDN </a>, we see following:</span><br />
<blockquote class="tr_bq">
<i style="background-color: white;">Creates a continuation that executes asynchronously when the target <a href="https://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.110).aspx">Task</a> completes.</i></blockquote>
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">Lets see an example:</span><br />
<pre class="sh_csharp sh_sourceCode" style="background-color: white; border: 1px solid rgb(204, 204, 204); font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px; padding: 3pt 6pt 3pt 4pt;"><span style="background-color: white;"><span class="sh_usertype" style="color: teal;">Task</span><span class="sh_normal"> </span>task1 <span class="sh_symbol">=</span> Task<span class="sh_symbol">.</span>Factory<span class="sh_symbol">.</span><span class="sh_function">StartNew</span><span class="sh_symbol">(()</span> <span class="sh_symbol">=></span> Console<span class="sh_symbol">.</span><span class="sh_function">Write</span> <span class="sh_symbol">(</span><span class="sh_string" style="color: #dc1414;">"creating first task</span><span class="sh_symbol">));</span></span>
<span class="sh_usertype" style="color: teal;">Task</span><span class="sh_normal"></span> task2 <span class="sh_symbol">=</span> task1<span class="sh_symbol">.</span><span class="sh_function">ContinueWith</span><span class="sh_symbol">(</span>ant <span class="sh_symbol">=></span> Console<span class="sh_symbol">.</span><span class="sh_function">Write</span> <span class="sh_symbol">(</span><span class="sh_string" style="color: #dc1414;">"continue anyway"</span><span class="sh_symbol">));</span></pre>
<span style="background-color: white;"><br />
</span> <span style="background-color: white;">But actually there are few interesting facts :)</span><br />
<span style="background-color: white;"><br />
</span> <span style="background-color: white;"><b>Fact 1:</b> task1 and task2 in previous example may run on a different threads. In order to obligate to run on the same thread we can use <a href="https://msdn.microsoft.com/en-us/library/system.threading.tasks.taskcontinuationoptions(v=vs.110).aspx">TaskContinuationOptions.ExecuteSynchronously</a>.</span><br />
<span style="background-color: white;"><br />
</span> <span style="background-color: white;"><b>Fact 2:</b> Its important to know that ContinueWith() method will be executed anyway, whenever Task succeeded, faulted or canceled. It give us great opportunity to deal sometimes with different cases accordingly: in case of exceptions do this and in case of success do that. We can achieve it like this:</span><br />
<span style="background-color: white;"><br />
</span><br />
<pre class="sh_csharp sh_sourceCode" style="border: 1px solid rgb(204, 204, 204); padding: 3pt 6pt 3pt 4pt;"><span style="background-color: white;"><span class="sh_usertype" style="color: teal; font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Task</span><span class="sh_normal" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> someT</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ask </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> Task</span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Factory</span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span class="sh_function" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">StartNew</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">(()</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=></span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_cbracket" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">{</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> <span style="color: blue;">throw new Exception()</span></span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">;</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_cbracket" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">}</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">);</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">
</span></span><span class="sh_usertype" style="color: teal; font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Task</span><span class="sh_normal" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">exceptions</span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_normal" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">someT</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ask</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span class="sh_function" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ContinueWith</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">(</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ant </span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=></span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> Console</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span class="sh_function" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Write</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">(</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ant</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Exception</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">),</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">
</span></span>TaskContinuationOptions.OnlyOnFaulted<span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">);</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">
</span></span><span class="sh_usertype" style="color: teal; font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Task</span><span class="sh_normal" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">noExceptions </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> task1</span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span class="sh_function" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ContinueWith</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">(</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">ant </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">=></span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> Console</span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">.</span><span class="sh_function" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">Write</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;"> </span></span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">(</span><span class="sh_string" style="color: #dc1414; font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">"No Exceptions!"</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">),</span><span style="font-family: consolas, courier new, monospace;"><span style="font-size: 14.3999996185303px; line-height: 17.2799987792969px;">
</span></span><span style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">TaskContinuationOptions<span class="sh_symbol">.</span>NotOnFaulted</span><span class="sh_symbol" style="font-family: consolas, 'courier new', monospace; font-size: 14.3999996185303px; line-height: 17.2799987792969px;">);</span></span></pre>
<span style="background-color: white;"><br /></span><span style="background-color: white;">Have a great coding time :)<br />
</span> <span style="background-color: white;"><br />
</span> <span style="background-color: white;"><br />
</span> <span style="background-color: white;"><br />
</span> Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-71704023233342688322015-07-17T12:00:00.000+03:002015-07-17T12:00:01.699+03:00C# Task - Attached and Detached Child TasksDevelopers can define parent-child relationships between task. The main idea is, parent task is completed when all its children tasks are completed.<br />
<br />
<b>Example1</b>:<br />
<br />
private static void childrenTasksExample()<br />
{<br />
var parent = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Parent task executing.");<br />
var child1 = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Attached child starting.");<br />
Console.WriteLine("Attached child completing.");<br />
}, <a href="https://msdn.microsoft.com/en-us/library/system.threading.tasks.taskcreationoptions(v=vs.110).aspx" target="_blank">TaskCreationOptions.AttachedToParent</a>);<br />
});<br />
parent.Wait();<br />
Console.WriteLine("Parent has completed.");<br />
}<br />
<br />
<b>Output1</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-1VGV5lPhzDI/VaYUdwiPSlI/AAAAAAAACs4/XyakHnUgnkA/s1600/hierarchy_child_tasks_csharp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="328" src="http://4.bp.blogspot.com/-1VGV5lPhzDI/VaYUdwiPSlI/AAAAAAAACs4/XyakHnUgnkA/s640/hierarchy_child_tasks_csharp.png" width="640" /></a></div>
<br />
<br />
Please notice to parent.Wait() method. Its says to the parent that it will be completed when everything inside it is completed.<br />
If you will try to run without mentioned earlier string, the results will be "slightly" different.<br />
<br />
<b>Output</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-AJ5MeT1wdpQ/VaYcL_SMKSI/AAAAAAAACtI/_ylvcbHK9mQ/s1600/hierarchy_child_tasks-without-wait-method_csharp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="336" src="http://4.bp.blogspot.com/-AJ5MeT1wdpQ/VaYcL_SMKSI/AAAAAAAACtI/_ylvcbHK9mQ/s640/hierarchy_child_tasks-without-wait-method_csharp.png" width="640" /></a></div>
<br />
Now we would like to execute 2 sons tasks within father task. We can achieve it like following (as expected)<br />
<br />
<b>Example2</b>:<br />
<br />
private static void childrenTasksExample()<br />
{<br />
var parent = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Parent task executing.");<br />
var child1 = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Attached child1 starting.");<br />
Console.WriteLine("Attached child1 completing.");<br />
}, TaskCreationOptions.AttachedToParent);<br />
<br />
var child2 = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Attached child2 starting.");<br />
Console.WriteLine("Attached child2 completing.");<br />
}, TaskCreationOptions.AttachedToParent);<br />
<br />
});<br />
parent.Wait();<br />
Console.WriteLine("Parent has completed.");<br />
}<br />
<br />
<b>Output2</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-n_GrABTOwi8/VaYdQUkx7BI/AAAAAAAACtU/OKV9RNfMZdk/s1600/hierarchy_2child_tasks_csharp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="336" src="http://4.bp.blogspot.com/-n_GrABTOwi8/VaYdQUkx7BI/AAAAAAAACtU/OKV9RNfMZdk/s640/hierarchy_2child_tasks_csharp.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-eRQRQYAQKjM/VaYdpJwyzvI/AAAAAAAACtc/W3NcbCNIen0/s1600/hierarchy_2child_tasks_second_execution_csharp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="336" src="http://1.bp.blogspot.com/-eRQRQYAQKjM/VaYdpJwyzvI/AAAAAAAACtc/W3NcbCNIen0/s640/hierarchy_2child_tasks_second_execution_csharp.png" width="640" /></a></div>
<br />
<br />
Notice that code is not define who run first within father's task. It only says that father task will complete only after everything else is completed inside it.<br />
<br />
<b>To explore:</b><br />
<br />
Let say that we second son should be executed right after first one is completed. So how do we achieve it ? MSDN suggest us to use TaskCreationOptions.PreferFairness. I will cover it in my future posts.<br />
<br />
<br />
<br />
Related sources (links):<br />
<br />
<ul>
<li><a href="https://msdn.microsoft.com/en-us/library/dd997417(v=vs.110).aspx" target="_blank">AttachedToParentMSDN</a></li>
<li><a href="http://blogs.msdn.com/b/pfxteam/archive/2009/07/07/9822857.aspx" target="_blank">PreferFairness (MSDN)</a></li>
</ul>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-82651418298330269712015-07-14T23:49:00.000+03:002015-07-15T15:45:34.102+03:00Perception shift<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ce1F3hHZXak/Ui-CT_hN1PI/AAAAAAAABMI/-nl6Dy8JJhU/s1600/enjoy-your-success.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="512" src="http://1.bp.blogspot.com/-ce1F3hHZXak/Ui-CT_hN1PI/AAAAAAAABMI/-nl6Dy8JJhU/s640/enjoy-your-success.jpg" width="640" /></a></div>
<br />
<br />
<br />
Lately i was experienced a rough and kinda intense period: a lot of things required my nearly immediate attention and response. It came simultaneously from different life aspects: academic (MSC degree), personal, family,organizational and etc. Neither i was prepared for such pressure, nor i had an idea how to handle all this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br />
</a></div>
At that point i have discovered "task priority" which is one of the vital tools that allowed to me to define, which task is more important at this specific moment, how many percentage of my attention i going to consecrate to this specific task. Which task is next. <br />
<br />
As a result, big bunch of unsolvable problems were divided to the single tasks with priorities, allowing me to maximize my focus on tasks solutions, rather than of feeling of epic failure. To save the story, it was a happy end after all :)<br />
<br />
In the middle of whole process there was something that "hit" me - "I should change my attitude regarding the problems".<br />
<br />
So far i following assumptions (assumptions that i formulated for myself):<br />
<br />
<blockquote class="tr_bq">
<b>Problems are good</b></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-GXkzTKvuABw/UkF5_QvRynI/AAAAAAAABNc/mHznXmvI93I/s1600/Good-quote-on-Problems.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="140" src="http://1.bp.blogspot.com/-GXkzTKvuABw/UkF5_QvRynI/AAAAAAAABNc/mHznXmvI93I/s320/Good-quote-on-Problems.jpg" width="320" /></a></div>
Problems makes our skills grow up. The idea is that when you handle some problem, you get more life experience. You point of view is changing and you may see the problem from a wider perspective. Experience you gained though your problems is not fictional ( like in TV programs) but your's own. And it it real.<br />
<br />
<blockquote class="tr_bq">
<b>Treat problem as a challenge</b></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-BbhdVVZts70/UkF5bD0BV0I/AAAAAAAABNU/NAzFr39ZQuE/s1600/Challenge-Banner.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="139" src="http://4.bp.blogspot.com/-BbhdVVZts70/UkF5bD0BV0I/AAAAAAAABNU/NAzFr39ZQuE/s320/Challenge-Banner.png" width="320" /></a></div>
The problem should be treated in a the manner of task or challenge. Same idea, different approach.When a problem defined as a problem, we subconsciously relate with them some negative energy. Challenge from another hand sounds completely different and it may push you toward a solution.<br />
<br />
<br />
<blockquote class="tr_bq">
<b>Think positive</b></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-siXRlmvMeBU/UmfDki0dHQI/AAAAAAAABOY/nRiYXAcBvlI/s1600/14381169-positive-thinking-word-cloud-concept-in-red-capital-letters-with-great-terms-such-as-good-mental-tho.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-siXRlmvMeBU/UmfDki0dHQI/AAAAAAAABOY/nRiYXAcBvlI/s320/14381169-positive-thinking-word-cloud-concept-in-red-capital-letters-with-great-terms-such-as-good-mental-tho.jpg" width="320" /></a></div>
Think positive. Behave positive. Be positive.Positive attitude helps you interpret less nice moment to the positively. Add some humor when helps to stay positive. Don't be sarcastic - be positive!<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Depending on how you pass your "test" (i.e. handled with the specific challenge), ability to recognize your weak sides, ability to analyze how improve yourself in next challenges will define your nature maturity.<br />
<br />
P.S.<br />
All above its just my personal experience and express my private point of view based on my own experience.<br />
<br />
<i>*All pictures in this post belong to their owners.</i><br />
<br />Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-50284945203336217832015-07-13T16:10:00.001+03:002015-07-15T09:51:21.284+03:00Threads vs Tasks in C#<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-7M0e3c_YHss/VaOnW37kn-I/AAAAAAAACso/EyhXh0dfnPA/s1600/ThreadVsTask.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="254" src="http://4.bp.blogspot.com/-7M0e3c_YHss/VaOnW37kn-I/AAAAAAAACso/EyhXh0dfnPA/s320/ThreadVsTask.png" width="320" /></a></div>
Today my point of interest is Thread vs Task. Finally i had a little amount of time between projects to dive deeper in order to "examine" the difference. Actually when you ask people what is the difference you hear a lot of different things but the feeling that this point is not organized enough for me. So i decided to clarify this point once and for all :)<br />
<br />
<b>Threads</b><br />
Threads are real OS thread with own its stack and resources. Threads allow to developer be fully controlled (by using Resume(), Suspend() or Abort() and etc). The problem is that threads are "time hungry" entities, which means that they will consume non trivial time at creation stage. In additional we should take in consideration time for context switching overhead performed by CPU.<br />
<br />
<b>ThreadPool</b><br />
ThreadPool is entity that optimize overheads of the threads and it manage them [threads] by itself. In return it gives developer small maneuver possibilities such as pool size and ability to submit work to execute at some point. And thats it!<br />
<br />
<b>Task</b><br />
Task is class introduces as part of TPL [Task Paralel Library] and it came with CLR 4.0. Task represent compromise of above cases. It relays on TaskScheduler which in his turn working against ThreadPool.<br />
<br />
Task able to return result after it completes (unlike ThreadPool). In addition we can run another task immediately when first one is completes.<br />
<br />
Example:<br />
<blockquote class="tr_bq">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="line number8 index7 alt1" style="background: none white !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: #666666; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; height: auto !important; left: auto !important; line-height: 15.3999996185303px; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="csharp plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-stretch: normal; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">Task<</code><code class="csharp keyword" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-stretch: normal; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">int</code><code class="csharp plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-stretch: normal; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">> t = Task.Run(() => 2)</code></div>
<div class="line number9 index8 alt2" style="background: none white !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: #666666; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; height: auto !important; left: auto !important; line-height: 15.3999996185303px; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="csharp spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-stretch: normal; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="csharp plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-stretch: normal; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">.ContinueWith((i) => i.Result * 2);</code></div>
</blockquote>
<br />
In this case when first task will be completed, the second task will be initiated and executed.<br />
It's important to mentioned that each time when task is created, it lays on thread delivered by ThreadPool.<br />
<br />
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a>Here we can see that we might have issue with long run operations, since if we don't have enough free threads within ThreadPool - we may stuck when we would like to create new task. In order to avoid this issue, use TaskCreationOptions that can specify LongRunning property which means suggests to the scheduler to dedicate a thread to the task.<br />
<div>
<br />
There are a lot of interesting facts about Tasks but i feel that i can not cover them all in this post. I believe that i will continue to write about my research in my future posts.</div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-33584619076977960702015-01-16T09:17:00.000+02:002015-01-16T09:17:00.212+02:00Kickstarter: PowerUp - Unbelivably founded project<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-JqFrcXFikVs/VLTFyI896XI/AAAAAAAACfc/_MkxxzqCFWo/s1600/powerup30.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-JqFrcXFikVs/VLTFyI896XI/AAAAAAAACfc/_MkxxzqCFWo/s1600/powerup30.jpg" height="492" width="640" /></a></div>
<br />
Looks like sometimes simple idea may become very popular and provide larger income that author can imagine to himself. This is exactly happened to the <a data-modal-class="modal_project_by" data-modal-title="Biography" href="https://www.kickstarter.com/projects/393053146/powerup-30-smartphone-controlled-paper-airplane/creator_bio">Shai Goitein</a>, author of Smartphone Controlled Paper Airplane on the KickStarter.<br />
<br />
<a name='more'></a>As a children we all crafted planes from the paper and hoped that it will fly as far as possible. But now just imagine that you paper plane has engine and you have an ability to control it. Sounds to great to be true ? Not with the Shai's invention !<br />
<br />
The idea behind the project is simple but still brilliant: Shai created Smart Module" that attached to the paper plane with the patented clips. Then you need to synchronize it with your phone. Simple as that !<br />
<br />
Among supported mobile you can find IOS and Android 4.3 or higher.<br />
<br />
Project raised $1.2M which $50.000 which may imply that a lot of us are just grown children :)<br />
<br />
<a href="http://www.kickstarter.com/projects/393053146/powerup-30-smartphone-controlled-paper-airplane" target="_blank">Link to project</a><br />
<br />Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-88355240746676879792015-01-15T02:00:00.000+02:002015-01-15T02:00:04.162+02:00Google Ventures Review 2013<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="" class=" " src="http://img.gv.com/wp-content/uploads/2013/08/bill-maris2.jpg?w=310&h=310&sharp=20&dpr=2&q=30&s=bf02f1e0ee0f75884946c0126aef1689" style="margin-left: auto; margin-right: auto;" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: x-small; text-align: start;"><a href="http://www.gv.com/team/bill-maris" target="_blank">Bill Maris</a> - </span><span style="font-size: x-small; text-align: start;">founded Google Ventures (GV) in 2009</span></td></tr>
</tbody></table>
<br />
<a name='more'></a><br />
<br />
Since then GV is one of the large investors in new ventures with $1.2 billion budget.<br />
<br />
In a list of the projects invested by GV , we can find <a href="http://www.astrid.com/">Astrid</a> (acquired by Yahoo), <a href="https://www.parse.com/">Parse </a>(acquired by Facebook), <a href="http://www.climate.com/">The Climate Corporation</a> (NASDAQ: FMI) and many others.<br />
<blockquote>
GV provides seed, venture, and growth-stage funding to the best companies — not strategic investments for Google.</blockquote>
Investment in start-ups come from the Google itself instead of external angels. In addition Google Ventures invest its money and resources in a variety of domains such as Enterprise, Mobile, Science, Consumer and others.<br />
<br />
As for some statistics:<br />
<ul>
<li>Since 2009 its invested in 225 companies in total (Most of them in mobile sphere - 28%).</li>
<li>In 2013 , 75 new companies got investment from GV.</li>
<li>9 Exists in 2013</li>
</ul>
Besides statistics and portfolio, useful articles could be found. For example you may read how GV helped Blue Bottle Coffee design a new website that boosted sales and time on site.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="" class=" " src="http://www.gv.com/wp-content/themes/google_ventures/images/case-studies/blue-bottle-header.jpg" height="412" style="margin-left: auto; margin-right: auto;" width="640" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: x-small; text-align: start;">Blue Bottle Design</span></td></tr>
</tbody></table>
<br />
More information can be found on <a href="http://www.gv.com/library/">site </a>of Google Investment.<br />
<br />
<br />
<br />
* All images taken from <a href="http://www.gv.com/" target="_blank" title="Google Ventures">GV </a>and belong to its authors.Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-78342474838634404762015-01-14T01:00:00.000+02:002015-07-13T13:46:08.415+03:00NFC Ring<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="http://4.bp.blogspot.com/-47ZVWkTpscE/VLTDIUhPGqI/AAAAAAAACfQ/DnVJVaYW8bs/s1600/nfc-ring.jpg" /></div>
<br />
<br />
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a>NFC technology is a data exchange format and based on existing radio frequency-identification (<a href="http://en.wikipedia.org/wiki/Radio-frequency_identification">RFID</a>) technology. RFID have a wide usage mostly among companies that working with a bulk of products on a daily basis.<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=427010772879381846" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><br />
<a name='more'></a><br />
Among them is a <a href="http://en.wikipedia.org/wiki/Wal-Mart" title="Wal-Mart">Wal-Mart</a>,Target,<a href="http://en.wikipedia.org/wiki/United_States_Department_of_Defense" title="United States Department of Defense">United States Department of Defense</a> and many others. NFC builds upon <a href="http://en.wikipedia.org/wiki/RFID" title="RFID">RFID</a> systems by allowing two-way communication between endpoints, where earlier systems such as <a href="http://en.wikipedia.org/wiki/Contactless_smart_card" title="Contactless smart card">contactless smart cards</a> were one-way only. Wikipedia<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="" src="https://s3.amazonaws.com/ksr/avatars/4784615/74727e3f7c917d6e68624758fbfa8d63.large.jpg?1371563295" style="margin-left: auto; margin-right: auto;" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: xx-small; text-align: start;">John McLear -inventor of NFC Ring</span></td></tr>
</tbody></table>
<br />
John McLear decided to run campaign on kickstarter in order to fund his new project related to the NFC technology. The idea of the project is sharing information in an easy and fun way, by the special ring. NFC Ring has two inlays, public and private. NFC Ring has 2 sensors (1 for public use and another for private use) and have no need to be charged.<a href="http://www.kickstarter.com/"><br />
</a><br />
<br />
As such it can be used to various daily tasks: unlock smartphone that supporting NFC, locks or unlock NFC doors. Ring allows to share links to web sites or WIFI passwords or even contact information.<br />
<br />
<a href="https://github.com/mclear/">Software</a> that comes with NFC Ring is <strong>open source</strong>, meaning you able to create programs or application for your own use.<br />
<br />
Kickstarter crowd funding model proved itself for many successful projects that chose it as alternative to the angels and VCs. In case of John he sets £30,000 as a goal, but succeeded to rise £240,000.<br />
<br />
<a href="http://www.kickstarter.com/projects/mclear/nfc-ring">Project </a>on kickstarter.<br />
<br />Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com1tag:blogger.com,1999:blog-427010772879381846.post-19382159984174312022015-01-13T08:56:00.000+02:002015-01-13T09:10:39.785+02:00CIRCUIT SCRIBE: DRAW CIRCUITS INSTANTLY<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-C4aIoPhkmKU/VLTBASliKAI/AAAAAAAACe8/XflpASLfZf8/s1600/Circuit-Scribe-Gift-1024x636.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-C4aIoPhkmKU/VLTBASliKAI/AAAAAAAACe8/XflpASLfZf8/s1600/Circuit-Scribe-Gift-1024x636.jpg" height="396" width="640" /></a></div>
<br />
<br />
<br />
<br />
There is a lot of interesting projects funded on <a href="http://www.kickstarter.com/">Kickstarter</a>. Today we will review some ambitious project which related to the electronic circuits.<br />
<br />
<br />
When some person wants to create <a href="http://en.wikipedia.org/wiki/Electronic_circuit">electronic circuit</a>, he requires some special electronic parts such as transistors, capacitors, diodes and <a href="http://en.wikipedia.org/wiki/Breadboard">breadboard</a>in order to test vitality of the design.<br />
<div>
<br />
<br />
<a href="http://2.bp.blogspot.com/-HFb-hrgGfzg/VLTBJtgz65I/AAAAAAAACfE/fHoUifTwg7U/s1600/circuit_scribe.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://2.bp.blogspot.com/-HFb-hrgGfzg/VLTBJtgz65I/AAAAAAAACfE/fHoUifTwg7U/s1600/circuit_scribe.jpg" height="353" width="640" /></a><br />
<br />
<br />
<br />
<a href="http://www.linkedin.com/in/analisarusso">Analisa Russo</a> from <a href="http://www.kickstarter.com/projects/electroninks/circuit-scribe-draw-circuits-instantly/creator_bio">Electroninks Incorporated</a> looked the way for creating low-cost, high-quality electronics that can be used for educational purposes as well as for life hacking or any other creative process. Analisa developed Circuit Scribe as part of her PhD work in Illinois University.<br />
<br />
<br />
So what is that Circuit Scribe we talking about ? Actually it is a roller-ball pen that writes with conductive non-toxic, water-based silver ink. It allows to create clear smooth ink lines on the paper. A pen is drying instantly and has no smell .<br />
<br />
<br />
Another great attribute of this project is that it is an Open-Source project. It allows to use Circuit Scribe with Arduino, Makey Makey, and many other electronic platforms.<br />
<br />
<br />
So why Kickstarter ? Since the authors of this projects wants to make it affordable to many people, they need to manufacture Circuit Scribe at a large scale. Another reason is to build an online education portal for Circuit Scribe. It will be relevant platform for kids, educators, & makers with activities, lesson plans, and user-submitted projects.<br />
<br />
<br />
Interesting fact that project’s goal was at $85,000.Till now project funded on Kickstarter more then $670,000 !<br />
<br />
<br />
Source : <a href="http://www.kickstarter.com/projects/electroninks/circuit-scribe-draw-circuits-instantly">KickStarter</a></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-88112427596265501142015-01-12T13:38:00.000+02:002015-01-13T08:56:41.848+02:00Blog design is updated<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-MuzILkC_2_Y/VLOyJx-KUkI/AAAAAAAACdw/vEEe4p_iAQw/s1600/FixIt_working.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-MuzILkC_2_Y/VLOyJx-KUkI/AAAAAAAACdw/vEEe4p_iAQw/s1600/FixIt_working.png" height="326" width="640" /></a></div>
<br />
<br />
There are passed a lot of time since i wrote my last post. I was busy at work (apparently project management isn't easy as it look like :) ) so i decided to be more active and to continue publishing posts more frequently then now.<br />
<br />
Anyway i changed UI design and i hope it will be more attractive and convenient for my readers and for me as well. I still need to fix some small details like pictures re-sizing and etc. Anyway it already starting looking good :)Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-15816403772792710592013-07-08T19:29:00.001+03:002015-01-13T08:57:23.244+02:00Simple examples in DART<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.dartlang.org/imgs/dart-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.dartlang.org/imgs/dart-logo.png" height="480" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
A week ago i was looking to make some project of mine and it led me somehow to the Dart. At my opinion, the best way to get familiar with new development lang is to code some small program. So i would like to share three very basic examples i coded:<br />
<br />
1. Chart Graph<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-JJ9t7DdYCWQ/Udrmv0a_CfI/AAAAAAAABJU/nv782Hg4OG0/s1600/pie_chart.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-JJ9t7DdYCWQ/Udrmv0a_CfI/AAAAAAAABJU/nv782Hg4OG0/s200/pie_chart.png" height="200" width="170" /></a></div>
The usage is very simple: you provide data and colors for each data. Data is numbers (like you see on the picture), colors is color for each data respectively.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
2. Clock Widget which looking like following :<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-rUcffcoBlwo/UdrincePu8I/AAAAAAAABJE/_Rg_M5qsZ68/s1600/2bpmg.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-rUcffcoBlwo/UdrincePu8I/AAAAAAAABJE/_Rg_M5qsZ68/s200/2bpmg.gif" height="200" width="156" /></a></div>
The idea behind this clock was that inner arc represent hour, medium arc represent minutes and the most external represent seconds. Each arc "closing" its radius (0 - 360 degrees) and then arc disappear and starting again. Inside we can see running clock. Unlike traditional watch, mine finish its cycle not on the top, but one the right side :)<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
3. Image Filter<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-aFHHkACAjs4/Udrn9SPBAUI/AAAAAAAABJk/wADSBxuOSwo/s1600/image_filter_dart.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-aFHHkACAjs4/Udrn9SPBAUI/AAAAAAAABJk/wADSBxuOSwo/s200/image_filter_dart.png" height="86" width="200" /></a></div>
Here i playing with pixels. A little bit tricky for understanding. Important to mention that each pixel represented by 4 params: R,G,B,alfa.<br />
<br />
<br />
<br />
<br />
The reason i publishing it, is that for someone it can give a little boost in the Dart. Anyway any comments are welcomed.<br />
<br />
All examples working for M5 dart version!<br />
<br />
All examples can downloaded it from <a href="https://github.com/jviaches/jDartExamples/archive/master.zip" target="_blank">here</a>. Good luck :)</div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-79104445058819553522013-07-05T00:06:00.004+03:002015-01-13T08:57:32.035+02:00Draw Image on Canvas in Dart<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.dartlang.org/imgs/dart-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.dartlang.org/imgs/dart-logo.png" height="275" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
I was looking for display image within canvas via dart. The problem is that the most trivial solution crossed my mind was :<br />
<br />
<pre class="brush:c#">CanvasElement context = query("#canvasImage");
CanvasRenderingContext2D ctx = context.context2D;
ImageElement image = new ImageElement(src: "myImage.jpg");
ctx.drawImage(image, x, y);
</pre>
<br />
But the problem that it is simply not working. So i came up with the following full functional solution :)<br />
<br />
<pre class="brush:c#">import 'dart:html';
CanvasElement context = query("#canvasImage");
CanvasRenderingContext2D ctx = context.context2D;
ImageElement image = new ImageElement(src: "myImage.jpg");
void main() {
drawImage();
}
void drawImage(){
var x = context.width / 2;
var y = context.height /2;
image.onLoad.listen(onData, onError: onError, onDone: onDone, cancelOnError: true);
}
onData(Event e) {
print("success: ");
ctx.drawImage(image, 0, 0);
}
onError(Event e) {
print("error: $e");
}
onDone() {
print("done");
}</pre>
<pre class="brush:c#"></pre>
<pre class="brush:c#"><span style="font-family: 'Times New Roman'; white-space: normal;">Examples working for M5 dart version!</span></pre>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-51400900451074580462013-05-16T13:26:00.000+03:002013-05-16T13:26:02.839+03:00Filter columns in DataGridRecently i have encountered in some issue filtering columns in DataGrid. That can be achieved by following code :<br />
<br />
<a href="http://4.bp.blogspot.com/-4G0Ws5q8fsY/UZSisZkciqI/AAAAAAAABEQ/ne5haFRB2wg/s1600/datagrid_incorrect_filter_code.png" imageanchor="1"><img border="0" height="468" src="http://4.bp.blogspot.com/-4G0Ws5q8fsY/UZSisZkciqI/AAAAAAAABEQ/ne5haFRB2wg/s640/datagrid_incorrect_filter_code.png" width="640" /></a><br />
<br />
The result of such code may look like following:<br />
<br />
<a href="http://4.bp.blogspot.com/-xrAczrJIJ5g/UZSh501IMsI/AAAAAAAABEI/kqO6OfYeRAA/s1600/DataGrid1.png" imageanchor="1"><img border="0" src="http://4.bp.blogspot.com/-xrAczrJIJ5g/UZSh501IMsI/AAAAAAAABEI/kqO6OfYeRAA/s320/DataGrid1.png" /></a><br />
<br />
But there is some problem with this code :<br />
<br />
<ul>
<li>When clicking on any column, we don't see any feedback it was clicked</li>
<li>No filter applied when clicked on column anyway</li>
</ul>
<div>
Actually the solution is very basic, although it need to be explained a little:</div>
<div>
<blockquote class="tr_bq">
We defined CanUserSort on each DataGrid column. We defined CanUserSortColumns in whole DataGrid as well. But there we miss something small but important detail: Since we defined DataGridTemplate and we didn't define how we would like to sort, WPF doesn't know the way to sort for us our items.</blockquote>
</div>
<div>
<br /></div>
<div>
In order to explain him, we should add property (SortMemberPath ="Property_name") in each DataGridTemplateColumn. So the following code will look similar to this:</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-tg5ILIDOMag/UZSmdTx50sI/AAAAAAAABEs/ByXv8KfpRLM/s1600/correctCode.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="468" src="http://3.bp.blogspot.com/-tg5ILIDOMag/UZSmdTx50sI/AAAAAAAABEs/ByXv8KfpRLM/s640/correctCode.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-chx51QT_2YU/UZSl6Z-Ce_I/AAAAAAAABEk/CSEoZyUHlIk/s1600/datagrid_correct_filter_code.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="214" src="http://2.bp.blogspot.com/-chx51QT_2YU/UZSl6Z-Ce_I/AAAAAAAABEk/CSEoZyUHlIk/s320/datagrid_correct_filter_code.png" width="320" /></a></div>
<div>
As we can see we do get feedback when pressing on the specific columns and our items just sorted as we required !</div>
<div>
<br /></div>
<div>
P.S. Reason i have used images when introducing the code is the in the plain code part of the symbols was deleted by the blog engine.</div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-42222878747413358432013-03-25T13:13:00.002+02:002015-07-15T08:09:46.585+03:00Inspiration and creativity<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-vo1VQak15qw/VLO7ys-PZjI/AAAAAAAACeM/kzGM2R5RXrk/s1600/inspiration.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://4.bp.blogspot.com/-vo1VQak15qw/VLO7ys-PZjI/AAAAAAAACeM/kzGM2R5RXrk/s1600/inspiration.png" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-XC2y3cGCfyQ/UVAXUeGNZlI/AAAAAAAAA-Q/KDsjNj_aJXs/s1600/inspiration.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://3.bp.blogspot.com/-XC2y3cGCfyQ/UVAXUeGNZlI/AAAAAAAAA-Q/KDsjNj_aJXs/s1600/inspiration.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://3.bp.blogspot.com/-XC2y3cGCfyQ/UVAXUeGNZlI/AAAAAAAAA-Q/KDsjNj_aJXs/s1600/inspiration.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<br />
On my opinion, inspiration is related directly to the creativity. When inspired, person feels less limitations than in regular situations and it can allow him to see daily basis routine just in different way.<br />
<br />
Inspiration bring with itself a mix of great and healthy feeling which can vary from person to person. For someone it is calm, happiness, ability to see ordinal thing in more wide spectrum. For other it can bring energy, willing to create or try different thing he is never tried before!<br />
<br />
Be optimistic can lead us directly to the inspiration which actually part of creativity. There is no creativity, if non inspiration is involved!<br />
<br />
On my opinion inspiration is state of mind that have a great influence on our mood, point of view, how we see surroundings or how we react to the external factors.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-UFElg-XVYVA/UVArZs6McII/AAAAAAAAA-g/9I_zMuQTrLI/s1600/Life.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-UFElg-XVYVA/UVArZs6McII/AAAAAAAAA-g/9I_zMuQTrLI/s1600/Life.jpg" /></a></div>
<br />
<br />
So it lead us to the next challenge: how we constantly reproduce inspiration ?<br />
<br />
I see following ways to keep our inspiration (of course it is very personal):<br />
<br />
<blockquote class="tr_bq">
1. Listen music that make you happy. It does not really matter what music it is. The key is, it does make you feel great!</blockquote>
<br />
<blockquote class="tr_bq">
2. Surround yourself with those kind of people. Let sad and crying people disappear from your life. Connect to happy and active people. Collaborate. Sometimes their look or smile or small talk will give you push to the right direction.</blockquote>
<br />
<blockquote class="tr_bq">
3. Be <a href="http://en.wikipedia.org/wiki/Proactivity" target="_blank">proactive</a>. Turn TV/PC off. Go walk on the fresh air. Any routine action we produce, put us on specific track were we stop thinking and doing mechanical actions. Stop live by <a href="http://en.wikipedia.org/wiki/Cognitive_inertia" target="_blank">inertia</a>.</blockquote>
<br />
<blockquote class="tr_bq">
4. Do something different/exceptional. It means be also open minded! To think different, to considerate, to take view of another person.</blockquote>
What are your ways ?<br />
<br />
P.S.<br />
I am sure there are a lot of others ways to constantly reproduce inspiration. I wanted just to show some point :) So be keep your inspiration back on track and <u>always </u>stay creative !<br />
<br />Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-8949317152484293752013-03-23T01:15:00.000+02:002015-01-13T08:57:55.314+02:00Android Fragment and how it relate to the fragmentation<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ASTMj-iywE8/VLO8vUuh_4I/AAAAAAAACeY/RAFTATw4ot8/s1600/android_logo_520.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-ASTMj-iywE8/VLO8vUuh_4I/AAAAAAAACeY/RAFTATw4ot8/s1600/android_logo_520.png" height="352" width="640" /></a></div>
<br />
<br />
After <a href="https://play.google.com/store/apps/details?id=com.delph.vrec.lite&hl=en" target="_blank">my first application</a> which was developed for version 2.x i decided that it is a good time to get know better an android API versions 4.x. So i decided to develop some program in order to take a trip for a most interesting and core features in android 4.x.<br />
<div>
<br /></div>
<div>
This is led me to the <a href="http://developer.android.com/guide/components/fragments.html" target="_blank">Fragments</a>. Actually fragments were introduces in Honeycomb (ver 3.0 and higher), but i haven't encountered with them than. Anyhow i felt that it is a good opportunity to know them "from the close distance" :) </div>
<div>
<br /></div>
<div>
It took me some time to understand what does fragmentation means. I read regarding fragment and its life cycle and it looks like it would take a couple of minutes to implement some fragments into my app. But there was a surprise :)</div>
<div>
<br /></div>
<div>
Apparently there were two implementation of Fragments. First one was related to android version below v 3.0 and the second one was for versions higher then android 3.0. At this point i stoping intimidate you and just gonna introduce key differences.</div>
<div>
<br /></div>
<div>
The key differences are:</div>
<div>
<blockquote class="tr_bq">
<ul>
<li><b><u>Fragments prior android version 3.0</u></b></li>
</ul>
<ul>
<li>In order to use Fragments you have to use <a href="http://developer.android.com/tools/extras/support-library.html" target="_blank">Support Package</a> and use <a href="http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html" target="_blank">FragmentActivity</a>.</li>
</ul>
<ul>
<li>getSupportFragmentManager() to get android.support.v4.app.FragmentManager</li>
</ul>
<ul>
<li>getSupportLoaderManager() to get android.support.v4.app.LoaderManager</li>
</ul>
</blockquote>
<blockquote class="tr_bq">
<ul>
<li><b><u>Fragments higher then android version 3.0</u></b></li>
</ul>
<ul>
<li>Use <a href="http://developer.android.com/reference/android/app/Activity.html" target="_blank">Activity </a>instead of FragmentActivity to hold Fragments</li>
</ul>
<ul>
<li>getFragmentManager() to get android.app.FragmentManager</li>
</ul>
<ul>
<li>getLoaderManager() to get android.app.LoaderManager</li>
</ul>
</blockquote>
<br />
Some tips and advises:<br />
<blockquote class="tr_bq">
1. Sometimes better to declare implicit everything related to fragments: Fragment, FragmentManager and etc..<br />
2. If you working prior android 3.0, please make sure that you don't have following imports:<br />
import android.app.Fragment;<br />
import android.app.FragmentTransaction;<br />
but you have android.support.v4.app.fragment and such..</blockquote>
<br />
P.S.<br />
<blockquote class="tr_bq">
1.I will update tips and advises constantly :)<br />
2. I always would like to hear your opinion.</blockquote>
<br /></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-20829882279592456822013-03-17T13:14:00.000+02:002015-01-13T08:58:04.869+02:00Exposure to android development<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ASTMj-iywE8/VLO8vUuh_4I/AAAAAAAACeY/RAFTATw4ot8/s1600/android_logo_520.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-ASTMj-iywE8/VLO8vUuh_4I/AAAAAAAACeY/RAFTATw4ot8/s1600/android_logo_520.png" height="352" width="640" /></a></div>
<br />
<br />
Lately i was asked to provide explanation regarding Android development in company i working for, in order to let to other people (mostly for developers, but not only) some taste of mobile development.<br />
<br />
For that reason i maid some presentation which included general overview of various android development aspects : some mobile devices statistics, a bit of development, Google Play (market) and some of promoting tips.<br />
<br />
Most of information was in speech, the presentation included just main points. If you find it useful, have some questions or propositions, please leave a message here or mail me :)<br />
<br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/17276892" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/Delph/exposure-to-android-development" target="_blank" title="Exposure to Android Development">Exposure to Android Development</a> </strong> from <strong><a href="http://www.slideshare.net/Delph" target="_blank">Jviaches</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-81950024122420332722013-02-12T09:17:00.002+02:002015-01-13T12:22:55.102+02:00Leap Motion Development - Connection and Initialization<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-1SJRvD1fOSs/URnoJjsc3oI/AAAAAAAAA5w/xZz_dyWNh78/s1600/leapMotion1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a><a href="http://1.bp.blogspot.com/-1SJRvD1fOSs/URnoJjsc3oI/AAAAAAAAA5w/xZz_dyWNh78/s1600/leapMotion1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a><a href="http://1.bp.blogspot.com/-1SJRvD1fOSs/URnoJjsc3oI/AAAAAAAAA5w/xZz_dyWNh78/s1600/leapMotion1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a><a href="http://1.bp.blogspot.com/-1SJRvD1fOSs/URnoJjsc3oI/AAAAAAAAA5w/xZz_dyWNh78/s1600/leapMotion1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-1SJRvD1fOSs/URnoJjsc3oI/AAAAAAAAA5w/xZz_dyWNh78/s640/leapMotion1.jpg" height="480" width="640" /></a></div>
Yesterday i finally got my new Leap Motion dev board. Since i always very interesting in various fields and aspects in development, i was very curious regarding this device capabilities.
<br />
<br />
<br />
<a name='more'></a><br /><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-9SxY85XMYlg/URnoLRGr5HI/AAAAAAAAA54/sAjI2MkCnqQ/s1600/leapMotion2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-9SxY85XMYlg/URnoLRGr5HI/AAAAAAAAA54/sAjI2MkCnqQ/s640/leapMotion2.jpg" height="480" width="640" /></a></div>
As expected when the box was opened and device was connected, I have installed drivers for the device (device come along downloaded SDK from <a href="https://developer.leapmotion.com/">https://developer.leapmotion.com</a>). After that i have created simple console project as explained <a href="https://developer.leapmotion.com/documentation/guide/Sample_C%23_Tutorial" target="_blank">here</a>. Since i Have Windows 8 x64 and Visual Studio 2012, i tried to run this project. It took me some time to understand what dll's should be involved and what their exactly location should be. So I would like to share this knowledge since i think i am not the only one who get lost a bit. Instructions:
<br />
<ul>
<li>1. Create simple project as explained <a href="https://developer.leapmotion.com/documentation/guide/Sample_C%23_Tutorial" target="_blank">here</a>.</li>
<li>2. Add reference to LeapCSharp.NET4.0.dll or LeapCSharp.NET3.5.dll (depends on what .NET version you are using) to your project. Those dlls can be found inside SDK - "Leap_Developer_Kit_0.7.3_2234_Windows\Leap_SDK\lib"</li>
<li>3. Copy all folder x64 inside your bin/debug folder as folder.</li>
<li>4. Run project and enjoy :)</li>
</ul>
<br />
At this point i exploring SDK to understand how things should be done :)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://0.gvt0.com/vi/_d6KuiuteIA/0.jpg" height="266" width="320"><param name="movie" value="http://www.youtube.com/v/_d6KuiuteIA&fs=1&source=uds" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="http://www.youtube.com/v/_d6KuiuteIA&fs=1&source=uds" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0tag:blogger.com,1999:blog-427010772879381846.post-29852005445587125862013-01-27T17:15:00.003+02:002015-01-13T08:58:13.679+02:00Windows 8 Hebrew to English<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-ivbDKfvkr_s/VLO-Y0knf0I/AAAAAAAACek/aDeoJW01mjE/s1600/windows-8-logo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-ivbDKfvkr_s/VLO-Y0knf0I/AAAAAAAACek/aDeoJW01mjE/s1600/windows-8-logo.jpg" height="320" width="640" /></a></div>
<br />
<br />
Today i will show how possible to turn Windows 8 Hebrew Edition to English one.<br />
Actually 3 main problem were the reason i looked the way to switch Windows 8 to English version:<br />
<br />
<ol>
<li>Close button in every window is located in the upper left corner. Its quite annoying especially after years working with close button located on the upper right corner. I am not really need it, since i working with shortcuts a lot, but still.. It just annoying :)</li>
<li>Menu bar on the desktop is looks reversed. In English version task-bar clock should be on the bottom left side, where in Hebrew version it located on the bottom left. Annoying as well.</li>
<li>Main GUI in Windows 8. In English version groups of icons arranged automatically from left to right, were in Hebrew version it quite opposite. Super annoying!</li>
</ol>
<div>
So lets see how we can switch Windows 8 Hebrew Edition to English one.</div>
<div>
<br /></div>
<div>
- In Hebrew version take your mouse to the bottom left side until some menu will pop up:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-E6JOYjJSwHY/UQVBhQWP4OI/AAAAAAAAA44/VzHxe5wpyIw/s1600/ChangeLang_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-E6JOYjJSwHY/UQVBhQWP4OI/AAAAAAAAA44/VzHxe5wpyIw/s320/ChangeLang_1.png" height="320" width="36" /></a></div>
<div>
and choose the item is shown in the picture.<br />
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Then in next widow choose option as shown on the picture bellow:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-eXtZdBSlwrU/UQVB-dez1mI/AAAAAAAAA5A/Yt7ebkn_WUw/s1600/ChangeLang_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-eXtZdBSlwrU/UQVB-dez1mI/AAAAAAAAA5A/Yt7ebkn_WUw/s400/ChangeLang_2.png" height="400" width="250" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Then in next widow choose option as shown on the picture bellow:</div>
<div class="separator" style="clear: both; text-align: left;">
1.</div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://2.bp.blogspot.com/-706Rr2dQsXQ/UQVCL1Ttc3I/AAAAAAAAA5I/ySQ4v-5_AC0/s1600/ChangeLang_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-706Rr2dQsXQ/UQVCL1Ttc3I/AAAAAAAAA5I/ySQ4v-5_AC0/s400/ChangeLang_3.png" height="175" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
2.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-ri95v7pvqr0/UQVCndMgEnI/AAAAAAAAA5Q/kA1ZTZQRwUw/s1600/ChangeLang_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-ri95v7pvqr0/UQVCndMgEnI/AAAAAAAAA5Q/kA1ZTZQRwUw/s400/ChangeLang_4.png" height="81" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
3. </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-7QtCNOXoDro/UQVCtw8LsiI/AAAAAAAAA5Y/tmU4yhDE9c8/s1600/ChangeLang_5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-7QtCNOXoDro/UQVCtw8LsiI/AAAAAAAAA5Y/tmU4yhDE9c8/s400/ChangeLang_5.png" height="210" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
When you double click item as shown on picture above, will ask from you to download English version.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-JBWRRXMXKXw/UQVDKImUejI/AAAAAAAAA5g/RTdXti5wNZw/s1600/ChangeLang_10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-JBWRRXMXKXw/UQVDKImUejI/AAAAAAAAA5g/RTdXti5wNZw/s320/ChangeLang_10.png" height="228" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
After downloading and updating process is done, siply reboot your PC and you up to work :)</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I hope it simple tutorial helpful for you.</div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com1tag:blogger.com,1999:blog-427010772879381846.post-87267254803403121322013-01-14T21:42:00.001+02:002015-07-14T23:27:27.274+03:00Code optimizations in .NET on MSIL level<h2>
Introduction </h2>
<div>
<br /></div>
The purpose of the article is to get familiar with compiler optimization in .Net. This is a brief overview that should give you a start vector and to introduce some basic showcases. Article is intended for beginners+ level.<br />
<br />
I hope you find useful this article.<br />
<br />
<h2>
Points of Interest </h2>
<div>
<br /></div>
When we write a code, its eventually transformed into machine code and its able to run, provide some outputs or demand some input from user following its business logic that we put it in our code.<br />
<br />
But the question, is exactly our code was transformed into machine code as we wrote it or there were some changes in the middle of the way in our code. The short answer is yes, some code change was occur. The idea behind that is very simple: .NET optimize code before it turns into machine code. Before we will dive in examples and explanation, lets try understand whole process.<br />
<br />
When we compile and run:<br />
<br />
<ol>
<li>1. CLR (Common Language Runtime) transform our code into MSIL (Microsoft Intermediate Language).</li>
<li>2. CLR compile MSIL into platform-specific code.</li>
<li>3. In case we run program, MSIL turns into machine code by JIT.</li>
</ol>
<div>
<br />
I know may for some of you it will sound complicated and for some of you its just collection of Chars (CLR,MSIL,JIT...), but do not worry! We interested only in first step, which is compiler optimizations.
<br />
<br />
Now lets see some example:<br />
<br />
<pre class="brush:c#">using (TextWriter w = File.CreateText("log.txt"))
{
w.WriteLine("This is line one");
}
</pre>
<br />
Lets try to remember what is 'using' for in this context with inner scope. In case we have some resources that we should release as quick as possible, we will use "using" in such statement (with using like this).<br />
<br />
And the reason we will do it, because it will ensure that those resources will be released right after exiting from the scope (by invoking Dispose() method). Actually this is short form will be translated later in form like following:<br />
<br />
<pre class="brush:c#">
bool flag;
TextWriter w = File.CreateText("log.txt");
try
{
w.WriteLine("This is line one");
}
finally
{
flag = w == null;
if (!flag)
{
w.Dispose();
}
}</pre>
<br />
Looks like after optimization, this code looks much convenient.<br />
<br />
By the way:<br />
<pre class="brush:c#"> for (int i = 0; i < 3; i++)
{
Console.Write(i);
}
</pre>
<br />
After optimization will looks like following:<br />
<pre class="brush:c#"> bool flag;
int i = 0;
while (true)
{
flag = i < 3;
if (!flag)
{
break;
}
Console.Write(i);
i++;
}
</pre>
<h2>
</h2>
<h2>
How to see code after optimization
</h2>
</div>
<div>
<br /></div>
<div>
I used <a href="http://www.telerik.com/products/decompiler.aspx" target="_blank">JustDecompile </a>from <a href="http://www.telerik.com/" target="_blank">Teleric</a>. After instalation it will look like this(ver. 2012.3.1119.12).</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-TqYn6xsJcVM/UPCckm6421I/AAAAAAAAA1w/VXWOIUKvy9o/s1600/JustDecompile.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="384" src="http://2.bp.blogspot.com/-TqYn6xsJcVM/UPCckm6421I/AAAAAAAAA1w/VXWOIUKvy9o/s640/JustDecompile.bmp" width="640" /></a></div>
<div>
<br /></div>
<div>
Create Console Application and put following code in Main() method and press F5:
<br />
<pre class="brush:c#">using (TextWriter w = File.CreateText("log.txt"))
{
w.WriteLine("This is line one");
}
</pre>
<br />
Now press Open button in JustDecompile and then File(s) and choose exe file from project you just build (usualy can be found in ..... /Bin/Debug/) Expand left panel of the JustDecompile application as shown and you will see the desired result:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-MQ6Jo4mnLD0/UPCgijgtY_I/AAAAAAAAA2E/IhEBJUp7ZAs/s1600/JustDecompile_final_result.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="384" src="http://1.bp.blogspot.com/-MQ6Jo4mnLD0/UPCgijgtY_I/AAAAAAAAA2E/IhEBJUp7ZAs/s640/JustDecompile_final_result.PNG" width="640" /></a></div>
<br />
<h2>
What Next:</h2>
</div>
<div>
Next is your practice. Experiment and get you knowledge more sharp.</div>
<div>
Thank you for your patience !</div>
Anonymoushttp://www.blogger.com/profile/15998539657143569440noreply@blogger.com0