Skip to content

Instantly share code, notes, and snippets.

@riyadparvez
riyadparvez / ImageRotator.cs
Last active December 10, 2015 17:28
A class for rotating bitmap image. It rotates image based on given rectangle without losing any information and giving white background to newly added region.
public class ImageRotator
{
private readonly Bitmap image;
private double angle;
public Image OriginalImage
{
get { return image; }
}
@riyadparvez
riyadparvez / DataTableToSql.cs
Created January 6, 2013 15:05
An extension method class which dumps a DataTable into database table using connection string and given table name
/// <summary>
/// Utility class for writing datatable to database
/// Creating table in database for that datatable using ADO.NET
/// </summary>
public static class DataTableToSql
{
/// <summary>
///
/// </summary>
/// <param name="table"></param>
@riyadparvez
riyadparvez / SqlTableCreator.cs
Last active August 12, 2022 12:41
Create Sql table based on given DataTable schema
// Copyright (c) 2012-2013, Riyad Parvez
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@riyadparvez
riyadparvez / CsvReader.cs
Created January 6, 2013 15:15
A csv reader class which reutrns CSV rows as List<List<string>>. So every row is a List<string>.
public class CSVReader : IEnumerable<List<string>>
{
private readonly string filePath;
private List<string> lines;
private List<List<string>> tokens;
private List<string> headers;
public string FilePath
{
@riyadparvez
riyadparvez / RoundStack.cs
Created January 6, 2013 18:34
Stack with capacity, bottom items beyond the capacity are discarded.
/// <summary>
/// Stack with capacity, bottom items beyond the capacity are discarded.
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class RoundStack<T>
{
private T[] items; // items.Length is Capacity + 1
// top == bottom ==> full
@riyadparvez
riyadparvez / Adding constant value to raster file in ArcGIS.md
Created January 7, 2013 14:22
This blog post shows how to add constant value to every grid in ArcGIS raster file.

Adding constant value to raster using arcpy#

Using overloaded arcpy addition (+) operator you can add constant value to raster.

constantValue = 5
outputRaster = inputRaster + constantValue

Now every cell value of outputRaster will be incremented by 5.

Apparently this is a great approach. You are just using simple addition operation. But the problem is outputRaster won't have any attribute table even if inputRaster has one. Because when you are adding two rasters if one of the rasters doesn't have attribute table, the output raster won't have one.

@riyadparvez
riyadparvez / Raster Addition.md
Created January 7, 2013 14:24
How to add two rasters in ArcGIS

How to add two raster using arcpy

Let's say you have two rasters raster1 and raster2 and you want to add them using arcpy. Most obvious approach is

additionRaster = raster1 + raster2

additionRaster is the addition of raster1 and raster2

@riyadparvez
riyadparvez / GetHashCode.cs
Created January 9, 2013 10:48
Best algorithm to override GetHashCode()
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + field1.GetHashCode();
hash = hash * 23 + field2.GetHashCode();
hash = hash * 23 + field3.GetHashCode();
return hash;
/// <summary>
/// This class implements string comparison algorithm
/// based on character pair similarity
/// Source: http://www.catalysoft.com/articles/StrikeAMatch.html
/// </summary>
public class SimilarityTool
{
/// <summary>
/// Compares the two strings based on letter pair matches
/// </summary>
@riyadparvez
riyadparvez / InversionCounter.cs
Created July 2, 2013 17:15
Count number of inversions in an array in C#. An inversion in an array is when i<j but a[i]>a[j]. Running time of this algorithm is quadratic O(n*n).
public class InversionCounter
{
int[] array;
int inversion = 0;
public InversionCounter (IEnumerable<int> arr)
{
array = arr.ToArray();
}