Skip to content

Instantly share code, notes, and snippets.

View Kashkovsky's full-sized avatar
😎

Denys Kashkovskyi Kashkovsky

😎
  • Grammarly, Inc.
  • Kyiv, Ukraine
View GitHub Profile
@Kashkovsky
Kashkovsky / CorsHandler.cs
Last active November 6, 2020 10:33
CORS delegating handler for Web API
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
//Add to Global.asax -- GlobalConfiguration.Configuration.MessageHandlers.Add(new CorsHandler());
namespace Common.Helpers
{
public class CorsHandler : DelegatingHandler
@Kashkovsky
Kashkovsky / StringHelper.cs
Created June 3, 2016 13:47
StringHelper Extension
using System.Linq;
using System.Text.RegularExpressions;
namespace Common.Extensions
{
public static class StringHelper
{
public static string ToUpperFirstChar(this string input)
{
if (string.IsNullOrEmpty(input))
@Kashkovsky
Kashkovsky / AllowCrossDomainJsonAttribute.cs
Created June 3, 2016 13:49
MVC Attribute allowing cross-domain requests
using System.Linq;
using System.Web.Mvc;
namespace Common.Helpers
{
public class AllowCrossDomainJsonAttribute : ActionFilterAttribute
{
const string Origin = "Origin";
const string AccessControlAllowOrigin = "Access-Control-Allow-Origin";
public override void OnActionExecuting(ActionExecutingContext filterContext)
@Kashkovsky
Kashkovsky / authService.js
Created June 3, 2016 13:52
AngularJS Authentication service
(function() {
'use strict';
app.factory('authService', authService);
authService.$inject = ['localStorageService'];
var authentication = {
isAuth: false,
customerId: 0
@Kashkovsky
Kashkovsky / authInterceptorService.js
Created June 3, 2016 13:55
AngularJS common interceptor
(function () {
'use strict';
app.factory('authInterceptorService', authInterceptorService);
authInterceptorService.$inject = ['$q', 'localStorageService', 'constantsService'];
function authInterceptorService ($q, localStorageService, constantsService) {
var authInterceptorServiceFactory = {};
function request (config) {
@Kashkovsky
Kashkovsky / validation.js
Created June 3, 2016 13:57
AngularJS phone number validation directive
(function () {
'use strict';
var phonePattern = /^\+{0,1}[\d ()-]+$/;
app.directive('phoneNumber', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$validators.phoneNumber = function (modelValue, viewValue) {
@Kashkovsky
Kashkovsky / dataToBlob.js
Created June 3, 2016 14:02
Convert data Uri to blob
function dataUrItoBlob(dataUri) {
var binary = atob(dataUri.split(',')[1]);
var mimeString = dataUri.split(',')[0].split(':')[1].split(';')[0];
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], { type: mimeString });
};
@Kashkovsky
Kashkovsky / upload-photo.cshtml
Last active June 3, 2016 14:25
Image Upload: AngularJs
<!-- ASP.NET part: "https://gist.github.com/Mr-Zoidberg/d9be453eb7d8cc7fc787f01dd381db17" -->
<!-- angular module and service are common so not included -->
<style>
.cropArea {
width: 200px;
height: 200px;
margin: 0 auto;
background-color: black;
}
.horizontal-center {
@Kashkovsky
Kashkovsky / ImageController.cs
Created June 3, 2016 14:22
Image upload: Asp.Net
public class ImageController : Controller
{
private readonly IImageService _imageService;
public ImageController(IImageService imageService)
{
_imageService = imageService;
}
[HttpPost]
@Kashkovsky
Kashkovsky / PasswordGenerator.cs
Last active June 3, 2016 16:12
Simple password generator
using System;
using System.Text;
namespace Common.Utility
{
public class PasswordGenerator
{
public static string Create(int length = 8)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";