Skip to content

Instantly share code, notes, and snippets.

View cyberhck's full-sized avatar

Nishchal Gautam cyberhck

View GitHub Profile
@aksel
aksel / middlewares.js
Last active June 28, 2019 21:45
Route HTTP status code middleware for router5
import { startsWithSegment } from 'router5-helpers';
import { transitionPath } from 'router5';
// Reduces the activated routes, so the last status is used, defaulting to 200
// Reducingg instead of finding, assures that child routes determine the status codes, even when a parent has a different one.
export const statusCodeDecorator = routes => () => (toState, fromState) => {
const status = getActivatedRoutes(routes, toState, fromState).reduce((s, route) => route.status || s, 200);
return Promise.resolve({ ...toState, status });
};
@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active May 25, 2023 03:55
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"