Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Tuesday, October 20, 2015

Shell script to run multiple programs in Linux

"Recently, I had a situation where I needed to execute multiple programs in Linux at the same time while redirecting their outputs to separated log files and wait for them to finish.
If you ever need to do something like that, I leave year the script that I used to accomplish that task:"

#!/bin/bash
 
# Add the full path processes to run to the array
PROCESSES_TO_RUN=("/home/joao/Code/test/prog_1/prog1" \
                  "/home/joao/Code/test/prog_2/prog2")
# You can keep adding processes to the array...
 
for i in ${PROCESSES_TO_RUN[@]}; do
    ${i%/*}/./${i##*/} > ${i}.log 2>&1 &
    # ${i%/*} -> Get folder name until the /
    # ${i##*/} -> Get the filename after the /
done
 
# Wait for the processes to finish
wait
 
Post source:  http://joaoperibeiro.com/execute-multiple-programs-and-redirect-their-outputs-linux/


Tuesday, March 6, 2012

How to license your free software with GNU GPL v3

As you all know a software license is something that tells the users what they can or cannot do with that especific software and it's also a way of giving some credit to the author for his software.

There are several types of licenses:

- Perpetual license
- Subscription license
- Freeware license
- Shareware license
- OEM (original equipment manufacturer)
- Educational or Academic Software
- Not for Resale (NFR) Software License
- And more...

This post is specifically about Freeware Licences and specially about Open Source because, as you already know, inside free software applications we have some that are open source and others that are closed source.

So let's see a little bit more about free and open source software (quoting Wikipedia.org):
A primary consequence of the free software form of licensing is that acceptance of the license is essentially optional — the end-user may use, study, and privately modify the software without accepting the license. However, if the user wishes to exercise the right of redistributing the software, then the end-user must accept, and be bound by, the software license.
Free and open-source licenses generally fall under two categories: Those with the aim to have minimal requirements about how the software can be redistributed (permissive licenses), and those that aim to preserve the freedoms that is given to the users by ensuring that all subsequent users recives those rights (copyleft Licenses).
An example of a copyleft free software license is the GNU General Public License (GPL). This license is aimed at giving all user unlimited freedom to use, study, and privately modify the software, and if the user adheres to the terms and conditions of GPL, freedom to redistribute the software or any modifications to it. For instance, any modifications made and redistributed by the end-user must include the source code for these, and the license of any derivative work must not put any additional restrictions beyond what GPL allows.[1]
Examples of permissive free software licenses are the BSD license and the MIT license, which give unlimited permission to use, study, and privately modify the software, and includes only minimal requirements on redistribution. This gives a user the permission to take the code and use it as part of closed-source software or software released under a proprietary software license.

free and open source license GPL


One of the most known and used license for this type of software is the GNU GPL(General Public License) that is now on version 3. The bases of this license, quoting gnu.org, are:

The Foundations of the GPL

Nobody should be restricted by the software they use. There are four freedoms that every user should have:
  • the freedom to use the software for any purpose,
  • the freedom to change the software to suit your needs,
  • the freedom to share the software with your friends and neighbors, and
  • the freedom to share the changes you make.
When a program offers users all of these freedoms, we call it free software.
Developers who write software can release it under the terms of the GNU GPL. When they do, it will be free software and stay free software, no matter who changes or distributes the program. We call this copyleft: the software is copyrighted, but instead of using those rights to restrict users like proprietary software does, we use them to ensure that every user has freedom.
So if you developed a software and you are thinking about distributing it as a free software, i created a little video explaning what you need to do to license your software with GNU GPL v3. I am not an expert on this but i have already done this and i am just trying to share my experience.

Video turorial:


Sunday, February 26, 2012

Read a file line by line to the end in VB.NET

This tutorial it's about reading a file line by line until the end in VB.NET. This is usefull, for instance, if you are using this file as a settings file and you inserted one setting per line then you can read them by order.

Visual Studio screenshot:


Code:


Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim file_dir As String = "file.txt"
        'parse file
        Try
            Dim sr As StreamReader = New StreamReader(file_dir)
            Do Until sr.EndOfStream
                TextBox1.Text += vbNewLine + sr.ReadLine()
            Loop
            sr.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

In this case you are reading and adding each line to a textbox but you can read this to a string array and keep the information to work with later. It's also important to use try catch because if the file doesn't exist or you don't have permissions to read it will not crash the application.

Sunday, February 12, 2012

VB.NET Limit textbox minimum and maximum characters

Let's imagine that you hava a textbox for a user to input something and you want that to be between a minimum and a maximum number of characters, how you do it on VB.NET? Let's see!

Code:

Maximum size limitation can be done in the textbox properties in the "MaxLenght" option.

textbox vb.net
To minimum size limitation it's only necessary to check when user clicks the button to send that information.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        check_text()
    End Sub

    Private Sub check_text()
        If TextBox1.Text.Length = 3 Then
            MessageBox.Show("Ok")
        Else
            MessageBox.Show("You need to insert 3 numbers")
        End If
    End Sub


Video tutorial:


Monday, February 6, 2012

Textbox for numbers only VB.NET

Sometimes we need to limit our user inputs to only numbers for instance in a quantity input and for that i leave here a tutorial on how to do that in VB.NET.

Code:

Public Class Form1    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or Asc(e.KeyChar) = 8 Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub



End Class


Video tutorial:


Friday, January 27, 2012

Checking if a directory exists and creating one in VB.NET

This tutorial contains you the necessary code to check if a directory exists and to create one if it returns false using VB.NET.

Code:

Imports System.IO


If Directory.Exists("c:\mydir") Then
        MessageBox.Show("Directory exists!")
Else
        Directory.CreateDirectory("c:\mydir")

        MessageBox.Show("Directory created!")
End If

Saturday, January 21, 2012

For Loop VB.NET / C#

This time i leave another very usefull loop, the "For Loop", in both VB.NET and C#.
Enjoy.


C#:
  for (int i = 0; i <= 5; i++)
  {
     //Do your code here
  }


VB.NET:
  Dim i As Integer
  For i = 0 To 5
      'Do your code here
  Next i
 

Monday, January 16, 2012

Switch Case / Select Case VB.NET / C#

I needed to remember the syntax of the switch / case for the .net languages and then i decided to share them with you here too so you can learn or remember them too.

C#:
  switch (option)
    {
        case "option1":
            // code for case "option1"
            break;
        case "option2":
            // code for case "option2"
            break;
        default:
            //code for every other options
            break;
    }

VB.NET:
Select Case option
    Case "option1"
          ' code for case "option1"
    Case "option2"
          ' code for case "option2"
    Case Else 
          ' code for every other options
End Select
 

Sunday, November 27, 2011

Java search bar - Click event and Enter key event (Netbeans)

Create a search bar in a java application using netbeans, configuring click event listener and ENTER key event listener in the jTextField.







Code for button click event listener and key listener in jTextField:

        jButton1.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                jLabel1.setText("You searched for: "+jTextField1.getText());
            }
        });
        
        jTextField1.addKeyListener(new KeyAdapter()
        {       
            @Override
            public void keyPressed(KeyEvent e)
            {
                if(e.getKeyCode() == KeyEvent.VK_ENTER)
                    jLabel1.setText("You searched for: "+jTextField1.getText());
            }
        })



Saturday, November 26, 2011

Zymic - Free Web Hosting



Lots of people wounder how they can put thir website online without spending much money or no money at all. There are several way of doing that and Zymic is on of them. Zymic provides a free hosting service with the following caracteristics:

Free Web Hosting - General Features
- Disk Space 5000MB
- Data Transfer (Monthly) 50000MB
- Control Panel ZHCP
- Number Of Accounts Unlimited
- FTP Access Yes
- Advertisements No

Free Web Hosting - PHP And Databases
- PHP Ver 5.2.12
- MySQL Databases 3
- SQLBuddy Ver Custom

