Skip to content

Instantly share code, notes, and snippets.

View chris-kobrzak's full-sized avatar

Chris Kobrzak chris-kobrzak

View GitHub Profile
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
@chris-kobrzak
chris-kobrzak / bulk-resize-images.sh
Last active July 31, 2018 23:11
Bulk resize images in directories preserving modification date timestamps
#!/usr/bin/env bash
for directory in */ ; do
dirTimestamp="$(GetFileInfo -d "$directory")"
(
cd "$directory"
# In this case img files have no extensions
for fileName in `find . -type f -maxdepth 1 ! -name "*.*"`; do
fileTimestamp="$(GetFileInfo -d "$fileName")"
import React, { Component } from 'react'
import { withRouter } from 'react-router'
const topCoordinates = [0, 0]
const { scrollTo } = window
class ScrollToTopHandler extends Component {
// Arrow method, requires stage 2 Babel preset
render = () => null
# Get the most recent commit ID
git rev-parse HEAD
# Detect if feature branch has been rebased on master
git checkout <your-feauture-branch>
git checkout master
masterHeadId=`git rev-parse HEAD`
@chris-kobrzak
chris-kobrzak / validation.js
Created December 18, 2017 12:21
Form validation logic that can be plugged to React event handlers
// Low-level, generic validation functions
// Signature: any => boolean
const hasLength = value => value.length > 0
const hasLettersAndDotsOnly = value => (
value.match(/^[a-z\.]+$/gi) !== null
)
/*
Map input fields to "types" that we want to validate in a certain way. This
@chris-kobrzak
chris-kobrzak / build-object-from-class.js
Last active June 14, 2017 09:58
[WIP] Use ES6 classes instead of object literals in Ember.js
export default function buildObjectFromClass (className) {
return Object.getOwnPropertyNames(className.prototype)
.filter(propertyName => propertyName != 'constructor')
.reduce((result, propertyName) => {
result[propertyName] = className.prototype[propertyName]
return result
}, {})
}