Warning: Use of undefined constant _FILE_ - assumed '_FILE_' (this will throw an Error in a future version of PHP) in /home/bolyarco/www-ikratko/ogrelab/wp-content/plugins/ad-blocker-stats-vip/ad-blocker-stats-vip.php on line 13

Zoneminder configuration for Floureon 1080P

2017-11-21   

Recently I bought Floureon 1080P 18x. I was planning to use it to test an idea about car license plate recognition. The camera came with software for Windows which was no go for me because I was planning to use Ubuntu linux. After spending some time looking for a linux software to control the cam I found Zoneminder. It is free and open source but it lacked support for Floureon cameras. Long story short, I had to make some additions to Zoneminder in order to make it work.

Here is a simple guide:

… more / още »

Sending new transfer (create transaction) to IOTA node using Java (aka sendTransfer)

2017-09-10   

Due to the lack of any official documentation it is hard to start using IOTA. Here you will find a short tutorial about sending transfer (i.e. creating transaction) and checking it's status.

I am assuming that you use Intellij IDEA.

Project setup

1. Create new gradle project

2. Add following dependencies to your build.gradle:

compile 'com.github.iotaledger:iota.lib.java:f43d606'
compile 'ch.qos.logback:logback-classic:1.2.3'

 

Building IotaAPI

In order to execute commands against IOTA node you have to create an IotaAPI instance. IotaAPI is the client that connects to a node and provides you the services of IOTA.

api = new IotaAPI.Builder().protocol(PROTOCOL).host(HOST).port(((Integer) PORT).toString()).build();

where PROTOCOL, HOST and PORT are constants defining the node's address.

Preparing and sending a transfer

For the sake of simplicity here we will send "empty" transfer, i.e. with value = 0.

The code:

List transfers = new ArrayList<>();  // (1)
Transfer t = new Transfer(ADDRESS_TO,  // (2)
        0, // (3)
        TrytesConverter.toTrytes("some msg"), // (4)
        "999999999999999999999999999"); // (5)
transfers.add(t);  // (6)
SendTransferResponse resp = api.sendTransfer(SEED, // (7)
        2, // (8)
        9, // (9)
        15, // (10)
        transfers, // (11)
        null,  // (12)
        ADDRESS_REMAINDER);  // (13)

First we need to prepare the transfer(s).

(1)  we are createing a list that will hold our transfer(s)

(2) ADDRESS_TO is the address of the recipient

(3) we set 0 for the value of the transfer, i.e. "empty" transfer

(4) this is the message. It is up to you what the message will contain but it must be encoded to trytes.

(5) optional tag, here we send empty tag, i.e. 999999999999999999999999999

(6) add the Transfer object to the list

(7) send the Transfer. Here SEED is your seed

(8)  2 is the security level (default value)

(9) 9 is the depth (default value)

(10) 15 is inWeightMagnitude which is basically the amount of PoW that is done for a transaction

(11) your transfer(s)

(12) prepared list of inputs. What an input really means is an address from which to take the iotas for the transfer. One transaction with value may use several inputs/address. We put null here because our value is 0

(13) address where the remainder of the transaction to be send. In our case not used because the value is 0. Remainder is difference between the sum of all inputs and the value of the transaction.

In the returned SendTransferResponse object you have a field successfully which is an array containing one boolean value per transaction which indicates if the transfer is send successfully. Please note that "send" differs from "confirmed". "Send" just means that the node received and accepted the transfer. Your transaction will now have "Pending" status.

If you send 2 transfers at once you will get 2 transactions. Those 2 transactions will be in the same bundle.

Now you may ask "Where is my transaction hash and how do I check if it is confirmed?". Well, oddly enough, SendTransferResponse does not contain the transaction hash(es) even though it is quite easy for it do to so because in the underlying code that information exist. It is probably just because the IOTA's java lib is still immature and this may change in the future.

In order to find your transaction's hash you will have to use:

FindTransactionResponse resp = api.findTransactions(new String[] {ADDRESS_FROM}, null, null, null);

In the response object you will get all transactions (their hashes) for this address and you will have to use the last. Then to check the status of the transaction:

GetInclusionStateResponse inclusionResp = api.getLatestInclusion(new String[] {transHash});

In inclusionResp there is a field 'states' which contain an array with the states of all matched transactions (in our case just one). If it is 'true' your transaction is approved.

