Archive | Programming Languages RSS feed for this section

How to test Applications using Eclipse ? (Introducing my new book)

16 May

Application testing plays very important role in any development process.  After spending numerous hours on it, I have decided to put what I felt was important in to a short book, which is intended to help developers  to get  started with  application testing using Eclipse.

918Y5X8TILL._AA1500_

The book is very practical, there is almost no theory, just recipes that introduce essential concepts of testing such as Breakpoints and JUnit tests.It is short and strict to the point. You can read it and do all the recipes in one day, and in the end, you will have deep understanding of how to debug your application using Eclipse.

The book is available in paperback as well as ebook formats.

Java Helper Class: BMI calculator, lb to kg converter, kg to lb converter, feet to cm converter, cm to feet converter

22 Mar

Hey Guy’s,

Long time no seen. Today I want to share with you Java helper class that I have designed for one  of the projects I am working on. This class will be useful for you, if your application works with height and weight conversions, also if you need to calculate Body Mass Index.

My helper class has following functionality:

- Kg to Lb Converter
- Lb to Kg Converter
- BMI (Body Mass Index) Calculator and “Classificator
- Feet to Cm Converter
- Cm to Feet Converter

Here is the class:

import java.text.DecimalFormat;

/**
* This class is used for any calculations connected with Weight and Height
*  - KG to LB converter (and vice versa)
*  - Feet to Cm converter (and vice versa)
*  - BMI Calculation
*
*/
public class HeightWeightHelper {

/**
*
* @param value double that is formatted
* @return double that has 1 decimal place
*/
private double format ( double value) {
  if ( value != 0){
   DecimalFormat df = new DecimalFormat("###.#");
   return Double.valueOf(df.format(value));
 } else {
   return -1;
 }
}

/**
*
* @param lb - pounds
* @return kg rounded to 1 decimal place
*/
public double lbToKgConverter(double lb) {
  return format(lb * 0.45359237 );
}

/**
*
* @param kg - kilograms
* @return lb rounded to 1 decimal place
*/
public double kgToLbConverter(double kg) {
  return format(kg * 2.20462262);
}

/**
*
* @param cm - centimeters
* @return feet rounded to 1 decimal place
*/
public double cmToFeetConverter(double cm) {
  return format(cm * 0.032808399 );
}

/**
*
* @param feet - feet
* @return centimeters rounded to 1 decimal place
*/
public double feetToCmConverter(double feet) {
  return format(feet * 30.48 );
}

/**
*
* @param height in <b>cm</b>
* @param weight in <b>kilograms</b>
* @return BMI index with 1 decimal place
*/
public double getBMIKg (double height, double weight) {
  double meters = height/100;
  return format( weight / Math.pow(meters,2));
}

/**
*
* @param height in <b>feet</b>
* @param weight in <b>pounds</b>
* @return BMI index with 1 decimal place
*/
public double getBMILb (double height, double weight) {
  int inch = (int)(height *12);
  return format((weight*703) / Math.pow(inch, 2));
}

/**
*
* @param bmi (Body Mass Index)
* @return BMI classification based on the bmi number
*/
public String getBMIClassification (double bmi) {

 if (bmi <= 0) return "unknown";
 String classification;

 if (bmi < 18.5) {
  classification = "underweight";
 } else if (bmi < 25) {
  classification = "normal";
 } else if (bmi < 30) {
  classification = "overweight";
 } else {
  classification = "obese";
 }

 return classification;
}

}//end of class

P.S If you want to have JUnit tests for this class let me know, I have them too :)

Regards,

Anatoly

Eclipse SWT migration to GTK + 3.0 status report: August 2012 – October 2012

16 Oct

Finally, I have decided to give a brief update on where are we standing with migration of SWT from GTK+ 2.0 to GTK+ 3.0.  The reason why I didn’t do  “status report”  earlier is pretty simple – huge amount of work and lack of time.

However, today, after an inspirational morning chat with our Team Lead ( Alexander Kurtakov), and after reading his SWT status reports, I’ve decided to post one of  my own.

Why status starting from August  ?  August was the month when all the “bug-fixing-action” started. Before that, there was some bug fixes from my side as well, but August appeared to be a starting point of major chunk of SWT bugs being fixed.

