Let's talk about something used by some users of Linux that handle large amounts of information, the grep command.
This command lets you search for occurrences of text or expressions in a file or stdin, excellent links to search, numbers, IPs and other elements in large log files.
Thursday, December 29, 2011
Quick way to encrypt your objects in Java
Hi, hope you have a good Christmas :) Mine was not bad, but here I am to write a little more.
Besides eating chocolates, these days I have continued some of my school works. One in specific is a game for android, that soon I will talk more in detail.
Besides eating chocolates, these days I have continued some of my school works. One in specific is a game for android, that soon I will talk more in detail.
One important thing in games is the possibility of save the scores in a way that no one can forge, at least directly. So how do this in Java?
The simplest idea that I remembered was to put the scores in a particular class, make it serializable, apply a xor and write it to a file, to recover do the reverse process.
Wednesday, December 21, 2011
Choosing good passwords
My schoolwork is finally
going well, so today I will take a break from works and everything
related to programming.
Let's talk about something
we use every day: passwords.
Even I who use computers
for many years, sometimes I make mistakes. One of those led to one of my hotmail account to be hacked, and that happened
precisely to the account that I use less and where I was using
just two simple words found in the dictionary. Fortunately all ended
well, but it isn't always the case ... so I prepared some tips that
sometime we don't remember.
Friday, December 16, 2011
Tips to help you choose your Linux distribution
In the last
three days I have been programming in android since I get up until I go to bed,
so the last thing I want to see now is Java. For that reason I'll talk about another topic:
Linux distributions.
As it happened
to me, anyone who wants to move from Windows to Linux will face her first
difficulty, choosing between a big number of distributions.
But what is
a distribution?
Just like in windows family, you have Windows 9x, NT and CE,
and for each of them, you have versions (as: 95,98,ME). In Linux it isn’t so different,
with the particularity that the core (kernel) are the same.
So what’s
the difference?
In Windows
you have a company with total control over the core, applications and interface
that the operating system will have, the final user may change something, but
not as much as he may want.
In Linux
anyone could grab the kernel, append a bunch of applications, tweak some
parameters and puff, there’s a new distribution!
The freedom
offered by Linux can look very good, but it isn’t always. This leads beginners
to get confused and to have a fragmentation of the “help content”. Even worse
is the fact that normally for the same thing there are at least two
alternatives, both with their flaws and both have their qualities.
So I'll
give some tips to help you choose one, and facilitate your entry into the magic of
Linux
Saving files to External Storage in Android
Just a
snippet of code for android that can help some of my friends.
String FILENAME = "myfile.txt"; boolean externalStorageMounted = false; boolean externalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { externalStorageMounted = true; externalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { externalStorageMounted = true; externalStorageWriteable = false; } else { externalStorageMounted = false; externalStorageWriteable = false; } if (externalStorageMounted && externalStorageWriteable) { File dbfile = new File(Environment.getExternalStorageDirectory(), FILENAME); FileOutputStream fos = new FileOutputStream(dbfile, true); //Do anything with fos try { if (fos != null) fos.close(); } catch (IOException e) { e.printStackTrace(); } }Ok, almost done, but not yet.Open your AndroidManifest.xml and add the following line
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
or using graphical interface: Permissions -> Add... -> android.permission.WRITE_EXTERNAL_STORAGE
And everything ready.
Wednesday, December 14, 2011
Recently a friend of mine told me about an attempt to put Android 4.0 on Samsung GT540, it seemed too unrealistic but it is perfectly true, here is the link to the blog of the person who is attempting such a feat.
http://aosp.mikegapinski.cba.pl/?page_id=14
And to give a special touch, a video too.
http://aosp.mikegapinski.cba.pl/?page_id=14
And to give a special touch, a video too.
If someone wants to try, do not forget to leave some feedback about this experience :)
Tuesday, December 13, 2011
Downloading files in Java via HTTP
Today a friend of mine asked me a small piece of code for an Android application that allows downloading a file via HTTP from a remote server and save it to a local file. I looked in my documents and quickly found a small download manager that did precisely that.
But now I will share with you a class in Java (android or not) that takes as argument a URL and the destination file and download it. Remember that this code is very basic and is only to give ideas.
To use it, you just need 2 lines of code in your main.
As you can see, it's simples :P
But now I will share with you a class in Java (android or not) that takes as argument a URL and the destination file and download it. Remember that this code is very basic and is only to give ideas.
public class DownloaderClass { public void downloadFile(URL url, File outputFile) { int BUFFER_SIZE = 4096; InputStream in = null; FileOutputStream fos = null; try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); if (conn.getResponseCode() / 100 != 2) { throw new RuntimeException("Response Code: " + conn.getResponseCode()); } in = conn.getInputStream(); fos = new FileOutputStream(outputFile); byte data[] = new byte[BUFFER_SIZE]; int numRead; while (((numRead = in.read(data)) != -1)) { fos.write(data, 0, numRead); } } catch (IOException e) { System.out.println(e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } if (in != null) { try { in.close(); } catch (IOException e) { } } } } }
To use it, you just need 2 lines of code in your main.
DownloaderClass dc = new DownloaderClass(); dc.downloadFile(new URL("http://hackedprojects.blogspot.com/favicon.ico"),new File("c:\\favicon.ico"));
As you can see, it's simples :P
Man dies electrocuted while stealing copper cables
Generally I
don’t care about daily news, but today I’ll make an exception.
In the last days I've heard news about stolen goods, from diesel from cars to money from the kindergarten‘s Christmas tree, all of them has been a success for the thieves, except that one:
In the last days I've heard news about stolen goods, from diesel from cars to money from the kindergarten‘s Christmas tree, all of them has been a success for the thieves, except that one:
Read text file line-by-line in Java
I know that it's simple, but I'll leave it here.
DataInputStream dis = null; try { dis = new DataInputStream(new FileInputStream("file.txt")); BufferedReader br = new BufferedReader(new InputStreamReader(dis)); String line; while ((line = br.readLine()) != null) { System.out.println(line); } } catch (Exception e) { System.err.println(e.getMessage()); }finally{ try { dis.close(); } catch (IOException ex) {} }
Data types conversions in java
In the last
weeks I've been programming in Java for 2 school works and others 3 more
projects, I'm the type of person how prefer thing more low-level, so I can say
that I never used it so much in so little time. The good thing about that is
that I'm finally learning many things about objects and events, it's just like
a new world.
So I have
been taking notes and I'll share a little about a thing that I always forget,
how to convert between data types commonly used.
Monday, December 12, 2011
Hello World!
Hi folks, I'm
David Silva aka Longinus, a Portuguese computer science student and this is my
new blog where I will publish some of my projects, notes, news, reviews and lot
more about programming in C /C++, Java, Android and PHP, Linux, Robotics and
Electronics. Wish you like and don't forget, leave some comments :P
Subscribe to:
Posts (Atom)