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 / 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
}, {})
}
@chris-kobrzak
chris-kobrzak / git-rebase-all-feature-branches.sh
Last active July 13, 2017 11:07
Capture all feature branches in Git, update base branch (default `master`), rebase forks on it and, optionally, force push to the central repository.
#/usr/bin/env bash
baseBranch=master
if [[ $# -eq 1 ]]; then
baseBranch=$1
fi
echo "Update the repository..."
git fetch -p
echo
@chris-kobrzak
chris-kobrzak / delay.js
Created May 4, 2017 13:30
Then-able JavaScript setTimeout incarnation
function delay(milliseconds) {
return new Promise(
resolve => setTimeout(resolve, milliseconds)
)
}
@chris-kobrzak
chris-kobrzak / README-Git-workflow.md
Last active February 2, 2017 22:42
Git source control workflow (draft)
@chris-kobrzak
chris-kobrzak / logic-in-jsx-improved.js
Last active September 23, 2016 22:07
Less logic in JSX resulting in code that's easier to read and transpiled to a simpler and more compact block of code
render () {
const { visible } = this.props
let visibleContent
if (visible) {
visibleContent = this.getVisibleContent()
}
return (
<div className={ visible ? 'expanded' : 'collapsed' }>
{ visibleContent } // No more logic here and useless "null"