How to check IOTA IRI neighbors or node status

2017-09-08   

So you had your IRI up and running and now you need to check the node status or how your neighbor are performing?

I am using this simple solution:

Prerequisites:
1. Chrome/Chromium browser
2. Restlet client plug-in for Chrome
3. Json export of the requests' definition

Install the plug-in, start it, then click Import in the loser left corner then select "Restlet client repository", select the file, then click checkbox next to IRI, then import.

In the left menu now you will have menu item IRI. Expand it, click on "Neighbors" and the neighbors request will be shown on the right. Change "http://yourserver:14265/" to reflect your server's address and port. Click "Save" to save the changes. Now click the "Send" button and scroll down. You should see something that looks like:

Click on "Node info" in the menu and do the same for it.

That is it. I hope this short tutorial was helpful.

[Android] Setting up Google single sign in

2017-01-16   

This post is more like a note to myself. Setting up Google sign in is not something I do very often. It happens on average once a year and each time I have to do it I have to struggle with the crappy documentation (because I manage to forget the implementation details).

 

So:
1 .Go to Google developer console at https://console.developers.google.com/apis/

2. Create new project, Click 'Credentials' menu item

3. Click the Create credentials button -> OAuth client ID -> Web application -> Create. Don't mind the "Web application" thing, you need this for the android app. Enter some name and then Save. Google will generate two things for it: Client ID and Client secret. Client ID is used in the android app when creating GoogleSignInOptions like this:

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.google_client_id))
                .build();

Client secret is used on the server side only.

4. Now we have to create android credentials for both debug and release (optionally) .

4.1. Debug

Click the Create credentials button -> OAuth client ID -> Android

For name use 'Android client debug' (for example)

For signing-certificate finger print use:

keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

to show the fingerprint (use SHA-1)

For package name use the package name from your AndroidManifest.xml. You may need to add '.debug' suffix if gradle is configured to add it when building debug version.

4.2. Release

Do the same but using the release key

keytool -exportcert -keystore android_release_keys.keystore -list -v

 

4. Go to https://developers.google.com/identity/sign-in/android/start-integrating

Click 'Get a configuration' file button. Select the app and package (usually release package, i.e. without debug). 'Continue and configure services'

There is a button 'Enable google sign in", Click it.

There is a button "Generate conf files". Click it.

There is a button 'Download google-services.json'. DON'T click it.

Go again to https://developers.google.com/identity/sign-in/android/start-integrating
Select the app, but enter the debug package, i.e. with the .debug suffix.'Continue and configure services'

There is a button 'Enable google sign in", Click it.

There is a button "Generate conf files". Click it.

There is a button 'Download google-services.json'. Click it and download the file. This file contains the configuration for both release and debug builds.

Copy the file in the root of the app module folder (that is NOT the project root).

Now everything should work.

Syntax highlighting for Rust language for Linux KDE's Kate

2015-04-06   

At this point (April 2015) Rust is in 1.0.0-beta and there are no complete IDE integration (either Eclipse or Idea) so we need to go back to basics (no, no, no, not vim/emacs, relax :-) ) and use Kate for editing source files.

Frankly, so far I've never used Kate for programming and was totaly unaware how to configure it and I had some trouble setting Rust's syntax highlighting so here is the short explanation how to do it:

1. Download rust.xml from here: https://github.com/rust-lang/kate-config/blob/master/rust.xml

Take care to save it in it's original XML form, not as HTML (as I did somehow the first time…)

2. Copy it in ~/.kde/share/apps/katepart/syntax/

3. Restart Kate

(btw, I use Kubuntu 14.04, other distros may have different location for the SH files…)

[Android] Android tools 2014

2014-08-28   

Good practice is to learn from the best. Here is a podcast with Jake Wharton where he mentions the libs and tools he uses.

In short here is the list:

Retrofit: http://square.github.io/retrofit/
Picasso: http://square.github.io/picasso/
Dagger: http://square.github.io/dagger/
OkHttp: http://square.github.io/okhttp/
Butter Knife: http://jakewharton.github.io/butterknife
Robolectric: http://robolectric.org/
Espresso: https://code.google.com/p/android-test-kit/
AssertJ Android: http://square.github.io/assertj-android
One more addition to the Wharton's list is:
Parcelabler (online tool for generating parcelable versions of your classes): http://www.parcelabler.com/

[Android] Dynamic ListView using Volley and NetworkImageView

2013-05-30   

Just added new example to the Android Volley Examples project which shows how to use Volley to populate dynamically ListView including loading of images using NetworkImageView. It also uses a simple read-ahead technique in order to load next page of data when the user reaches close to the end of the current page in order to minimize the wait.

dynamic-list-view-volley

[Android] Android Volley With GET and POST Parameters Example

2013-05-28   

Just added a simple example how to use GET and POST parameters to the Android Volley Examples project. You can find it under "GET and POST parameters" button.

Basically the example is quite simple: there is activity with two EditText fields used to enter a number and two buttons "Request with GET params" and "Request with POST params". You have to enter some digits in the fields, press one of the buttons and the request will be send to the server containing the parameters. Server will add the two numbers and return the sum which will be displayed bellow the buttons.

1. Request with GET parameters

In order to send request with GET parameters there are two alternatives:

1.1. To embed them directly in the string of the URL (as shown in the example) like:

String uri = String.format("http://ave.bolyartech.com/params.php?param1=%1$s¶m2=%2$s",
                           num1,
                           num2);
StringRequest myReq = new StringRequest(Method.GET,
                                        uri,
                                        createMyReqSuccessListener(),
                                        createMyReqErrorListener());
queue.add(myReq);

In the code above num1 and num2 hold the parameters' values.

1.2. If you are using Volley with with external HttpClient (4.2.x) you can use URIBuilder in order to build the URI in more convenient way

 

2. Request with POST parameters

You will need override getParams() method of the request and return a Map<String, String> that holds your parameters and their values like:

StringRequest myReq = new StringRequest(Method.POST,
                                        "http://ave.bolyartech.com/params.php",
                                        createMyReqSuccessListener(),
                                        createMyReqErrorListener()) {

    protected Map<string, string=""> getParams() throws com.android.volley.AuthFailureError {
        Map<string, string=""> params = new HashMap<string, string="">();
        params.put("param1", num1);
        params.put("param2", num2);
        return params;
    };
};
queue.add(myReq);

 

getpost

[Android] Using Android Volley With Self-Signed SSL Certificate

2013-05-28   

In brief:

  1. Get Volley from git clone https://android.googlesource.com/platform/frameworks/volley
  2. Get Android Volley Examples project from git clone git://github.com/ogrebgr/android_volley_examples.git
  3. Copy your keystore (BKS format) containing the self-signed public key in res/raw
  4. Open Act_SsSslHttpClient in the examples project, find "R.raw.test" and replace it with your keystore name (without the .pem extension)
  5. Find "new SslHttpClient(" and replace the default password "test123" with the password for your keystore
  6. Replace "44400" with the HTTPS port of your server/virtualhost. If you use the standart 443 -- then you may remove this parameter entirely
  7. Replace "https://tp.bolyartech.com:44400/https_test.html" with your  URL. Please make sure that you are using HTTPS otherwise it will work without as normal request, i.e. without encryption
  8. Start the app, go to "HTTPS with self-signed cert", then "Execute HTTPS request"
  9. If successful you will see something like "This is the result of successful HTTPS request. Congrats!". If some error occurres please check your logcat.
  10. Copy SslHttpClientSslSocketFactorySsX509TrustManager and your keystore to your project and enjoy! :-)

 

In details:

When you create an android app there is  no problem to execute HTTPS request against server with certificate issued by well-known Certification authority. However if you try to you use self-signed certificate you are in trouble -- certificate will be rejected by … more / още »

[Android] Using Volley (Android) With External HttpClient (4.2.x)

2013-05-26   

By default Volley uses the built-in AndroidHttpClient on systems that are < Gingerbread and HttpUrlConnection on newer. For some this may not be enough. Someone may need Cookies support, other may need to work self-signed SSL certificate.   Probably there are few more reasons to use external HttpClient but most prominent one is that you may have old code that relies on it.

About 2 years ago I wrote Using newer version of HttpClient on Android (like 4.1.x). Now as follow up I added an example how to use Volley with such external HttpClient in my Android Volley Examples project.

Basically all I had to do is to create a new class ExtHttpClientStack, copy the functionality from the HttpClientStack and redirect all method calls from the built-in HttpClient to the external one.