Skip to content

Instantly share code, notes, and snippets.

Léon Pelletier leye0

Block or report user

Report or block leye0

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@leye0
leye0 / is-contained-within.directive.ts
Last active Dec 11, 2019
Angular - Directive - Add a class to an element if the element is contained within an element specified by a selector
View is-contained-within.directive.ts
import { Directive, Input, OnChanges, SimpleChanges, ElementRef } from '@angular/core';
@Directive({
selector: '[isContainedWithin]'
})
export class IsContainedWithinDirective implements OnChanges {
@Input() isContainedWithin: string = '';
@Input() classToAdd: string = '';
View Angular Action|Observe rxjs pattern.md

Note: Un des objectifs de cette approche est de faciliter l'intégration éventuelle de ngrx/store, en plus de favoriser la modification des données à l'intérieur des services, de centraliser le data à l'intérieur d'un "data store" - et rendre stateless les services - et finalement de simplifier les components en maximisant leur passivité. La version ci-dessous n'implémente pas encore le concept de data store et d'action.

Structure du code

MyPotatoService.ts:

export class MyPotatoService {

    potatos$: BehaviorSubject<PotatoApiModel[]> = new BehaviorSubject<Potato>(null);
@leye0
leye0 / gist:5cb118fa6821ab81122864ac8e57d0e1
Created Dec 11, 2018
xlf-translate.js - Support ng-bootstrap i18n entry id format
View gist:5cb118fa6821ab81122864ac8e57d0e1
#!/usr/bin/env node
'use strict';
// Based on
// Fix on https://github.com/tsvetomir/xlf-translate to...
// -> support ID fields directly on a trans-unit 'id' attribute instead of trans-unit.node.meaning (ex: ng-bootstrap i18n)
// -> support description generated from id and source instead of missing trans-unit.node.description
// See: https://github.com/tsvetomir/xlf-translate/issues/9
const jp = require('jsonpath');
@leye0
leye0 / xlf-extract.js
Created Dec 11, 2018
xlf-extract.js - Support ng-bootstrap i18n entry id format
View xlf-extract.js
#!/usr/bin/env node
'use strict';
// Fix on https://github.com/tsvetomir/xlf-extract to...
// -> support ID fields directly on a trans-unit 'id' attribute instead of trans-unit.node.meaning (ex: ng-bootstrap i18n)
// -> support description generated from id and source instead of missing trans-unit.node.description
// See: https://github.com/tsvetomir/xlf-extract/issues/5
const fs = require('fs');
const cheerio = require('cheerio');
@leye0
leye0 / sugg.directive.ts
Created Dec 4, 2018
Some select / dropdown / autocomplete / nameit directive (almost) clear of useless options
View sugg.directive.ts
// Disclaimer: Use bootstrap 4 classes
import { Directive, Input, OnInit, ElementRef, Output, EventEmitter, SimpleChanges, OnChanges, HostListener } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { debounceTime, filter } from 'rxjs/operators';
const key_arrow_up = 38;
const key_arrow_down = 40;
const key_enter = 13;
@Directive({
@leye0
leye0 / add-missing-translations.js
Created Nov 27, 2018
Merge YAML source translation into destination translation and only add missing entries
View add-missing-translations.js
// Little script to add missing source translation into destination translation file so it is easier to maintain
// Usage:
// add-missing-translations src=en dest=fr
const fs = require('fs');
const YAML = require('yaml');
function toKeyValues(args) {
return args.map(arg => arg.split('='))
View gist:72a63745503a66b4fa3b4e038e541929
Here’s a simple example of what I’m saying:
```
<style>
.div1 {
overflow-x: hidden;
overflow-y: scroll;
height: 100px;
width: 20px;
}
View FindFriendlyColorName.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace lol
{
public static class ColorHelpers
{
public static string GetColorName(Color c)
{
@leye0
leye0 / zoomdrag.js
Created Jan 7, 2017
Make an element zoomable and draggable
View zoomdrag.js
$('document').ready(() => {
let zoom = 1;
let nContainer = document.getElementById('container'); // Get zoomed element
let originalOffset; // We'll retain original zoomed element offset
$(nContainer).draggable(); // Use jQuery UI plugin to make zoomed element draggable
$('.zoomable').on('mousewheel', function (e) {
e.preventDefault();
let zoomOut = e.originalEvent.deltaY > 0;
if ((zoomOut && zoom === 1) || (!zoomOut && zoom === 100)) return; // Ignore action
if (!originalOffset) originalOffset = {left: nContainer.offsetLeft, top: nContainer.offsetTop }; // Memorizes original zoomed element offsets
View VideoEncoderCore.java
/*
* Copyright 2014 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
You can’t perform that action at this time.