Sunday, December 25, 2011

How to convert LPWSTR to string in VC++

Author: ArkM
Source: http://www.daniweb.com/software-development/cpp/threads/155420



C++ Syntax (Toggle Plain Text)
  1. bool cvtLPW2stdstring(std::string& s, const LPWSTR pw,
  2. UINT codepage = CP_ACP)
  3. {
  4. bool res = false;
  5. char* p = 0;
  6. int bsz;
  7.  
  8. bsz = WideCharToMultiByte(codepage,
  9. 0,
  10. pw,-1,
  11. 0,0,
  12. 0,0);
  13. if (bsz > 0) {
  14. p = new char[bsz];
  15. int rc = WideCharToMultiByte(codepage,
  16. 0,
  17. pw,-1,
  18. p,bsz,
  19. 0,0);
  20. if (rc != 0) {
  21. p[bsz-1] = 0;
  22. s = p;
  23. res = true;
  24. }
  25. }
  26. delete [] p;
  27. return res;
  28. }
  29.  
  30. int main()
  31. {
  32. wchar_t msg[] = L"Hello, world!";
  33. std::string s("\?");
  34.  
  35. cvtLPW2stdstring(s,msg);
  36. std::cout << s << std::endl;
  37.  
  38. return 0;
  39. }


Tuesday, December 20, 2011

Private Web Browsing with SSH Tunneling and Putty By Corey on March 9th, 2010


Private Web Browsing with SSH Tunneling and Putty

Web browsing through SSH tunneling gives you the ability to browse the web privately by encrypting all web traffic out of your computer.  This gives you privacy to know that anyone eavesdropping on your connection using something like Wireshark. It also allows you to by-pass any internet content restrictions that may be in place where you are, such as a workplace or public connection.  I personally use this because I don’t like the idea of someone else listening in, and I don’t like being restricted.
What we will do is use a free program called Putty to connect to an SSH server that we have set up home. Then we will configure the machine that we are on to pass all web traffic through this encrypted connection and out through our home connection. Anyone listening in will only see one connection to your home IP, and the rest will be encrypted traffic.
Note: There is now an update to this post that also Passes all DNS Queries Through SOCKS in Firefox. Be sure to read that after you finish this tutorial for added privacy.

What You Will Need

  • An SSH server, or access to one.  (Note: Free shell providers don’t take kindly to people doing this through their servers, so check with them before you do this)  Setup of SSH server not covered here.
  • Putty client downloaded to the machine you will be working on.
  • Ability to connect outbound from your location.  Many work places limits or prevents outbound SSH connections.  You may need to run yours on a different port.

Step 1 – Configure Putty

After downloading Putty, launch it and in the left menu, go toConnection -> SSH -> Tunnels .  On the right side, enter any port above 1024 in the Source Port and select Dynamic from the radio buttons directly below it, then click Add.
It should now say D7070 in the box above.
Next, on the left side, go back to Session, and add a session profile for your home server by entering in the address underHost Nameensure that SSH is selected underneath.  Next, create a name for your profile, and enter it in Saved Sessionsbox and then click save.  Finally, click Open at the bottom and log into your SSH server.

Step 2 – Configure Web Browser

Firefox
If you’re using the Mozilla Firefox web browser, you can configure it by going to Tools -> Options menu and then clicking Advanced on top and then select the Network tab and then Settings under Connection section.
On the Connection Settings windows, enter in 127.0.0.1 in the SOCKS Host box, and your port you selected earlier, in this case 7070.  Ensure that SOCKSv5 is selected underneath.  That’s it, now press OK until you are back at your browser window.  You’re done.
Internet Explorer
If you are using Microsoft Internet Explorer then you can go to theTools -> Internet Options menu.  Click on the Connections tab and then LAN Settings down below. Now, on the Local Area Network (LAN) Settings page, but a check mark in the Use aproxy server for your LAN and in Bypass proxy server for local addresses and then click the Advanced button.
In the Proxy Settings page, enter 127.0.0.1 in the Socks box, and the port you selected in the box next to it, in our case 7070. Now, click OK until you are back at the web browser window.
Google Chrome
Unfortunately there is no native way of setting this up in Google Chrome.  However, someone has created an extension for it that you will have to add yourself called Proxy Switchy! which you will have to add yourself. I don’t currently have Google Chrome installed so I can’t provide step-by-step instructions.

Testing

The good thing about this setup is that you don’t have to configuration anything on the SSH Server side.  To test your tunnel, just go to http://www.whatismyip.com and it should display the IP address of your home server and not your current physical location.
That’s it, enjoy, and happy private browsing!

Sunday, December 4, 2011

Thursday, December 1, 2011

make blip 2.0 error: region `rom' overflowed by 6806 bytes

mkdir -p build/telosb
    compiling PppRouterC to a telosb binary
ncc -o build/telosb/main.exe  -Os -O -DRPL_ROUTING -DRPL_STORING_MODE -I/opt/tinyos/tos/lib/net/rpl -I/opt/tinyos/tos/lib/ppp -I/opt/tinyos/tos/lib/fragpool -DPPP_HDLC_RX_FRAME_LIMIT=1 -DPPP_HDLC_TX_FRAME_LIMIT=8 -DIN6_PREFIX=\"fec0::\" -DBLIP_DERIVE_SHORTADDRS -DCC2420_HW_ACKNOWLEDGEMENTS  -DCC2420_HW_ADDRESS_RECOGNITION -DPACKET_LINK -DTOSH_DATA_LENGTH=112 -I/opt/tinyos/tos/lib/net/ -I/opt/tinyos/tos/lib/printf/ -I/opt/tinyos/support/sdk/c/blip/ -I/opt/tinyos/tos/lib/net/blip/ -I/opt/tinyos/tos/lib/net/blip/interfaces/  -I/opt/tinyos/tos/lib/net/blip/nwprog/ -I/opt/tinyos/tos/lib/net/blip/shell/ -I/opt/tinyos/tos/lib/net/blip/serial/ -I/opt/tinyos/tos/lib/net/blip/platform/ -I/opt/tinyos/tos/lib/net/blip/icmp/ -I/opt/tinyos/tos/lib/net/blip/dhcp/ /opt/tinyos/support/sdk/c/blip/lib6lowpan/iovec.c /opt/tinyos/support/sdk/c/blip/lib6lowpan/in_cksum.c /opt/tinyos/support/sdk/c/blip/lib6lowpan/ip_malloc.c /opt/tinyos/support/sdk/c/blip/lib6lowpan/utility.c /opt/tinyos/tos/lib/net/blip/table.c -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DDEFINED_TOS_AM_GROUP=0x22 -DIDENT_APPNAME=\"PppRouterC\" -DIDENT_USERNAME=\"ubuntu\" -DIDENT_HOSTNAME=\"ubuntu\" -DIDENT_USERHASH=0xf67b89f7L -DIDENT_TIMESTAMP=0x4ed7f4e0L -DIDENT_UIDHASH=0x839cc16fL  PppRouterC.nc -lm 
/opt/tinyos/tos/platforms/telosa/PlatformHdlcUartC.nc:40:2: warning: #warning Enabling DMA on UART1RX
/opt/tinyos/tos/chips/cc2420/lpl/DummyLplC.nc:39:2: warning: #warning "*** LOW POWER COMMUNICATIONS DISABLED ***"
/opt/tinyos/tos/chips/cc2420/link/PacketLinkC.nc:38:2: warning: #warning "*** USING PACKET LINK LAYER"
/opt/tinyos/tos/lib/net/blip/shell/UDPShellP.nc:260: warning: call via function pointer
/opt/tinyos/tos/platforms/telosa/PlatformHdlcUartP.nc:181: warning: `HdlcUart.receivedByte' called asynchronously from `UsartInterrupts.rxDone'
/usr/bin/../lib/gcc/msp430/4.5.3/../../../../msp430/bin/ld: build/telosb/main.exe section `.text' will not fit in region `rom'
/usr/bin/../lib/gcc/msp430/4.5.3/../../../../msp430/bin/ld: section .vectors loaded at [0000ffe0,0000ffff] overlaps section .text loaded at [00004000,00011993]
/usr/bin/../lib/gcc/msp430/4.5.3/../../../../msp430/bin/ld: region `rom' overflowed by 6806 bytes
collect2: ld returned 1 exit status
make: *** [exe0] Error 1


Using latest tools from http://tinyprod.net/debian-dev/ 
However it did not compile with stanford version either, so I guess it is not question of toolchain.
Comment 1 by project member marku...@gmail.comToday (12 hours ago)


Fix is commenting
#OPTFLAGS += -O
in support/make/telosb.target.

Tuesday, November 1, 2011

How to use Unix/Linux commands at the Windows command prompt

source: http://www.root777.com/security/how-to-use-unixlinux-commands-at-the-windows-command-prompt/


A lot of us who use Linux at work/school or have always grown up using unix commands for years and more often than not, there might have been instances where a ls command comes more naturally than the dir command at the command prompt in Windows. For the most part, a lot of us work around this drawback using the excellent tool: Cygwin. Cygwin is available for windows users here.The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the UNIX system calls and environment these programs expect.
With these tools installed, it is possible to write Win32 console or GUI applications that make use of the standard Microsoft Win32 API and/or the Cygwin API. As a result, it is possible to easily port many significant Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software . Even if the development tools are of little to no use to you, you may have interest in the many standard Unix utilities provided with the package. They can be used both from the bash shell (provided) or from the standard Windows command shell.
While Cygwin would be an obvious choice for many Unix/Linux power users, there is an excellent and a much simpler alternative to using Cygwin. In this article, we will show you how to run your Unix commands right in the windows command prompt.
For this, we will be using CoreUtils. CoreUtils is available through Sourceforge and is available for download here. If you look in here, there are a number of GNUWin32 packages available, the one we would be using is the CoreUtils package. CoreUtils is a collection of basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every OS. And when I talk about File utilities, they include chgrp, chmod, cp, dd, du, ln, ls, mkdir, mv, rm, touch, vdir among others. A sample of the text utilities include cat, cksum, cut, join, md5sum, shasum, sort, split etc. The shell root commands include echo, chroot, hostname, nice, pathchk, tty, who, whoami and yes su. So it is pretty much the whole nine yards here… The direct link for download of the CoreUtils package available through SourceForge is available here.
Once installed, you will need to add the path to the utilities to your PATH environment variable. Follow the steps below to achieve this
1. Click on Start –> Run and enter sysdm.cpl to bring up the system properties Dialog
2. Click on the Advanced tab –> Environment variables button Path to environment variable
3. In the System Variables pane, scroll down to Path and then click on edit.
4. Under Edit System Variable, in the variable value, at the end of the line , type the following including the semicolon which separates the individual elements in the path variable. ;C:\Program Files\GnuWin32\bin
env variable properties
Congratulations !! You have now added the GNUWin directory to your path and Unix commands can now be executed directly from the command line and run natively on the Win32 command prompt without the need for any emulation layer as shown below using the example of dir vs ls
command prompt comparing dir vs lsDownloads and Sources
1. Download CYGWIN
2. Download CoreUtils

How to Root Nexus S (2.3.6 works) and Nexus S 4G – Tutorial

souce: http://androidadvices.com/how-to-root-nexus-s-and-nexus-s-4g-%E2%80%93-tutorial/


For all those who own Sprint handsets of Nexus S as well as Nexus S 4G, here comes a great news as you can now enjoy the rooting process for your handsets, be it any version of firmware you are on, you can easily root your handsets easily. Basically, the rooting unlocks the device to a whole new level of possibilities which are helpful in further customizing the device which is the best part of the Android devices compared to other devices like Apple or say even Nokia whose operating systems are not so customizable which Android are. For your simplicity, we have come up with the simplest possible procedure to root your device unlike some of the complex and lengthy techniques.
So, let’s check out the same in the due course of this article on how you can easily root you devices. Before proceeding to the rooting procedure, you will have to ensure that you follow the below mentioned pre requisites carefully also most importantly you will have to also note that the rooting procedure will void the warranty, though the warranty can be claimed back once you un root the device. So, let’s proceed and see the instructions below. And also, we take no responsibility for your device and we should not be held responsible for any manner in part or in whole and proceed for the tutorial to root solely at your risk. It’s an unlikely even that you may brick your phone if you follow the instructions which are mentioned below.
Nexus SNexus S 4G
Pre Root Instructions:
  • Warranty will get void once you root Nexus S as well as Nexus S 4G, though warranty can be claimed once you un root your device.
  • In an unlikely event you may lose all the data which is present in your device, so it’s recommended to create a backup of all the data like call logmessagesapplications, music, videos and other data which is present in the phone, so that you can restore the same once the rooting process is completed.
  • Ensure that you have the installed the latest framework in your computer or also you can install the latest version of KIES which is dubbed as KIES 2 so as to ensure that all the required drivers are installed successfully.
  • It’s very important to maintain a minimum battery power of 50% so as to facilitate the smoother rooting process or else there is a high possibility that your device may end up turning completely off in the process of rooting.
  • Since the process of rooting will be taking place, all the APN settings with which you access the Internet will be wiped off completely, so ensure that you have noted all the required settings for accessing the internet so that you can configure them again back once the device gets rooted. Also, additionally ensure that you have also backed up the MMS Settings and other settings as in an unlikely event sometimes you may end up losing all the 3G Settings as well as the APN or MMS settings in the process of Rooting the device.
  • Last but not the least follow the below mentioned instructions carefully so as to save your phone from being turned into an expensive paper weight.
Procedure to Root Sprint 4G as well as Nexus S as well as Nexus S 4G:
  • First up you will have to download the Rooting package for Nexus S / Nexus S 4G device to your computer. Please note that after you download the zip file, you will have to unzip the same and in the process of unzipping if it prompts for the password then enter the password as androidadvices.com and nothing else. Kindly make a note of it as it has been found that despite mentioning several times its repeatedly being asked in the comments section.
Extracted files Nexus S Root
  • It’s always recommended to extract the files to the desktop as it will be easier for you to find the same. Now, after extraction of the files, just connect your Nexus S 4G or Nexus S device to the computer with the help of USB cable but ensure that you have enabled the USB Debugging which can be done by going to Settings > applications > Development  and enable USB Debugging. Its highly recommended to not to mount the SD card when you connect your phone with the computer.
Nexus S Debugging
  • Now, next up you will have to open the One click Nexus S 4G folder along with the drivers which should be required to root the device. Also, most importantly the drivers will be in the folder of PDA NET A 300 x64 for the 64 bit windows while for 32 bit windows you will have to select PDA NET A 300 32 bit.
  • After this you will have to click on the Run.exe file as soon as you finish installing the drivers.
  • That’s it you will have to now follow the on screen instructions to root your Nexus S 4G or Nexus S device. Please note that this process takes around 10 minutes which is the maximum time it will take for rooting the device.
Press Key to continue
  • Now, as soon as the rooting is finished you will have to reboot the device after which you will have to open the Android Market Place and then search for the application called the Root Checker and download the same.
ROOTING Path
After successful completion of the download, just tap on the application to open the same after which it will tell you whether the device has been successfully rooted or not, if the device is not rooted then you will have to follow the above procedure to root the same.
Please note that you will have to reconfigure the APN settings after updating the firmware to access the data services and the Internet services as all the Internet APN settings will be reset. You will have to contact your Service provider which is Verizon Wireless to get more info on the APN Settings. Not to forget also configure the MMS Settings. Do let us know if you face any issues while rooting the device as we will see to it that the issues are solved. Just in case if the rooting process is interrupted in the middle then you just need to re follow the whole procedure from the start to root your device.

Thursday, July 28, 2011

How to export HTML table to Excel file

1
2
protected void Button1_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition","attachment;filename=myexcel.xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw); mytable.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { }

Reference: Jessica Cao http://forums.asp.net/p/1086952/1625783.aspx

Monday, July 25, 2011

Display records information based on selected item from ComboBox in Access

Option Compare Database

Private Sub Form_Current()
    If Me.NewRecord Then
        Me.NameofTable = ""
    Else
        Me.NameofTable.SetFocus
        Me.NameofTable.Requery
        Me.NameofTable = Me.NameofTable.ItemData(Forms(0).CurrentRecord - 1)
    End If
End Sub

Private Sub NameofTable_Click()
    ' at this point, cbx text = cbx value
    If Me.NewRecord Or Me.NameofTable.ListIndex = -1 Then
         Me.nameoftabledum = Trim(Me.NameofTable)
         DoCmd.RunCommand acCmdSaveRecord
     Else
         If Me.NameofTable.ListIndex <> Forms(0).CurrentRecord - 1 Then
             DoCmd.GoToRecord , , acGoTo, Me.NameofTable.ListIndex + 1
         End If
    End If
End Sub

Private Sub NameofTable_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
        If Me.NameofTable.SelLength < Len(Me.NameofTable.Value) Then
            ' delete part of the text
        Else   ' delete record
            Dim m As Integer
            m = Forms(0).CurrentRecord
            DoCmd.RunCommand acCmdDeleteRecord
            Me.NameofTable.Requery
            Forms(0).Requery
            If m > 1 Then m = m - 1
            DoCmd.GoToRecord , , acGoTo, m
         End If
    End If
End Sub


Friday, July 22, 2011

Retrieve RSS feeds and display in ASP.Net VB

Function ProcessRSSItem() As String
        Dim rssURL As String = "http://www.abc.com/rss.rss"

        Dim myRequest As WebRequest = System.Net.WebRequest.Create(rssURL)
        Dim myResponse As WebResponse = myRequest.GetResponse()

        Dim rssStream As Stream = myResponse.GetResponseStream()
        Dim rssDoc As New XmlDocument()
        rssDoc.Load(rssStream)

        Dim nsmg As New XmlNamespaceManager(rssDoc.NameTable)
        nsmg.AddNamespace("dc", "http://purl.org/dc/elements/1.1/")

        Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")

        Dim title As String = ""
        Dim link As String = ""
        Dim description As String = ""
        Dim i As Integer = 0
        Dim numItems As Integer = 1
        Dim sb As New System.Text.StringBuilder
        Dim rssDetail As XmlNode

        Do Until numItems = 10
            rssDetail = rssItems.Item(i).SelectSingleNode("dc:language", nsmg)
            Console.WriteLine(rssDetail.InnerText.ToString())
            If rssDetail.InnerText.Equals("en-US") Then
                rssDetail = rssItems.Item(i).SelectSingleNode("title")
                If rssDetail.Equals(Nothing) = False Then
                    title = rssDetail.InnerText
                Else
                    title = ""
                End If

                rssDetail = rssItems.Item(i).SelectSingleNode("link")
                If rssDetail.Equals(Nothing) = False Then
                    link = rssDetail.InnerText
                Else
                    link = ""
                End If

                rssDetail = rssItems.Item(i).SelectSingleNode("description")
                If rssDetail.Equals(Nothing) = False Then
                    description = rssDetail.InnerText
                Else
                    description = ""
                End If

                sb.Append("

" + title + "
") sb.Append(description + "

") numItems = i + 1 End If i = i + 1 Loop Return sb.ToString End Function

Wednesday, July 6, 2011

How to display all selected nodes in TreeVirw VB

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim names As String = ""
        Dim values As String = ""
        For Each parentNodes As TreeNode In trvIndustrySelections.Nodes
            For Each childNodes As TreeNode In parentNodes.Nodes
                If (childNodes.Checked) Then
                    names = childNodes.Text + "; " + names
                    values = childNodes.Name + "; " + values
                End If
            Next
        Next

        txtCurrentSelectNames.Text = names
        txtCurrentSelectValues.Text = values
    End Sub

Sunday, April 24, 2011

How to resize Root Partition on Ubuntu in VMWare Workstation

source: http://www.virtualdojo.net/resize-rootpartition-on-ubuntu-v9-10-workstation/

The Virtual Machine (VM) templates I created for each Operating System (OS) were made with the smallest possible Virtual Hard Drives to conserve space. When I deploy one of these VM templates I almost always run into disk space problems. This is an easy situation to deal with in both the Windows and Linux OS.

Default partitioning with Ubuntu v9.10 will create a primary EXT4 partition for the root file system, and a small extended partition with a linux-swap partition. Partitions must be unmounted and the last partition on the disk in order to resize them. Since you cannot unmount the root partition once you booted from it, you must boot a CD to accomplish this task.

Mount the Ubuntu v9.10 Workstation ISO on the VM and boot. Press the [ESC] key quickly to get the VMware boot menu. Select the “CD-ROM Drive” option and press the [ENTER] key. Select your language then use the “Try Ubuntu without any change to your computer” option to boot the Ubuntu OS completely from CD.

Once you are at the desktop, start the partition editor by clicking “System > Administration > GPartEd” from the top navigation bar of the desktop. We will make all changes to the partition table using the GPartEd utility.

It is highly recommended that you clone or backup the VM before manipulating the partition table. While the potential to lose data exists, you can relax a bit since changes to the partition table will not be made until you click the “Edit > Apply All Operations” option from the GPartEd menu.

We must first turn off Swap and then delete the Swap partition and the Extended partion that it resides in before we can resize the root partition.

Turn off the Swap partition by clicking “Partition > Swap Off” from the GPartEd menu.

Delete the Swap partition by selecting it from the partition list and then clicking “Partition > Delete” from the GPartEd menu. The swap partition does not contain any valuable data and does not need to be backed up.

Delete the Extended partition by selecting it from the partition list and then clicking “Partition > Delete” from the GPartEd menu.

Resize the Root partition by selecting it from the partition list and then clicking “Partition Resize/Move” from the GPartEd menu. Drag the top slider all the way to the right to use all unallocated space. Then type in the amount of space you want to leave to recreate the swap partition into the “Free Space Following (MiB)” field. Be sure that the “Free Space Preceding (MiB)” value is set to “0″. Click the [Resize/Move] button to accept the changes.

Create a new Extended partition by selecting “Unallocated” from the partition list, then click “Partition > New” from the GPartEd menu. Drag the top slider all the way to the right to use the remainder of your unallocated space. Change the “Create As” type to “Extended Partition” (File System will automatically be set to “Extended”) and click the [Add] button to create the new partition.

Create a new Swap partition by selecting “Unallocated” under your “Extended” partition from the partition list and then clicking “Partition > New” from the GPartEd menu. Drag the top slider all the way to the right to use the entire Extended partition for your Swap. Change the “Create As” type to “Logical Partition” and change the “File System” type to “Linux-Swap” then click the [Add] button to create the new partition.

Save changes to the partition table by selecting “Edit > Apply All Operations” from the GPartEd menu. Click the [Apply] button on the confirmation dialog popup to begin applying the changes. Wait a few minutes while the changes are made on the hard drive then shutdown the VM.

Modify the VM settings to unmount the Ubuntu v9.10 Workstation CD then boot the VM. Check your partition table using the GPartEd utility to verify the changes were made then begin consuming your newly allocated storage!