HNotepad :: Haskell -> Gtk2Hs -> HNotepad ()

Hi !

this time went ahead with Gtk2 + Haskell [Gtk2Hs]. First GUI program… so.. thought to make simple Notepad 😛

wasn’t a waste anyway.. learned quite a few things.

code might not be pure Haskellish.. but I’m slowly getting used to use Haskell.. 🙂

This is how it looks –

and you can download source [.hs + glade file] from my skydrive or have a quick look at source on hpaste

Download Link

My first Haskell Adventure !

Hi !

I’ve been trying to spend some time with Haskell for long but college.. assignments … etc..were keeping me away. Finally got time + kick + excitement last night and decided to code something meaningful.
Thought to solve this challenge one more time >

Its quite simple. Read from input.txt [which is actually a twitter feed] > remove duplicate id entries > sort in descending order of Timestamp and save to output.txt.

Took pretty long time though. I was also reading relevant pages from RWH. had to read some things like Monads twice/thrice to understand. Then talking to folks in IRC #Haskell.. Still have to go through alot.

but it was fun. yeah! my first Haskell program that works as expected 😀

here’s the code. It still requires alot of cleaning and will do that after posting this. but this is the final v1.0 that works. So wanted to share this one only 😀

Continue reading

Fetch twitter feed on your Form

Here’s a way to fetch twitter feed on form.

Twitter provides RSS feed of every account, provided account visibility is Public.

If you are using New twitter, you’ll have to find out your twitter feed link by

1] either leave new twitter preview and find RSS links on right sidebar, or
2] click on the RSS Feed icon in browser addressbar. It will probably show your favorites feed. Note the userid from URL.

Now, use that userid in this fashion :

Once you get your twitter feed rss url, its simple to fetch entries.

Sample code using my twitter feed :

You’ll need a RichTextBox and a Button on form. Keep default names.

	Dim items As Xml.XmlNodeList = FetchTwitterFeed("")
	'Iterate and print each title
	For Each item As System.Xml.XmlNode In items
		RichTextBox1.AppendText(item.ChildNodes(0).InnerText & vbCrLf)
		'childNodes(0) gives title
		'for rest node indices like link,time etc
		'check source string

Read more for FetchTwitterFeed() Function –

Continue reading

Copy folder using

Imports System.IO
Public Class Form1
	Private Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, Optional ByVal Overwrite As Boolean = False)
		Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath)
		Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)
		' the source directory must exist, otherwise throw an exception
		If SourceDir.Exists Then
			' if destination SubDir's parent SubDir does not exist throw an exception
			If Not DestDir.Parent.Exists Then
				Throw New DirectoryNotFoundException _
					("Destination directory does not exist: " + DestDir.Parent.FullName)
			End If
			If Not DestDir.Exists Then
			End If
			'copy all the files of the current directory
			Dim ChildFile As FileInfo
			For Each ChildFile In SourceDir.GetFiles()
				If Overwrite Then
					ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)
				' if Overwrite = false, copy the file only if it does not exist
				' this is done to avoid an IOException if a file already exists
				' this way the other files can be copied anyway...
					If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then
						ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), False)
					End If
				End If
			' copy all the sub-directories by recursively calling this same routine
			Dim SubDir As DirectoryInfo
			For Each SubDir In SourceDir.GetDirectories()
				CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, _
						SubDir.Name), Overwrite)
			Throw New DirectoryNotFoundException("Source directory does not exist: " + SourceDir.FullName)
	End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	CopyDirectory("C:\zipMe", My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Folder1", False)
End Sub

Copy folder using Shell32 :-

Continue reading

Communicate between two Visual Basic Applications

How to communicate between 2 different visual basic applications.

Simple technique by using SendMessage()

	'Main app that tries to communicate with other
	Public Class Form1
		'Project App1

		Private Const APP2_MSG1 As Integer = 6541

		Declare Auto Function SendMessage Lib "user32.dll" _
		(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
		 ByVal wParam As Integer, ByVal lParam As Integer) As Integer

		Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
		Handles Button1.Click
			Dim p() As Process = Process.GetProcessesByName("App2")
			If p.Count > 0 Then
				Dim hWnd As IntPtr = p(0).MainWindowHandle
				SendMessage(hWnd, APP2_MSG1, 0, 0)
				Debug.WriteLine("Msg sent")
			End If
		End Sub
	End Class

Read more to get code of Listening application

Continue reading

Get Screen information related to Form location

	If Screen.FromPoint(Me.Location).Primary Then
		'is primary
	End If

Get device name on which form is currently on :


Get Screen resolution of display, your form is currently on :

	Dim rect As Rectangle = Screen.FromPoint(Me.Location).Bounds