Monthly Archives: January 2017


Script to clone all git repositories from all projects of a privately hosted Bitbucket server

The following script can download all git repositories from all of the projects that you have access to on a privately hosted Bitbucket server.

The execution work-flow of this script is as follows:

  1. It will ask for your username (the one you use to login on the Bitbucket server)
  2. Then it will ask for your password, the password will not be visible on screen as you type because we disabled the echo functionality for that step.
  3. Later, you will be prompted to provide the URL of the server, for this step be sure to define the protocol if it is http or https and the correct port number as well (e.g. https://bitbucket.bytefreaks.net:7990)
  4. Finally, you will be requested to give the location to where the repositories should be cloned to.
  5. Then the script will connect to the server, get the list of projects that you have access to and for each project retrieve the repositories of the project and clone them in the designated folder.
clone.all.hosted.bitbucket.sh (compressed) (57 downloads)

#!/bin/bash

echo -n "Username: ";
read username;
echo -n "Password: "; 
#Disabling echo, so that password will not be visible on screen
read -s password
#Enabling echo
echo

echo -n "Server (e.g https://repository.bytefreaks.net:7990): ";
read server;
echo -n "Location to clone repositories in: ";
read location;

mkdir -p "$location";
cd "$location";

#Getting all projects
curl --user "$username:$password" "$server/rest/api/1.0/projects/" | \
  grep -oP '"key":"\K\w+' | xargs -I {} -n 1 -I_project -- sh -c \
    "curl --user \"$username:$password\" \"$server/rest/api/1.0/projects/_project/repos\" | grep -o '\"ssh:[^ ,]\+' | xargs -L1 git clone";

exit 0;

clone.all.hosted.bitbucket.sh (compressed) (57 downloads)

 

Notes for the future:

  • Separate the cloned repositories per project
  • Support for people that have hundreds of projects and/or hundreds of repositories using the paging functionality

asn1c: undefined reference to `SET_OF_encode_uper’

The following post is for the https://lionet.info/asn1c/ (repository: https://github.com/vlm/asn1c/)

When trying to link an ASN.1 structure that uses a SET OF, with support for Unaligned Packed Encoding Rules (UPER), we get the following error: undefined reference to 'SET_OF_encode_uper'.

Unfortunately, there is currently no solution for this problem, so we replaced the SET OF with a SEQUENCE OF.

The SEQUENCE OF type is the list (array) of simple or constructed types. The SET OF type models the bag of structures. It resembles the SEQUENCE OF type, but the order is not important: i.e. the elements may arrive in the order which is not necessarily the same as the in-memory order on the remote machines.

— From http://lionet.info/asn1c/asn1c-usage.html

Original (problematic) code

Elements ::= SEQUENCE
{
    property INTEGER,
    objects SET OF object
}

Updated (working) code

Elements ::= SEQUENCE
{
    property INTEGER,
    objects SEQUENCE OF object
}

 


Fedora 25: Connect to Windows Remote Desktop with RD Gateway Server

Since you are searching for this information, you may have found out that there is no way for Vinagre remote desktop viewer to connect to a Windows Server via Windows Remote Desktop (RDP) when a RD Gateway Server is needed for the configuration.

What we did to make this work was only to install remmina  on our machine using this command sudo dnf install -y remmina;.

Remmina by default supported the configuration using RD Gateway Server so we did not have to do nothing more than just use it.

Useful links:


asn1c: How do I know how big a buffer to allocate before using ‘uper_encode_to_new_buffer’?

The following post is for the https://lionet.info/asn1c/ (repository: https://github.com/vlm/asn1c/)

There is no need to compute the space needed.

If you pass the address to a pointer that is NULL pointer as the last parameter of uper_encode_to_new_buffer(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints, void *sptr, void **buffer_r) , then it will allocate by itself the required space.


void *buffer = NULL;
asn_per_constraints_s *constraints = NULL;
ssize_t ec = uper_encode_to_new_buffer(&asn_DEF_Image, constraints, image, &buffer);


asn1c: What is the ‘write_stream’ parameter in the example code

The following post is for the https://lionet.info/asn1c/ (repository: https://github.com/vlm/asn1c/)

The asn1c usage manual (PDF), mentions an element called write_stream but it does not define what it is.

What write_stream is can be found in converter-sample.c  and in the manual under the name write_out:


/* Dump the buffer out to the specified FILE */
static int write_out(const void *buffer, size_t size, void *key) {
  FILE *fp = (FILE *)key;
  return (fwrite(buffer, 1, size, fp) == size) ? 0 : -1;
}

write_out is function that has the following signature write_out(const void *buffer, size_t size, void *app_key) and is used as a callback by der_encode() and other functions.

This callback receives as input the pointer to an element (const void *buffer), the size of that element (size_t size) and some context (void *app_key).
In this example, we can see that the user is using der_encode() which accepts a FILE * as the last parameter, which later is passed to write_out() as the context.


Practice Problem for Google Hash Code 2017 1

Happy new year people!!

Google released a practice problem for Google Hash Code 2017!

Please do not forget to register!

Practice Problem for Google Hash Code 2017 - Problem Statement (439 downloads)

Practice Problem for Google Hash Code 2017 - Data Sets (319 downloads)

Submission deadline:     Thursday, Feb 23, 19:30 Cyprus time (18:30 CET)

Pizza

Practice Problem for Hash Code 2017

Introduction

Did you know that at any given time, someone is cutting pizza somewhere around the world? The decision about how to cut the pizza sometimes is easy, but sometimes it’s really hard: you want just the right amount of tomatoes and mushrooms on each slice. If only there was a way to solve this problem using technology…

Problem description

Pizza

The pizza is represented as a rectangular, 2-dimensional grid of R rows and C columns. The cells within the grid are referenced using a pair of 0-based coordinates [r, c] , denoting respectively the row and the column of the cell.

Each cell of the pizza contains either:

  • mushroom, represented in the input file as M ; or
  • tomato, represented in the input file as T

Slice

A slice of pizza is a rectangular section of the pizza delimited by two rows and two columns, without holes.
The slices we want to cut out must contain at least L cells of each ingredient (that is, at least L cells of mushroom and at least L cells of tomato) and at most H cells of any kind in total – surprising as it is, there is such a thing as too much pizza in one slice.

The slices being cut out cannot overlap. The slices being cut do not need to cover the entire pizza.

Goal

The goal is to cut correct slices out of the pizza maximizing the total number of cells in all slices.

Input data set

The input data is provided as a data set file – a plain text file containing exclusively ASCII characters with lines terminated with a single \n character at the end of each line (UNIX- style line endings).

File format

The file consists of:

  • one line containing the following natural numbers separated by single spaces:
    • R (1 ≤ R ≤ 1000) is the number of rows,
    • C (1 ≤ C ≤ 1000) is the number of columns,
    • L (1 ≤ L ≤ 1000) is the minimum number of each ingredient cells in a slice,
    • H (1 ≤ H ≤ 1000) is the maximum total number of cells of a slice
  • R lines describing the rows of the pizza (one after another). Each of these lines contains C
    characters describing the ingredients in the cells of the row (one cell after another). Each character is either M (for mushroom) or T (for tomato).

Example Input File

3 5 1 6
TTTTT
TMMMT
TTTTT

3 rows, 5 columns, min 1 ingredient per slice, max 6 cells per slice

Submissions

File format

The file must consist of:

  • one line containing a single natural number S (0 ≤ S ≤ R × C) , representing the total number of slices to be cut,
  • U lines describing the slices. Each of these lines must contain the following natural numbers
    separated by single spaces:

    • r1 , c1 , r2 , c2 (0 ≤ r1, r2 < R, 0 ≤ c1, c2 < C)  describe a slice of pizza delimited by the rows r1 and r2 and the columns c1 and c2 , including the cells of the delimiting rows and columns. The rows ( r1 and r2 ) can be given in any order. The columns ( c1 and c2 ) can be given in any order too.

Example

3
0 0 2 1
0 2 2 2
0 3 2 4

Example description

3 slices.
First slice between rows (0,2) and columns (0,1).
Second slice between rows (0,2) and columns (2,2).
Third slice between rows (0,2) and columns (3,4).

Slices described in the example submission file marked in green, orange and purple.

Validation

For the solution to be accepted:

  • the format of the file must match the description above,
  • each cell of the pizza must be included in at most one slice,
  • each slice must contain at least L cells of mushroom,
  • each slice must contain at least L cells of tomato,
  • total area of each slice must be at most H

Scoring

The submission gets a score equal to the total number of cells in all slices.

Note that there are multiple data sets representing separate instances of the problem. The final
score for your team is the sum of your best scores on the individual data sets.

Scoring example

The example submission file given above cuts the slices of 6, 3 and 6 cells, earning 6 + 3 + 6 = 15 points.

Past editions

— From https://hashcode.withgoogle.com/past_editions.html

Hash Code started in 2014 as a one-day programming competition for students and professionals from across France. We introduced the Online Qualification Round in 2015 where more than 1,500 students and professionals competed. The top teams were then invited to the Google Paris office to face off in the Final Round of the competition. In 2016 we scaled the competition to the rest of Europe, the Middle East and Africa where more than 17,000 people signed up to compete. You can take a look at the problems and winning teams from past editions of Hash Code below.

Past problem statements

Schedule Satellite Operations

Hash Code 2016, Final Round
Hash Code 2016, Final Round - Problem (145 downloads)
A satellite equipped with a high-resolution camera can be an excellent source of geo imagery. While harder to deploy than a plane or a Street View car, a satellite — once launched — provides a continuous stream of fresh data. Terra Bella is a division within Google that deploys and manages high-resolution imaging satellites in order to capture rapidly-updated imagery and analyze them for commercial customers. With a growing constellation of satellites and a constant need for fresh imagery, distributing the work between the satellites is a major challenge. Given a set of imaging satellites and a list of image collections ordered by customers, schedule satellite operations so that the total value of delivered image collections is as high as possible.

Optimize Drone Deliveries

Hash Code 2016, Online Qualification Round
Hash Code 2016, Online Qualification Round - Problem (156 downloads)
The Internet has profoundly changed the way we buy things, but the online shopping of today is likely not the end of that change; after each purchase we still need to wait multiple days for physical goods to be carried to our doorstep. Given a fleet of drones, a list of customer orders and availability of the individual products in warehouses, schedule the drone operations so that the orders are completed as soon as possible.

Route Loon Balloons

Hash Code 2015, Final Round
Hash Code 2015, Final Round - Problem (75 downloads)
Project Loon aims to bring universal Internet access using a fleet of high altitude balloons equipped with LTE transmitters. Circulating around the world, Loon balloons deliver Internet access in areas that lack conventional means of Internet connectivity. Given the wind data at different altitudes, plan altitude adjustments for a fleet of balloons to provide Internet coverage to select locations.

Optimize a Data Center

Hash Code 2015, Online Qualification Round
Hash Code 2015, Online Qualification Round - Problem (162 downloads)
For over ten years, Google has been building data centers of its own design, deploying thousands of machines in locations around the globe. In each of these of locations, batteries of servers are at work around the clock, running services we use every day, from Google Search and YouTube to the Judge System of Hash Code. Given a schema of a data center and a list of available servers, your task is to optimize the layout of the data center to maximize its availability.

Street View Routing

Hash Code 2014, Final Round
Hash Code 2014, Final Round - Problem (138 downloads)
The Street View imagery available in Google Maps is captured using specialized vehicles called Street View cars. These cars carry multiple cameras capturing pictures as the car moves around a city. Capturing the imagery of a city poses an optimization problem: the fleet of cars is available for a limited amount of time and we want to cover as much of the city streets as possible.


Google Hash Code 2017 – Online Qualification Round Schedule

19:00 EET:

  • The hub will open to the public
  • People can view the live stream (Nat & Lo videos) on the video projector
  • Teams can set themselves up with the help of the volunteers

19:30 EET:

  • Live stream starts

19:45 EET:

  • Task will be made available, competition starts
  • Scoreboard will be displayed on the video projector
  • Participating teams will be confirmed in the Judge System

23:30 EET:

  • End of the competition
  • Announcement of the score for the local teams

00:00 EET:

  • The hub will close

 

Hashtag for the competition #hashcode2017


C: Read a floating number that might be in the format of scientific notation

This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print out the number with the scientific notation and without it.


#include <stdio.h>
#include <stdlib.h>

int main() {
  printf("This code will read a floating number that might be in the format of scientific notation from the keyboard.\nThen it will print it out with the scientific notation and without\n");
  double input;
  printf("Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)\n");
  scanf("%lf", &input);
  printf("With scientific notation '%e'\n", input);
  printf("Without scientific notation '%lf'\n", input);
  return 0;
}

Examples

This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print it out with the scientific notation and without
Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)
4.5e-10
With scientific notation '4.500000e-10'
Without scientific notation '0.000000'
This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print it out with the scientific notation and without
Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)
4.5e-3
With scientific notation '4.500000e-03'
Without scientific notation '0.004500'

asn1c: Generating code using ‘Automatic Tags’ and negative value as default value creates invalid function names

The following post is for the https://lionet.info/asn1c/ (repository: https://github.com/vlm/asn1c/)

When compiling the following ASN.1 data structure

GeographyModule DEFINITIONS AUTOMATIC TAGS ::= BEGIN

    Coordinates ::= SEQUENCE
    {
        -- latitude from -90 till 90 degrees --
        latitude INTEGER(-9000000..9000000) DEFAULT -8000000,
        -- longitude from -180 till 179.99999 degrees, worst precision 1.1132m at equator --
        longitude INTEGER(-18000000..17999999) DEFAULT -12000000
    }

END

the use of both the AUTOMATIC TAGS option and the use of a negative value -8000000 in the position of the default value causes asn1c to create invalid function names in the Coordinates object.

For example, the above ASN.1 syntax will produce the following invalid function name int asn_DFL_2_set_-800000(int set_value, void **sptr).

Compilation command for asn1c

From folder asn1c_gps/asn1 we used the following command:

/home/developer/asn1c/asn1c/asn1c -pdu=auto -S /home/developer/asn1c/skeletons/ -fcompound-names -gen-PER ../geography.asn1

Version of asn1c

'ASN.1 Compiler, v0.9.28'

Example

Full example code demonstrating the bug can be found here ( asn1c_gps - Full example - Demonstrating Bug (42 downloads) ).

If you want to use the code and see that all other operations are fine, replace _- with _minus_ in the file Coordinates.c and the code will become valid and usable.

After you perform the above change, you can use the code in main.cpp to see the our cycle of execution that encodes and decodes an object.