Archive for category development

Toast message for Xamarin Forms

toastdemo_androidtoastdemo_ios

Quick and easy solution for toast messages in Xamarin Forms, it supports iOS and Android platforms. Toast message provides simple feedback in a small popup (which is disappearing in some seconds) like on the screenshots on the left (Android) and the right (iOS) sides.


Read the rest of this entry »

, , , , , , , , , ,

3 Comments

Localization for GOLANG

I created and published small package to be used for localization of go applications, you can find it here https://github.com/bykovme/gotrans

Installation

Install the package with the command

go get github.com/bykovme/gotrans

Prepare translation files

JSON files should use following format as in the example below:

{
    "hello_world":"Hello World",
    "find_more":"Find more information about the project on the website %s"
}

JSON file name should use standard language code or language-country code supported by browsers, if you are developing web app. At least one file with English locale should be in the localization folder with the name “en.json”.

Quick documentation

There are just 3 functions in the package

InitLocales(path string)

Use the relative or absolute path to set the folder where all the JSON files with translations are located. Make sure that all the files with translations have extension “.json”

Tr(lang string, key string) string

Get translation value by the language & key

DetectLanguage(acceptLanguage string) string

This function will be useful when you are creating web application, it detects the language from HTTP header Accept-Language, check the usage of the function in the example below

Example of using gotrans package

The same example is located within the package here

package main

import (
    "fmt"
    "net/http"

    "github.com/bykovme/gotrans"
)

func handler(w http.ResponseWriter, r *http.Request) {
    lang := gotrans.DetectLanguage(r.Header.Get("Accept-Language"))
    fmt.Fprintf(w, "<html><head><title> %s </title></head><body>", gotrans.Tr(lang, "hello_world"))
    fmt.Fprintf(w, "<h2> %s </h2>", gotrans.Tr(lang, "hello_world"))
    githubLink := "https://github.com/bykovme/gotrans"
    link := fmt.Sprintf(`<a href="%s">%s</a>`, githubLink, githubLink)
    fmt.Fprintf(w, gotrans.Tr(lang, "find_more"), link)
    fmt.Fprint(w, "</body></html>")
}

func main() {
    err := gotrans.InitLocales("langs")
    if err != nil {
        panic(err)
    }

    http.HandleFunc("/", handler)
    http.ListenAndServe(":3000", nil)
}

Behaviour

If the key is not found in the localization file, it will try to find the same key in English localization (“en.json”), if the key is not found there as well, the key will be returned instead of value.

, , , , , ,

Leave a comment

How to use https on Google App Engine for all requests for custom domain

Before use the settings below, make sure that you uploaded and assigned appropriate SSL certificate to your app project.

Forcing GAE to use https is very easy, just need to mention the option “secure” with value “always” in “app.yaml” file (other options are “optional” for using both http & https (default behavior) and “never” for using http only), the example below in for golang app, the same approach is used for other languages.

application: your-app-here
version: 1
runtime: go
api_version: go1

- url: /.*
  script: _go_app
  secure: always

, , , ,

Leave a comment

Setting SSL certificate for Google App Engine

Help on the topic can be found here: https://cloud.google.com/appengine/docs/python/console/using-custom-domains-and-ssl

Telling long story shortly:

1. Generate key & signing request with the command

openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr

2. Send “server.csr” file to your favorite certificate issuer and receive .crt files

3. Convert your private key into the format google requires:

openssl rsa -in myserver.key -out private.key.pem

4. Concatenate all .crt file into one

cat www_example_com.crt ASecureServerCA.crt ATrustCA.crt ATrustExternal.crt > public.crt

5. Upload public.crt & private.key.pem in google cloud console

6. Map your certificate with the website and enjoy.

, , ,

1 Comment

Night Notes MD – welcome to the world of open source

Last years I’m using my own cross platform app (developed with QT/C++) to write and keep notes on my Mac and Windows computers, it is simple markdown editor/viewer which turns any your folder with text or markdown files into convenient app.

Additional features on top of standard Markdown:

  • internal links
  • keeping passwords, copying the password to clipboard by clicking links

Today I decided to give the app to the world and  make it open source

Screen Shot 2016-06-01 at 18.45.05

