I want to substantiate information about Eclipse with some practice. The story will focus on a cross-platform programming. Do you like cross-platform software? I just love it - it's so convenient to use the same tools in any operating system!
We will use a simple chiming clock as a program for porting. I wrote this program ages ago, even when I was a student, but still use it.
The specification is as follows: every hour it must strike the number of hours, every half of an hour it must strike once.
The code for Windows looks like this:
Let's run through the code:
<windows.h> - the standard library for win32-programs.
<mmsystem.h> - we use a function called "sndPlaySound" from this library
int main () - the usual main function
int h, m, s; - declare integer variables to store hours, minutes and seconds
SYSTEMTIME lpSystemTime; - the structure for storing the system time
while (1) (- beginning of an infinite loop, so the program will work permanently
GetLocalTime (& lpSystemTime); - here we fill the structure "lpSystemTime" with current system time
h = lpSystemTime.wHour; - choose from "lpSystemTime" structure the field with the number of hours and put it in the variable "h"
m = lpSystemTime.wMinute; - the same for minutes
s = lpSystemTime.wSecond; - the same for seconds
if (h>12) {h=h-12;} - as the number of hours is represented with a number from 0 to 23, and I don't want to listen dozens of bell strikes, it was decided to limit it by 12. Accordingly, the number of hours representation was converted from military to regular one. For example, if it is 17 o'clock, then the chiming clock wil strike 17 - 12 = 5 times.
//if (h==0) h=12; - the commented line that handles a situation when the number of hours is equal to zero (midnight). Why it is commented? Because when the clock strikes 11 times in 23:00 it's no one sleeps yet and it's tolerated, but when in night silence a bell strikes 12 times... As a result, it was decided not to strike at midnight.
Sleep (1000) - since we are interested in time only with pricision up to seconds, then it is not necessary to utilize the CPU always - let it sleeps for 1000 milliseconds.
if ((m == 30) & (s == 0)) {sndPlaySound ("bell.wav", SND_ASYNC);}; - if the number of minutes is 30, and the number of seconds is 0 (i.e. exactly an half of an hour), then play asynchronously the file called "bell.wav", i.e. strike once. The function called "sndPlaySound" accepts only "wav"-files, so the piece of the intro of "Metallica - For whom the bell tolls.mp3" had to be converted. Note that if you specify such a filename, it will be searched only in the working directory, so, if you want to put it apart you need to specify a full path.
if ((m == 0) & (s == 0)) - this condition is satisfied when the number of minutes equal to zero and the number of seconds is zero too. That is, when it is exactly an hour sharp.
for (int i=0; i<h; i++) - a loop from zero to the current number of hours. That is, for example, if it's five o'clock, then this part will be repeated five times.
sndPlaySound ("bell.wav", SND_ASYNC); - this function asynchronously plays the already known sound of a bell toll.
Sleep (2000) - waiting for two seconds. This is important because playing is asynchronous: the second bell is heard before the end of the first, if the bell sample is longer than two seconds, or with a slight delay if the sound is shorter. In general, this value must be chosen depending on the selected signal.
return 0; - return zero. In fact, considering that there is the infinite loop before, we will never reach this line.
Now we turn to porting. The source for Linux looks like this:
There are only three functions in the program - to get the system time, to play a sound file, and to sleep. Let's start with including of libraries that contain these functions:
time.h - a library with functions for working with time
unistd.h - a library with "sleep" function
stdlib.h - and this library will allow us to make a system call to play the sound file directly from the program.
The "main" function and declaration of variables for hours, minutes and seconds left without changes.
But the structure containing a system time now looks somewhat different:
The difference is because Windows function "GetLocalTime" immediately fills the structure of time expanding it by years, months, days, etc., but Linux function "time" returns unix-time, i.e. time represented in seconds, and for its transformation into what we need we have to use another function - "localtime".
We see these differences after the identical while (1):
Accordingly, it is a different procedure of filling variables of the structure - a Linux-variant even a bit C++-style:
Converting time from the military standard to the regular one remains the same. But "sleep" now in seconds rather than milliseconds:
Conditions under which the sounds are played remained unchanged, but now it's different ways to play: in Linux it can be done easily through the system call "play file_name.wav":
In such case playing will be synchronous (next toll will not start until the previous ends), so the duration between beats can be adjusted by file length. So the second "sleep" is not needed.
That's all the differences. But the program is very tiny. Doing something like this you understand that you shouldn't criticize severely Blizzard or Valve, because they don't want to port their games to Linux. Especially if the cross-platform feature initially wasn't expected.
PS I can't share the source in the text form instead of images, because of paranoid "antihacker". So if you want it - PM me.
Today we’ll talk about Opera, of course not about an art form. This article will explore how to combat annoying ads using tools of a popular browser.
To conclude the topic of ad-blocking (1, 2), we consider the same for the Opera web browser.
You haven’t to install add-ons and plug-ins, because everything is already built-in to the browser.
The same page of popular website Habrahabr remains our goal:
We’re calling a context menu by right-clicking and will select the option Block content:
Then we’ll click on that we want to block and these images are removed:
Besides I can see another banner that I did not even notice - it is white.
Once all that is needed (more precisely all that is not needed) is blocked - we click "Done":
The images were removed. It remained only to block a contextual advertising. It is necessary to know a web site, from which the ad has been transmitted in order to successfully combat it. To do this, we’ll move the mouse cursor on the one of links in the table and look at the web site in a browser's status bar:
Now we’ll open the list of blocked content:
In the list we’ll click Add and enter the following mask for blocking "*an.yandex.ru*":
Now we’re updating the web page and enjoying the lack of advertising:
This is the second article dedicated to the ad blocking setup in browsers. This time we will discuss the web browser developed by Google. At the time of writing the article described browser extensions worked only in develop-version. Now it is possible to use the latest stable build of Google Chrome.
---------------------------------------------------------------------------------------------------
To continue the topic of annoying advertising blocking I'll tell you about popular web browser developed by Google.
You'll need a developer version of Google Chrome to be able to use add-ons. You can download it by the following a link:
If you look at browser’s properties you will easy notice that the version begins with the number 4:
This is just what we need.
Now install AdBlock+. You can install it from here (Link).
Once the content-filtering extension is installed, the icon of add-on appears in Chromium:
Everything is ready.
Thus, the purpose is the same - to block two advertisements from Habrahabr website:
So, we begin clicking the AdBlock+ icon and selecting "Block element" option (at the same time we are memorizing keyboard shortcuts for this operation):
Then move the mouse cursor on the area you want to block. Chrome will offer different options and highlight them:
When clicking a selected area the browser highlights it in red and displays a window with a filter which will block the area.
I could not select the entire table of the advertising So I had to click on each part of advertising area. At the same time new filters are added to the existed ones separated by commas. There is no user-friendly filter editor, so I have copied the filter’s string and placed it in a text file. When I carefully examined the text, I noticed that each block contains the same div class = "yandex-direct":
An idea came to my head. I click on the same icon and select “Edit rules”:
And replace its contents with the class = "yandex-direct" in square brackets:
It works! The entire table has been disappeared.
It is not so simple about Flash web banner. It's necessary to click on the banner ad:
The banner is activated as a link when clicking it. By the way, in a previous article I focused on the fact that it is no need to click on the links while inspecting by DOM Inspector. I mentioned the DOM Inspector – because of dev builds of Chromium has a similar tool. This tool is called by right-clicking on the area you need to inspect and selecting the "Inspect Element" option in a context menu:
The page's source code is opened. There we can see the part of source code responsible for this area, it is displayed on the page:
It is possible to expand a hierarchy of source code and move the cursor on the strings inside the main unit. You can see that the area containing the banner is highlighted when moving the cursor on the first string:
As can be seen div class = "banner" is responsible for the banner. Without thinking twice I call a rule editor and add the following:
The situation with annoying ad banner that is displayed when visiting one of your favorite websites is familiar to everyone. It becomes the last straw between "I understand that a website must earn" and "How long will it last?" Sometimes the owners of the website provide a model without online advertising. But it happens very rarely and that's why we have to fight with the annoying advertising by ourselves.
Today I want to tell how to block the banners and advertising areas using the add-ons of Firefox.
First of all, we should install these useful additions. There are three additions of my adblock unit:
Once installed, the add-ons icons are appeared in the interface of Firefox:
When first running after installation of Adblock Plus you can directly subscribe to the blacklists:
As an example, we will consider popular website Habrahabr . During reading I noticed two advertising areas:
Let's start with the flash banner on the right. If you move the mouse cursor on the banner Adblock Plus adds button "Block":
Clicking this button will invoke the menu with filter suggestions that would be used for this and similar banners to be displayed. You can write yours variant:
Any of the images can be blocked, just right-click it and choose corresponding item of context menu:
It is more difficult to cope with a text block, because this is not an image and requires additional efforts.
First, we need to know which block of a code is responsible for the text displaying. If you understand a web programming, you can find the answer to this question in the code page. Otherwise DOM Inspector comes to the rescue. You can find it in the Tools menu bar:
Once DOM Inspector is run we click the button "Inspect" located in the upper right corner:
After clicking the same page as the one that we can see in the browser it will be rendered in the bottom edge of Inspector:
Then we click the arrow in the upper left corner to inspect a required unit:
Then we will click any place of the table with advertising except references:
The Inspector highlights in red selected area and moves to the string of the code that is responsible for showing it. Now move up the hierarchy of code by clicking the string of the code until the Inspector is highlighted the entire table:
When entire table will be in red box, we call a context menu at the found string and choose one of the options in the tab "Copy selector". You should focus an attention on it and choose something unique. If you simply selected "DIV", the whole page would be hidden.
After that you have to create a new style. To do this, click the icon Stylish in the lower left corner of the browser (not DOM Inspector, but browser) and select Manage Styles in the menu that appears:
Stylish window is opened and we will create a new style:
You have to specify a name (necessarily) and tags (optionally) for a new style:
You should specify namespaces (@ namespace url(http://www.w3.org/1999/xhtml);), as well as the domain in which this style will work (@-moz-document domain ("habrahabr.ru ")). If the domain is not specified, the style will be applied everywhere.
Then we enter data that you want to hide (.yandex-direct) and options to hide ((display: none!important;)). It is needed only to click the "Save" and it is done.
You can compare, before:
And after:
As regards the flash, it is used mainly for videos. In the vast majority of cases is advertising. And the most annoying ads it moves and flashes. So I created a rule for Adblock Plus, which blocks everything by the pattern "*.swf" and thus make a few exceptions - for youtube and several others video hosting services. It really helps.
Hey!
Do you know anything about AV-School camp? Sure you know!
I've got a couple of pictures here from summer (Camp episode 2. Yaroslavl, Russia). You can find it in .ru gallery.
And I shooted about 150 photos for our stop-motion movie. Take a look:
I believe that sometime we will make a really international camp in Europe and all of you will take a chance to participate in it.