Tool – ProjectEuler Solution

After reading some reviews of interviews at Microsoft and Google, I am inspired to train myself for solving mathematical problems and writing algorithms. http://projecteuler.net/ is my first “mountain peak” to conquer. This website has until now more than 350 problems of many fields in mathematics. It’s suitable for training to write efficient algorithms to solve complicated computing tasks. I’m just at starter level and don’t have much time for it but when I have free time I’ll solve some of them. To manage all solved problems, I have written a GUI Tool which loads all problems as plugins, allow me to enter argument with its value and invoke the calculate method to get result back.
The tool will scan folder “Extensions” at its startup directory and load all plugins written for him. Therefore you can write your own plugin, copy to “Extensions” folder and use the tool as GUI to run your solution.
I also created a Web-version of this tool but the website version is very limited. It doesn’t permit to upload your solutions (I know you’re good hackers) and customize value of argument (I’ll improve the website version in next version so that you can customize the input).

  • Version: 1.0.0.0
  • Supported OS: All Windows

NOTE: If this tool doesn’t work with your system, post here your errors.

LINK DOWN: http://hintdesk.com/Web/Tool/ProjectEulerSolution.zip

WEBSITE: http://projecteulersolutionweb.apphb.com/ (the website is pretty slow at first load. Sorry for that, I don’t have any Windows host to host my application)

HISTORY:

  • [1.0.0.0] : Beta Version

SCREENSHOT

ProjectEuler Solution

