Projects
By Firoz AnsariMay 12, 20192 min readComments (0)

randr is a command line tool which recursively searches files content for source string and replaces it with the target string. With that, randr will also recursively rename files or folders name which matches source string to target string. You can also specify a command flag, if you want to rename or replace based on case sensitive or case insensitive search.

randr - Example

To illustrate the usage of randr, consider you have a project folder with the following structure:

// Project Folder: c:\Projects\Payroll\

// c:\Projects\Payroll\Models\Worker.cs
public class Worker {}

// c:\Projects\Payroll\Services\WorkerService.cs
public class WorkerService {}

// c:\{rojects\Payroll\Repositories\WorkerRepository.cs
public class WorkerRepository {}

// c:\Projects\Payroll\Helpers\Worker\Extensions.cs
public static class Extensions {}

Let's refactor above project using randr and change Worker entities to Employee. randr command to refactor will look like following which will replace any files text which contains Worker to Employee as well as will rename any file or folder with contains Worker to Employee.

randr.exe -find=Worker -replace=Employee -match=true -location=c:\Projects\Payroll\

After running randr successfully, our example project folder will look like following:

// Project Folder: c:\Projects\Payroll\

// c:\Projects\Payroll\Models\Employee.cs
public class Employee {}

// c:\Projects\Payroll\Services\EmployeeService.cs
public class EmployeeService {}

// c:\Projects\Payroll\Repositories\EmployeeRepository.cs
public class EmployeeRepository {}

// c:\Projects\Payroll\Helpers\Employee\Extensions.cs
public static class Extensions {}

Please go over README.md in the project repository for parameter usage details.

GIT Repository:
randr

By Firoz AnsariMay 07, 20191 min readComments (0)

This Chrome extension will give you a visual glance of the DIV tags in the page. Just hover your mouse pointer over the page and extension will highlight DIV under the pointer with a Red background color. The intensity of Red background color signifies the depth of highlighted DIV related to its parent DIV layers. You no more have to dig through Chrome DevTools to inspect DIV layout in the page.

DIV Glance

DIV Glance Extension Page: DIV Glance

I created this extension just for the sake of learning Chrome extension development. As I saw the practical usage of this extension later, I tried to polish it a bit to make it more presentable. At the core of this extension, it simply injects following CSS style to the page — nothing fancy.

<style type="text/css">
  div:hover
  {
    outline:1px solid red;
    background-color:#ff000010;
  }
</style>
By Firoz AnsariNovember 09, 20173 min readComments (0)

TSqlCodeGen is a simple template based SQL script code generator which generates code using table structure. Provide your target table and template to the TSqlCodeGen and it will generate code you for based on your template. The tool is very handy if you are dealing with a table with a large number of columns.

TSqlCodeGen - Template based SQL script code generator

How To

Open TSqlCodeGen script in the SQL Management Studio, provide your table name and template, press F5 to execute TSqlCodeGen and have your code generated in result Pane. Copy generated code from the result pane and paste in your project.

TSqlCodeGen - Introduction

You can create you own TSqlCodeGen template using following tags.

$table    : Table name
$field    : Column Name
$type     : .NET Data Type
$sp_type  : SQL Data Type
$default  : .NET Default Value
$length   : Column Max Length

{loop}    : Start Loop Tag
{/loop}   : End Loop Tag

{sap}     : Separator Start Tag
{/sap}    : Separator End Tag

Usage

To understand TSqlCodeGen usage, let's use a basic template which will generate a simple list of columns appended after the table name.

SET @Template = '
** Generate simple list of table columns saprated by comma /v1.0
$table: {loop}$field{sap}, {/sap} {/loop}
'

Generated Code:

Categories: CategoryID, CategoryName, Description, Picture

TSqlCodeGen - Usage With Comma

Example 1: Create a UPDATE Stored Procedure

** Generate a basic update stored procedure based on table columns /v1.0
CREATE PROCEDURE [dbo].[usp_Update$table]{loop}
  @$field = $sp_type{sap},{/sap}{/loop}
AS
BEGIN

  UPDATE dbo.$table WITH (ROWLOCK)
  SET {loop}
    $field = @$field{sap},{/sap}{/loop}
  WHERE --TODO

  RETURN -1
END

Generated Code:

CREATE PROCEDURE [dbo].[usp_UpdateCategories]
  @CategoryID = INT,
  @CategoryName = NVARCHAR(15),
  @Description = NTEXT,
  @Picture = IMAGE
AS
BEGIN

  UPDATE dbo.Categories WITH (ROWLOCK)
  SET 
    CategoryID = @CategoryID,
    CategoryName = @CategoryName,
    Description = @Description,
    Picture = @Picture
  WHERE --TODO

  RETURN -1
END

Example 2: Create a C# entity class

** Create a basic C# entity class /v1.0
using System;
using System.Collections.Generic;
using System.Text;

namespace NorthWind
{
  public class $table
    {{loop}
    public $type $field { get; set; }{/loop}
  }
}

Generated Code:

using System;
using System.Collections.Generic;
using System.Text;

namespace NorthWind
{
  public class Order
  {
    public Int32 OrderID { get; set; }
    public String CustomerID { get; set; }
    public Int32 EmployeeID { get; set; }
    public DateTime OrderDate { get; set; }
    public DateTime RequiredDate { get; set; }
    public DateTime ShippedDate { get; set; }
    public Int32 ShipVia { get; set; }
    public Double Freight { get; set; }
    public String ShipName { get; set; }
    public String ShipAddress { get; set; }
    public String ShipCity { get; set; }
    public String ShipRegion { get; set; }
    public String ShipPostalCode { get; set; }
  }
}

GIT Repository:
TSqlCodeGen

By Firoz AnsariMarch 30, 20072 min readComments (0)

Flash cards are a collection of cards which has a question on one side and answer on another. It was be used to learn vocabulary, formulas, foreign language, technical or domain terms, etc. This learning tool was developed to maximize the efficiency of studying memorization intensive subjects.

I attempted to make UI bit minimal so that the whole interface will occupy very little space on your screen. I usually prefer to have this application position at the top-center of the screen.

FlashCard uses a simple text file for questions and answers which are separated by pipe delimitator. Based on your selection application will display questions sequentially or randomly.

FlashCard Screenshot

To select the order of the questions, right click on the capsule, and check/uncheck the popup menu item Random Order.

FlashCard Popup Menu

You don't need any setup to run this application. Just unzip the attached flashcard.zip to your local disk folder and run the .exe file. FlashCard will ask you to provide a path for the flashcard text file. This text file will have your all questions and answers.

You will need any text editor to create your own flashcard text file. Open your text editor and list out your questions and respective answers separated by pipe (|). Please refer attached readme.txt for more details.

FlashCard is build using Delphi 5. I decided to go with the Delphi so that I can have a native binary which requires no runtime or depended on DLLs. Just run your .exe program and you are done. Perfect to develop small utility application or tools.

Download: FlashCardv1.zip

License

Copyright (c) 2007 Firoz Ansari. https://firozansari.com

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2021 Firoz Ansari.
All Rights Reserved.