Tag Archives: JSON

Simple QML vs EFL comparison

Recently I found

QmlMiner

elemines

Surprisingly, the QML implementation didn’t take much time:

Activity Hours Comment
Development time spent on JavaScript code
8
I have never written any minesweeper engine
Development time spent on QML code
12
Dialogs, button, animations(explosions) etc.

I should also mention my experience with related technologies:

  1. Intermediate Qt knowledge (3 years)
  2. A few months of QML development
  3. Basic Javascript knowledge (only used with QML code)

Plain Qt knowledge was not a requirement in this case because the QmlMiner contains no C/C++ code at all. Understanding QML and simple JS was just enough. The QmlMiner can be executed with the qmlviewer tool but afterwards I added simple main.cpp for memory and startup performance tests to make “lightness” of the QML app possibly similar to elemines. Basically, qmlviewer has many features that are not needed for the task.
After creating the QmlMiner I reviewed some source code of elemines to spot similarities and noticed that both applications have corresponding game engines and default.edc (*.edc) file has syntax similar to JSON. It has programs section which I believe is somewhat similar to QML states.
Another observation is that the edc file is a resource of data used in C code. The C code creates objects, imperatively defines interactions between them and lays out the UI. Please note these are only my guesses – guesses of developer neither much experienced in plain C nor in EFL.


2. Source code size and used languages

I measured size of source code with the wc command and SLOCCount tool. SLOCCount was used to count lines of elemines C code and QmlMiner’s C++ code (it skipped comments). wc (with -l option) was used to count lines of QML files and eliemines’s deafult.edc file. The QML file didn’t have any comments and the edc file had only 20, which I excluded. I assumed that the whole QmlMinerModel.qml file contains JS code – it is the ,,game engine”. Other files describe the GUI (look and behavior). I didn’t analysed the build system files (Makefiles in elemines and a pro file in QmlMiner) because they are not very relevant.

The results are as follows:

lines of code
purpose
QmlMiner
EFL elemines
Business logic jacascript <div …read more
Source: FULL ARTICLE at Planet KDE

Malformed session key while using Facebook API

By pandeesh

Hi,

I am doing some experiments with facebook API and unable to update the status using the API.
My code is as follow as:

Code:

use WWW::Facebook::API;
use JSON::Any;

my $query=new CGI;
my $j = JSON::Any->new;
my $api_key="#MY API KEY#";
my $secret="#MY SECRET KEY#";
my $fb = WWW::Facebook::API->new(
desktop => 0,
api_key => $api_key,
secret => $secret,
session_key => $query->cookie($api_key.'_session_key'),
session_expires => $query->cookie($api_key.'_expires'),
session_uid => $query->cookie($api_key.'_user')
);

my $res = $fb->stream->publish(
message => 'Test message',
attachment => $j->objToJson(
{ name => 'Foo bar baz',
href => 'http://www.google.com/',
description => "this is a thing"
} ),
action_links => $j->objToJson(
[ { text => 'action link text',
href => 'http://www.foobar.com/'
} ] )
);


In the original code, i replaced with original api and secret keys .
But i am receiving the below error an di don’t have any clue how to fix this.

Code:

Odd number of elements in hash assignment at C:/Dwimperl/perl/site/lib/WWW/Facebook/API.pm line 164.
Error during REST stream.publish call:
params =
action_links:[{"href":"http://www.foobar.com/","text":"action link text"}]
api_key:#api_key#
attachment:{"href":"http://www.google.com/","name":"Foo bar baz","description":"this is a thing"}
format:JSON
message:Test message
method:facebook.stream.publish
session_key:session_expires
v:1.0
response =
{"error_code":102,"error_msg":"Session key is malformed.","request_args":[{"key":"action_links","value":"[{"href":"http://www.foobar.com/","text":"action link text"}]"},{"key":"api_key","value":"#api_key#"},{"key":"attachment","value":"{"href":"http://www.google.com/","name":"Foo bar baz","description":"this is a thing"}"},{"key":"format","value":"JSON"},{"key":"message","value":"Test message"},{"key":"method","value":"facebook.stream.publish"},{"key":"session_key","value":"session_expires"},{"key":"v","value":"1.0"},{"key":"sig","value":"fa1423663792249368fd00e9f102b992"}]}


Any thoughts on this.

Thanks in Advance!

–Pandeesh

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

URL extraction from JSON file

By busyboy

I’m trying to export URLs from within a JSON file which in turn resulted from export of Mozilla-Firefox bookmarks. Its single line file with below given values from awk

Code:

$ awk 'END { print NR }' bookmarks.json
1
$ awk 'END { print NF }' bookmarks.json
2706
$ awk -F, 'END { print NF }' bookmarks.json
4754


using sed, it gives me only 1st occurrence and rest is missed.

Code:

$ sed 's/.*"(http:.*)"/1/' bookmarks.json
http://www.oracle.com/us/products/servers-storage/servers/blades/index.html","charset":"UTF-8}]}]}
$


extract from json file is something like below:

Code:

{"title":"","id":1,"dateAdded":1331548812311000,"lastModified":1331549028262000,"type":"text/x-moz-place-container","root":"placesRoot","children":[{"title":
"Bookmarks Menu","id":2,"parent":1,"dateAdded":1331548812311000,"lastModified":1342096853234000,"type":"text/x-moz-place-container","root":"bookmarksMenuFold
er","children":[{"title":"Recent Tags","id":925,"parent":2,"annos":[{"name":"Places/SmartBookmark","flags":0,"expires":4,"mimeType":null,"type":3,"value":"Re
centTags"}],"type":"text/x-moz-place","uri":"place:sort=14&type=6&maxResults=10&queryType=1"},{"index":1,"title":"Recently Bookmarked","id":924,"parent":2,"a
nnos":[{"name":"Places/SmartBookmark","flags":0,"expires":4,"mimeType":null,"type":3,"value":"RecentlyBookmarked"}],"type":"text/x-moz-place","uri":"place:fo
lder=BOOKMARKS_MENU&folder=UNFILED_BOOKMARKS&folder=TOOLBAR&sort=12&excludeQueries=1&maxResults=10&queryType=1"},{"index":2,"title":"","id":26,"parent":2,"da
teAdded":1243009025055489,"lastModified":1331549044829000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{445
36f3f-1d99-4e6d-8b77-d5e89c334d2d}2"}],"type":"text/x-moz-place-separator"},{"index":3,"title":"Get Bookmark Add-ons","id":27,"parent":2,"dateAdded":12430090
25055489,"lastModified":1331549044829000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{44536f3f-1d99-4e6d-8
b77-d5e89c334d2d}3"}],"type":"text/x-moz-place","uri":"https://en-us.add-ons.mozilla.com/en-US/firefox/bookmarks/"},{"index":4,"title":"","id":28,"parent":2,
"dateAdded":1243009025055489,"lastModified":1331549044829000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{
44536f3f-1d99-4e6d-8b77-d5e89c334d2d}4"}],"type":"text/x-moz-place-separator"},{"index":5,"title":"Mozilla Firefox","id":29,"parent":2,"dateAdded":1243009025
055489,"lastModified":1331549044845000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{44536f3f-1d99-4e6d-8b7
7-d5e89c334d2d}5"}],"type":"text/x-moz-place-container","children":[{"title":"Help and Tutorials","id":30,"parent":29,"dateAdded":1243009025055489,"lastModif
ied":1331549044845000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{44536f3f-1d99-4e6d-8b77-d5e89c334d2d}6"
}],"type":"text/x-moz-place","uri":"http://en-us.www.mozilla.com/en-US/firefox/help/"},{"index":1,"title":"Customize Firefox","id":31,"parent":29,"dateAdded"
:1243009025055489,"lastModified":1331549044845000,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{44536f3f-1d
99-4e6d-8b77-d5e89c334d2d}7"}],"type":"text/x-moz-place","uri":"http://en-us.www.mozilla.com/en-US/firefox/customize/"},


Regards,

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Robert Collins: Simpler is better – a single event type for StreamResult

StreamResult, covered in my last few blog posts, has panned out pretty well.

Until that is, that I sat down to do a serialised version of it. It became fairly clear that the wire protocol can be very simple – just one event type that has a bunch of optional fields – test ids, routing code, file data, mime-type etc. It is up to the recipient at the far end of a stream to derive semantic meaning, which means that encoding a lot of rules (such as a data packet can have either a test status or file data) into the wire protocol isn’t called for.

If the wire protocol doesn’t have those rules, Python parsers that convert a bytestream into StreamResult API calls will have to manually split packets that have both status() and file() data in them… this means it would be impossible to create many legitimate bytestreams via the normal StreamResult API.

That seems to be an unnecessary restriction, and thinking about it, having a very simple ‘here is an event about a test run’ API that carries any information we have and maps down a very simple wire protocol should be about as easy to work with as the current file or status API.

Most combinations of file+status parameters is trivially interpretable, but there is one that had no prior definition – a test_status with no test id specified. Files with no testid are easily considered as ‘global scope’ for their source, so perhaps test_status should be treated the same way? [Feedback in comments or email please]. For now I’m going to leave the meaning undefined and unconstrained.

So I’m preparing a change to my patchset for StreamResult to:

  • Drop the file() method altogether.
  • Add file_bytes, mime_type and eof parameters to status().
  • Make the test_id and test_status parameters to status() optional.

This will make the API trivially serialisable (both to JSON or protobufs or whatever, or to the custom binary format I’m considering for subunit), and equally trivially parsable, which I think is a good thing.


…read more
Source: FULL ARTICLE at Planet Ubuntu

New plugins to the Kate, utils to: Python, JavaScript, Django and XML

The project plugin in kate.git master nowhas four new more plugins, with many features in each one: Python (autocomplete, smart snippets, parse checker, pep8 checker and pyflakes checker), Javascript (autocompletes, jquery snippet, pretty JSON, and jslint checker), Django (smart snippets and utils to Django template) and XML (pretty xml). There are also many generic functions and generic classes in these that will be useful to the new plugins developers.

I began to develop these plugins in 2009, this was my first version:-). I wanted to set a shortcut to a snippet, as it was not possible (now it is posible) I started to develop these plugins to Kate.

In November 2011, I created a repository on github to develop new features and share them. I have to thank Alejandro Blanco, Jeroen van Veen, Javier Romero, Martin Borho, Justin Chudgar and Yaco Sistemasfor helping me in this project.

In October 2012 Christoph Cullmann (Kate maintainer) sent me an e-mail, in which he asked me if I was interested to contribute with KDE project. I answered: “Of course!”…. finally I have a little time, and I have been able to integrate these plugins in the kate.git

Features to Python Plugin:

  • Python dynamic autocomplete using pyplete, this is in beta… It requires development, but now it is very useful.
  • Smart snippets:
    1. Insert an __init__ method into a class.
    2. Insert a super call into a method.
    3. Insert a call recursive into a method or into a function
  • Simple snippet: Insert the debug instrunctions “import ipdb; ipdb.set_trace()”
  • Checkers: When you save the file it is syntax checked, pep8 checked and pyflakes checked. You can invocate them any other time.


Python auto complete

Features to Javascript Plugin:

  • JavaScript static autocomplete, using a JSON file.
  • JQuery static autocomplete using a JSON file.
  • Pretty JSON: Pretty format of a JSON code selected
  • JSLint checker:When you save the file it is JSLint checked. You can invocate it any other time.
  • JQuery snippet, insert the ready code of the jQuery

JSLint checker

Features to Django Plugin:

  • Smart snippets:
    1. Create a model class
    2. Create a form class
    3. Template to the urls.py file
  • Simple snippet: Insert the typical imports of a views.py file
  • Template Django utils
    1. Insert the tag block/endblock. The name of the block will be the text selected
    2. Close the last templatetag open

Create a form class

Pretty XML:

Pretty format of an XML code selected

Pretty XML

Generic features:

Also I have added many generic functions and generic classes, likely the more outstanding are the autocompletations. Now you can create a code completion model with very few lines:

import kate
from libkatepate.autocomplete import AbstractJSONFileCodeCompletionModel, reset

class MyCodeCompletionModel(AbstractJSONFileCodeCompletionModel):

    MIMETYPES = [] #  ...read more 
Source: FULL ARTICLE at Planet KDE