Free Web Hosting - Domain Names
- Sub-Domains Yes
- TLD Domain Yes

Free Web Hosting - Zymic Hosting Control Panel (ZHCP) Features
- File Manager Yes
- MySQL Management Yes
- Free Support Yes
- Account Settings Yes

I am using Zymic for a while and i'm really happy with their service.




Thumbs up to TweakUniverse for this video.

Sunday, November 20, 2011

Inserting an image in a Java GUI using NetBeans

This is a quick tip on Java about inserting an image on a JFrame using a JLabel in Netbeans IDE. Since NetBeans don't give a direct way to insert images this is the best way to do it. 
Keep programming and learning!



Monday, November 14, 2011

Order a vector in C

This tutorial presents two ways of order a vector using the programming language C.
We can use the typical way with two for cicles that can become really slow when the vector length is big (like 3555555) or a less commun way but a faster and smaller (in lines of code).

Typical way:

#include <stdio.h>


int main()
{
int v[5] ={2,5,3,2,4};
int v_temp;
int i,j;
for (i=0; i<5; i++)
{
for (j=0; j<5; j++)
{
if(v[i] <= v[j] && i!=j)
{
v_temp=v[j];
v[j]=v[i];
v[i]=v_temp;
}
}
}
for (i=0; i<5; i++)
{
printf("%d -> %d\n",i,v[i]);
}
return 0;
}


Other way:


#include <stdio.h>


int sort(const void *x, const void *y) {
  return (*(int*)x - *(int*)y);
}


int main()
{
int v[5] ={2,5,3,2,4};
int i;
qsort(v, 5, sizeof(int), sort); /*less lines of code and way faster ordering the vector qsort(name_of_vector,length_of_vector,sizeof(type_of_variable),name_of_function) in this case name_of_function is "sort"*/
for (i=0; i<5; i++)
{
printf("%d -> %d\n",i,v[i]);
}
return 0;
}


The result in both methods it's:

0 -> 2
1 -> 2
2 -> 3
3 -> 4
4 -> 5

Monday, October 3, 2011

Give a better look to your login forms

Note: This tutorial it's not for beginners but it's for people already with some knowledge of HTML and CSS.

So instead of creating a regular login form like this:

User:

Password:



Code:

<html>
<head>
</head>
<body>
<form action="" method="post">
User:<br>

<INPUT type="text" name="username" size="25"><br>
Password:<br>
<INPUT type="password" name="password" size="25"><br><INPUT type="submit" value="Send">
</form>
</body>
</html>

 You can add some stuff that will make your login form look a lot more professional and nice like this:

 User:

 Password:



Code:


<html>
<head>
<style>
input:focus {
outline: none;
}/*This CSS propriety takes out that yellow border that apears when you select the input box with your mouse*/
#login_div{
font-family: Impact, fantasy;
font-size: 13px;
color: #66665E;/*font color*/
letter-spacing:2px;
}
.login_form{
background-color:#EDEDED;
border-type:solid; /*configure border*/
border-width:3px; /*configure border*/
border-color:#3088bc; /*configure border*/
font-family: Impact, fantasy;/*font type*/
font-size: 13px;
color: #66665E;/*font color*/
letter-spacing:2px;/*space between letters*/
-moz-border-radius: 7px 7px / 7px 7px;/*configure the rounded corners*/
border-radius: 7px 7px / 7px 7px;/*configure the rounded corners*/
}
</style>
</head>
<body>
<div id="login_div">
<form action="" method="post">
&nbsp;User:<br>
<INPUT type="text" name="username" size="25" class="login_form"><br>
&nbsp;Password:<br>
<INPUT type="password" name="password" size="25" class="login_form"><br>
<INPUT TYPE="image" SRC="submit.png" ALT="Submit Form" style="margin-top:4px;margin-left:2px;"><!-- Change the image of the submit button -->
</form>
</div>
</body>
</html>

I hope it helped.