Link to the project: https://gitlab.com/bykovme/nightnotes

If you want to try the app immediately, you can download dmg and install the app on your Mac OSX from here: https://gitlab.com/bykovme/nightnotes/tree/master/Downloads/Mac

Enjoy

, , ,

Leave a comment

How to debug if you use goapp instead of go

I recently switched my editor for GOLANG from Sublime Text to Visual Studio Code using it together with plugin vscode-go. It is working perfectly and now there is much more pleasant to code in this IDE using GO. But I still missed one feature: debugger. vscode-go supports  visual debugging using delve but the issue is that I’m developing with go both for google application engine (GAE) and creating also usual go programs, dalve refused to work when I was trying to debug usual GO programs using GOAPP (I have just a symlink from ‘go’ to ‘goapp’ in SDK, no separate go is installed) giving me the following error:

couldn't detect GO version

Looks like the parser of dalve couldn’t detect version of GO because google adds to it additional information and the output of the command ‘go version’ looks like

go1.6 (appengine-1.9.35)

instead of the standard

go1.6

So, I decided that it can be fixed easily and found this check in the file go_version.go

Next thing I did, I just added the code below  in the check to remove this part “(appengine-1.9.35)” from version information, the change should go in line 27 just after ‘if strings.HasPrefix(ver, go) {‘ in the file go_version.go

    indexStart := strings.Index(ver, "(")
    if indexStart > 0 {
        indexEnd := strings.Index(ver, ")")
        if indexEnd > indexStart {
            ver = ver[:indexStart] + ver[indexEnd+1:]
            ver = strings.Trim(ver, " ")
        }
    }

Then I compiled/installed dalve  again and my debugger inside of Visual Studio Code started to work!

Enjoy!

, , , , , ,

Leave a comment

Setup Sublime Text to work with golang and Google App Engine (mac)

If you want to create applications with GO, deploy them to google app engine and use Sublime Text as your IDE then this step-by-step tutorial is for you (tutorial is  for Mac but it can be used for other platforms)

Step 0:

Download and install golang SDK from Google:
https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go

Unpack it somewhere (I usually use the folder “$HOME/SDKs”)

Step 1:

Install Sublime Text 3, you can find it here:
https://www.sublimetext.com

Step 2:

Install package control for Sublime Text, find all relevant information about installation process here: https://packagecontrol.io/installation

Step 3:

Install GoSublime package: https://github.com/DisposaBoy/GoSublime

Press cmd+shift+p, type ‘Package Control: Install Package’ or select it from the list, then type GoSublime and install the package

Step 4:

Setup  variables GOROOT & GOPATH in your environment (put the information below into .bash_profile on Mac/Linux)

Type in command line

cd ~
open .bash_profile -a "Sublime Text"

And add following lines to the end of the file

# Change the variables below to the path where you installed go_appengine
export GOSDK=/Users/user/SDKs/go_appengine
export GOROOT=$GOSDK/goroot
export GOPATH=$GOSDK/gopath
export PATH=$GOSDK:$GOROOT/bin:$PATH

Step 5:

Go to $GOROOT/bin & $GOROOT/pkg folders and execute the a commands below to create appropriate symlinks (GoSublime does not know anything about ‘goapp’, it knows only about ‘go’, we should simulate it)

cd $GOROOT/bin
ln -s goapp go
cd $GOROOT/pkg
ln -s darwin_amd64_appengine darwin_amd64

Step 6:

Create your first go app for GAE: create folder somewhere and create there 2 files, hello.go with the following content

package hello

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, world!")
}

and app.yaml with the following content (change gae-app-name-hello to real gae ID before deploying!)

application: gae-app-name
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

If you did everything correctly then your Sublime Text should have code completion and console to run go commands. Press in Sublime Text cmd+9 and type ‘build’ in the console, it should compile and build your app. If build is successful then go to terminal and type in the app folder ‘goapp serve’, the app will run locally, you can check it with your web browser on the link http://localhost:8080

Step 7:

Deploy your app using command ‘goapp deploy’ in your app folder (do not forget to perform all the prerequisites to setup app engine, check this link for more info: https://cloud.google.com/appengine/docs/go/gettingstarted/uploading)

Enjoy!

, , , , , , ,

Leave a comment