Skip to content

Instantly share code, notes, and snippets.

View dorthrithil's full-sized avatar
🧗

Felix Engelmann dorthrithil

🧗
  • Koblenz, Germany
View GitHub Profile
@dorthrithil
dorthrithil / combobox-reset-searchtext.directive.ts
Last active June 22, 2022 13:39
Reset search text of Clarity Comboboxes
import {Directive, OnInit} from '@angular/core';
import {ClrCombobox} from '@clr/angular';
/**
* Utility directive to add a missing feature to Clarity comboboxes: Resetting the combobox search text after a
* selection. Clarity didn't add it for a11y reasons - for apps that don't need to worry about this in such a strct way
* this directive can help. Attach it to any Clariy Combobox and the searchtext will be set to empty string after the
* selection changes.
*/
@Directive({
@dorthrithil
dorthrithil / anti-clipping.directive.ts
Last active May 28, 2022 15:26
Prevent Clarity Angular dropdown clipping - Directive that prevents clipping of Clarity dropdowns (maybe also popovers etc. - not tested) when they are inside * containers that hide overflow. The trick is to just detach the element and attach it to the body.
/**
* Directive that prevents clipping of Clarity dropdowns (maybe also popovers etc. - not tested) when they are inside
* containers that hide overflow. The trick is to just detach the element and attach it to the body.
* Use it like this on the element that is clipping:
*
* ```
* <clr-dropdown-menu clrPosition="bottom-left" appAntiClipping>
* ```
*/
@Directive({
@dorthrithil
dorthrithil / arbitrary-piped-function.pipe.ts
Last active May 4, 2021 15:06
Angular: pipe any function in your template
/**
* Pipe that let's you pipe just anything! Function calls in your templates are normally a bad idea, performance wise.
* However you can get around this problem by writing pipes that don't trigger on every CD cycle but only when the arguments change.
* Doing this for every function you want can be painful however! Here comes arbitraryPipedFunction for the rescue!
* Just pass the function, the arguments, the context and some extra arguments you may want to include in the watches arguments for the
* pipes internal CD. There you go. One pipe to rule them all.
*/
@Pipe({
name: 'arbitraryPipedFunction'
})
@dorthrithil
dorthrithil / textAngular: modifyHtml
Created July 16, 2015 11:48
A simple function which removes all styles from text pasted from Word or Browsers.
// created for use in textAngulars ta-paste="modifyHtml($html)" option
// http://textangular.com/
$scope.modifyHtml = function($html){
var DOMTree = jQuery(jQuery.parseHTML($html, null, false));
jQuery.each(DOMTree, function(key, value){
jQuery(value).removeAttr('style').find('*').removeAttr('style').removeClass();
});
return jQuery('<div>').append(DOMTree).html();
};
@dorthrithil
dorthrithil / ncloc.py
Created May 2, 2015 05:41
calculates & prints loc and ncloc of python files
import tokenize
from token import *
def print_metrics(path):
"""prints LOC and NCLOC of the input file"""
fo = open(path, "rb") # open file in byte mode
tokens = tokenize.tokenize(fo.readline) # tokenize it