Skip to content

Instantly share code, notes, and snippets.

View faridprogrammer's full-sized avatar
😃
Working

Farid Bekran faridprogrammer

😃
Working
View GitHub Profile
@faridprogrammer
faridprogrammer / iran_universities.sql
Last active May 21, 2019 08:04
All IRAN universities sql insert
-- Dolati = 1,
-- PayamNour = 2,
-- Elmi_Karbordi = 3,
-- GheirEntefaee = 4,
-- Azad = 5,
-- Fani = 6
insert into universities (name, type)
SELECT N'دانشکده فنی و حرفه‌ای پسران قزوین (شهیدبابایی)' as name ,6 as type
UNION ALL SELECT N'دانشکده فنی شهید بهشتی کرج' as name ,6 as type
@faridprogrammer
faridprogrammer / Classes.cs
Last active August 31, 2019 10:53
All IRAN provinces and cities SQL table insert script and entity classes for ABP
public class City: Entity<Guid>
{
public string Name { get; set; }
public Guid ProvinceId { get; set; }
public Province Province { get; set; }
public double Lat { get; set; }
public double Long { get; set; }
}
public class Province: Entity<Guid>
public static class MimeTypeMap
{
private static readonly Lazy<IDictionary<string, string>> _mappings = new Lazy<IDictionary<string, string>>(BuildMappings);
private static IDictionary<string, string> BuildMappings()
{
var mappings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
#region Big freaking list of mime types
@faridprogrammer
faridprogrammer / FilesController.cs
Created June 6, 2019 22:17
Simple file upload for aspnet core and angular 6+- ABP (Upload component)
public class FilesController: BistoonControllerBase
{
[HttpPost, DisableRequestSizeLimit]
public IActionResult Upload()
{
try
{
var file = Request.Form.Files[0];
var folderName = Path.Combine("UploadedFiles");
var pathToSave = $"c:\\{folderName}";
@faridprogrammer
faridprogrammer / abp-fa.xml
Created June 8, 2019 14:01
ABP Persian translation
<?xml version="1.0" encoding="utf-8" ?>
<localizationDictionary culture="en">
<texts>
<text name="HomePage" value="صفحه نخست" />
<text name="About" value="درباره" />
<text name="WelcomeMessage" value="به ایران استارتآپ خوش آمدید!" />
<text name="FormIsNotValidMessage" value="فرم معتبر نیست. لطفا خطاها را بررسی و رفع کنید." />
<text name="TenantNameCanNotBeEmpty" value="Tenant name can not be empty" />
<text name="InvalidUserNameOrPassword" value="نام کاربری یا رمز ورود نامعتبر است" />
<text name="ThereIsNoTenantDefinedWithName{0}" value="There is no tenant defined with name {0}" />
@faridprogrammer
faridprogrammer / regex.md
Last active June 30, 2019 09:39
Useful RegEx

Collection of useful RegEx patterns for developers

1. Website with www or http:// or https://

(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,}

2.Email Address

^\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{1,})+$

@faridprogrammer
faridprogrammer / formpost.cs
Created June 17, 2019 11:29
Simple form post with HttpClient C#
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StringContent(username), "username");
form.Add(new StringContent(useremail), "email");
form.Add(new StringContent(password), "password");
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "profile_pic", "hello1.jpg");
HttpResponseMessage response = await httpClient.PostAsync("PostUrl", form);
response.EnsureSuccessStatusCode();
@faridprogrammer
faridprogrammer / SecurityHelper.cs
Created June 17, 2019 11:30
Simple security helper
public static class SecurityHelper
{
public static string MD5Hash(string input)
{
StringBuilder hash = new StringBuilder();
MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider();
byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input));
for (int i = 0; i < bytes.Length; i++)
{
@faridprogrammer
faridprogrammer / HttpHelper.cs
Created June 17, 2019 11:30
Simple http helper
public static class HttpHelper
{
public static async Task Post<T>(string baseUrl, string url, T contentValue)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(baseUrl);
var content = new StringContent(JsonConvert.SerializeObject(contentValue), Encoding.UTF8, "application/json");
var result = await client.PostAsync(url, content);
@faridprogrammer
faridprogrammer / DropAllObject.sql
Created July 7, 2019 06:15 — forked from dannylloyd/DropAllObject.sql
Deletes all objects in database
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)