Skip to content

Instantly share code, notes, and snippets.

View tspringborg's full-sized avatar
💭
I may be slow to respond.

tspringborg

💭
I may be slow to respond.
  • Magnificent.pizza
  • Copenhagen, Denmark
View GitHub Profile
@tspringborg
tspringborg / replaceTokens.ts
Created January 22, 2020 15:19
replaceTokens function
export const replaceTokens = (str, args): string => {
// *********** replaces all tokens like so: **********
// ${[0]foo} will be replaced with the value of ...args[0].foo
// where args are the arguments supplied to the decorated function
// ***************************************************
let parsedStr = str;
/*
\$ matches the character $ literally (case sensitive)
{ matches the character { literally (case sensitive)
\[ matches the character [ literally (case sensitive)
// Koch Snowflake - by Martijn Steinrucken aka BigWings 2019
// Email:countfrolic@gmail.com Twitter:@The_ArtOfCode
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//
// This effect is part of a tutorial on YouTube
// https://www.youtube.com/watch?v=il_Qg9AqQkE
vec2 N(float angle) {
return vec2(sin(angle), cos(angle));
}
@tspringborg
tspringborg / click.outside.directive.ts
Last active December 18, 2019 14:49
angular clickOutside directive
import {Directive, ElementRef, EventEmitter, HostListener, Output} from '@angular/core';
@Directive({
// tslint:disable-next-line:directive-selector
selector: '[clickOutside]'
})
export class ClickOutsideDirective {
private readonly startTime: number;
constructor(private elementRef: ElementRef) {
@tspringborg
tspringborg / material-module.ts
Created September 18, 2019 07:19
ng material module
import {DragDropModule} from '@angular/cdk/drag-drop';
import {ScrollingModule} from '@angular/cdk/scrolling';
import {CdkTableModule} from '@angular/cdk/table';
import {CdkTreeModule} from '@angular/cdk/tree';
import {NgModule} from '@angular/core';
import {
MatAutocompleteModule,
MatBadgeModule,
MatBottomSheetModule,
MatButtonModule,
@tspringborg
tspringborg / compoundedInterest
Created July 11, 2019 13:34
Simple compounded Interest
function compoundedInterest(value, pct, times) {
return value*(Math.pow(1 + pct/1, times) - 1);
}
@tspringborg
tspringborg / gist:309e27672e2f4fd8b3b44e4db8b718c3
Created July 10, 2019 16:41
javascript binomial cooefficient
function binomial(n, k) {
if ((typeof n !== 'number') || (typeof k !== 'number'))
return false
let coeff = 1
for (var x = n-k+1; x <= n; x++) coeff *= x
for (x = 1; x <= k; x++) coeff /= x
return coeff
}
//https://ask.wireshark.org/questions/33938/how-can-i-filter-by-website-names
http.host=="exact.name.here"
http.host contains "partial.name.here"
Both of those filters are case-sensitive.
http.host matches "(?i)web\.site\.name"
http.host matches "(?i) web[.]site[.]name"
@tspringborg
tspringborg / function-is-in-viewport.js
Created October 28, 2015 11:02
check if element is in browser viewport
function isElementInViewport (el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
@tspringborg
tspringborg / gist.js
Created October 7, 2013 09:24
backbonejs inheritance
///facilitates inheritance ....gist from https://gist.github.com/1542120
;(function(Backbone) {
// The super method takes two parameters: a method name
// and an array of arguments to pass to the overridden method.
// This is to optimize for the common case of passing 'arguments'.
function _super(methodName, args) {
// Keep track of how far up the prototype chain we have traversed,
// in order to handle nested calls to _super.
@tspringborg
tspringborg / floatparent_height
Created July 30, 2013 10:47
Although elements like <div>s normally grow to fit their contents, using the float property can cause a startling problem for CSS newbies: if floated elements have non-floated parent elements, the parent will collapse.
.content:after{
content: " ";
display: block;
height: 0;
clear: both;
*zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML += '<div class="ie7-clear"></div>' );
}
.ie7-clear {
display: block;
clear: both;