Skip to content

Instantly share code, notes, and snippets.

View chris-kobrzak's full-sized avatar

Chris Kobrzak chris-kobrzak

View GitHub Profile
@chris-kobrzak
chris-kobrzak / getCurrentPositionTask.js
Created October 20, 2021 16:05
Promisified navigator.geolocation.getCurrentPosition
function getCurrentPositionTask(positionConfig) {
const { geolocation } = navigator
return new Promise((resolve, reject) => {
const handleSuccess = ({ coords }) => {
resolve(coords)
}
const handleError = error => { reject(error) }
@chris-kobrzak
chris-kobrzak / postman-jwt-auth-pre-request.js
Last active September 22, 2021 15:14
Postman pre-request script for automatic JWT-authentication. Please see config options at the top of the script.
// Environment variable names config
const env = {
ACCESS_TOKEN: '_token', // This env var will be created by the script
AUTH_TIME: '_authTime', // This env var will be created by the script
BASE_URL: 'baseUrl',
ID: 'username',
SECRET: 'password'
}
// API config
const api = {
@chris-kobrzak
chris-kobrzak / interface-with-generics.cs
Created April 30, 2021 14:31
c# interface with generics
using MyService.Core.Models;
namespace MyService.Providers.Mappers
{
public interface IMyMapper<in T> where T : ISomething
{
MappedSomething MapToSomething(T somethingGeneric);
}
public class MyConcreteMapper : IMyMapper<SomethingA>
@chris-kobrzak
chris-kobrzak / convert-m4a-to-ogg.sh
Created February 28, 2021 22:22
Convert .m4a to .ogg files
for m4aFile in *.m4a; \
do ffmpeg -i "$m4aFile" \
-ab 128k \
ogg/"${m4aFile%.m4a}.ogg"; \
done
@chris-kobrzak
chris-kobrzak / namei.sh
Last active April 14, 2021 11:47
Display all permissions on a path and its parents on Linux
namei -om /path/to/a/dir-or-file
# Sample output
#
# f: /usr/local/bin/nginx_modsite
# drwxr-xr-x root root /
# drwxr-xr-x root root usr
# drwxr-xr-x root root local
# drwxr-xr-x root root bin
# -rwxr-xr-x root root nginx_modsite
kafkacat -L -b <BROKER_URL:PORT> -t <KAFKA_TOPIC>
@chris-kobrzak
chris-kobrzak / search-apt-history.sh
Created February 20, 2020 17:09
Search APT history on Debian systems
find /var/log/apt -name 'history.log*' -exec zgrep -- '<YOUR SEARCH TERM>' {} +
@chris-kobrzak
chris-kobrzak / isWithinRadius.js
Last active February 20, 2020 20:53 — forked from moshmage/withinRadius.js
Compares two points' latitude and longitude and returns true if within provided metres
const {asin, cos, sin, sqrt, PI} = Math
const EARTH_RADIUS_KM = 6371
const METERS_IN_KM = 1000
// const deg2rad = n => Math.tan(n * (Math.PI / 180))
const convertDegToRad = degries => degries * (PI / 180)
/**
* is One Point within Another
@chris-kobrzak
chris-kobrzak / injectLambdaDependencies.js
Last active September 6, 2019 10:56
Injecting dependencies to an AWS Lambda function
// Dependency injection helper
const injectLambdaDependencies = (handle, dependencyMap) => (event, context) => {
const enhancedContext = Object.assign({}, context, dependencyMap)
return handle(event, enhancedContext)
}
// Dependencies, possibly returned by a factory
const dependencyMap = { doSomething: () => 'foo bar' }
@chris-kobrzak
chris-kobrzak / testUrls.sh
Last active August 7, 2018 09:56
Gentle URL checker
#!/usr/bin/env bash
# - consumes a list of URL paths from a file called `paths.txt` (a simple
# new-line separated list),
# - concatenates them with base URLs (that can be defined with environment
# variables),
# - hits these URLs every <interval> seconds in a seqential way
# - waits a little longer every <batch> and <bigBatch> URLs to ease out
# the pressure on your server