SPARQL session at the Wikimedia Prague Pre-Hackathon

Am at the Prague pre-hackathon and the guys from Wikipedia UK and Wikipedia Austria gave a session on SPARQL queries. It seems to be a very cool way to get results from Wikidata and visualise it. Adam Shorland and Tobias Schönberg took this session for all the Wikimedia Commons App team in Wikimedia Czech Republic office.

SPARQL session at the Prague pre-hackathon

They gave us an introduction to get started with SPARQL queries. SPARQL is an RDF query language, that is, a semantic query language for databases, able to retrieve and manipulate data stored in Resource Description Framework (RDF) format.

Here are a few sample queries that can give you a feeling of how it works.

Query to see a list of world heritage sites

SELECT ?item ?itemLabel ?coord ?image
{
    ?item wdt:P1435 wd:Q9259 .
    ?item wdt:P17 ?country .
    ?item wdt:P625 ?coord .
    ?item wdt:P18 ?image
    SERVICE wikibase:label  {bd:serviceParam wikibase:language "en"}
}

See the results here:

Query to show a list of nearby places without any images

The Android Wikimedia Commons app uses this query to get a list of nearby places which don’t have an image on Wikimedia commons. Anyone is welcome to contribute to the Android app.

SELECT
     (SAMPLE(?location) as ?location)
     ?item
     (SAMPLE(COALESCE(?item_label_preferred_language, ?item_label_any_language)) as ?label)
     (SAMPLE(?classId) as ?class)
     (SAMPLE(COALESCE(?class_label_preferred_language, ?class_label_any_language, "?")) as ?class_label)
     (SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
     (SAMPLE(COALESCE(?emoji0, ?emoji1)) as ?emoji)
     ?wikipediaArticle
     ?commonsArticle
   WHERE {
     # Around given location...
     SERVICE wikibase:around {
       ?item wdt:P625 ?location.
       bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral.
       bd:serviceParam wikibase:radius "${RAD}" . # Radius in kilometers.
     }

     # ... and without an image.
     MINUS {?item wdt:P18 []}

     # Get the label in the preferred language of the user, or any other language if no label is available in that language.
     OPTIONAL {?item rdfs:label ?item_label_preferred_language. FILTER (lang(?item_label_preferred_language) = "${LANG}")}
     OPTIONAL {?item rdfs:label ?item_label_any_language}

     # Get the class label in the preferred language of the user, or any other language if no label is available in that language.
     OPTIONAL {
       ?item p:P31/ps:P31 ?classId.
       OPTIONAL {?classId rdfs:label ?class_label_preferred_language. FILTER (lang(?class_label_preferred_language) = "${LANG}")}
       OPTIONAL {?classId rdfs:label ?class_label_any_language}

       # Get icon
       OPTIONAL { ?classId wdt:P2910 ?icon0. }
       OPTIONAL { ?classId wdt:P279*/wdt:P2910 ?icon1. }
       # Get emoji
       OPTIONAL { ?classId wdt:P487 ?emoji0. }
       OPTIONAL { ?classId wdt:P279*/wdt:P487 ?emoji1. }
       OPTIONAL {
          ?sitelink schema:about ?item .
          ?sitelink schema:inLanguage "en"
       }
       OPTIONAL {
           ?wikipediaArticle   schema:about ?item ;
                               schema:isPartOf <https://en.wikipedia.org/> .
           SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
         }

         OPTIONAL {
           ?commonsArticle   schema:about ?item ;
                               schema:isPartOf <https://commons.wikimedia.org/> .
           SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
         }
     }
   }
   GROUP BY ?item ?wikipediaArticle ?commonsArticle

See the results here:

Greek Salad

Here’s a recipe for a very filling salad that you can enjoy as an evening snack or a quick low-fat dinner. Preparing a greek salad doesn’t require much effort and you can prepare it on your own even in college hostel or PG/flat.

IMG_20160513_223633

Greek salad: Dice 2 cucumbers, 1 onion, ½ tomato, 1 bell pepper, 3-4 black olives(optional), pepper, pinch of salt & lemon juice. Garnish with coriander. Serve chilled.

Here are other salad recipes you could try.

  1. Minty Sprout Salad
  2. Sprout Salad

Minty Sprout Salad

You can prepare minty sprout salad as an evening snack and enjoy it without worrying about the calories it has. 🙂

wpid-wp-1461486210863

Minty Sprout salad: Take ½ cup of Black eyed beans(lobiya) soaked overnight. Take 1 onion & 1 tomato finely chopped, 1 cucumber chopped, 2 tablespoon chopped mint, 2 tablespoon coriander, green chilli finely chopped & lemon juice & salt to taste. Combine the Beans & salt to pressure cook for 3-4 whistles till they are soft, drain & allow to cool and serve chilled.

Sprout Salad

Here’s another healthy salad that you can prepare and enjoy without much effort. It can be a very filling evening snack so that you can avoid eating junk food when you hungry between lunch and dinner.

wpid-wp-1461486137194.jpg

Sprouts salad: Boil 3 spoon sprouted moong. Sauté veggies like onion, cucumber, tomato, capsicum, beans and carrots. Add them to sprouted moong. Add salt, pepper, and some lemon juice. Garnish with coriander.

Even sprouted moong is available in the markets or you can soak a handful of moong overnight to use it in your salad. Here’s a variant of the sprout salad recipe described in this post.

The Internship

It was the last day of my third year and I was packing my bags to go back home. Lots of companies had visited our campus for summer internship recruitment and I didn’t got selected in any of them. It was really frustrating to go through the selection procedure of every company and finally get rejected. Most of my friends were going to intern in companies like Microsoft, Amazon, Samsung etc.

Then on the last day I got a mail asking if I would be interested to intern in a stealth mode startup based in Bangalore. I was obviously not interested to join another startup. In the past I had interned with two startups and the experience was great but not again. The person who mailed me had seen my Windows Phone app development articles on a few websites(Tuts+ & WindowsAppTutorials) and was impressed by my profile. Here’s a excerpt from his mail.
“I came across your profile and liked your articles which you have published on tuts and your other blogs. I was wondering if you like to intern with us in coming summer vacation and help us with our Windows Phone app 🙂 .”
I enquired about the work and other details and finally he convinced me to blindly come to Bangalore and work with their team. He didn’t give out details what they are actually building.

The next two months were wonderful. Later on I came to know that its another startup(Zeta) from Directi’s founder Bhavin. The team had engineers from Google, Facebook, Microsoft, LinkedIn and Directi. I was the only fresher(or intern) in the team and others had atleast 3-4 years of experience. The work was awesome and I never felt that I was just an intern. I am not very good at algorithms and competitive coding so it was impossible to imagine working in Directi which has one of the toughest selection procedures.

It was a completely new experience for me. I hadn’t worked on projects at this scale where there were proper teams to handle server, client, infra, UX, platform etc. Directi was incubating it so they had enough resources in spite of being a startup. Directi’s tagline resonated perfectly with every single individual in the team, “Intelligent people, uncommon ideas”. Every one was self motivated and very excited about the work we were doing. Even the other teams in Directi didn’t have a clue about what we were building. Intense discussions, priority log meetings, daily standups and weekly team updates were a part of the work schedule.

As a intern I was grateful to have a awesome mentor and great team. My mentor made sure that i got work that would be learn new things and not repetitively picking up similar tasks. We had weekly one on one interactions in which he discussed how I could utilize the coming weeks in a better way. For most part of the internship I didn’t know who was my official mentor as I could go and get help from anyone. I was amazed to see that terms we came across in our Software Engineering books were actually being used/implemented here. Another good thing about this internship was that I was not assigned a side project which had no impact on the main project. I was able to contribute to the main project from Day 2 itself. Infact my contribution was over 60% in a team of 4 to the windows-client codebase during those two months. 😀

It was literally a life changing experience for me as one day I was packing my bags to return home and on the next day i was flying to Bangalore to work in a ‘stealth mode startup’. I got an opportunity to work in one of the best teams with a great mentor and arguably the best stipend that any company that visits our campus offers(except Codenation but it didn’t select anyone). It got a lot sweeter when they offered me a pre-placement offer about a month before my internship ended.

The farewell couldn’t have been better with a team lunch(with funny farewell speeches) and an awesome gift from the whole client side team :D. They kept bugging me to stay and complete my BTech later :D. I realized that they were serious when Ramki actually asked me to explain why do I need to complete my BTech :P.

Efficient way of selecting a random row from a huge mysql table

Just read a blog post that described a efficient way of selecting a random row from a huge mysql table.

A great post handling several cases, from simple, to gaps, to non-uniform with gaps.

http://jan.kneschke.de/projects/mysql/order-by-rand/

If you want to get more than one row returned, you can:

  • execute the Query several times
  • write a stored procedure which is executing the query and stores the result in a temp-table
  • make a UNION

Captcha and Recaptcha

The reCAPTCHA service supplies subscribing websites with images of words that optical character recognition (OCR) software has been unable to read. The subscribing websites (whose purposes are generally unrelated to the book digitization project) present these images for humans to decipher as CAPTCHA words, as part of their normal validation procedures. They then return the results to the reCAPTCHA service, which sends the results to the digitization projects.

Scanned text is subjected to analysis by two different optical character recognition programs. Their respective outputs are then aligned with each other by standard string-matching algorithms and compared both to each other and to an English dictionary. Any word that is deciphered differently by both OCR programs or that is not in the English dictionary is marked as “suspicious” and converted into a CAPTCHA. The suspicious word is displayed, out of context, along with a control word already known. The system assumes that if the human types the control word correctly, then the response to the questionable word is accepted as probably valid. If enough users were to correctly type the control word, but incorrectly type the 2nd word which OCR had failed to recognize, then the digital version of documents could end up containing the incorrect word. The identification performed by each OCR program is given a value of 0.5 points, and each interpretation by a human is given a full point. Once a given identification hits 2.5 points, the word is considered valid. Those words that are consistently given a single identity by human judges are later recycled as control words

How to integrate Google AdMob in Windows Phone 8 app?

When it comes to monetization using in-app advertisements in Windows Phone apps, there are quite a few option like Microsoft’s Pubcenter, Mobfox, Smaato, AdDuplex, Nokia’s Inneractive and Google’s Admob. In the past two years I have tried all these ad providers and have finally struck to Google’s Admob. There was a period when Microsoft’s Pubcenter gave the best returns but gradually its fill rates started dropping and earnings dropped by around 99.5% for developers outside US. That made me try other ad providers available for WP and frankly none of them are as good as Pubcenter(the old one) but now developers don’t have a choice. In this post I will show you how you can integrate AdMob in your Windows Phone app..

Heres how you can add AdMob in Windows Phone 8 app using C#

Here’s my comprehensive article on integrating AdMob in windows phone app.

Closest matching search from a database table using PHP

I was working on a project where I was required to build a search functionality which shows the most relevant results at the top. A basic search that just matches the string entered to the entries in a database is simple to build. I wanted to build something better so I used a few things which seemingly gives much better results.

  • I have an array at the start of the script where i specify which columns are to be searched($search_columns)
  • Another array lets me specify other columns which are to be included in the search results but are not be searched($other_columns)
  • I assume a maximum length of search term for convenience($max_search_length)
  • I define the maximum percentage of dissimilarity between the search term and the entry($dissimilarity)
  • I first find the position of substring ie search term with values from all the columns which were specified earlier. If a match is found then i store the starting position of the substring else i store the maximum length of search term which i assumed earlier.
  • Now i use longest common consequence between the search term and  entry to find the percentage of dissimilarity between them.
  • Then i use a multisort function which lets me specify the sort criteria for every column and then apply multisort on it.
  • Finally the results are saved in $sortedData 2D array.

Fork it on github here.

Circular image cropping using CSS

I wished to crop my image in home page to look circular. I tried a few things which made the image oval but not a perfect circle. Finally I got a piece of code, and was able to achieve the desired effect. So I thought about sharing the code. It might be handy in some situations. Simply put your image inside the clip-circle div and edit the css to have desired image size.

If you are an app developer and want to display a circular image in your app then have a look at this post

http://www.maskaravivek.com/blog/windows-phone/displaying-circular-image-in-windows-phone-app/