Skip to content

Instantly share code, notes, and snippets.

View SmithWilson's full-sized avatar
:octocat:
.net developer

Kirill Moskalev SmithWilson

:octocat:
.net developer
View GitHub Profile
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Example
{
public class ModelStateValidationFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
@SmithWilson
SmithWilson / SaltService
Last active January 16, 2019 19:19
md5
public class SaltService : ISaltService
{
public string Generate()
{
var saltBytes = new byte[8];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetBytes(saltBytes);
}
using System;
using System.Collections.Generic;
using System.Linq;
using MpReserver.DataModel.EfEntities.School.Course;
using MpReserver.Reckoning.Search.Params;
namespace MpReserver.Reckoning.Search.Filters
{
// TODO: Rewrite this with specifications pattern.
DECLARE @Result VARCHAR(MAX),
@TableName SYSNAME = 'IncomeShippingProductsServices',
@CLASSNAME NVARCHAR(500) = 'public class ';
SET @Result = @CLASSNAME + @TableName + '
{'
SELECT @Result = @Result + '
public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }'
@SmithWilson
SmithWilson / LinqToSqlHelper
Created December 12, 2019 21:24
Linq To Sql
public static class LinqToSqlHelper
{
public static (string, IReadOnlyDictionary<string, object>) ToSqlWithParams<TEntity>(this IQueryable<TEntity> query)
{
var enumerator = query.Provider
.Execute<IEnumerable<TEntity>>(query.Expression)
.GetEnumerator();
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
var enumeratorType = enumerator.GetType();
var selectFieldInfo = enumeratorType.GetField("_selectExpression", bindingFlags) ?? throw new InvalidOperationException($"cannot find field _selectExpression on type {enumeratorType.Name}");
const fileUrl = window.URL.createObjectURL(downloadEvent.response);
const extension = getFileExtension(file.originalFileName);
const MimeTypesMap = {
png: 'image/png',
gif: 'image/gif',
jpg: 'image/jpg',
jpeg: 'image/jpeg',
pdf: 'application/pdf',
import { Directive, HostListener } from '@angular/core';
import { NgControl } from '@angular/forms';
@Directive({
selector: '[formControlName][appPhoneMask]',
})
export class PhoneMaskDirective {
constructor(public ngControl: NgControl) { }
import { useEffect, useState } from "react";
import "./styles.css";
function lazy(importFunc, { fallback }) {
return function () {
const [{ state, component: Component }, changeState] = useState({
state: "loading",
component: null
});
useEffect(() => {
public class SftpConfig
{
public string Host { get; set; }
public int Port { get; set; }
public string User { get; set; }
public string Password { get; set; }
public string RemoteFilePath { get; set; }
public string LocalFilePath { get; set; }
}