Skip to content

Instantly share code, notes, and snippets.

@jwarby
jwarby / ..s
Last active August 29, 2015 14:00
..s - change up to a parent directory by specifying it's name
#! /bin/bash
# Change to a directory higher in the tree by name.
#
# Usage:
# [someone@apc /var/www/mysite/mysubfolder] $ ..s www
# [someone@apc /var/www] $
#
function ..s() {
CUR_PATH=`pwd`
@jwarby
jwarby / pdf-singleify
Last active August 29, 2015 14:01
Split PDFs which have 2-page spreads into 1-per-page PDF - usage ./pdf-singleify input.pdf output.pdf. Requires pdfinfo, ghostscript and pdftk
#! /bin/bash
file="$1"
function getDimensions() {
local page_size=`pdfinfo "$file" | grep "Page size"`
[[ $page_size =~ ([0-9\.]+)[[:space:]x]+([0-9\.]+) ]]
let page_width="${BASH_REMATCH[1]/.*} / 2"
let page_height="${BASH_REMATCH[2]/.*}"
let offset="-$page_width"
}
@jwarby
jwarby / recompile-less
Last active August 29, 2015 14:01
Recompile all LESS files in a specified directory
#! /bin/bash
#
# Recompiles all LESS files found (recursively) in the specified directory, e.g.
#
# [someome /public/css]$ recompile-less .
# or
# [someone /myapp]$ recompile-less public/css
find "$1" -name '*.less' | while read line; do
echo "Recompiling $line..."
REPLACE=`echo $line | sed "s|\.less|\.css|"`
@jwarby
jwarby / git-duf
Last active February 11, 2019 15:45
Delete untracked files and folders from git repositories - place on your `$PATH` as `git-duf` and use as `git duf`
#! /bin/bash
#
# Delete untracked files in a git repository.
# https://gist.github.com/jwarby/697a81fe3941474b3509
#
# Options:
#
# -h, --help
# show usage information
# -f, --force
@jwarby
jwarby / glu
Created November 11, 2014 07:09
View all unpushed commits (excluding merges)
git log --no-merges --author="`git config user.name`" `git rev-parse --abbrev-ref --symbolic-full-name @{u}`..HEAD
@jwarby
jwarby / jshintrc
Last active August 29, 2015 14:10
Personal .jshintrc style guide file
{
/* jwarby's JavaScript Style Guide
* v1.1.0
*
* https://gist.github.com/75aeeab0793a60d14303
* =====================================================
*/
/*
* ENVIRONMENTS
@jwarby
jwarby / tag.vim
Created September 17, 2015 06:35
Append hashtags to the end of a commit message in Vim - intended for adding the initials of peer reviewers, but will work for any tags (you may want to change the function name if so). Usage: :PRed JB EC / :PRed JB / :PRed JB EC DS, etc
function! AddPeerReviewerInitials(...)
" Go to the top of the file
execute ':normal gg'
" Find the first comment line, and go up one line
let lineIndex = search('^#') - 1
" If line is blank, go up another one (my setup adds a new line when amending commit messages)
if !getline(lineIndex)
let lineIndex = lineIndex - 1
@jwarby
jwarby / fsaCompliance.js
Last active October 6, 2016 00:27
A middleware for Redux which verifies that all actions dispatched to the store follow the Flux Standard Action (https://github.com/acdlite/flux-standard-action) pattern. A warning is shown (only once) for each action which violates the pattern.
import { isFSA } from 'flux-standard-action'
function createFSAComplianceMiddleware() {
const alreadyWarnedAbout = []
return ({ dispatch, getState }) => next => action => {
const { type } = action
if (!isFSA(action) && alreadyWarnedAbout.indexOf(type) === -1) {
// eslint-disable-next-line no-console
@jwarby
jwarby / fsaCompliance.js
Created October 6, 2016 00:26
A saga for redux-saga which verifies that all actions dispatched to the store follow the Flux Standard Action (https://github.com/acdlite/flux-standard-action) pattern. A warning is shown (only once) for each action which violates the pattern.
import { takeEvery } from 'redux-saga'
import { isFSA } from 'flux-standard-action'
const alreadyWarnedAbout = []
export function* fsaCompliance() {
yield* takeEvery('*', function* checkCompliance(action) {
const { type } = action
if (!isFSA(action) && alreadyWarnedAbout.indexOf(type) === -1) {
@jwarby
jwarby / .eslintrc
Created January 18, 2017 01:23
ESLint configuration file for React/React Native projects
{
"extends": "eslint:recommended",
"parser": "babel-eslint",
"env": {
"node": true,
"mocha": true,
"es6": true
},
"rules": {
"import/default": 2,