Write your 2015 goals before the year begins

To-Do listWriting goals is one of the most important tasks that I believe everyone should pay attention to. It’s all about your plans for the upcoming year.

Unfortunately, most people don’t have an annual plan which is so bad. Some people have goals to achieve in their mind but don’t write their goals down which is not so good as well. Some write their annual goals after the year is begun.

None of those I’ve mentioned are good. I believe, we all have long-term goals. Writing your tasks down is one of key parts of being a successful person. It’s important to plan for a day/week/month/year before it begins. For example, if you’re going to plan for tomorrow, you should write your tasks down tonight.

In addition, be realistic when writing your goals. For instance, you may won’t be able to accomplish 20 tasks in a single day. Just write three most important tasks and sort them by priority.

Write three most important plans you want to do in the upcoming year. If you’re writing those on a paper, it can be stuck on your room’s wall. If you’re writing your plans/tasks in a file stored in your computer like what I do, put them somewhere on your desktop; so, you can see them every day.

Before install a Chrome extension, check out its permissions

Chrome-Store1It’s about a week that I am working on developing a Chrome extension. Actually, this was my first experience developing an extension. During the process of R&D, I’ve checked out some of existing Chrome extension for learning purposes. While searching, I’ve found some extensions which had suspicious activities. Actually, some of them has access to users’ sensitive information such as files on their computer!

The fact is that, extensions are one of the most dangerous piece of software I’ve ever worked with because of the access level they can get. A Chrome extension can get access to almost anything on your computer. from file system, to your web history. Even most desktop apps don’t have access to such resources. Here are some of things an extension can do and you may want to consider:

  • It can have direct access to all of your Chrome stuff: including your tabs, websites you visit, your password and a lot more.
  • It can have access your file system. This means that an extension can access all of your personal files in your computer.
  • It can execute a file: The extension developer can also include an executable file inside a chrome extension and run it in background without notifying you about. This can be very dangerous. Assume that extension developer develops a keylogger using C++ and run it on your computer. As a result, it can gather all of your password and personal information and then send it to a server.
  • It also can access system memory and CPU as well. This is ridiculous because only some low-level apps and services can have access to such resources.
  • And a lot more…

The following is an example of a chrome extension that has access to your computer resources more than it really needs (I’ve omitted the extension name and logo):

chrome-extension-permissions

As you can see in the above picture, This extension want to have access to nearly everything on your computer:

  • It can access your USB devices!
  • It can communicate with native applications such as kernel processes.
  • It can access your entire Google Drive account including all of your personal documents, photos, and etc.
  • It has full access over your network connections.

Permissions in a Chrome extension can be gained in the manifest.json file. The extension developer can request any access he/she wants. Google reads this file when a user attempts to install the extension and shows the above dialog.

Conclusions

You MUST check out an extension’s permissions before attempting to install it. An extension can be very dangerous. make sure it only asks for permissions it needs. For example, a game don’t need access to the browser proxy. You should not allow such permissions.

Even extensions which are downloaded from Chrome Web Store are not safe since there’s no review process behind them.

Note that everything I’ve mentioned in this post works the same in Firefox; consequently, a Firefox extension can also have unlimited access over your computer.

Hope it helps.

Nostalgia! Installing MS-DOS alongside Windows 3.1 on Virtual Box

You may remember MS-DOS and Windows 3.1 if you are 28 or older. These were the most important software and apps on a computer in that time. Most of us had memorable moments with these operating systems and applications. Actually, I started programming with QBasic and then moved to Visual Basic on Windows.

MS-DOS 6

Today I decided to get back to that sweet moments and tried to install MS-DOS on Virtual Box.

The first thing I had to do was to find the MS-DOS OS and other files; so, I can install it on my virtual machine. As a result, I Googled and found https://winworldpc.com. This is an amazing site contains most of old and nostalgic operating systems, games, applications and developer tools. In addition to MS-DOS, I also downloaded and installed some other apps on the virtual machine which I’ve listed below:

  • Windows 3.1: One of the first operating systems with graphical user interface by Microsoft.
  • Borland C++ for MS-DOS: A powerful IDE (Actually in its own age) to develop, debug and compile C and C++ applications in DOS.

As a gift for this Christmas, I packaged all of the apps alongside MS-DOS OS into a single “.VHD Virtual Hard Drive” file which can be access via the following link:

