Skip to content

Instantly share code, notes, and snippets.

View nilsandrey's full-sized avatar
🏠

Nils nilsandrey

🏠
View GitHub Profile
@nilsandrey
nilsandrey / interceptor.ts
Last active October 10, 2019 15:31
"Slow requests are commonly causing performance problems in Angular apps. Here is an interceptor that can log your HTTP requests, so you can measure the roundtrip time for your requests" from https://twitter.com/chrislydemann at https://twitter.com/chrislydemann/status/1182282767935123457?s=20
import {
HttpEvent,
HttpHandler,
Httpinterceptor,
HttpRequest
} from "@angular/common/http";
import { Injectable } from "@angular/core";
import * as moment from "moment";
import { Observable } from "rxjs";
import { tap } from "rxjs/operators";

Keybase proof

I hereby claim:

  • I am nilsandrey on github.
  • I am nilsandrey (https://keybase.io/nilsandrey) on keybase.
  • I have a public key ASCa0L4jG7UpSExhx7EfSguzVkf4dMxEw2pbwAyMHr2IFgo

To claim this, I am signing this object:

@nilsandrey
nilsandrey / name-shortening functions.js
Last active May 2, 2024 02:46
Name-shortening functions from Hacker News own JS for web site
// From yesenadam at https://news.ycombinator.com/item?id=23590848
function $(id) { return document.getElementById(id); }
function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }
function byTag (el, tg) { return el ? el.getElementsByTagName(tg) : [] }
function allof (cl) { return byClass(document, cl) }
function hasClass (el, cl) { var a = el.className.split(' '); return afind(cl, a) }
function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} }
function remClass (el, cl) { if (el) { var a = el.className.split(' '); arem(a, cl); el.className = a.join(' ') } }
function html (el) { return el ? el.innerHTML : null; }
@nilsandrey
nilsandrey / xkcd-com-234.md
Created August 25, 2020 19:11
Some xkcd.com
@nilsandrey
nilsandrey / .dockerfile
Last active December 17, 2020 20:13
Dockerfile to containerize a Next.js app by @oliverjumpertz@twitter
FROM node: 14-alpine as build
ENV NEXT_TELEMETRY_DISABLED=1
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY ..
RUN yarn install && \
yarn build
FROM node: 14-alpine
@nilsandrey
nilsandrey / 01_ensure_environment.rb
Created February 17, 2021 23:05
Ensure required environment variables are set when booting up Rails. https://boringrails.com/tips/ensure-rails-env-vars
# config/initializers/01_ensure_environment.rb
if Rails.env.development?
%w[
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
S3_BUCKET
ALGOLIA_ID
ALGOLIA_API_KEY
ALGOLIA_SEARCH_KEY

Testing toc

Links:

The toc 1

Content of the toc 1.

@nilsandrey
nilsandrey / mock-pipe.ts
Created March 10, 2021 16:41
How to mock Pipe when testing Component (https://stackoverflow.com/a/56701741/2100126)
// If you want reusable util function for mocking pipes, you can try this option:
export function mockPipe(options: Pipe): Pipe {
const metadata: Pipe = {
name: options.name
};
return <any>Pipe(metadata)(class MockPipe {});
}
@nilsandrey
nilsandrey / daemon.json
Last active March 16, 2021 16:04
Docker daemon can be set up to forward the logs to Syslog, which then logs into messages or a separate file if you configure Syslog correctly. (On CentOS7) Change your /etc/docker/daemon.json to something like this, and then restart docker daemon https://www.reddit.com/r/docker/comments/m63noe/how_can_i_store_docker_logs_to_a_file_real_time/gr3t…
{
"log-driver": "syslog",
"log-opts": {
"tag": "dockerlogs {{.Name}}/{{.ID}}"
}
}
@nilsandrey
nilsandrey / install-node-14-ubuntu.sh
Created March 16, 2021 22:07
NodeSource Node.js Binary Distribution: v14 in Ubuntu
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs