Skip to content

Instantly share code, notes, and snippets.

@leye0
leye0 / gist:6f4cc9d2d9e0930f9e051f187b6dd38a
Created September 15, 2022 15:39
git logging cheat sheet
# Get commit# for tag
git rev-list -n 1 tags/${myTag}
# Get branches containing commit#
git branch -a --contains ${myCommit}
@leye0
leye0 / is-contained-within.directive.ts
Last active December 11, 2019 17:39
Angular - Directive - Add a class to an element if the element is contained within an element specified by a selector
import { Directive, Input, OnChanges, SimpleChanges, ElementRef } from '@angular/core';
@Directive({
selector: '[isContainedWithin]'
})
export class IsContainedWithinDirective implements OnChanges {
@Input() isContainedWithin: string = '';
@Input() classToAdd: string = '';

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 December 11, 2018 14:48
xlf-translate.js - Support ng-bootstrap i18n entry id format
#!/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 December 11, 2018 14:47
xlf-extract.js - Support ng-bootstrap i18n entry id format
#!/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 December 4, 2018 15:31
Some select / dropdown / autocomplete / nameit directive (almost) clear of useless options
// 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 November 27, 2018 18:31
Merge YAML source translation into destination translation and only add missing entries
// 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('='))
Here’s a simple example of what I’m saying:
```
<style>
.div1 {
overflow-x: hidden;
overflow-y: scroll;
height: 100px;
width: 20px;
}
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 January 7, 2017 06:52
Make an element zoomable and draggable
$('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