Skip to content

Instantly share code, notes, and snippets.

View arman-hpp's full-sized avatar
😊
Focusing

Arman Hasanpour arman-hpp

😊
Focusing
View GitHub Profile
@arman-hpp
arman-hpp / SplitByIteration.cs
Created May 10, 2017 17:09
Split By Iteration
List<string> Split(string str, int iterateCount)
{
var words = new List<string>();
for (int i = 0; i < str.Length; i += iterateCount)
if (str.Length - i >= iterateCount)
words.Add(str.Substring(i, iterateCount));
else
words.Add(str.Substring(i, str.Length - i));
@arman-hpp
arman-hpp / Resharper.cs
Created May 21, 2017 13:15
Resharper Attr
[SuppressMessage("ReSharper", "InconsistentNaming")]
@arman-hpp
arman-hpp / FixCustomerName.sql
Created June 8, 2017 05:27
Fix Customer Name
DROP FUNCTION IF EXISTS [dbo].[LEVENSHTEIN]
GO
CREATE FUNCTION [dbo].[LEVENSHTEIN](@left VARCHAR(100),
@right VARCHAR(100))
RETURNS INT
AS
BEGIN
DECLARE @difference INT,
@lenRight INT,
@arman-hpp
arman-hpp / SeperateShamsiDate.sql
Created November 17, 2017 16:08
Seperate Shamsi Date
SELECT STUFF(STUFF(13961201, 5, 0, '/'), 8, 0, '/')
@arman-hpp
arman-hpp / JEncyptor.cs
Created December 17, 2017 15:17
Encyptor
public static class JEncyptor
{
public static Tuple<string, string> CreateKeyPair()
{
var cspParams = new CspParameters { ProviderType = 1 };
var rsaProvider = new RSACryptoServiceProvider(1024, cspParams);
var publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false));
var privateKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(true));
return new Tuple<string, string>(privateKey, publicKey);
}
@arman-hpp
arman-hpp / ParallelForEachProgress.cs
Created January 13, 2018 17:47
Parallel.ForEach Progress
SynchronizationContext ctx = SynchronizationContext.Current;
int count = 0;
Parallel.ForEach(collection, (item) =>
{
ComputeYourStuff(item);
Interlocked.Increment(ref count);
ctx.Post(d => { progressBar.Value = count; }, null);
});
@arman-hpp
arman-hpp / DetectVolume.cs
Created February 18, 2018 03:47
Detect Volume
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent");
watcher.EventArrived += Watcher_EventArrived;
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();
private static void Watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
@arman-hpp
arman-hpp / DetectUsb.cs
Created February 18, 2018 03:50
Detect Usb
private static void button1_Click()
{
var scope = new ManagementScope("root\\CIMV2") {Options = {EnablePrivileges = true}};
try
{
var query = new WqlEventQuery
{
EventClassName = "__InstanceCreationEvent",
WithinInterval = new TimeSpan(0, 0, 1),
Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'"
@arman-hpp
arman-hpp / GetADInfo.cs
Created February 18, 2018 07:00
Get AD Info
private static void GetInfo()
{
var domain = new PrincipalContext(ContextType.Domain);
Console.WriteLine("Domain.Name: " + domain.Name);
Console.WriteLine("Domain.UserName: " + domain.UserName);
Console.WriteLine("Domain.ConnectedServer: " + domain.ConnectedServer);
Console.WriteLine("Domain.ContextType: " + domain.ContextType);
Console.WriteLine("Domain.Options: " + domain.Options);
Console.WriteLine("Domain.Container: " + domain.Container);
@arman-hpp
arman-hpp / deleteduplicate.cs
Created July 5, 2018 05:30
delete duplicate by keeping original
WITH CTE AS
(
SELECT *
,ROW_NUMBER() OVER
(
PARTITION BY [CreditVerifierRoleId],[CreditRuleJobGroupId],[CreditGrade],[SalaryRate],[AveragingRate],[AveragingMonthDuration],[MaxCredit],[MaxGuaranteePerCustomer],[CreditRuleType],[BeginDate],[EndDate],[CreatedOn],[CreatedBy],[ModifiedOn],[ModifiedBy]
ORDER BY [CreditVerifierRoleId],[CreditRuleJobGroupId],[CreditGrade],[SalaryRate],[AveragingRate],[AveragingMonthDuration],[MaxCredit],[MaxGuaranteePerCustomer],[CreditRuleType],[BeginDate],[EndDate],[CreatedOn],[CreatedBy],[ModifiedOn],[ModifiedBy]
) AS RN
FROM [QTasBankDatabase].[Loan].[CreditRules]
)