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 / flatten.js
Last active August 23, 2016 06:20
Javascript array flattening
/**
* Flattens an array of arbitrarily nested arrays into
* a flat array. e.g. [[1,2,[3]],4] -> [1,2,3,4]
*
* @param items - source array
* @return - flat array
*/
function flatten(items) {
const flat = [];
@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 / 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: `
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 / 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 / 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;
@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 / 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 / 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 / index.html
Created March 29, 2019 08:00
Practice on JS
<!DOCTYPE html>
<html>
<head>
<title>Javascript TODO list</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">