quarta-feira, dezembro 01, 2021

How to simulate paper texture in GIMP

 Step 1: Launch GIMP, and select File-menu > New. Choose the height and width of your paper in pixels, and press ‘OK’. For A4 paper, the size should be 3508 x 2480 pixels.

Step 2: Select Filters-menu > Noise… and choose ‘RGB Noise’. Apart from ‘Preview’ make sure all other check-boxes are unchecked.

Step 3: Do you want your paper to be smooth, or would you like to have a texture that’s tad stronger? Take your pick as you slide the tab on ‘Red’ ‘Green’ or ‘Blue’ between 0.20 to 0.69. Do notice how all three values move in tandem. Check out the preview which may show granular dots increase or decrease in density. I prefer values between 0.20 to 0.32. Once you find a pattern to your taste, click ‘OK’.

Step 4: Go to Image-menu > Mode > Grayscale. This one step will make the dots appear more textured, and shrink your file to one-third its size in kilobytes or megabytes, which is a good thing.

Step 5: Go to Filters-menu > Blur > Gaussian Blur. Choose a value between 3 and 9 on the slider below. Check out the ‘Preview’ to see what suits your taste, and click ‘OK. You’re done. If required, you may re-apply Gaussian Blur with a different value, for an even smoother finish.

Save your file in the format of your choice, and you’re done.


Further tips:

Use the Color-menu > Brightness-Contrast slider to set the tonality of your paper.

quarta-feira, fevereiro 06, 2013

How to disable Overlay Scrollbars in Ubuntu 12.04

There is a simple way to disable the annoying overlay scrollbars in Ubuntu 12.04. Just run the command bellow in the Linux console:


gsettings set org.gnome.desktop.interface ubuntu-overlay-scrollbars false


You don't need to reboot. Just close the applications and open them again, so the old style bars (which are much better) will become visible!

domingo, dezembro 09, 2012

How to install Xfce in Ubuntu 12.04

If you want to use less machine resources on Ubuntu 12.04, or if you simply didn't like Gnome 3 layout and usability, here goes a nice tip to you: use the Xfce desktop enviroment. It's lightweight and makes me remember the good old times from Gnome 2 also (this is just a personal opinion).

To install it on Ubuntu 12.04, use the  following command:

sudo apt-get install xfce4

After installation, you are going to be able to choose your desktop enviroment the next time you try to log in.


Another option is to download and install Xubuntu, a Linux operating system based on Ubuntu that comes with Xfce by default.

Xubuntu 12.04 with Xfce 4.10

sexta-feira, outubro 19, 2012

Original GameMenu.res file for Counter-Strike 1.6

For CS 1.6 players sometimes it is necessary to restore the GameMenu.res file. In most cases, it is placed at "C:\Program Files\Valve\cstrike\resource". You can open it using the Notepad.

Bellow is the code of the original file:


"GameMenu"
{
"1"
{
"label" "#GameUI_GameMenu_ResumeGame"
"command" "ResumeGame"
"OnlyInGame" "1"
}
"2"
{
"label" "#GameUI_GameMenu_Disconnect"
"command" "Disconnect"
"OnlyInGame" "1"
"notsingle" "1"
}
"4"
{
"label" "#GameUI_GameMenu_PlayerList"
"command" "OpenPlayerListDialog"
"OnlyInGame" "1"
"notsingle" "1"
}
"8"
{
"label" ""
"command" ""
"OnlyInGame" "1"
}
"9"
{
"label" "#GameUI_GameMenu_NewGame"
"command" "OpenCreateMultiplayerGameDialog"
}
"10"
{
"label" "#GameUI_GameMenu_FindServers"
"command" "OpenServerBrowser"
}

"11"
{
"label" ""
"command" ""
}
"12"
{
"label" "#GameUI_GameMenu_ChangeGame"
"command" "OpenChangeGameDialog"
"notsteam" "1"
"notsingle" "1"
"notmulti" "1"
}
"13"
{
"label" "#GameUI_GameMenu_Options"
"command" "OpenOptionsDialog"
}
"14"
{
"label" "#GameUI_GameMenu_Quit"
"command" "Quit"
}
}

terça-feira, maio 08, 2012

Linux "nice" command: running a program with modified scheduling priority

There is a very useful program for Linux for setting different priorities to a program: the nice command.
Priority ranges in Linux varies from -20 (greater priority) to 19 (lesser priority). So, the lesser the value, the greater is the scheduling priority.
Use nice is simple. In the example shown bellow, we want to run the program "your_program_name" using priority value 10:

nice -n 10 your_program_name

The default priority value is 0. If you want to set a priority less than 0 (greater priority than the default), you should run it as system root.

quinta-feira, abril 12, 2012

How to set line spacing in LaTeX

Some simple (but very important) commands you should know about line spacing in LaTeX:

\singlespacing - sets the text to single line spacing
\onehalfspacing - sets the text to one half spacing
\doublespacing - sets the text to double spacing

To use such commands, you should use the following package: \usepackage{setspace}


Bellow, there's a simple example about how to use these commands:


\begin{document}
\onehalfspacing
First part of the text (using one half spacing)
\doublespacing
Second part of the text (using double spacing)
\end{document}

quinta-feira, dezembro 29, 2011

Raspberry Pi, the tiny and powerful US$25 computer

Here I'll be posting some videos about the Raspberry Pi, when they become avaliable.


Presentation of one of the first final boards:




First video of the Gertboard connected to the Raspberry Pi's GPIO:

quarta-feira, dezembro 28, 2011

The abusive price of electronics in Brazil

Last month, I've heard about the Raspberry Pi project. It's about a US$25~35 board, with an 700 MHz ARM processor (the Broadcom BCM 2835), 128/256 MB of RAM, USB, HDMI and Ethernet (depending of the model) connectors. Those boards are suposed to run some Linux distributions (initially Fedora and Debian) and programming languages such as Python, Java, C (and others), and it's aimed to educational proposes (but can you imagine the things that could be possible to do with such hardware?)





I've been very excited with the news that the Raspberry Pi final boards would be finished in December/2011 or January/2012, and they would be sold first in United Kingdom and maybe in the United States. Although, at the same time, I got worried about the possibility of that board never come to Brazil (the country I live) or to become a very expensive product that only few people could get access to. Since it's not being sold yet (until the publication of this post), I had a hope that all my worries could not become true.

Today, I knew that there is another similar project, but with a board (the BeagleBoard) that is more sophisticated than the Raspberry Pi, and is being sold for the recommended price of US$149 in the rest of the world, but in Brazil, due to a restriction of Texas Instruments that prohibits brazilians to buy that board directly from the United States through the Internet, it costs about R$850~975 !!!












Just for comparison, today US$1,00 is about R$1,90. So, we can conclude is that the BeagleBoard is being sold for, at least, 3 times it's recommended price.







I really hope that the Raspberry Pi can become a reality in brazilian education (from schools to universities), and I can't wait to get my own board. But if it costs much more than US$25~35, I'm sure that the dream is really, really over!

segunda-feira, novembro 21, 2011

Using a SSH connection as a proxy (SSH Tunneling)



For many people it is necessary to go the University to access many websites to download papers or journals. What many of those people don't know, is that is possible to create a socket (Windows/Linux) with a SSH (Secure Shell) server and then connect to the University server direct from your computer, using that SSH connection as a proxy server to your web browser (IE, Firefox, Chrome, Opera, etc). For that, you need:
*One client ssh (you can use Putty on Windows, for instance)
*Have a valid username and password to access the University server.

Bellow, there's one example about how it could be done using Windows (XP) platform.

In Putty's main screen we need to create a new "Saved Session". In this example, we called it "Tunneling". Create then save it. After that, in the same screen, set the host name and port.




Then in Category "Connection" click in SSH->Tunnels. Choose one random port (in this example we chose 8084) from your computer and type it in the "Source port" field. Before add, you need to set it as "Dynamic" (the default is "Local" as in the picture bellow, so change it).




After doing that, you can connect to the SSH server. Once connected is time to configure your browser. We are going to use Firefox web browser in this example, but it can be done in any other, like IE, Chrome, Opera, Safari, etc.

Open Firefox. At the upper menu click on Tools->Option, then choose "Advanced" and finally the "Network" tab. Click the "Settings..." button.

Select the "Manual Proxy Configuration", and set the IP "127.0.0.1" to SOCKS. The source port should be the same as you chose for your Tunneling configuration for Putty (in this example: 8084).


Click the "OK" button, then your IP address within the Internet is going to be the same as the server you are connected. To the Internet, it is as if you were accessing from your University (for example).

In fact, you are using the SSH server as a proxy server, and the data transmitted between you and that server are encrypted.

domingo, setembro 18, 2011

The Unix Time

Don't you know what is Unix Time?
According to Wikipedia: "Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds."

It's a linear representation of time, because we're just working with the amount of seconds that have passed from an event in the past (January, 1, 1970 00:00 - UTC time). Hence, it is widely used in computer systems because it's easy to store (only one "integer" variable is needed), and it makes some time calculations easier. Basically, you will work with dates the same way you work with integer numbers.


Bellow, we list some examples about how to get the Unix Time in different programming languages:

C#:

(DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds;



Java:

System.currentTimeMillis()/1000;



JavaScript:

Math.round(new Date().getTime()/1000.0);



MySQL:

SELECT unix_timestamp(now())



Oracle PL/SQL:

SELECT (SYSDATE - TO_DATE('01/01/1970 00:00:00', 'MM-DD-YYYY HH24:MI:SS')) * 24 * 60 * 60 FROM DUAL



Perl:

time



PHP:

time()



PostgreSQL:

SELECT extract(epoch FROM now())



Python:

time.time()



R:

as.numeric(Sys.time())



Ruby:

Time.now



SQL Server:

SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())



Unix or Linux shell:

date +%s

domingo, julho 03, 2011

How to send an E-mail using the Linux command line (The Mutt Mail User Agent)

Yesterday I needed to send an e-mail with a file attached using the Linux command line. The solution was quite simple but I spent some very important minutes to find it. So there is it:


$ mutt -s "Mail's subject" -a file_to_attach.rar user@provider.com


I hope it could be useful to you one day.

sexta-feira, abril 22, 2011

DD-WRT - A Linux-based firmware for wireless routers

Are you satisfied with configuration options of your wireless router?



If the answer is "No", you should know that there are many third-party firmwares that you can install on your device, and give it options that you would find only in high-end routers.
In this post, I'm going to introduce DD-WRT. It's a free third-party linux-based firmware, under the terms of GPL license. It include features like daemon-based services, IPv6 support, Wireless Distribution System (WDS), RADIUS, Quality of Service (QoS), radio output power control, and many others.

I tried DD-WRT in my D-Link DIR-300 wireless router and I got many new functionalities, such as iptables, traffic graphs, better QoS support, blocking websites by URL or keyword, and others. One interesting thing is that now I can use my Wi-Fi router as a Client or as a Repeater (even the other wireless routers of the network doesn't support WDS). I present you some printscreens from its configuration pages:


Wireless Modes



Used CPU and Memory



Traffic Chart of this Month


DD-WRT can be downloaded at: http://www.dd-wrt.com. Note that firmware upgrades have a risk of damaging your device. Please read carefully all about it on the website. There you will find if your wireless router is compatible with DD-WRT or not.

String format for DateTime in C#

In C# language, there are the following custom format specifiers for date and time:
y - year
M - month
d - day
h - hour 12
H - hour 24
m - minute
s - second
f - second fraction
F - second fraction, trailing zeroes are trimmed
t - P.M or A.M
z - time zone


Some examples on how to use them (the output is commented at the end of each line):


/*
In this example, we create an DateTime object (whose name is "dt") that representes
the date and time: 2008-03-09 16:05:07.123
*/

DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone

segunda-feira, abril 18, 2011

Some important Taylor/Maclaurin series

Have you ever asked yourself about how your scientific calculator or your computer "know" the sine or the cosine of a number?

Maybe you thought that those devices had predefined tables inside their memories to calculate those functions. But in fact those tables don't exist! So, how those devices are able to give you the correct answer with great precision?

The truth is that they use algorithms that calculate the results of Maclaurin functions. According to Wikipedia: "A Taylor series is a representation of a function as an infinite sum of terms calculated from the values of its derivatives at a single point. Taylor series were formally introduced by the English mathematician Brook Taylor in 1715. If the series is centered at zero, the series is also called a Maclaurin series, named after the Scottish mathematician Colin Maclaurin who made extensive use of this special case of Taylor series in the 18th century."

This is an important subject of Calculus, but the objective of this post is to show some of those functions, so we won't make demonstrations here. If you really want to study it further, I recommend you to check the book: "Calculus - Volume 2, by James Stewart". Bellow you can appreciate that interesting way to calculate some well known functions:

The exponential function:


Sine and Cosine (and hyperbolic ones):








We can tell you those are ways to approximate the functions values, and precision depends only of the value of n. Note that those sommations go from zero to the infinity, then the value of those sommations converge to the real values of those functions, but computers can't calculate them to infinity. Thus, we calculate each sommation to a finite (and relatively "small") value of n, in a manner that satisfies the desired precision that we need. One example is given bellow:


Here we calculate the exponential function for x = 2 (that is: e^2)


For n = 1 , the sommation is: 1.0
For n = 2 , the sommation is: 3.0
For n = 3 , the sommation is: 5.0
For n = 4 , the sommation is: 6.33333333333
For n = 5 , the sommation is: 7.0
For n = 6 , the sommation is: 7.26666666667
For n = 7 , the sommation is: 7.35555555556
For n = 8 , the sommation is: 7.38095238095
For n = 9 , the sommation is: 7.3873015873
For n = 10 , the sommation is: 7.38871252205
For n = 11 , the sommation is: 7.38899470899
For n = 12 , the sommation is: 7.38904601571
For n = 13 , the sommation is: 7.38905456683
For n = 14 , the sommation is: 7.38905588239
For n = 15 , the sommation is: 7.38905607033
For n = 16 , the sommation is: 7.38905609538
For n = 17 , the sommation is: 7.38905609852
For n = 18 , the sommation is: 7.38905609888
For n = 19 , the sommation is: 7.38905609893
For n = 20 , the sommation is: 7.38905609893

According to the built-in function of Python's math library, e^2 is: 7.38905609893

In this example, we conclude that n equal or greater than 19 gives a good precision (if compared with Python's built-in function) for x = 2. But for greater values of x, we should increase the number of iterations. Let's check another example, for x = 5:


For n = 1 , the sommation is: 1.0
For n = 2 , the sommation is: 6.0
For n = 3 , the sommation is: 18.5
For n = 4 , the sommation is: 39.3333333333
For n = 5 , the sommation is: 65.375
For n = 6 , the sommation is: 91.4166666667
For n = 7 , the sommation is: 113.118055556
For n = 8 , the sommation is: 128.619047619
For n = 9 , the sommation is: 138.307167659
For n = 10 , the sommation is: 143.68945657
For n = 11 , the sommation is: 146.380601025
For n = 12 , the sommation is: 147.603848505
For n = 13 , the sommation is: 148.113534955
For n = 14 , the sommation is: 148.309568205
For n = 15 , the sommation is: 148.37958008
For n = 16 , the sommation is: 148.402917371
For n = 17 , the sommation is: 148.410210275
For n = 18 , the sommation is: 148.412355247
For n = 19 , the sommation is: 148.412951072
For n = 20 , the sommation is: 148.413107868
For n = 21 , the sommation is: 148.413147067
For n = 22 , the sommation is: 148.4131564
For n = 23 , the sommation is: 148.413158522
For n = 24 , the sommation is: 148.413158983
For n = 25 , the sommation is: 148.413159079
For n = 26 , the sommation is: 148.413159098
For n = 27 , the sommation is: 148.413159102
For n = 28 , the sommation is: 148.413159102
For n = 29 , the sommation is: 148.413159103
For n = 30 , the sommation is: 148.413159103
According to the built-in function of Python's math library, e^5 is:148.413159103


Now note that n = 19 isn't enough to give the same precision as before. And the precision for n = 19 will get worse for greater values of x. Thus, the greater is x, the greater is the number of necessary iterations to get a good approximation of the real value of the function.

terça-feira, setembro 07, 2010

How to compile a Beamer presentation using MikTex 2.8

After 3 days trying to compile one presentation using Beamer on MikTeX 2.8, I finally found out how to do it.


I noticed that MikTeX didn't came with the beamer package installed on it. So I tried to install beamer manually through its "Package Manager", but it didn't solve the compilation errors.

After "burning" some neurons, I tried to install the packages pgf and xcolor, and now it works very well.

There's one feature about MikTeX that could help you to save a lot of time when trying to "find" the correct packages. On its Maintenance menu, you can find the Settings application. Open it, and search for the "Install missing packages on-the-fly" option. Change its value to Yes.

quinta-feira, abril 08, 2010

How to configure Grub 2 in Ubuntu 9.10 (Karmic Koala)

I've installed Ubuntu version 9.10 (Karmic Koala) recently, and previously I had another operating system installed in my computer. I tried configure Grub (GRand Unified Bootloader) to execute the dual boot screen, so I noticed that this version of Grub was not the same as the previous versions of Ubuntu.


Ubuntu 9.10 uses Grub 2, and there are some new features to make it easy to configure.
First: You should NOT edit the /boot/grub/grub.cfg file. This file replaces the old /boot/grub/menu.lst Grub legacy file. By the way, it no longer exists.

Actually, there is another configuration file /etc/default/grub that can be edited by a root user (like the old menu.lst). Some of the parameters of this file are:

GRUB_DEFAULT: Sets the default and pre-selected menu entry. Entries may be numeric or saved.

GRUB_DEFAULT: Sets the default menu entry by menu position. As with Grub Legacy, the first "menuentry" in grub.cfg is 0, the second is 1, etc.

GRUB_DEFAULT: Sets the default menu entry by name. Example: "Windows XP Professional (on /dev/sda1)".

GRUB_DEFAULT: Sets the default menu entry with whatever was selected on the last boot. If the menu is displayed during boot, the previously selected option will be highlighted. If no action is taken, this is selection which will be booted at the end of the timeout, or if the menu is hidden.

GRUB_TIMEOUT: No change from Grub Legacy. This is the number of seconds before the default entry is automatically booted.
Setting a value of -1 will display the menu until the user makes a selection (no timeout).

There are another parameters that were ommited in this post.

After you edit /etc/default/grub, run the command update-grub at console as root user, so /boot/grub/grub.cfg will be updated automatically by system.

For further information about Grub 2, read: https://wiki.ubuntu.com/Grub2.

segunda-feira, janeiro 12, 2009

How to build JNI applications using Dev-C++ and Netbeans

JNI is an acronym of Java Native Interface. It is a programming framework that allows your Java code to call and to be called by native applications. So, you can write libraries in other languages, such as Assembly, C/C++, or even C#.

Here, we are going to talk about how to write a DLL in C/C++, using Dev-C++ 4.9.9.2 (avaliable at: http://www.bloodshed.net/devcpp.html). Dev-C++ is not upgraded for a long time, so feel free to use CodeBlocks (the process of building a DLL is almost the same. You can download Codeblocks at: http://www.codeblocks.org). I used Dev-C++ because it seemed nice to me.

Before we start, let's talk about some advantages and disadvantages of JNI:

Using JNI you can...:
* Call Windows API functions.
* Increase execution speed.
* Call API functions of some product which is in C or C++, from Java Client.

Some disadvantages:
* Forget "write once run anywhere" (your code is not portable between different platforms).
* It is difficult to debug runtime error in native code.
* There is a potencial security risk.
* Only applications and signed Applets can invoke the JNI.
* There is no garbage collection at the JNI side (This means that you must dealloc the used memory your code previously alloced).

Now that you know the advantages and risks, let's show an example about how to use JNI with Dev-C++ and Netbeans.

First, configure Dev-C++. Go to Tools -> Compiler Options and create a new compiler set.



Now, go to the Directories tab (as shown bellow) and add the include paths of JDK to C and C++ (be careful here! As I said, you should add to C and then to C++ !!!).

You should add the following directories (you can find them in the JDK folder):
C:\Program Files\Java\jdk1.6.0_07\include
C:\Program Files\Java\jdk1.6.0_07\include\win32

Those are the folders of my computer! They can change according to your JDK version, OS languaage/partition. Be careful!
If you are curious, inside those folders you can find the jni.h file, that you are going to need ahead.

Now that you configured Dev-C++, go to File -> New -> Project (at the top menu), and create a DLL project.


Then, delete the files that came with the project (in the example: dllmain.cpp and dll.h).


Now, create new files in the project (Example.h and Example.cpp).




Here you can see the JNI side code. The header files and functions should be written as shown. The declaration of a function is composed by the following: Java_PackageName_ClassName_methodName (look again to the images above).
To create a DLL, simply Compile your DLL project (in the top Menu, go to: Execute -> Compile).

Finally, create a Java Application at NetBeans (avaliable at: http://www.netbeans.org). At the java project, you should create a package equals to PackageName and a class equals to ClassName.
Copy the DLL into your java project folder.



Now, make a reference to your DLL using System.loadLibrary method. To call a native method, you should create a "signature" method on Java side, using the native keyword. See the code bellow:



Now, compile you class and run it! :-)

Have fun! =]