Skip to content

Instantly share code, notes, and snippets.

View adhamankar's full-sized avatar

Abhijeet adhamankar

View GitHub Profile
  • mkdir my-typescript-package && cd my-typescript-package
  • Create a git repository
    git init  
    echo "# My typescript package" >> README.md 
    git add . && git commit -m "Initial commit" 
    git remote add origin < Git Repository Url >
    git push -u origin master
  • Init your Package (to generate package.json)
@adhamankar
adhamankar / ApplicationService.cs
Last active February 19, 2020 09:21
Notification framework
private void NotifyWelcomeToTheHub(User user)
{
var notificationDto = new AppNotificationDto
{
User = user.ProjectedAs<IdTitle>(),
InviteeEmail = user.Email,
SenderEmail = user.Email,
Title = string.Format("Welcome to the Hub"),
Template = "<<template>>.xsl",
Type = NotificationTypes.<<Type>>
public static class Extensions
{
public static string GetEnumDescription(this Enum value)
{
if (value == null) return string.Empty;
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return (attributes != null && attributes.Length > 0) ? attributes[0].Description : value.ToString();
}
@adhamankar
adhamankar / Modal-service.ts
Created January 18, 2016 12:18
Angular- ModalService - wrapper on top of $modal service
/// <reference path="../../_references.ts" />
module Common.Services {
"use strict";
export class ModalService implements Common.Framework.IModalContainer {
public static $inject = ["$modal"];
public static Factory($modal: ng.ui.bootstrap.IModalService) {
return new ModalService($modal);
@adhamankar
adhamankar / Application.ts
Created August 13, 2015 06:47
Localization provider
myApp.provider("Localization", {
loadResource: ["Localization", (Localization) =>
Localization.loadResource(this.resourceName === undefined || this.resourceName === null ? this.controller : this.resourceName)
],
$get: ["$http", ($http: angular.IHttpService) => {
return {
loadResource: (resourceName?: string) => $http.get("<localization api>")
};
}]
@adhamankar
adhamankar / DataService.ts
Last active November 1, 2015 21:01
TypeScript+ Angular DataService based on observer pattern
module CommonServices {
export class DataService<T> {
public data: T;
private observerCallbacks = []; // Observer pattern implementation
public registerCallback = (callback) => {
this.observerCallbacks.push(callback);
};
public setData = (instance: T) => {
this.data = instance;
@adhamankar
adhamankar / ClientContainerCtrl.ts
Created May 4, 2015 11:30
Angular popup service
export class ClientContainerCtrl {
public static $inject = ["$scope", "$http", "$state", "ApiConfig", "popup"];
constructor(public $scope: ng-IScope, public $http: ng.IHttpService
, public $state: ng.ui.IStateService, public ApiConfig: IApiConfig, public popup: Common.Services.ModalService
) {
super($scope, $http);
this.init();
}
@adhamankar
adhamankar / AuthenticationInterceptor.ts
Created February 16, 2015 05:31
Implementing angularjs Interceptor using TypeScript
module App {
"use strict";
//Method name should be exactly "response" - http://docs.angularjs.org/api/ng/service/$http
export interface IInterceptor {
request: Function;
requestError: Function;
response: Function;
responseError: Function;
}
@adhamankar
adhamankar / XslUtil.cs
Created February 2, 2015 12:53
Xsl transform implementation
public static class XslUtil
{
public static string Transform(this string xml, string transformXslFile)
{
XslTransform xslt = new XslTransform();
xslt.Load(transformXslFile);
XPathDocument xpath = new XPathDocument(XmlReader.Create(new StringReader(xml)));
XmlReader xmlReader = xslt.Transform(xpath, null);
if (xmlReader != null)
@adhamankar
adhamankar / XmlSerializationUtil.cs
Created February 2, 2015 12:50
XML Serialization helper code
public static class XmlSerializationUtil
{
public static string Serialize<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}