Skip to content

Instantly share code, notes, and snippets.

@imran3
imran3 / retry-http-errors.interceptor.spec.ts
Last active July 24, 2024 17:53
Retry http errors mechanism in Angular
import { HttpClient, HttpErrorResponse, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AppConfig } from '../../services/app-config/app-config.interface';
import { AppConfigService } from '../../services/app-config/app-config.service';
import { MOCK_APP_CONFIG } from '../../services/app-config/mock/get-config.mock';
import { RetryHttpErrorsInterceptor } from './retry-http-errors.interceptor';
describe('RetryHttpErrorsInterceptor', () => {
@anichitiandreea
anichitiandreea / typescript_coding_standards.md
Last active April 29, 2025 05:48
TypeScript Code Conventions
@apieceofbart
apieceofbart / test.js
Last active August 20, 2024 23:56
Async testing with jest fake timers and promises
PLEASE CHECK THIS REPO WITH THE EXAMPLES THAT YOU CAN RUN:
https://github.com/apieceofbart/async-testing-with-jest-fake-timers-and-promises
// Let's say you have a function that does some async operation inside setTimeout (think of polling for data)
function runInterval(callback, interval = 1000) {
setInterval(async () => {
const results = await Promise.resolve(42) // this might fetch some data from server
callback(results)
}, interval)
@grochowski
grochowski / medium_posts_to_csv.js
Last active December 11, 2021 19:53
Export Medium Reading List to CSV
/**
* Export Medium Reading List to CSV
* Based on Imrat Jn article on Medium
* https://medium.com/@imrat/1-trick-inbox-zero-readinglist-86964bc55df3
* added titles, links
* tested on Firefox 67 on Windows, should also work on Safari 11.1.2
*
* Go to the reading list, scroll as far as you can (in order to load all the posts),
* Put this into your console
*/
@shprink
shprink / _mixin.scss
Created October 16, 2018 17:32
Angular Material Sass to CSS variables
@function mat-color($palette-primary, $hue: default, $opacity: null) {
@if type-of($hue) == number and $hue >= 0 and $hue <= 1 {
@return mat-color($palette-primary, default, $hue);
}
$color: map-get($palette-primary, $hue);
$opacity: if($opacity == null, opacity($color), $opacity);
@if type-of($opacity) == string {
$new-string: str-replace($color, ')', '-alpha, 1)');
@yubing24
yubing24 / account.component.html
Created August 9, 2018 05:51
Angular Material Side Navigation with Expandable Menus
<mat-toolbar color="accent">
<button mat-icon-button matTooltip="Application Menu" (click)="sidenav.toggle()">
<mat-icon>settings</mat-icon>
</button>
Account Settings
<span style="flex: 1 1 auto;"></span>
<div>
<button mat-icon-button matTooltip="Switch Apps">
<mat-icon>apps</mat-icon>
</button>
@workfel
workfel / karma.conf.js
Created July 25, 2018 07:04
Angular Karma configuration for VSTS with junit & cobertura coverage config
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
@tienthanh2509
tienthanh2509 / install-openvpn-24.sh
Last active September 3, 2024 09:16
Install OpenVPN 2.4.x on Ubuntu 16.04 Xenial
curl -s https://swupdate.openvpn.net/repos/repo-public.gpg | apt-key add -
echo "deb http://build.openvpn.net/debian/openvpn/stable xenial main" > /etc/apt/sources.list.d/openvpn-aptrepo.list
apt update
apt install -y openvpn
@ahmeti
ahmeti / only-number.directive.md
Last active September 18, 2024 02:44
Angular 5 - Only Number Input, Only Number Decimal
@OliverJAsh
OliverJAsh / foo.ts
Last active January 27, 2025 18:24
Records and dictionaries in TypeScript
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.