What was the numbers when I’ve started?

 OVERALL: 

         approximately 180 errors/warnings that needed to be fixed before we can build SWT with GTK+ 3.0

 FROM THEM:

            1. approximately 60 of them were deprecations within GTK+  2.0 library
                       1.1. approximately 30 of them required Cairo graphics library implementation to substitute deprecated methods
                       1.2. approximately 30 of them required substitution with new API methods
            2. approximately 120 of them were deprecations that can be tested only after GTK+ 3  is actually built

ALL of them needed to be version guarded to ensure backward-compatibility

Deadline: In August nobody was sure how much work will be done, but there was a hope that at least some of the errors/warnings will be resolved before January 2013.

What was  my workflow (same workflow persists now) ?

1.  I have opened public GIT repo to store all my bug-fixes
2, I have created solution for every method that is deprecated.
3. For every error/warning, I have opened  separate bug and gave link to my patch in the description of the bug. All bugs are blocked here
3.Patches were reviewed by Eclipse commiters and pushed to Eclipse master branch.

Now you can say:

“ALL THIS IS BORING, GIVE ME SOME NUMBERS! WHERE SWT STANDS NOW?!”

Today is October 16 2012.

In 2,5 months of hard work we have:

- 60 errors/warnings remaining ( 120 errors/warnings resolved)
– Red Hat Eclipse Team Leader  Alexander Kurtakov became SWT commiter
– I got my RHCSA Certificate (off topic but I am still very excited about that fact :) )

Did anyone expect such decline of errors/warnings in such short period?

I don’t think so!

 What’s next ? We are hoping to resolve ALL the issues and build against GTK+ 3 by the middle of December  (pretty good hugh ?)

More detailed SWT October statuses can be found here
Regards,
Anatoly

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

Image

Just received my RHCSA certificate

11 Oct
RHCSA Anatoly Spektor

RHCSA Anatoly Spektor

How to reset root password in Linux (RHEL,FEDORA) ? What to do if you forgot root password ?

18 Sep

Today I want to give you some very useful tips on what to do if you have forgotten your root password.
ATTENTION: This trick will only work if didn’t  setup GRUB password yet.    (if you did – sucks to be you :) )

Use Case:

You want to install something, change permissions on a file  or  do any other action that actually requires root password , which you don’t remember. I would start to panic, If i where you, but wait, there is some small hack you can do, to get back on track.

In this post I will show you how you can become a root without knowing you root password and reset it. I will also give you tips how to protect yourself from this vulnerability.

Let’s start.

1. Boot in Single User Mode

 a. Reboot your computer
 b. Wait until menu say’s to press any key to the Boot/GRUB menu, press any key

   At this point you should see menu similar to this:

grub-menu-image

c. Point to the OS you forgot your  password from and press “e

 
d.  Go to “kernel” line and add word “single” to the end of kernel string.

e. Press “b” to boot with new option for kernel

   Note: If you did something wrong, you could see “black screen of death” but don’t worry, everything you edit in boot menu is temporary, just reboot and you are good to go again.

c. If you did everything correctly you should see command line interface, where you are logged in as “root”.

How cool is that ?

2. Set SELinux to Permissive

a. If you try to change password right away, in RHEL or Fedora you won’t be able to do it because SELinux by default is enforcing.

  Good thing is that we can easily change SELinux enforcing mode. First lets find out the state of SELinux and if it is Enforcing, lets change it to Permissive. Type this in your command line:


$ getenforce

Enforcing

$ setenforce 0

Permissive

4. Change Root Password


$passwd

new password: ******

You will see that all tokens are updated.  Type ‘reboot’, and after you reboot, you will have your NEW root password. (write it down!) :)

But what if someone else would want to change my password in the same way ?

This is very legit question, and it was my first thought when I found out this easy way to change root password. How to protect yourself ? The answer is to put password on Boot menu.

How to lock GRUB/Boot menu ? ( I will show it on GRUB, however GRUB2 works similarly)

Here are a couple of simple steps how to set password on your GRUB:

 1. Open Terminal and login as root:


$ su -

Enter your root password.

2. Now type:

$ grub-md5-crypt

3. Enter password you want your grub (this can be different from your root password)  and click enter you will get md5 encoded string.

Let’s say your  md5 string is:


$1$sdlfksdlfksdlf/

4. Now use your text editor to go to grub.conf file, I use VI:

vi  /boot/grub/grub.conf

after “hidemenu” line enter:

password –md5 < paste here your encrypted md5 string>

(in my case it would be: password –md5 $1$sdlfksdlfksdlf/ )

5. Save the file.

6. To check if it works, try logging to Single User Mode, you will set instead of “e” to edit kernels string, you will need to enter password first.

That’s it for today!

Regards,

Anatoly

SWT migration to GTK+ 3.x: Use Cairo Instead GDK : First Patch – Tracker Widget

7 Jun

I am continuing series of posts about   SWT migration to GTK+ 3.x . Today, I will  write about patch for SWT Tracker Widget, that omits some of GTK+ 3.x deprecated methods.

When I started working on patch for Tracker, it was very important for me understand what Tracker Widget is intended to do. I found very good implementation of  SWT Tracker widget   here 

Actual code is:


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tracker;

public class Tracker_test {

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.open();
shell.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
Tracker tracker = new Tracker(shell, SWT.NONE);
tracker.setRectangles(new Rectangle[] { new Rectangle(e.x, e.y, 100, 100), });
tracker.open();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

When you run this code, you see small rectangle. It appears when you  right-mouse click and disappears when you  release right-mouse click. It looks like this:

From this example, we can see that Tracker is intended to track mouse movements and mouse clicks. It works great, the only problem is that some code in Tracker Widget is outdated, and it won’t built with GTK+ 3.x. I am talking about code in drawRectangles() method inside Tracker.java.

Let’s look at this code:


void drawRectangles (Rectangle [] rects) {
int   window = OS.gdk_get_default_root_window();
if (parent != null) {
window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
}
if (window == 0) return;
//TODO: Use Cairo
int gc = OS.gdk_gc_new (window);
if (gc == 0) return;
int /*long*/ colormap = OS.gdk_colormap_get_system ();
GdkColor color = new GdkColor ();
OS.gdk_color_white (colormap, color);
OS.gdk_gc_set_foreground (gc, color);
OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);
OS.gdk_gc_set_function (gc, OS.GDK_XOR);
for (int i=0; i
Rectangle rect = rects [i];
int x = rect.x;
if (parent != null && (parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - rect.width - x;
OS.gdk_draw_rectangle (window, gc, 0, x, rect.y, rect.width, rect.height);
}
OS.g_object_unref (gc);
}

If we take a look at  GDK documentation , we will find out that gdk_gc_newgdk_color_white gdk_gc_set_foreground, gdk_gc_set_subwindow, gdk_gc_set_function and even  gdk_draw_rectangle are all deprecated since GTK version 2.22 and should not be used in newly written code. And as a hint, there is ‘ // TODO: Use Cairo’.

So I here is some of the changes I made to this code:

1. I replaced gdk_gc_new  with  gdk_cairo_create

2. OS.gdk_gc_set_function (gc, OS.GDK_XOR)  was replaced with equivalent function  Cairo.cairo_set_operator(cairo,Cairo.CAIRO_OPERATOR_DIFFERENCE)  (this function is responsible for rectangle to disappear on mouse release)

3. gdk_draw_rectangle was replaced with cairo_rectangle, as cairo saves everything to buffer first, you need to release changes. In my case I used cairo_stroke. ( it fills just contour of rectangle)

4. gdk_color_white was replaced with  cairo_set_source_rgb(cairo, 1, 1, 1);

5. I also had to add line width,  and antialising (without antialising  line width didn’t work)

So my code looks like this:

if(OS.USE_CAIRO){
int /*long*/ cairo = OS.gdk_cairo_create(window);
if (cairo == 0) error (SWT.ERROR_NO_HANDLES);

Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
Cairo.cairo_set_line_width(cairo, 1);
Cairo.cairo_set_operator(cairo,Cairo.CAIRO_OPERATOR_DIFFERENCE);
Cairo.cairo_set_antialias(cairo, Cairo.CAIRO_ANTIALIAS_NONE);

for (int i=0; i<rects.length; i++) {
Rectangle rect = rects [i];
Cairo.cairo_rectangle (cairo, rect.x, rect.y, rect.width, rect.height);
Cairo.cairo_stroke(cairo);
}
Cairo.cairo_destroy(cairo);
return;
}

After run with Cairo, I have the same output as GTK version does.

I have posted bug report with my patch here:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=380287  ( As for June 7, patch is not reviewed yet, as Eclipse reviewers are extra-busy with new version of Eclipse coming out very soon)
I have coded couple of other patches, and I will definitely do some posts on them after this first patch is reviewed.

Regards,

Anatoly

Update:

Unfortunately there is one case where current patch does not work properly, as it supposed to. This case is when you pass “display” to the Tracker constructor. In GDK version it is supposed to use GDK_INCLUDE_INFERIORS that puts rectangle on top of all other windows, however Cairo does not have this luxury, and all my attempts to put in on top is clipped by child windows.

I keep on working on it, and I will keep you updated!

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

SWT migration from GTK+ 2.x to GTK+ 3.x : Introduction

17 May

In the earlier post I was exploring Standard Widget Toolkit. I have created simple application to see how SWT works. In this post I want to show couple of reasons, why SWT cannot be easily migrated from GTK+ 2.x to GTK 3.x .

Let’s approach this issue step by step.

What is GTK + ?   

As I have found out from GTK+ Project website (http://www.gtk.org/)   ” GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off tools to complete application suites.” GTK+ supports most widely used programming languages, thus making it one of the main tools  in User Interface development.

How GTK+ is connected with SWT ?

As I have found out, GTK+ library is widely used in SWT.

How to build SWT with GTK+ 2.x ?

I have pulled SWT source code using tutorial  from here   and built it using following commands:


export JAVA_HOME=/usr/lib/jvm/java

./git/eclipse.platform.swt/bundles/org.eclipse.swt/bin/library

sudo ./build.sh

Everything built just fine.  However, problems started when I tried to built it with GTK+ 3.x.

How to build SWT with GTK+ 3.x ?

To be able to build SWT with GTK+ 3.x I have uncommented line


#define GDK_DISABLE_DEPRECATED

in:


./git/eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/os.h

After doing it, I tried to built again. Unfortunately this time built was not succesful.

Here is the sample of the output:

Building SWT/GTK+ for linux x86
gcc -O -Wall -DSWT_VERSION=4230  -DLINUX -DGTK -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -fPIC  `pkg-config --cflags gtk+-2.0` -c os.c
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1bitmap_1create_1from_1data’:
os.c:4930:2: warning: implicit declaration of function ‘gdk_bitmap_create_from_data’ [-Wimplicit-function-declaration]
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1color_1white’:
os.c:5078:2: warning: implicit declaration of function ‘gdk_color_white’ [-Wimplicit-function-declaration]
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1draw_1drawable’:
os.c:5273:2: warning: implicit declaration of function ‘gdk_draw_drawable’ [-Wimplicit-function-declaration]
........

Why SWT cannot be built with GTK+ 3.x ?

After small research I have found out that some of the methods of GTK library that SWT uses are deprecated.
Complete guide on what need to be change to migrate from GTK+ 2.x to GTK+ 3.x can be found here .

Most  depreciation are already resolved, except  ones that are supposed to  use Cairo graphics library  for drawing. Next couple of months, I will be working  on implementing Cairo library into SWT instead of deprecated gdk methods, so it could be successfully migrated to GTK+3.x.

More about Cairo in my next posts…

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

What is Standard Widget Toolkit for Eclipse (SWT) ?

15 May

Here I am at my new workplace. Next 8 months I will be working in Eclipse team, on migration of SWT  from GTK2 to GTK3.

If these words does not tell you much, don’t worry, I am pretty much in the same situation, but what I am going to do in the next couple of days is to explore this issue as much as I can, and  write down my findings here.

Let’s start with SWT.  My first stop in finding info about SWT was here: http://www.eclipsepluginsite.com/swt.html

After reading  introductory chapter,  I have  found out that SWT stands for   Standard Widget Toolkit.  As I have understood from the reading, SWT is a collection of tools, intended for creating stand alone java applications or eclipse plugins  with basic UI components (such as buttons, trees etc). What is  special about SWT, is that it uses native OS components, so when you build application with SWT it feels like this application is intended for the particular OS.

I decided to build a simple application using one of the examples provided in the reading.

Simple SWT Application

/*
 *  Name: BlogButton.java
 *  Description:  SWT  button on click changes text and background color
 *
 *  Author: Anatoly Spektor
 *  Date: May 14,2012
 * */

import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.*;

public class BlogButton {

public static void main(String[] args) {
 // creating new object of Display myDisplay
 //in SWT Display manages connection between app and OS
 final Display myDisplay = new Display();
 // creating instance of shell - which is actual window
 Shell myShell = new Shell(myDisplay);

// setting window title
 myShell.setText("Window Title");
 //setting size
 myShell.setSize(400,400);
 // setting layout
 myShell.setLayout(new FillLayout());
 // creating button object in myShell
 // passing PUSH behaviour
 final Button button = new Button(myShell, SWT.PUSH);
 // passing button label
 button.setText("Show Blog URL");

// adding event listener to button
 button.addSelectionListener(new SelectionAdapter() {
 public void widgetSelected(SelectionEvent event) {
 //on selected change button label
 button.setText("myprogrammingblog.com");
 // set text color to red
 button.setForeground(myDisplay.getSystemColor(SWT.COLOR_RED));

}
 });

// open - pushes shell on the top of drawing order and makes it visible
 myShell.open();

// checking if shell is Disposed or not
 while (!myShell.isDisposed()) {
 // check if there is work to do for this shell and if not
 // put it in sleep mode so no CPU is consumed
 if (!myDisplay.readAndDispatch()) myDisplay.sleep();
 }
 // disposing an object
 myDisplay.dispose();
 }
 }

Output:

Before Click:
SWT button before click

After Click:

SWT button after click snapshot

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

Java – How to format string using SampleDateFormat ?

6 Apr

One of the blog readers asked me this question, how to format string using SampleDateFormat to mm/dd/yyy.

Here is a small piece of code, I hope some of you will find it useful.

a. Frist – import 2 libraries:


import java.text.SimpleDateFormat;
import java.util.Date;

b. Here is code:


Date date = new Date(); // creating date object
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy hh:mm a");
// creating SampleDate object and passing the pattern to constructor ("a" means show AM or PM)
System.out.println( "Here is today's date: " +  formatter.format(date) + ");

//The output: Here is today's date: 04/06/12 10:52 AM

Regards,

Anatoly Spektor

How to setup TinyMCE using ASP.NET (C#) ? How to customize TinyMCE buttons ?

5 Mar

Today we are going to take a look at one of the most customizable Rich Text Editors for Asp.Net – TinyMCE.

How to setup tinyMCE

In this post I will give you couple of tricks how to easily set  it up, customize and avoid most common problems such as “Required Field Validator” and “A potentially dangerous Request.Form value was detected” errors.

Let’s start.

1. First of all download TinyMCE from here:

http://www.tinymce.com/download/download.php (download first one)

2. Unpack “tinymce” folder to your Web Project root folder.

(My project is divided into Admin and Member sections, and tinymce is used only Admin that’s why I unpacked it in Admin folder)

3. Now go to the page where you will be using TinyMCE and add following code at the top:

<script language="javascript" type="text/javascript">
 tinyMCE.init({
                  mode: "textareas",
                  theme: "advanced",
                  theme_advanced_toolbar_location: "top",
                  theme_advanced_buttons1: "italic,underline,separator,justifyleft,justifycenter,justifyright,separator,formatselect,separator,bullist,numlist,link,unlink",
                  theme_advanced_buttons2: "",
                  theme_advanced_buttons3 : "",
                  encoding: "xml"
 });
</script>
<!--end of code -->

4. Let’s take a look at each line, so you know how to customize your tinyMCE toolbar:

a. mode: “textareas”

- means that it will replace all textareas or

b. theme: “advanced”

      – means that you choose advanced theme

c.  I used “theme_advanced_toolbar_location:

-  because when I first installed tinyMCE toolbar appeared at the bottom. So to fix it I used theme_advanced_toolbar_location property

d. theme_advanced_buttons1:

       -  describes what buttons will appear on first row of toolbar (theme_advanced_buttons2 and 3 describes second and third rows)

List of the buttons is here: http://www.tinymce.com/wiki.php/Buttons/controls

e. encoding: “xml”

- solves  “A potentially dangerous Request.Form value was detected”, which won’t allow you to submit the Web Form

This is all what you need to set up your tinyMCE.

However, there is one more trick that will help you to avoid problem of Required Field Validator saying that your textarea is empty.

5. All you need to do is add following to your textarea or asp:TextBox:

OnClientClick=”tinyMCE.triggerSave(false,true);”

Example:

<asp:Button ID="btnPublish" runat="server" Text="Publish" CssClass="button"
 Height="36px" Width="88px" onclick="btnPublish_Click1"
 ValidationGroup="postValid" OnClientClick="tinyMCE.triggerSave(false,true);"/>

So here what I got:

Java: How to split Java String with delimeter comma, space, new line, tab ? [SOLVED]

20 Feb

Sometimes it is very important to split a string on a comma \n \t etc. This piece of code will help you with it.


import java.util.*;

 public class split{

  public  static void main ( String args[]) {
       // this is my string
	String s = "Java,	Programming	is ,,, fun do you agree? ."; split
	String regexp = "[\\s,;\\n\\t]+"; // these are my delimiters
	String [] tokens; // here i will save tokens
	// length is 7 because i know that my string will consist of 7 tokens
	for(int i=0;i<7;i++){
		tokens = s.split(regexp);
		System.out.println(tokens[i]);
	}
   }
}

 // tokens are: Java Programming is fun do you agree?

Check out more posts on “Useful Java Functions and Tutorials”

Java: How to find Longest String in ArrayList ? [FUNCTION]

19 Feb

While I was playing with Java code, I have coded a class that has method that finds longest String in the ArrayList. Method is very simple, but I am sure that some of you will find it useful.

So here it is:

 // I have a class attribute:
private ArrayList wordsList = new ArrayList();

// here is method itself:
public String longest_word(){
	String longest_word="";
	int maxLength=0;
		for(int i=0; i

			if(wordsList.get(i).length() > maxLength){
			  maxLength = wordsList.get(i).length();
			  longest_word = wordsList.get(i);
			}
		}
	return longest_word;
	}

Check out more posts on “Useful Java Functions and Tutorials”

GitHub: How to clone GitHub repo ? How to push to Github? How to get files from GitHub ? (Ubuntu)

20 Jan

GitHub is an online repository. Many people find it very confusing to use GitHub, so I’ve decided to share my experience of using it on Linux Ubuntu.

So in this post we will discuss:

1. How to set up and clone repo to your local machine avoiding message: Permission denied (publickey).
2. How to  transfer all changes you are making INTO Github
3. How to get those changes FROM GitHub

My way could not be the most efficient one, but it works for me. :)

How to setup up GitHub to your local machine ?

So for the first part, you need to download Git and set your SSH key. Thanks to the GitHub documentation,  step by step guide is here:

http://help.github.com/linux-set-up-git/

How to clone your repo to your local machine ?

(in git terminology it’s called “checkout“)

First you need to find your repo address. It can be find  on your GitHub repo page:

Copy the address in the box (git@github.com……/….git)

Open the terminal and go to the folder where you want to have your git to be located.

  Type command:

git clone ADDRESS YOU COPIED

Here is my output:

How to  transfer all changes you are making INTO Github ?

(in GitHub it is called Push)

There are 3 steps to transfer your changes to GitHub:

a. You need to add files  —> git add .

(“.” means all the files, no worries, it will add everything that was changed.)

b. You need to Commit you changes –> git commit  -m “Message you want to see near your commit”

c. Push your changes to the server –> git push

My output:

On the repo I now see that README file has my commit message (I changed only README.txt):

 How to get those changes FROM GitHub ?

git checkout

git pull

These commands will bring all the  new stuff from GitHub to your machine.

Good Luck,

Anatoly

Java : How to swap two objects [Problem Solved]

12 Jan

As you might knowJava does not support pointers, thus swapping things around could create problems.  In this post I will show an example of swapping two objects.

We have Employee class that holds information about Employees and SwapDemo3 class that will actually swap two employees inside a swap() method.

Swap() method will be using set and get methods of Employee class to get the private data from it.

So here is Employee Class we will be working with:

Continue reading 

Merry Christmas!

24 Dec

photo taken from:     http://www.worldofchristmas.net

ActionScript 3.0 – How to find duplicate array elements ? [SOLVED]

12 Dec

    private function hasDuplicates(arr:Array):Boolean{

      var x:uint;
      var y:uint;

    			for (x = 0; x < arr.length ; x++){

        			for (y = x + 1; y < arr.length; y++){

            				if (arr[x] === arr[y]){
                				return true;
            				}

        			}
    			}
    			return false;
		}

  

This small function returns true if array has duplicate elements  or false if there are no duplicates.

So if you have array “test1″ and you need to make sure there are no duplicates, you could do something like this:


  if( !hasDuplicates(test1) ) // if there are no duplicates it will return "true" in this case

           trace ("There are no duplicates in array test1");

    

Have fun,

Anatoly

Big Blue Button – Polling Module – New feature! PollPreview [Demo Video]

18 Nov

ActionScript 3 How to redraw/refresh Canvas ?

17 Nov

Use this two functions:


         invalidateDisplayList();
          validateNow();

Good Luck,

Anatoly

ActionScript 3, Flex 4 Script – How to dynamically create CheckBoxes, RadioButtons and add them to the View

17 Nov

Couple of hours I was “googling” to  find the best solution on how to create Checkboxes and Radio Buttons on fly in ActionScript 3  under Flex4. Unfortunately for me, everything, that  I was able to find was either outdated, or just not for me. So I created my script from scratch, and  decided to share it with you, so you could re-use it in your projects ( don’t forget to link on me :) ).

I have made a lot of comments so you could easier understand how it works, but if you have questions, please ask. Also  this function is easy editable so you could adopt it to your needs.


// function receives Array.length and ArrayCollection
private function createButtons(amount:uint, content:ArrayCollection):void{

  var _cb:CheckBox;
  var _rb:RadioButton;
  var _tx: Text;
  var _hb: HBox;

      // creating buttons one by one
      for (var i:int = 0; i < amount; i++) {

          _tx = new Text();
          _hb = new HBox();
          _tx.name = "option" +i;
          _tx.width = 200;

      // assigning array element to text field

          _tx.text =content.getItemAt(i).toString();

     //adding HBox to the view

          options.addChild(_hb);

     // if global var _isMultiple is true  drawcheckboxes,
     // otherwise radioButtons

          if(_isMultiple){

                 _cb= new CheckBox();

                   // giving button a name of array element to process it easier later

                _cb.name=content.getItemAt(i).toString();

               // defining gap between the buttons

                _cb.y=i*20;

              // adding buttons to the Horizontal Box

               _hb.addChild(_cb);

         }else{ // if not _isMultiple

               _rb = new RadioButton();

                // giving button a name of array elelment to process it easier later

               _rb.name = content.getItemAt(i).toString();

                // assigning radio to the same group

               _rb.groupName = "answers";
                _rb.label ="*";	

                _hb.addChild(_rb);

         }
        // adding text near button

         _hb.addChild(_tx);

      } // end of loop

} // end of function

 

options is repesented as:


       <mx:Box id="options" >
        </mx:Box>

Here is what I’ve got (when _isMultiple is false):

Cheers,

Anatoly

Big Blue Button: How to compile bbb-client on Ubuntu using mxmlc [BASH SCRIPT]

20 Oct

One of the problems, that I have encountered when installed Big Blue Button client on Ubuntu, was that Flash Builder does not work on Unix platforms. So there were no options for me compiling a single module. The only options I found was recompiling all modules at once. It would be ok, if it won’t took at least a minute for each compilation. Than I realized that there is this wonderful thing “mxmlc” which compiles mxml files, however it needs libraries and bundles. I spend some time writing the “compilation line”.

So to make story short…. Continue reading 

Follow

Get every new post delivered to your Inbox.

Join 273 other followers

%d bloggers like this: