Skip to content

Instantly share code, notes, and snippets.

View MurhafSousli's full-sized avatar
🌴
On vacation

Murhaf Sousli MurhafSousli

🌴
On vacation
View GitHub Profile
@MurhafSousli
MurhafSousli / index.html
Created March 25, 2019 11:32
kasim-murhaf
<!DOCTYPE html>
<html>
<head>
<title>Reputation Ranking</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css" />
<link rel="stylesheet" href="style.css">
</head>
@MurhafSousli
MurhafSousli / safe.pipe.ts
Created September 29, 2018 16:04
Safe sanitizer for Angular
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(protected sanitizer: DomSanitizer) {}
@MurhafSousli
MurhafSousli / make-directory.ts
Last active May 28, 2018 21:58
Create directory recursively for a giving path
import { existsSync, mkdirSync } from 'fs';
import { dirname } from 'path';
function makeDirectory(target: string) {
// check if parent directory exists
const parentDir = dirname(target);
if (!existsSync(parentDir)) {
makeDirectory(parentDir);
@MurhafSousli
MurhafSousli / date-time.js
Created October 12, 2017 03:59
Date and time js function
//using your function (passing in date)
function formatAMPM(date) {
let days = date.getUTCDate();
let month = date.getUTCMonth() + 1;
const year = date.getUTCFullYear();
let hours = date.getHours();
let minutes = date.getMinutes();
const ampm = hours >= 12 ? 'pm' : 'am';
// converts hours to 12 hour instead of 24 hour
hours = hours % 12;
import {Directive, Input, ElementRef, Renderer} from '@angular/core';
import {WindowService} from "../../window/window.service";
@Directive({
selector: '[affix]'
})
export class AffixDirective {
@Input() affix: any;
parent: HTMLElement;
@MurhafSousli
MurhafSousli / ripple.directive.ts
Created April 13, 2017 12:08
Ripple directive angular
import {Directive, ElementRef, HostListener, Renderer2} from '@angular/core';
@Directive({
selector: '[ripple]'
})
export class RippleDirective {
hostEl;
constructor(private renderer: Renderer2, el: ElementRef) {
@MurhafSousli
MurhafSousli / test-model.ts
Created February 26, 2017 12:37
Getting a model with WpService
/*
* This example demonstrates how to get a single post by id
*/
import { Component } from '@angular/core';
import { WpModel, WpPost } from "ng2-wp-api";
@Component({
selector: 'test-model',
template: `
@MurhafSousli
MurhafSousli / test-collection.ts
Last active May 21, 2017 00:19
Get collection using WpService
/*
* In this example, we display a collection of posts, pagination and a button to load the next page.
* we also set the QueryArgs for the request to get embedded posts and filter the results to 6 posts per page
*
* get pagination properties from `wpCollection.service`
*/
import { Component, OnInit } from '@angular/core';
import {WpEndpoint, WpService, CollectionResponse} from 'ng2-wp-api';
@Component({
@MurhafSousli
MurhafSousli / advancedCollection.ts
Last active February 26, 2017 12:20
ng2-wp-api Getting Collection
import {Component, ViewChild, AfterViewInit} from '@angular/core';
import {WpEndpoint, CollectionDirective, CollectionResponse} from '../../core/wordpress';
@Component({
selector: 'feed-page',
templateUrl: `
<div class="feed" #feed [wpCollection]="postsEndpoint" [wpArgs]="postsArgs">
<ul>
<li *ngFor="let post of posts">{{post.title()}}</li>
@MurhafSousli
MurhafSousli / html-sanitizer.pipe.ts
Last active August 16, 2023 04:08
HTML Dom Sanitizer Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({
name: 'sanitizeHtml'
})
export class HtmlSanitizerPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}