Skip to content

Instantly share code, notes, and snippets.

View pradeepn's full-sized avatar

Pradeep Nagendiran pradeepn

  • Chennai, IN
View GitHub Profile

AngularJS + RequireJS done right

Since AngularJS 2.x is not here yet, many applications are still being written using Angular 1.x. When the application that is more complex than the trivial examples you may found out there, it may end up having many modules, services, controllers, view templates and so on. In those real world cases, the main entry point of the application index.html may become a mess like this:

<!DOCTYPE html>
<html ng-app="myApp">
	<head>
        <!-- Angular and modules -->
		<script src="path-to/angular.js"></script>
@pradeepn
pradeepn / CsvSplitWIthDoubleQuotes.cs
Created November 8, 2016 12:20
Csv Split Function With Double Quotes
string line = "5,10,,\"a,b,c\",5";
string[] parts = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
//string[] output = {5,10,,"a,b,c",5};
@pradeepn
pradeepn / AsymCipher.cs
Created November 28, 2016 15:05
Symmetrical & Asymmetrical Ciphers
using System;
using System.Security.Cryptography;
using System.Text;
namespace Utilities.Cryptography
{
/// <summary>
/// Asymmetrical Cipher uses two keys. A public key for Encryption and private key for decryption.
/// Public key should be shared with client and private key needs to be in the server to in order to decrypt the message encrypted with public key.
/// </summary>
@pradeepn
pradeepn / NameGenerator.cs
Created November 28, 2016 15:47
Simple Name Generator
public static class NameGenerator {
private const string Names = "SMITH,JOHNSON,WILLIAMS,JONES,BROWN,DAVIS,MILLER,WILSON,MOORE,TAYLOR,ANDERSON,THOMAS,JACKSON,WHITE,HARRIS,MARTIN,THOMPSON,GARCIA,MARTINEZ,ROBINSON,CLARK,RODRIGUEZ,LEWIS,LEE,WALKER,HALL,ALLEN,YOUNG,HERNANDEZ,KING,WRIGHT,LOPEZ,HILL,SCOTT,GREEN,ADAMS,BAKER,GONZALEZ,NELSON,CARTER,MITCHELL,PEREZ,ROBERTS,TURNER,PHILLIPS,CAMPBELL,PARKER,EVANS,EDWARDS,COLLINS,STEWART,SANCHEZ,MORRIS,ROGERS,REED,COOK,MORGAN,BELL,MURPHY,BAILEY,RIVERA,COOPER,RICHARDSON,COX,HOWARD,WARD,TORRES,PETERSON,GRAY,RAMIREZ,JAMES,WATSON,BROOKS,KELLY,SANDERS,PRICE,BENNETT,WOOD,BARNES,ROSS,HENDERSON,COLEMAN,JENKINS,PERRY,POWELL,LONG,PATTERSON,HUGHES,FLORES,WASHINGTON,BUTLER,SIMMONS,FOSTER,GONZALES,BRYANT,ALEXANDER,RUSSELL,GRIFFIN,DIAZ,HAYES,MYERS,FORD,HAMILTON,GRAHAM,SULLIVAN,WALLACE,WOODS,COLE,WEST,JORDAN,OWENS,REYNOLDS,FISHER,ELLIS,HARRISON,GIBSON,MCDONALD,CRUZ,MARSHALL,ORTIZ,GOMEZ,MURRAY,FREEMAN,WELLS,WEBB,SIMPSON,STEVENS,TUCKER,PORTER,HUNTER,HICKS,CRAWFORD,HENRY,BOYD,MASON,M
@pradeepn
pradeepn / ApiAuthorizeAttribute.cs
Created November 30, 2016 10:48
Api Authorize Attribute With AllowRole and DenyRole features
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class ApiAuthorizeAttribute : AuthorizationFilterAttribute
{
private static readonly string[] _emptyArray = new string[0];
private readonly object _typeId = new object();
private string _aroles, _droles;
private string[] _arolesSplit = _emptyArray, _drolesSplit = _emptyArray;
@pradeepn
pradeepn / EnableCorsAttribute.cs
Created November 30, 2016 15:47
EnableCorsAttribute.cs
///Enabling CORS Support with Dynamic Orgins
///In Web.API this attribute can be added using Microsoft.AspNet.WebApi.Cors as detailed at
///http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
///In MVC you could create a filter attribute to do this work for you:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,
AllowMultiple = true, Inherited = true)]
public class EnableCorsAttribute : FilterAttribute, IActionFilter {
private const string IncomingOriginHeader = "Origin";
private const string OutgoingOriginHeader = "Access-Control-Allow-Origin";
@pradeepn
pradeepn / LocalAFTokenDispatcher.cs
Last active December 1, 2016 13:09
Validate Localhost and Validate Antiforgerytoken Dispatcher
public class LocalAFTokenDispatcher : HttpControllerDispatcher
{
public LocalAFTokenDispatcher(HttpConfiguration config)
: base(config)
{
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
#region LocalhostValidation
@pradeepn
pradeepn / GetWeather.cs
Created December 9, 2016 12:37 — forked from syed-afraz-ali/GetWeather.cs
Simple CQRS using MediatR
using System;
using MediatR;
namespace MediatR_101
{
// The Query GetWeather that we will use to get weather status of any city
public class GetWeather : IRequest<Weather>
{
public GetWeather(String city)
{
@pradeepn
pradeepn / CQRSWithMediatR.txt
Last active June 13, 2018 14:43
CQRS with MediatR
MediatR
Simple mediator implementation in .NET for In-process messaging.
Supports request/response, commands, queries, notifications and events, synchronous and async with intelligent dispatching via C# generic variance.
https://github.com/jbogard/MediatR/wiki
Workflow
Workflow is kind of container for business logic. It could combine set of queries and commands into single operation which matters to end user.
@pradeepn
pradeepn / usb-credit-card-reader.js
Created December 16, 2016 07:32 — forked from stracqan/usb-credit-card-reader.js
Very simple jQuery implementation that reads card data from a USB Magnetic Strip Credit Card Reader.
/**
*
* Simple jQuery Script to parse credit card data
* that was collected via a USB Magnetic Stripe
* Credit Card Reader.
*
* To get this to work, focus your cursor (either
* programmatically or via a click, it's your choice) on an input field #credit-card-number
* and then with the card reader plugged in, swipe
* the card and it will take over from there