(Auto-)connect Raspberry Pi to a NAS or other network share

When using the Raspberry Pi for electonics testing you might want to put your scripts on a network share or NAS.  This way you don’t need to write your scripts on your Pi nor do you need to use USB-drives. Keep in mind that your SD card can get corrupted at any time when you don’t shut down correctly. Imagine your frustration if at that time it holds (was holding) your only copy of your work…

Anyway, it’s quite simple to achieve a conection to from your Raspberry Pi to your NAS. Here’s how i did it:

First ensure you are in root mode:

 Text |  copy code |? 
sudo –i

Create a directory that will be linked to the share later on:

 Text |  copy code |? 
mkdir /home/pi/FolderName

where “FolderName” can be any name you want.

To connect your Pi to your NAS (automatically)  we need to alter /etc/fstab:

 Text |  copy code |? 
nano /etc/fstab

Add the following to the bottom of this file:

 Text |  copy code |? 
//ip_of_server/share /home/pi/FolderName cifs _netdev,username=your_username,password=your_password,users,auto,user_xattr 0 0

username=… and password=… are optional in case your share is protected by a username and password.  If this is not the case, just leave it out.  _netdev is very important because it will ensure that the volume is not mounted before the networking structure is up, and that there is an unmount before shutting down the network.

After this, you can mount the share manually by typing:

 Text |  copy code |? 
mount -a

The network share should now be mounted automatically after a reboot.

Please note that putting your network share’s credentials in fstab like this is not considered “best practice” in production environments. You should put them in a seperate file that is only readible by the system, or something like that…

PiNetwork

Using custom navigationtemplates in an asp.NET wizard

Sometimes the standard way of displaying the navigation buttons does not suffice when you are presenting a wizard in your asp.NET webforms application or website.

There are three templates you can customize:

  • <startnavigationtemplate></startnavigationtemplate> (for the first step in your wizard) 
  • <stepnavigationtemplate></stepnavigationtemplate> (for all intermediate steps)
  • <finishnavigationtemplate></finishnavigationtemplate> (for the finishing step)

It’s important that you assign the correct “CommandName” to the custom buttons you will use.   You can see in the below axamples what they are:

StartNavigationTemplate

 ASP |  copy code |? 
<StartNavigationTemplate>
 <asp:Button ID="btnNext" runat="server" CssClass="WizardControlButton" CommandName="MoveNext" 
                 Text="Go to the next step" CausesValidation="true" 
                 ValidationGroup="userdataValidationGroup" />
</StartNavigationTemplate>

StepNavigationTemplate

 ASP |  copy code |? 
<StepNavigationTemplate>
 <asp:Button ID="btnPrevious" runat="server" CssClass="WizardControlButton" 
             Text="Go to the previous step" CommandName ="MovePrevious" />
 <asp:Button ID="btnNext" runat="server" CssClass="WizardControlButton" CommandName="MoveNext"
             Text="Go to the next step" CausesValidation="true" 
             ValidationGroup="userdataValidationGroup" />
</StepNavigationTemplate>

FinishNavigationTemplate

 ASP |  copy code |? 
<FinishNavigationTemplate>
 <asp:Button ID="btnPrevious" runat="server" CssClass="WizardControlButton" 
             Text="Go to the previous step" CommandName="MovePrevious" />
 <asp:Button ID="btnSubmit" runat="server" CommandName="MoveComplete" Text="Submit this form"
             CausesValidation="true" ValidationGroup="userdataValidationGroup" />
</FinishNavigationTemplate>

Force-update your HTC Radar WP 7.5 (Mango) to Windows Phone 7.8? Yes you can !

Even if no update is visible on your phone or in zune, it might still be possible to update your WP7.5 to 7.8.

Here’s how:

— Disclaimer: Works on my machine, no warranties, any damage is your own fault.  If you don’t want to take the risk, wait until the update is released. —

The key to be able to force the update is to disable the internet connection at the exact right time between checking for updates and consulting the server to check if it has been released for your device.

  1. Disable WIFI and cellular data on your phone.
  2. Connect your phone to the computer.
  3. Goto settings > update and time how long it takes before the message appears that there is no update available.
  4. Select an other tab.
  5. Select the update tab again and wait about 2 seconds less than the timing in step 3, then disconnect the internet (unplug the cable of turn of the WIFI on your PC)  This is the hardest part, finding the right timing.  Possibly you have to try this a few times.
  6. You will see that there is an update available.  Clikc the update button and re-enable the internet connection before you go on.
  7. Follow the instructions to install the update.

 Possibly you will have to install several updates before you reach WP7.8.  Simply repeat the above steps for each update:

Update 1:  8773 >> 8779

Update 2: 8779 -> 8783

Update 3: 8783 -> 8858 (woohoo! WP 7.8)

Keyword (not provided) in Google Analytics? Here’s how you resolve it:

Since October 2011, Google Analytics does not show data from organic searches by logged in users.  This means dat you can no longer see which keywords were used by ‘google users’ to reach your site.  For SEO purposes it’s not really a good idea to discard this data, since you might make descisions for your site based on incomplete data.

Here’s how you resolve the “(not provided)” issue for Google Analytics:

Register your site in Google Webmaster Tools.

  • Go to http://www.google.com/webmasters/
  • Log in using the same Google account used for google Analytics.
  • Click “Add a site” and insert your website’s URL.
  • Let Google verify that you are the site’s owner.  In our case you should be able to verify trough the google analytics account.
  • Your site should be added.

Google Analytics interface

You should now be able to integrate google webmaster tools in the google analytics interface. Look for it in the SEO section.

Redirecting users within or outside your website using the .htaccess file

The .htaccess file is a very powerful configuration file on linux hosting.  From within this file you can configure a whole range of options, today we will look into the redirecting capabilities.

Creating the .htaccess file

  1. Create a file called htaccess.txt and edit it with notepad or any other plain text editor.
  2. Upload the file to your server (using FTP)
  3. Rename the remote file to .htaccess

301: Permanent redirect

If your website has permanently moved to a new location you can set a socalled 301 redirect.  Users will be sent to the new location immediately, and search engines know your new location.

 Text |  copy code |? 
Redirect 301 / http://mynewdomain.com/

302: Temporary redirect

You guessed it: Your website has temporary moved (for instance to a christmas version)


 Text |  copy code |? 
Redirect 302 / http://mytempreplacementdomain.com/

 Redirect your entire site to a subfolder

In the following, you should change mydomain.com and subdirectory according to your needs.


 Text |  copy code |? 
RewriteEngine on
# Change mydomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
 
# Change 'subdirectory' to be the directory you will use for your main domain.
 
RewriteCond %{REQUEST_URI} !^/subdirectory/
 
RewriteCond %{REQUEST_FILENAME} !&minus;f
 
RewriteCond %{REQUEST_FILENAME} !&minus;d
 
# Change 'subdirectory' to be the directory you will use for your main domain.
 
RewriteRule ^(.*)$ /subdirectory/$1
 
# Change mydomain.com to be your main domain again.
 
# Change 'subdirectory' to be the directory you will use for your main domain
 
# followed by / then the main file for your site, index.php, index.html, etc.
 
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
 
RewriteRule ^(/)?$ subdirectory/index.html [L]

Getting the create command to work for Apache Cordova (Phonegap) on windows systems

Apache Cordova logoSo you’ve followed the instructions provided by Apache cordova (phonegap) here and still get an error message:”

Missing one of the following:

JDK: http://java.oracle.com

Android SDK: http://developer.android.com

Apache ant: http://ant.apache.org

” ?

You’ve added everything to the “PATH environment variable” and it still doesn’t seem to work?

Don’t worry, here’s how you can solve this issue:

Modify your PATH environment variable so you can use ALL of the following commands in any directory in the console window:

  • java
  • javac
  • ant
  • adb
  • android

Then check if the environment variable JAVA_HOME is set correctly.  Make sure that this variable is set and it refers to the root directory of your JDK and not JRE.

Also: do not use a dash (-) or space in the directory or project name.

Enable multiple users in Android 4.1.x

Finally!  Multi-user support has come to the tablet-scene.  We’ve been used to be able to switch users on computers for ages now, but until recently, it wasn’t possible in the world of tablets.

Multi user support is supported in both Android 4.1 and android 4.2, but there is no gui in 4.1

Therefore we need to handle the management of the users ourselves using terminal commands.

Assuming you have a rooted android installation, you need to execute the following commands in the terminal window:

Elevate your rights using this command:

 Text |  copy code |? 
su

To add add a user:

 Text |  copy code |? 
pm create-user newUserName

List all users:

 Text |  copy code |? 
pm list-users

Delete a user:

 Text |  copy code |? 
pm remove-user 1

Note that the primary user has the index 0 (zero)

To start using the new user-account,  hold the Power/Lock button to bring up the power menu, and you should see the other users.

If you want to change the username, go to  /data/system/users and edit the “user1.xml” file (change the ’1′ to the user’s index).  Then change the name in that file.  Save & reboot.

The userlist.xml file shows which user has which index number, or use the list-users command (see above).

EF Code First: Change the table schema for junction tables (also called linktables or relationtables)

To change the table schema for junction tables (also called linktables or relationtables) in EF Code First, you cannot use data annotations (at this time).

If you want to have a full code first mapping feature set you must use Fluent API. Defining anything related to junction tables is considered as advanced mapping feature and it is currently available only in Fluent API.

Let’s say we have a many-to-many relationship between locations and Contacts, so a location can have many contacts and a contact can have many locations.

By default, entity framework will generate a junction table using the default ‘dbo’ schema, but we want to define the schema name.  Here’s how:

 C# |  copy code |? 
 modelBuilder.Entity<Location>()
                .HasMany(a=> a.Contacts)
                .WithMany(b=> b.Locations)
                .Map(m => m.ToTable("LocationContacts", schemaName: "LOC")); 

After adding this code to your DbContext class (in ‘OnModelCreating’) you can update the database.  Notice how the schema name changed to ‘LOC’.

c# equivalents of good ol’ vb constants

So what CAN you use instead of the vb constants?

  • vbCrLf => “rn”
  • vbCr =>”r”
  • vbLf => “n”
  • vbTab =>”t”
  • (more will be added later)

 

What SHOULD you use instead of vbCrLf.

 
Because not all operating system handle line endings the same way, it is probably a better idea to use Environment.NewLine instead of “rn”
 
 

Two ways to enable delete confirmation in an asp.net gridview

Sometimes, if not always, you want users to confirm their delete command.  Here’s how to do it in an asp.net gridview commandfield:

First method: Convert the commandfield to a templatefield:


 ASP |  copy code |? 
<asp:TemplateField HeaderText="Delete"> 
        <ItemTemplate> 
                <asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" 
OnClientClick="return confirm('Are you sure you want to delete this ?');" ></asp:Button> 
        </ItemTemplate> 
</asp:TemplateField>

 

Second method: Use the OnRowDatabound event to attach your javascript to the button:

     

 ASP |  copy code |? 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="Id" DataMember="DefaultView" DataSourceID="SqlDataSource1"
        Width="100%"&nbsp;OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" ButtonType="Button" >
                <ControlStyle CssClass="button" ></ControlStyle>
                <ItemStyle Wrap="False" ></ItemStyle>
            </asp:CommandField>

 

 

Code behind:

  

 ASP |  copy code |? 
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //In this sample, there are  3 buttons and the second one is Delete button, that's why we use the index 2
            //indexing goes as 0 is button #1, 1 Literal (Space between buttons), 2 button #2, 3 Literal (Space) etc.
            ((Button)e.Row.Cells[0].Controls[<strong>2</strong>]).OnClientClick = "return confirm('"Do you really want to delete?');";
        }
    }