Ramezanpour MS-DOS.zip

Note: The zip file password is: ramezanpour.net

All you need to do is to download this package, unzip it and then import it in your Virtual Box. If you don’t know how to import a VHD file in Virtual Box, follow these instructions:

Open Virtual Box and click on “New” icon to create a new Virtual Machine.

create-vm-01

The “Create Virtual Machine” window asks for three things. The first is a name which can be anything you want. The second is type which has to be set to “Other”. The third is version which must be DOS. By clicking “Next” you’ll be navigated to the second step which is memory allocation. Since MS-DOS is a very small OS, 32 MB of RAM is enough but you can select as much as you want (Don’t select too much memory because MS-DOS may not support it).

create-vm-02

After the amount of RAM is defined, click next to navigate to the third section. This page will ask you to whether you want to create a new virtual hard drive or use an existing one. Select “Use an existing virtual hard drive file” then select the VHD file you’ve downloaded above.

You’re done. You can now start your MS-DOS 6.22 by double clicking on its icon in Virtual Box.

Enjoy and Happy Christmas!

Introducing GoldenDict: The best dictionary I’ve worked with so far

I’ve been a big fan of Babylon dictionary for a long time. During that time, Babylon dictionary helped me a lot to look up words and phrases from languages other than Persian.

Unfortunately, Babylon became useless for me since the release of version 10, due to some bugs it had; so, I removed it from my computer. Also, during these couple of years, I’ve moved to platforms other than Windows such as Linux and Mac; therefore, I couldn’t use Babylon even if it worked correctly.

Introducing GoldenDict

68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3833373734392f3330343230352f33383439656235342d393633372d313165322d396462382d3735363633663463343466392e706e67A few days ago, a friend of mine, introduced me GoldenDict and blown my mind. It is the best dictionary look up program I’ve ever worked with. It has a lot of benefits over other dictionaries; so, I decided to write a blog post to mention some of its features:

  • It’s completely free and open-source! This means you can use it as much as you want without even paying $1 for it. However, you can donate if you want. If you’re a developer, you can also contribute and make it even better.
  • It supports multiple dictionary file formats including Babylon glossaries, StarDict and others. Consequently, you can import all glossaries you had before! This is a very good feature if you’re a former Babylon user or want to migrate to GoldenDict. Actually this is a very important feature for me because, I’ve had some Babylon glossaries before and wanted to use them.
  • It has the Scan popup functionality. You can easily translate words even from other apps. As you may know, Babylon also has such feature but as I tested, GoldenDict word detection is much better.
  • It’s cross-platform; so, you can use it in nearly all of your devices. GoldenDict is available for Windows, Mac, Linux and even Android phones.

golden-dict

To download GoldenDict, please check out GoldenDict.org. As I’ve mentioned, GoldenDict is a free product and you don’t have to pay for it; but, if you think this project worth it, please make a donation to help making it even better.

How to create dynamic XML sitemaps in ASP.NET MVC

When developing web applications (especially websites), some rules have to be obeyed. One of those rules are Sitemaps. Sitemap is an essential to tell more about a website to search engines. According to sitemaps.org, sitemaps are an easy way for webmasters to inform search engines about pages on their sites:

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.

Implement sitemaps in ASP.NET MVC is very easy and this post is going to cover it.

There are several ways to implement sitemaps in ASP.NET MVC. Since sitemaps are just XML files, they can be generated using XLINQ (LINQ to XML) technology.

The process of creating a sitemap in a website can be divided into the following steps:

  • Get a list of URLs which has to be included in the sitemap.
  • Create the sitemap XML in code.
  • Return the created XML to the user.

Note: You don’t really need to create an actual XML file. All of the process above can be done inside a controller action.

The first step is to get the list of objects we want to create the sitemap based on. In this post, I have a list of categories which have a unique URL based on its ID. So:

public ActionResult SiteMap() {
    var items = categoryService.SelectAll();
}

After that, it’s time to create the XML document. Sitemaps must have a specific format; so, they can recognized by search engines. The following is a valid XML sitemap:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset>

As you know, creating such XML file in LINQ to XML is a very simple task to do:

public ActionResult SiteMap() {
    XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
    const string url = "http://example.com/Category/{0}";
    var items = categoryService.SelectAll();
    var sitemap = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XElement(ns + "urlset",
        from i in items
        select
        new XElement(ns + "url",
            new XElement(ns + "loc", string.Format(url, i.CategoryId)),
            new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
            new XElement(ns + "changefreq", "always"),
            new XElement(ns + "priority", "0.5")
    )));
}

As you can see in above code, we’ve simply created an XML file in sitemap format. Now we can return it to the user.

return Content("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + sitemap.ToString(), "text/xml");

Look at the code above. When creating normal actions, we usually return a View or PartialView objects; but, since we’re going to return a content, we use the Content method. Content method requires two arguments. The first argument is the content we’re going to return to the user as string and the second is the content’s MIME type.

Hope it helps.

The most essential apps I use everyday

Since I purchased my first ever smartphone which was an iPhone 3G, I started using some apps to help me get organized, learn more, stay in touch with my friends and family and have fun on my device.

During these four years I have used and tried a lot of apps and selected some of them to fulfill my needs. Nowadays, I can’t live without some of these apps. In this post I am going to share some of the most effective apps I use everyday. I thought this might be useful for you as well.

1. iPhone’s official Mail App

Mail appOne of the most important applications I use on my iPhone is the Mail app. The built-in iPhone mail app is not as feature-rich as some other third-party applications but I think its features are enough. It covers all of my expectations including the following:

  • It let me setup multiple accounts on it. Currently, I have setup my iCloud account and my main (i [at] ramezanpour [dot] net) account on it.
  • It supports signatures.
  • Its has a feature called VIP; so, you can add the most important people you’re communicating with in it. Email from those people will be shown bolder than others; also, they will be placed in a separate folder called VIP.
  • It supports all major email providers including GMail, Yahoo, AOL, Outlook and also Exchange.

2. Podcasts

Podcasts appOne of the iOS’s most unique features over Android or other mobile operating systems is the podcast. Podcasts app will let you have all of your favorite podcasts in one place. I usually connect my iPhone to my car’s stereo and listen to my favorite podcasts instead of listening to music.

Podcasts are available in a wide range of categories such as music, news, arts, education, science and technology. I have subscribed to some science and technology podcasts and listen to them when on my way to work or returning home. My wife also likes some of them; so we listen to them together.

3. Viber

ViberAlmost all of friends are using Viber nowadays. It’s the most popular messaging app in Iran. According to a report, more than 40 million Iranians are using Viber these days. Viber let me stay in touch with my friends and family at a very low cost. It’s not the best messaging app (I perfer Whatsapp messenger) but since most of my friends are using it’s difficult to find them on other messaging apps.

4. Skype

SkypeAlthough Viber covers all of my text needs; but, when it comes to voice and video messaging, Skype is by far the best option. The voice quality is awesome (Even with Iran’s bad internet service) and the service is almost free. I use Skype to talk to some of my friends who live overseas. Beside its mobile app, Skype is also available for desktop computers as I am currently using it in my Windows and Mac machines.

5. Evernote

Evernote“Getting used to productivity apps is always a very hard thing to do but once you get used to them, your life gets brighter.” - Mohammad M. Ramezanpour

Evernote is one of those apps I use almost everyday. Since I use Evernote I don’t use papers anymore. I use Evernote for taking notes and creating checklists. One of the good features of Evernote is the ability to share a note or notebook with someone else. My wife has created a shopping list in Evernote and shared it to me. Every time she needs something at home, she adds a new item to that list. We go shopping almost every week and purchase things according to that list.

6. DropBox

DropBoxDropBox is the best online cloud storage. I have been using SkyDrive (OneDrive) and Google Drive but in my opinion, non of them were as powerful as DropBox. DropBox is available in all operating systems. I use it in my iPhone, Windows and Mac devices. DropBox is very simple and easy to use. One of the coolest features of DropBox in comparison with other cloud storage apps is its “Lan Sync” feature which let users to share files in-between without using the internet bandwidth. all of the files will be transferred via local network.

I use some other apps but these 6 apps are very essential for me. What apps do use the most? Please share your list by commenting down below.

Hope it helps.

Create an on-demand VPN connection programmatically in iOS 8

A while ago, I published a post about configuring and managing VPN connections programmatically in iOS 8. By default, established VPN connection will be disconnected if user iOS device goes to sleep to save battery life. To avoid this, Apple introduced a feature called on-demand; so, iOS will get connected to VPN whenever it needs to connect to the internet.

Well, it can be implemented programmatically too using the NetworkExtension framework and that’s exactly what this post is all about. In this post, I am going to create an on-demand VPN connection using NetworkExtension; therefore, VPN connection will be established whenever an app opens a network connection.

Note: I am not going to describe how to create a VPN connection in this post. If you’re not familiar with creating a VPN connection programmatically, please take a checkout my post.

Turn on On-Demand

The first thing you need to do is to tell the NetworkExtension framework that you want to create an on-demand connection. To do so, set the onDemandEnabled property to YES:

[[NEVPNManager sharedManager] setOnDemandEnabled:YES];

turning on-demand on is not enough. You will also need to tell the OS when exactly you want on-demand to be enabled. To do so, you will need to assign some rules to your configuration. These rules called “On-demand rules”:

What are On-demand rules?

On-demand rules are set of attributes which must be set to tell the OS when VPN connection should be established on-demand. onDemandRules property accepts an array of rules. Consequently, you can set multiple rules for a VPN configuration.

For example, you can set a rule and tell the OS to establish the VPN connection whenever user wants to open Apple.com; otherwise, the VPN connection won’t be established.

One thing you may want to do it to activate the VPN connection whenever an app open a network connection; so, all iOS network traffic will be transferred through your VPN server. To achieve this, NEOnDemandRuleConnect class must be used.

In Network Extension framework, Apple has provided some useful on-demand rule templates you can make use of. Although you can create your own rule, it’s possible to use templates as well.  NEOnDemandRuleConnect class is one of those templates. It will tell the OS to establish VPN connection whenever iOS needs to connect to the internet; as a result, users will always connect to your VPN servers whenever they want to access the internet. As far as I know, this is what most VPN providers and users want:

[[NEVPNManager sharedManager] setOnDemandEnabled:YES];
NSMutableArray *rules = [[NSMutableArray alloc] init];
NEOnDemandRuleConnect *connectRule = [NEOnDemandRuleConnect new];
[rules addObject:connectRule];
[[NEVPNManager sharedManager] setOnDemandRules:array];

Once you changed the configuration you have to save it using saveToPreferencesWithCompletionHandler: method.

Hope it helps :)

How to get persistent reference to a keychain item in iOS

Keychain is a very good idea from Apple. It lets app developers to store and retrieve sensitive data securely.

Keychain Services provides secure storage of passwords, keys, certificates, and notes for one or more users. A user can unlock a keychain with a single password, and any Keychain Services–aware application can then use that keychain to store and retrieve passwords. Keychain Services Programming Guide contains an overview of Keychain Services, discusses the functions and data structures that are most commonly used by developers, and provides examples of how to use Keychain Services in your own applications.

The following shows how keychain works:

unlocking_keychain. Photo taken from: developer.apple.com

During the process of creating VPN profiles programmatically in iOS 8, the NEVPNProtocol.passwordReference property requires a persistence reference to a keychain item with the kSecClassGenericPassword class. This post covers saving and getting persistence references to a keychain item in iOS.

Getting started with Keychain

The process of saving data in keychain is very simple once you understand it. To start working with Keychain, Security.framework needs to added to your project. Security framework has 4 major methods which enables you to access iOS keychain. These methods are:

  • SecItemAdd
  • SecItemCopyMatching
  • SecItemDelete
  • SecItemUpdate

As it can be guessed from each method’s name SecItemAdd, SecItemDelete and SecItemUpdate adds, deletes and updates data. SecItemCopyMatching method searches for a specific keychain item and copies item data to a reference variable if available. For more information about these four methods checkout Apple’s Keychain Services Reference page.

Saving data

Note: There’s actually no difference in saving normal and persistent references to the keychain!
The following adds a NSData object to the iOS keychain:

NSData *data = [Your data]; // Data to save. It can be a string too.
NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
[dict setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
NSData *encodedKey = [@"[Your key name]" dataUsingEncoding:NSUTF8StringEncoding];
[dict setObject:encodedKey forKey:(__bridge id)kSecAttrGeneric];
[dict setObject:encodedKey forKey:(__bridge id)kSecAttrAccount];
[dict setObject:service forKey:(__bridge id)kSecAttrService];
[dict setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible];
[dict setObject:data forKey:(__bridge id)kSecValueData];

OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dict, NULL);
if(errSecSuccess != status) {
    NSLog(@"Unable add item with key =%@ error:%ld",key,status);
}

After the data is saved it can be get anytime from keychain.

Getting Data

Data can be get from keychain using the following code:

NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
[dict setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
NSData *encodedKey = [@"[Your key name]" dataUsingEncoding:NSUTF8StringEncoding];
[dict setObject:encodedKey forKey:(__bridge id)kSecAttrGeneric];
[dict setObject:encodedKey forKey:(__bridge id)kSecAttrAccount];
[dict setObject:service forKey:(__bridge id)kSecAttrService];
[dict setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible];
[dict setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
[dict setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnPersistentRef]; // The most important part
    
CFTypeRef result = NULL;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dict,&result);
    
if( status != errSecSuccess) {
    NSLog(@"Unable to fetch item for key %@ with error:%ld",key,status);
    return nil;
}
    
NSData *resultData = (__bridge NSData *)result; //Your data is ready

The most important part of the above code is in line 9 where kSecReturnPersistentRef attribute is set. This attribute tells the keychain to return a persistent reference to the keychain item.

Hope it helps :)

Introducing timeago: A jQuery library to update fuzzy timestamps automatically

You may have seen at least one of these timestamps in websites especially social networks:

time1

time3

These timestamps are very important and useful in all websites that time matters. But you may have wondered how to implement such a thing in your own web applications.

There are a couple of ways to do so. The first one is to implement this functionality server side. I’ve implemented a server side C# function to do it; but, there would be a very big issue: As the time goes on, the timestamp won’t update! The whole page needs to be refreshed! You may have use ajax to refresh the time but this method also costs lots of resources. The best place to do such a thing is client and that’s exactly what timeago does!

What is timego?

Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. “4 minutes ago” or “about 1 day ago”).

Timeago has lots of advantages over server side implementation I’ve mentioned above. Here are some:

  • It is very lightweight (About 8KB when not minified and about 4KB when minified and GZiped)
  • Runs on user’s browser; consequently, it won’t cost any server resources.
  • It can be used alongside caching techniques while it runs on client.
  • The timestamps’ values will update live so there’s no need to refresh the whole page or make ajax requests to update them.
  • It’s free and open-source!

How to use timeago?

Using timeago it very simple. Imagine you have a span element in your web page and you want to update the value of this field using timeago. The very first step is to use jquery.timeago.js file in your page’s head element. You also need jQuery library as well; so, add it too if you haven’t:


After that place your ‘span’ as following:

July 17, 2008

As you may have noticed that we put the real datetime we want to calculate from in the ‘title’ attribute. The final step is to add the following piece of javascript in your page:

$(document).ready(function() {
  $("span.timeago").timeago();
});

You’re done! The javascript code above converts all span elements which has “timeago” class.

How to download timeago

Since timeago is an open-source project, it can be found by its GitHub repository or its official website at: http://timeago.yarp.com/. Don’t forget to check out its website for more examples.

This library was very useful for me. Hope it does the same for you.

Quick post: Testing in-app purchases in iOS 8

I love quick posts, they’re short and handy. Some topics should be explained as short as possible. I name these quick posts. In this (quick) post, I want to talk about significant changes to iOS 8 simulator when testing in-app purchases; so, here you go:

iOS simulator - Photo taken from http://www.ralfebert.de/ios/ueberblick-ios-xcode/icon_simulator.pngTesting in-app purchases is one of the most important tasks to do in your applications; because, it’s the way you can make money from your app. In-app purchases were one of those features which had to be tested on a real device only.

Prior to iOS 8, developers had to have at least one real device (an iPod Touch for example) to test their apps’ in-app purchases. But in iOS 8, Apple has made significant changes to its iOS simulator. Now developers can do much more as it’s possible to test in-app purchase functionality right in the simulator even if no real device is available!

This is a very important improvement especially for me as a developer who is working with iOS 8 new feautres. If this feature was not available, I had to install iOS 8 beta on my iPhone which I prefer not to.

There might be more improvements in iOS simulator which I haven’t faced yet. If you know any of them, let the world know them as well by commenting down below.

Have a nice coding ;-)