Skip to content

Instantly share code, notes, and snippets.


Omid K. Rad omidkrad

View GitHub Profile
View EntityExtensionMethods.cs
using System.Linq;
using System.Reflection;
namespace System.Data.Linq
/// <summary>
/// LINQ-to-SQL extension methods
/// </summary>
public static class EntityExtensionMethods
omidkrad /
Last active Aug 29, 2015
Steps to compact a Virtual Hard Disk

Steps to compact a Virtual Hard Disk

From inside VM (guest):

  1. Disk Cleanup -> Cleanup system files
  2. Turn off VM

From outside VM (host):

  1. Attach VHD as a drive (for example V:)
  2. Delete pagefile.sys and swapfile.sys if you don't want them to be in the parent VHD. They will be created again in the child VHD when Windows starts.
  3. defrag V: /h /u /v /x
omidkrad / Clean-IISExpress.ps1
Last active Jun 20, 2017
Delete IISExpress sites using PowerShell
View Clean-IISExpress.ps1
Set-Alias appcmd "$env:ProgramFiles\IIS Express\appcmd.exe"
appcmd list site /text:SITE.NAME | % { appcmd delete site $_ }
# or remove IISExpress directory
Remove-Item -Recurse $env:USERPROFILE\Documents\IISExpress

Git Tips

Reviving a discarded commit

You created a commit but then discarded it with git reset --hard <SHA> without first syncing it with the server repository (GitHub). Use this PowerShell command to find the SHA of the discarded commit.

Get-ChildItem -Path .\.git\objects\??\* -Recurse | sort -Property CreationTime -Descending | select -first 1 | % { $_.FullName.Substring($_.FullName.Length-41).Replace('\', '') }
omidkrad / gist:4b6933fac239221fc012
Last active Aug 29, 2015
Script to remove nuget.targets import from all .csproj files
View gist:4b6933fac239221fc012
# Migrating MSBuild-Integrated solutions to use Automatic Package Restore
# See also:
# and:
findstr /s /m /i NuGet.targets *.*proj | % {$file = get-item $_; $txt = Get-Content $file | Select-String "nuget`.targets" -NotMatch; $txt | Set-Content $file -Encoding UTF8 }
findstr /s /m /i RestorePackages *.*proj | % {$file = get-item $_; $txt = Get-Content $file | Select-String "RestorePackages" -NotMatch; $txt | Set-Content $file -Encoding UTF8 }
omidkrad / ExecJavaScript.ps1
Last active Apr 13, 2020
PowerShell function to run JavaScript/JQuery and return results back to PS, with timeout
View ExecJavaScript.ps1
# PowerShell function to run JavaScript/JQuery and return results back to PS, with timeout
# some web page with jQuery in it
$url = ""
Function ResetTimer
$script:startTime = [DateTime]::Now
View IfNotNull.cs
// This is an attempt to implement the Null-propagating operator ?. as extension methods.
// I was not able to do it in a single method that would work with both value types and
// reference types as return type. Maybe there's a way to do it or use overloads?
public static class ExtensionMethods
/// <summary>
/// Use this method to safely invoke properties, methods or other members of a nullable
omidkrad / moment.lang.fa.js
Created Dec 18, 2012
Persian language localization settings for momentjs.
View moment.lang.fa.js
// moment.js language configuration
// language : persian (fa)
// author : Omid K. Rad :
(function () {
// Notes: Persian culture specs are taken from:
// The document is old but the data is valid. Use RTL embedding for correct formatting.
// Month names are transliterated French from Gregorian calendar. For dates based on Persian
// calendar, see this related project:
var lang = {
months: "ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اُکتبر_نوامبر_دسامبر".split("_"),
You can’t perform that action at this time.