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
private string GetImei()
{
var permissionCheck = ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadPhoneState);
if (permissionCheck == Permission.Denied)
{
ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.ReadPhoneState }, 0);
}
var mTelephonyMgr = (TelephonyManager)GetSystemService(TelephonyService);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
@arman-hpp
arman-hpp / radcombobox.cs
Created August 2, 2018 03:13
radcombobox.cs
private void cmbDocumnetType_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
args.VisualItem.Font = cmbDocumnetType.Font;
}
@arman-hpp
arman-hpp / serialbox.cs
Last active July 6, 2018 03:47
serialbox
private const int MaxLen = 7;
txtSerial1.MaxLength = MaxLen;
txtSerial2.MaxLength = MaxLen;
txtSerial3.MaxLength = MaxLen;
txtSerial4.MaxLength = MaxLen;
@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]
)
@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 / 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 / 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 / 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 / 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 / SeperateShamsiDate.sql
Created November 17, 2017 16:08
Seperate Shamsi Date
SELECT STUFF(STUFF(13961201, 5, 0, '/'), 8, 0, '/')