Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Jalalx / IUnityContainerExtensions.cs
Created April 29, 2015 21:18
Unity extensions for WPF Prism apps
using System;
namespace Microsoft.Practices.Unity
{
public static class IUnityContainerExtensions
{
/// <summary>
/// Registers a ContentControl for navigation using the name parameter.
/// </summary>
/// <typeparam name="T">The type of ContentControl to register</typeparam>
@Jalalx
Jalalx / ILoggerFacadeExtensions.cs
Created April 29, 2015 21:20
Extensions for Prism ILoggerFacade interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Prism.Logging;
namespace Microsoft.Practices.Prism.Logging
{
public static class ILoggerFacadeExtensions
@Jalalx
Jalalx / InterceptableViewModelBase.cs
Last active August 29, 2015 14:21
Implements INotifyPropertyChanged and MarshalByRefObject for interception in view models.
/// <summary>
/// Implements <see cref="INotifyPropertyChanged"/> and <see cref="MarshalByRefObject"/> for interception in view models.
/// </summary>
public abstract class InterceptableViewModelBase : MarshalByRefObject, INotifyPropertyChanged
{
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
@Jalalx
Jalalx / TcpCommunication.cs
Created June 9, 2015 11:14
Represents Client and Server classes to communicate in TCP/IP networks.
using System;
using System.Net;
using System.Threading;
namespace System.Net.Sockets
{
public class Client
{
// Fields...
private Socket clientSocket = null;
/*
Sample of use:
<ComboBox ItemsSource="{Binding Source={ Extensions:ByteEnumerationExtention {x:Type type:MyEnum} }}" DisplayMemberPath="Description"
SelectedValuePath="Value" SelectedValue="{Binding SelectedItemInViewModel}"/>
public enum MyEnum : short
{
[Description("گزینه 1")]
Item1 = 1,
@Jalalx
Jalalx / sample.cs
Last active May 27, 2016 03:46
Calling member method of a normal class without instantiating.
public class Foo
{
public void Method1()
{
Console.WriteLine("Method1: this == null: {0}", this == null);
}
}
var m1 = typeof(Foo).GetMethod("Method1");
var method1 = Delegate.CreateDelegate(typeof(Action<Foo>), m1) as Action<Foo>;
@Jalalx
Jalalx / OpenSslCert.bat
Created September 7, 2016 09:47
Batch script to generate Open SSL self signed certificate
# Batch script to generate Open SSL self signed certificate
openssl req -new -x509 -nodes -newkey rsa:1024 -keyout webhook_pkey.key -out webhook_cert.pem -days 3650
openssl pkcs12 -export -out newfile.pfx -inkey privcert.key -in pubcert.pem -certfile CARoots.pem
@Jalalx
Jalalx / heaviest_it_table_index.sql
Last active June 20, 2020 17:55
Query for determining heaviest hit tables and indexes. More info: https://goo.gl/Zxx2U8
--get most used tables
SELECT
db_name(ius.database_id) AS DatabaseName,
t.NAME AS TableName,
SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) AS NbrTimesAccessed
FROM sys.dm_db_index_usage_stats ius
INNER JOIN sys.tables t ON t.OBJECT_ID = ius.object_id
WHERE database_id = DB_ID('MyDb')
GROUP BY database_id, t.name
ORDER BY SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) DESC
@Jalalx
Jalalx / TimeSpan.js
Created October 1, 2016 08:35
Simple TimeSpan for javascript
function TimeSpan(seed) {
//"00:00:00"
var self = this;
self.hour = seed.substr(0, 2);
self.minute = seed.substr(3, 2);
self.second = seed.substr(6, 2);
self.addSecond = function () {
self.second++;
if (self.second >= 60) {
@Jalalx
Jalalx / BotUserAgentUtility.cs
Created October 24, 2016 13:00
Detects most know crowlers
public class BotUserAgentUtility
{
public static bool IsBot(string userAgent)
{
var Crawlers = new List<string>()
{
"googlebot","bingbot","yandexbot","ahrefsbot","msnbot","linkedinbot","exabot","compspybot",
"yesupbot","paperlibot","tweetmemebot","semrushbot","gigabot","voilabot","adsbot-google",
"botlink","alkalinebot","araybot","undrip bot","borg-bot","boxseabot","yodaobot","admedia bot",
"ezooms.bot","confuzzledbot","coolbot","internet cruiser robot","yolinkbot","diibot","musobot",