Skip to content

Instantly share code, notes, and snippets.

View djabif's full-sized avatar

Dayana Jabif djabif

View GitHub Profile
@djabif
djabif / matching-passwords.validator.ts
Last active May 19, 2023 14:10
Angular Validator for Matching Passwords
import { FormControl, FormGroup } from '@angular/forms';
export class PasswordValidator {
// If our validation fails, we return an object with a key for the error name and a value of true.
// Otherwise, if the validation passes, we simply return null because there is no error.
static areNotEqual(formGroup: FormGroup) {
let firstControlValue: any;
let valid = true;
@peavers
peavers / firestore-scroll.service.ts
Last active February 3, 2023 15:47
Enables infinite/virtual scrolling with ngx-virtual-scroller and Firestore
import {Injectable} from '@angular/core';
import {BehaviorSubject, Observable} from "rxjs";
import {AngularFirestore} from "@angular/fire/firestore";
import {map, mergeMap, scan, tap, throttleTime} from "rxjs/operators";
import {ChangeEvent} from "ngx-virtual-scroller";
/**
* Enables infinite scrolling with ngx-virtual-scroller and Firestore. Most of the hard work goes to
* https://angularfirebase.com/lessons/infinite-virtual-scroll-angular-cdk.
*
@djabif
djabif / phone.validator.ts
Last active February 28, 2023 12:38
Angular Phone + Country Validator
//Complete example for Ionic Framework in: https://ionicthemes.com/tutorials/about/forms-and-validation-in-ionic
//Complete example for Angular in: https://angular-templates.io/tutorials/about/angular-forms-and-validations
import { AbstractControl, ValidatorFn } from '@angular/forms';
import * as libphonenumber from 'google-libphonenumber';
export class PhoneValidator {
// Inspired on: https://github.com/yuyang041060120/ng2-validation/blob/master/src/equal-to/validator.ts
static validCountryPhone = (countryControl: AbstractControl): ValidatorFn => {
@djabif
djabif / form.ts
Last active February 28, 2023 12:38
Ionic Password validator
import { PasswordValidator } from '../../validators/password.validator';
this.matching_passwords_group = new FormGroup({
password: new FormControl('', Validators.compose([
Validators.minLength(5),
Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$') //this is for the letters (both uppercase and lowercase) and numbers validation
])),
confirm_password: new FormControl('', Validators.required)
}, (formGroup: FormGroup) => {
return PasswordValidator.areEqual(formGroup);
@djabif
djabif / slugify.pipe.ts
Last active June 28, 2024 21:59
Angular Pipe to transform a string into a slug
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'slugify'})
export class SlugifyPipe implements PipeTransform {
transform(input: string): string {
return input.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
angular.module('sfViewCtrlDirective', [])
.directive('open', OpenDirective);
function OpenDirective() {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
console.log('device is ready');
$element.on('click', function() {
@mlynch
mlynch / info.plist
Last active August 6, 2023 07:31
Disable App Transport Security in iOS 9
<!--
This disables app transport security and allows non-HTTPS requests.
Note: it is not recommended to use non-HTTPS requests for sensitive data. A better
approach is to fix the non-secure resources. However, this patch will work in a pinch.
To apply the fix in your Ionic/Cordova app, edit the file located here:
platforms/ios/MyApp/MyApp-Info.plist
And add this XML right before the end of the file inside of the last </dict> entry:
@hijonathan
hijonathan / example.coffee
Last active February 14, 2023 15:14
Javascript implementation of the largest remainder method http://en.wikipedia.org/wiki/Largest_remainder_method
values = [
13.626332
47.989636
9.596008
28.788024
]
# Round these percentage values into integers, ensuring that they equal 100% at the end.
roundedValues = getLargestRemainder values, 100
# [14, 48, 9, 29]
@stephenhardy
stephenhardy / git-clearHistory
Created April 26, 2013 22:14
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@tony4d
tony4d / p4merge4git.md
Created August 24, 2012 19:00
Setup p4merge as a visual diff and merge tool for git