Skip to content

Instantly share code, notes, and snippets.

View RobertoPrevato's full-sized avatar
🐍
Working and having fun on GitHub

Roberto Prevato RobertoPrevato

🐍
Working and having fun on GitHub
  • Warsaw, Poland
View GitHub Profile
public class ImageMiddleware
{
private readonly RequestDelegate _next;
private readonly string _path;
public ImageMiddleware(RequestDelegate next, string path)
{
_next = next;
this._path = path;
}
@dfee
dfee / ip_regex.py
Last active December 7, 2023 19:39
Python IPV4 / IPV6 Regular Expressions (REGEX)
# Constructed with help from
# http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
# Try it on regex101: https://regex101.com/r/yVdrJQ/1
import re
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])'
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')'
IPV6SEG = r'(?:(?:[0-9a-fA-F]){1,4})'
IPV6GROUPS = (
@toddlers
toddlers / Dockerfile
Created July 27, 2016 11:24
using envsubst in Dockerfile
FROM ubuntu:trusty
RUN \
apt-get update \
&& apt-get -y install gettext-base \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV VALUE=foo
ENV VALUE1=boo
COPY config.txt source_config.txt
@michalochman
michalochman / gulpfile.js
Last active May 19, 2021 22:11
gulp.js: babelify + browserify + sourcemaps
/* jshint strict: false */
/* globals require, console */
var gulp = require('gulp');
var exit = require('gulp-exit');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
@Jaza
Jaza / Private-pypi-howto
Last active July 2, 2023 16:24
Guide for how to create a (minimal) private PyPI repo, just using Apache with directory autoindex, and pip with an extra index URL.
*
@scotthorn
scotthorn / viewport-shots.js
Last active June 29, 2020 08:49
Nightwatch.js script for taking screenshots of a given URL at various browser widths.
/*
* Takes provided URL passed as argument and make full height screenshots of this page
* with several viewport widths using Nightwatch.js with Selenium.
*
* These viewport widths are taken from common android and iOS devices. Modify as needed.
*
* Takes an optional second argument for the path where screenshots are saved.
*
* Usage:
* $ nightwatch -t viewport-shots.js http://example.com
@kelvinn
kelvinn / cmd.sh
Created July 24, 2014 02:55
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@kevinburke
kevinburke / results.txt
Last active July 28, 2022 02:33
Performance of ''.join vs .format() in Python
$ python test_time.py
join_test: 21.3 seconds
format_test: 36.6 seconds
@brettz9
brettz9 / HTMLSelectElement.prototype.selectedOptions.js
Last active July 25, 2019 16:04
selectedOptions shim (multiple select) with IE8 support
/**
* Polyfill for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects are implementation-dependent,
* IE doesn't need to work this way). Also works on strings,
* fixes IE to allow an explicit undefined for the 2nd argument
* (as in Firefox), and prevents errors when called on other
* DOM objects.
* @license MIT, GPL, do whatever you want
-* @see https://gist.github.com/brettz9/6093105