Baccega Andrea Blog

The future is web3.0

Posted on by veke87


Flatterizor is a PHP library developed in order to issue a very specific problem.

Sometimes you have a complex object and you need to store it into your database. Most cases the serialize function does work. Unfortunately sometimes it does not ( not because serialize is broken/bugged ).

The Library is useful only if the followings are true:

  • You want to store your object inside a database
  • Your object is not “Flat”  ( meaning you’ve at least a value in your object that is an array or an object itself )
  • You want to use your Database SQL to Search & filter objects with a particular value.

The last sentence is actually the most appealing. Lets take, for example, the following objects:

<?php
  $bob = new stdClass();
  $bob->name = 'Bob';
  $bob->permissions = array( );
  $bob->permissions['can_write'] = true;
  $bob->permissions['can_read'] = true;

  $mat = new stdClass();
  $mat->name = 'Mat';
  $mat->permissions = array( );
  $mat->permissions['can_write'] = false;
  $mat->permissions['can_read'] = true;
view raw objects.php This Gist brought to you by GitHub.

Continue reading

Posted on by veke87 | Posted in Development, Wordpress | Tagged , ,


Leave a comment

Posted on by veke87


You start doing some research about this topic when one of the following events occurs:

  • You lose your data
  • You start hosting third party data

Continue reading

Posted on by veke87 | Posted in Development | Tagged , , , ,


Leave a comment

Posted on by veke87


It happens you need to execute some piece of code only on the first time the user start using your app.

Lets say you want to show a quick tutorial to the user just once — Indeed, when the user open your app for the first time.

Well, an easy solution would be to use a SharedPreference to store the info we need to accomplish this “task”.

Below, a snippet with a simple method ( to be included inside your activity class ) that will “solve” the problem.

private Boolean firstTime = null;
/**
* Checks if the user is opening the app for the first time.
* Note that this method should be placed inside an activity and it can be called multiple times.
* @return boolean
*/
private boolean isFirstTime() {
if (firstTime == null) {
SharedPreferences mPreferences = this.getSharedPreferences("first_time", Context.MODE_PRIVATE);
firstTime = mPreferences.getBoolean("firstTime", true);
if (firstTime) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean("firstTime", false);
editor.commit();
}
}
return firstTime;
}

Posted on by veke87 | Posted in Android, Development | Tagged ,


Leave a comment

Posted on by veke87


When you build a new Service-Website from scratch you’ll probably have to face with this. Passwords are the most sensitive data we have and your application should behave securely enough to maintain user’s data private!

Some time ago you it was a common pattern to store the user password as plain text ( or with some Symmetric-key algorithm ). This let the user to retrieve their password withouth setting a new one.

From this pattern a fork was born which required to answer a predefined question in order to make the application send the password back to the user.

It seems these patterns are not used anymore in favor of the actual one which involves a more structured application/user flow in order to let the user regain access to the application. I’m talking about password reset.

The new way

Continue reading

Posted on by veke87 | Posted in Development | Tagged , , ,


Leave a comment

Posted on by veke87


If you’re a web developer you confronted by this at least once. If you don’t own a development webserver you’ll need to make your developments in the production webserver. This means that everyone could see your work-in-progress easily.

A common pattern is to create an index.html file ( which gets served – almost ever – before index.php ) which will contain a specific landing page with an “under construction” text.

How to serve the index.html file to “regular people” while you work on wordpress ( index.php ) ?

It’s quite easy using .htaccess and mod_rewrite of apache. The basic concepts are:

  • WordPress logged in people will see the “work in progress” website
  • Not logged in people will see the “site under construction” page

In order to achieve that, you’ve to prepend the following lines to your .htaccess file  ( placed in your document root ) :

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} index.html$
  RewriteCond %{HTTP_COOKIE} ^.*wordpress_logged_in.*$ [NC]
  RewriteRule . /index.php [L]
</IfModule>

As you can see we only override the normal web-flow only if the browser is going to request the index.html file and the user has the wordpress_logged_in cookie setted.

Whenever you need to see your “real website” you just need to point your browser to http://example.com/wp-admin , login and then you’ll be able to see the website you’re creating and not the “under construction” page.

Note: This is only a partial solution and people could be smart enough to emulate the wordpress_logged_in cookie and see your work in progress anyway. In my case-scenarios this was more than enough.

 

Posted on by veke87 | Posted in Development | Tagged , ,


Leave a comment

Posted on by veke87


Sooner or later I always remember I’ve a blog. This time the topic is XSS.

If you don’t have a clue of what XSS is maybe you should read this before reading this article.

Continue reading

Posted on by veke87 | Posted in Development | Tagged , , ,


2 Comments

Posted on by veke87


Sooner or later you’ll have to deal with it. If you’re an html developer and you write also in javascript you’ll surely know the onchange event.

Unfortunately it’s a little bit tricky to find the same event on android.

The onChange event is helpful when you’ve to deal with the following things:

  • Let the user know (in realtime) how many characters he typed.
  • Let the user know (in realtime) how many remaining characters he is allowed to type.
  • Make realtime processing of the content ( like sending it online and fetch some partial results of the partial typed edittext )

You’ve to implement your own instance of TextWatcher and let the edittext know that you want to be notified at each change by calling the method EditText.addTextChangedListener.

Below i will give you a simple example ( it’s written on the fly but you’ll understand the idea )

			((EditText)findViewById(R.id.et_testo)).addTextChangedListener(new TextWatcher() {

			public void afterTextChanged(Editable s) {
				((TextView)findViewById(R.id.numcaratteri)).setText(String.format(getString(R.string.caratteri), s.length()));

			}

			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub

			}

		});

Posted on by veke87 | Posted in Android, Development | Tagged ,


7 Comments

Posted on by veke87


Since it was a little hard for me finding it, here you can find the trusted CAs in Android 2.2 Froyo.

In order to get my result on each android device you’ve to download this file and place it on $JAVA_HOME/lib/ext . Plus, you should have $JAVA_HOME/bin in your $PATH

adb pull /system/etc/security/cacerts.bks cacerts.bks
keystore cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -list -v >> certificates.txt

After the break my certificates.txt.

Continue reading

Posted on by veke87 | Posted in Android


3 Comments

Posted on by veke87


There are multiple solutions out there but i did create my own.

It’s simple as 1,2,3. Hope it helps.

		// CODEIGNITER HACK
		$tmp = explode('?',$_SERVER['REQUEST_URI']);
		$tmp = explode('&', $tmp[1]);

		foreach($tmp as $keyval) {
			$tmpAppoggio = explode('=', $keyval);
			$_GET[urldecode($tmpAppoggio[0])]=urldecode($tmpAppoggio[1]);
		}
		// end of codeigniter hack

Posted on by veke87 | Posted in Development | Tagged ,


8 Comments

Posted on by veke87


I just figured out how to write an sms without sending it really on android froyo 2.2 using the content provider.

I’ll write only the snippet here. Hope it helps

	/**
	 * writes an sms on the contentprovider
	 * @param ctx Context
	 * @param mobNo mobile number
	 * @param msg text of the message
	 */
	private final static void storeMessage(Context ctx,String mobNo, String msg) {
		ContentValues values = new ContentValues();
		values.put("address", mobNo);
		values.put("body", msg);
		ctx.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
	}

Obviously you should set the right permissions on the manifest ( Yes the following are all needed for this task ) :

<manifest>
	....
	....
	<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
	<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
</manifest>

Posted on by veke87 | Posted in Android | Tagged , , ,


Leave a comment