PLUGIN INSTRUCTION
– To write your own plugin which works with this GUI tool, you should create a library and add reference to libraries

  • RPESPlugIn.dll (which can be found in “Extensions” folder)
  • System.ComponentModel.Composition.dll
  • – Your solution class must implement the IProblemSolution interface and define some attributes as example below

    [ProblemSolutionAttribute("Problem 1", @"If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
    
    Find the sum of all the multiples of 3 or 5 below 1000.
    ")]
    public class Problem1Solution : IProblemSolution
    {
    	public string GetResult(List<ProblemArg> probArgs)
    	{
    		Stopwatch stopWatch = new Stopwatch();
    		stopWatch.Start();
    
    		double result = Calculate(probArgs);
    
    		stopWatch.Stop();
    		return string.Format("Result: {0}\nTime elapsed: {1} ms", result, stopWatch.ElapsedMilliseconds);
    	}
    
    	public double Calculate(List<ProblemArg> probArgs)
    	{
    		int n = Convert.ToInt32(probArgs.First().Value) - 1;
    		return SumDivisibleBy(n, 3) + SumDivisibleBy(n, 5) - SumDivisibleBy(n, 15);
    	}
    
    	public double ProjectEulerCalculate(List<ProblemArg> probArgs)
    	{
    		throw new NotImplementedException();
    	}
    
    	private int SumDivisibleBy(int n, int factor)
    	{
    		int i = (n / factor);
    		return factor * i * (i + 1) / 2;
    	}
    
    	public List<ProblemArg> RequiredInputArgs
    	{
    		get
    		{
    			return new List<ProblemArg>() { new ProblemArg { DefaultValue = "1000", Name = "Integer n", RegularExpression = "^[0-9.]+$", MaxLength = Int32.MaxValue.ToString().Length } };
    		}
    	}
    }
    

    – There are 2 required attributes for your class solution. One is the name of problem which should be shown in combo box and the other is the description of problem which should be displayed in text box.

    – If you want to allow user enter value of argument, you should define the RequiredInputArgs property to give a list of argument back. The list can contain more arguments which will be show in list box under problem description.

    – The GetResult(List probArgs) gives you a signal that the user want to invoke your solution with his defined value (if any). In this function you can make your calculation (which can be in Calculate(List probArgs) function but it must not) and give the result back with type of string.

    So it’s pretty easy to write extension for this GUI tool. Try yourself to write your own solution and let this tool manages all solution for you.

    Tools – Doidw – Do I DDos this website?

    Last year I have seen a lot of DDOS attacks aimed to website of news or independent communities. These websites were attacked by a botnet built from unknown virus (which wasn’t detected by any antivirus at that time). Some professionals found some variants of this virus but the websites were still heavily attacked.

    Some of professional users are willing to help to find more variants of this virus. They would like to check if computers of their families are members of this botnet. However using a sniffer then running through forest of packet to identify which processes are flooding the websites, is too complicated for them.

    Continue reading Tools – Doidw – Do I DDos this website?

    Thumboim – Thumbnail generator for many images

    This tool “Thumboim” helps you to generate thumbmails of many images and display all of these thumbnails in one images. This tool is helpful when you have a gallery and would like to have an overview of all images. Just simply choose an folder where your images locate, enter gallery name and it’s description. The default output size is 1024*768 can be changed anytime as you want then click “Generate thumbnails” to finish. You’ll be asked for output file at the end. Please note that this tool doesn’t work recursively, he scans only the given directory – not sub directory. Extract zip file and run program from extracted folder.

    • Version: 1.0.0.3
    • Supported OS: All Windows

    NOTE: If this tool doesn’t work with your system, post here your errors.

    LINK DOWN: http://hintdesk.com/Web/Tool/Thumboim.zip

    HISTORY:

    • [1.0.0.3] : Fix some bugs and improve output when description and name are blank
    • [1.0.0.2] : Data validation, fix some warningss and some small bugs
    • [1.0.0.1] : Beta Version

    SCREENSHOT
    Thumboim
    Thumboim output

    C#, Tools – Video Converter with ffmpeg

    Last month I bought a new digital camera Canon PowerShot SX210IS 14.1 MP Digital Camera with 14x Wide Angle Optical Image Stabilized Zoom and 3.0-Inch LCD (Black) . My old one is somehow broken, the taken photos were not as good as before. So I decide to buy a new one with better video capturing feature. Canon PowerShot SX210IS can capture
    – stunning HD movies with Dynamic mode for enhanced image stabilization when shooting movies using wide-angle settings or
    – smooth HD video (720p) with stereo sound for a truly natural, high quality HD experience.
    It sounds great, doesn’t it?

    However, as you know, the file size of a HD video is always too big. It’s about over 100 MB for only some minutes which is a big disadvantage for sharing over internet. Therefore I would like to write a small tool basing on ffmpeg – an open source command line video converter – to convert the video from MOV to AVI format (can be played in any version of Windows Media Player ) and to reduce simultaneously the file size up to 90% of the original. The GUI of this tool is very simple as below

    VidCon

    This tool takes path to original video file as his input then call the ffmpeg with this syntax

    ffmpeg.exe -i "inputfile" "outputfile"
    

    to convert file into AVI. The important metadata like duration and fps will be displayed when user gives him the input video file. It is very simple tool because I do not write any code for video converting. I simply parse ffmpeg input / output and write this tool as ffmpeg GUI. There is nothing special in the code if you read this blog post before http://hintdesk.com/c-read-console-output-asynchronously/

    Just using the same code of this post in combination with some regex rules you can read the metadata of input file as well as the current progress when converting

    enum VideoProperties
    {
    	[DescriptionAttribute(@"[D|d]uration:.((\d|:|\.)*)")]
    	Duration,
    	[DescriptionAttribute(@"[s,].([0-9]+(?:\.[0-9]*)?) fps")]
    	Fps,
    	[DescriptionAttribute(@"frame=\s+([0-9]*)")]
    	CurrentFrame,	
    }
    

    There is only a small problem with Drag and Drop on text box when I was writing this software because in the text box control of WPF, the Drag and Drop events are marked as handled and prevent us from handling these events ourselves. Therefore although we set the AllowDrop on true, the cursor is always shown as not drop allowed when we drop something on it. To solve this problem we must set the triggers for 3 events: PreviewDragEnter, PreviewDragOver, PreviewDrop and handle these events as below

    <TextBox AllowDrop="True" Grid.Column="0" Text="{Binding SelectedFilePath}"   Name="txtIpodPath" VerticalAlignment="Center" Height="31">
    	<i:Interaction.Triggers>                        
    		<i:EventTrigger EventName="PreviewDragEnter">
    			<cmd:EventToCommand Command="{Binding PreviewDragCommand, Mode=OneWay}" PassEventArgsToCommand="True" />
    		</i:EventTrigger>
    		<i:EventTrigger EventName="PreviewDragOver">
    			<cmd:EventToCommand Command="{Binding PreviewDragCommand, Mode=OneWay}" PassEventArgsToCommand="True" />
    		</i:EventTrigger>
    		<i:EventTrigger EventName="PreviewDrop">
    			<cmd:EventToCommand Command="{Binding PreviewDropCommand, Mode=OneWay}" PassEventArgsToCommand="True" />
    		</i:EventTrigger>
    	</i:Interaction.Triggers>
    </TextBox>   
    
    private RelayCommand<DragEventArgs> handleDropCommand;
    public ICommand HandleDropCommand
    {
    	get
    	{
    		if (handleDropCommand == null)
    			handleDropCommand = new RelayCommand<DragEventArgs>(e => HandleDropEvent(e));
    		return handleDropCommand;
    	}
    }
    
    private void HandleDropEvent(DragEventArgs e)
    {
    	if (e.Data == null)
    	{
    		return;
    	}
    
    	string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
    	SelectedFilePath = files[0];
    	ffmpegWrapper.ReadInputFile(SelectedFilePath);
    }
    
    private RelayCommand<DragEventArgs> previewDragCommand;
    public ICommand PreviewDragCommand
    {
    	get
    	{
    		if (previewDragCommand == null)
    			previewDragCommand = new RelayCommand<DragEventArgs>(e => HandlePreviewDragEvent(e));
    		return previewDragCommand;
    	}
    }
    
    private void HandlePreviewDragEvent(DragEventArgs e)
    {
    	e.Effects = DragDropEffects.All;
    	e.Handled = true;
    }
    
    
    private RelayCommand<DragEventArgs> previewDropCommand;
    public ICommand PreviewDropCommand
    {
    	get
    	{
    		if (previewDropCommand == null)
    			previewDropCommand = new RelayCommand<DragEventArgs>(e => HandleDropEvent(e));
    		return previewDropCommand;
    	}
    }
    

    You can see that in the code above I use the same function to handle 2 events PreviewDragEnter and PreviewDragOver. Just allow all DragDropEffects and set the Handled on true to tell that we would like to handle these events ourselves. If you do not set Handled on true, you won’t get any information when catching the Drop event.

    Maybe it’s interesting for you about the formula to calculate the number of frames of a video file : Frame = Duration * Fps. Using this information I can display the converting progress smoothly with a progress bar because ffmpeg does not give us any info about number of frames but he shows the current frame when he converts the video. Knowing total number of frames of video file in combining with current frame, we can estimate how long ffmpeg will take until finishing. In C#, the formula will be implemented as below.

    public int Frame
    { 
    	get 
    	{
    		TimeSpan tempTimeSpan = new TimeSpan();
    		string[] timepieces = Duration.Split(new char[] { ':', '.' });
    		if (timepieces.Length == 4)
    		{
    			 tempTimeSpan = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
    		}
    
    		if (Duration != null && Fps != null)
    			return (int)(tempTimeSpan.TotalSeconds * double.Parse(Fps, CultureInfo.InvariantCulture));
    		else
    			return 0;
    	}
    }
    

    In this first version, I do not provide any advanced features so that one can set the frame rate,fps, codec or something like that. And I do not intend to build these features into this tool because I think as normal user I have no idea about frame rate or codec. In next version I will build only one feature more allowing user to set the size of output video. For example, user can set that he would like to have an AVI about 2 MB so that he can attach it in an email. The tool will change the video properties inside to reach the given output size.

    In summary, this tool can be used to convert any video format to AVI format which has smaller file size and is compatible to any version of Windows Media Player meaning can be played under any version of Windows operating system. If you want to try it, you can easily download it here “VidCon – Video Converter with ffmpeg“. As normal no source code avaible for any tool.

    Ipod To PC – Tool to copy files from Ipod to PC

    This tool “Ipod To PC” helps you copy all of your music files in your Ipod to PC. This tool is necessary if the music files on your PC were deleted cause of hard disk damage. Connect Ipod to your PC, the music folders in Ipod will be automatically located. If not, you must locate yourself where Ipod drive is. Then choose a folder in your PC and click button “Copy To PC” to start the process.

    • Version: 1.0.0.0
    • Supported OS: All Windows

    NOTE: If this tool doesn’t work with your system, post here your errors.

    LINK DOWN: http://hintdesk.com/Web/Tool/Ipod%20To%20PC.zip

    HISTORY:

    • [1.0.0.0] : Beta Version

    SCREENSHOT
    Ipod To PC

    Files Over LAN

    This tool “Files Over LAN” helps you sending files over LAN without configuring or installing anything. To send files, download and run tools simultaneously at 2 computers, select file and destination, then click “Send It”. At the destination, you’ll be asked to accept file or not. If you accept, the file will be transferred directly between 2 computers.

    • Requirements : .NET Framework 3.0 (if you are using Windows Vista/ Windows 7, you don’t need to download this framework)
    • Version: 1.0.0.0
    • Supported OS
      • All Windows
    • All comments for this tool. Post directly below.

    NOTE: If this tool doesn’t work with your system, post here your errors.

    LINK DOWN: http://hintdesk.com/Web/Tool/Files%20Over%20LAN.zip

    HISTORY:

    • [1.0.0.0] : Beta Version

    SCREENSHOT

    YM Login BG

    The program YM Login BG allows you to change the background of login dialog of yahoo messenger to make it more beautiful. You just need to choose a bitmap image and press apply and then you will have an interesting background on login dialog. If you don’t like the background anymore just press restore ym. The tool will restore the backup file for you.

    * Requirements : .NET Framework 2.0
    * Version: 1.0.0.0
    * Supported version of Yahoo Messenger 10 and 9
    o Windows 32-bit and 64-bit
    * All comments for this tool. Post directly below.

    NOTE: If this tool doesn’t work with your system, post here your errors.

    LINK DOWN: http://hintdesk.com/Web/Tool/YM%20Login%20BG.zip

    HISTORY:

    * [1.0.0.0] : Beta Version

    SCREENSHOT

    DeReactor – A deobfuscator for .net reactor

    .Net Reactor is a popular packer for .Net. It provides a lot of features to protect the source code from decompiling. One of them is the obfuscation. This tool DeReactor will help you to deobfuscate the assembly after unpacking. Please take a note that this tool is not an unpacker. You must unpack manually before using this tool to deobfuscate.

    After deobfuscate, a patched assembly will be saved at the same folder of the application. Use Reflector to see result.

    This tool will be updated soonly with more functions. Now it’s on BETA version. Use it on your risk. I’ll do it when I have more time.

    • Version: 1.0.0.0
    • Supported Version of Dotfuscator
      • may be all
    • Want more functions. Post a comment directly under.

    NOTE:

    • If this tool doesn’t work with your packed assembly, send it to me. DO NOT blame me if this one doesn’t work. I’m just a newbie.

    LINK DOWN: When you want to post this tool to somewhere. Please post url to my site, that keeps update for this tool when you do that.

    Link down: DeReactor

    HISTORY:

    • [1.0.0.0] : BETA Version.

    SCREENSHOT