Skip to content

Instantly share code, notes, and snippets.

View chandermani's full-sized avatar

Chandermani chandermani

  • London
View GitHub Profile
$scope.disposableMail = function (email) {
if (!email) return true;
return email.indexOf('@mailinator.com') >= 0 ? false : true;
}
$scope.duplicateMailRemoteCheck = function (email) {
return $timeout(function () {
return ['[email protected]', '[email protected]', '[email protected]'].indexOf(email) >= 0 ? false : true;
}, 2000);
}
<input type="email"
ng-model='userEmail'
name='email' required
class="form-control"
custom-validator="disposable"
validate-functions='disposableMail'/>
<input type="email"
ng-model='userEmail'
name='email' required
class="form-control"
custom-remote-validator="duplicate"
remote-validate-functions="duplicateMailRemoteCheck"
update-on-blur=""/>
@chandermani
chandermani / databaseacess
Created April 21, 2014 04:39
Multiple queries with PetaPoco
var planEmployees = this.DB
.Query<Xhr.Data.Model.EmployeeLeavePlanView>("WHERE LeavePlanId=@0", p.Id);
planEmployees.ForEach(e =>
{
var creditHistory = this.LeavesService.GetCredits(e.ID);
var newCredits = creditCalculator.CalculateNewCredits(processStartTime, creditHistory);
@chandermani
chandermani / dataaccess.cs
Created April 21, 2014 04:47
Fix PetaPoco DataReader error
var planEmployees = this.DB
.Query<Xhr.Data.Model.EmployeeLeavePlanView>("WHERE LeavePlanId=@0", p.Id)
.ToList(); //Did a ToList() to realize this query
// Same as it was earlier
@chandermani
chandermani / AuthHttp.ts
Last active February 14, 2021 12:48
Angular 2, Http service wrapper to pass authorization token with each request.
import {Injectable, EventEmitter} from 'angular2/core';
import {Http, Headers, RequestOptions, RequestOptionsArgs, Response, RequestMethod, Request, Connection, ConnectionBackend} from 'angular2/http';
import * as Rx from 'rxjs';
export enum Action { QueryStart, QueryStop };
@Injectable()
export class AuthHttp {
process: EventEmitter<any> = new EventEmitter<any>();
@chandermani
chandermani / orderBy.ts
Created March 28, 2016 03:06
orderBy pipe in Angular2
@Pipe({
name: 'orderBy'
})
export class OrderByPipe {
transform(value: Array<any>, args: any[]): any {
let field: string = args[0];
if(value==null) {
return null;
}
if (field.startsWith("-")) {
@chandermani
chandermani / workout-history-tracker-v1.service.ts
Last active May 13, 2018 14:51
Workout History Tracker V1
import { CoreModule } from './core.module';
import { Injectable } from '@angular/core';
import { ExercisePlan } from '../workout-runner/model';
@Injectable({
providedIn: CoreModule
})
export class WorkoutHistoryTrackerService {
private maxHistoryItems = 20; // Tracking last 20 exercises
private currentWorkoutLog: WorkoutLogEntry = null;
private void PrintMatrix(int[][] matrix){
for(int i=0;i<matrix.Length;i++) {
for(int j=0;j<matrix[0].Length;j++) {
Console.Write(matrix[i][j] + " ");
}
Console.WriteLine("");
}
}
private void PrintMatrix(int[,] matrix){