Skip to content

Instantly share code, notes, and snippets.

@thom-nic
thom-nic / cidr_iter.sh
Last active December 11, 2020 04:50
Generate all IPv4 addresses in bash from a CIDR or netmask
#!/bin/bash -ue
# Modified "CIDR to IP range" function taken from https://stackoverflow.com/a/18120519/213983
# use like `cidr_iter "192.168.1.1/24"`
cidr_iter() {
# create array containing network address and subnet
local network=(${1//\// })
# split network address by dot
local iparr=(${network[0]//./ })
# if no mask given it's the same as /32
@thom-nic
thom-nic / _spacing-helpers.scss
Last active September 3, 2020 15:28 — forked from jacurtis/_spacing-helpers.scss
SASS Margin and Padding Helpers Loop. Generates .mts type helper classes.
/*
* Spacing helpers for consistent margin and padding on elements. Uses rems (not px!)
*
* With the current default settings, generates classes like:
* .mts = margin-top: 0.5rem
* .phl = padding-left: 2rem; padding-right: 2rem; // h = horizontal = left/right
*
* Inspired by:
* https://github.com/mrmrs/css-spacing
* https://getbootstrap.com/docs/4.0/utilities/spacing/
@thom-nic
thom-nic / override.conf
Created August 2, 2017 02:50
How to get sane terminal behavior with embedded linux/ RPi + usb-serial cable and GNU Screen!
# what's more frustrating than using `screen` to a serial console then running `less` or `vim` and having it
# not use your full window width & height like a NORMAL ***ING TERMINAL EMULATOR
# this belongs in /etc/systemd/system/serial-getty\@ttyS0.service.d/override.conf
# If your terminal is something other ttyS0, adjust as needed.
# This is for Systemd (Debian Jessie and above, ubuntu Xenial/ Zesty, etc.
# There's a non-systemd equivalent in /etc/login.defs I think
[Service]
Environment="TERM=linux"
@thom-nic
thom-nic / chromedriver.js
Last active April 12, 2017 06:24
Chromedriver auto-start service for WebdriverIO without Selenium
const chromedriver = require('chromedriver');
const retry = require('p-retry');
const http = require('axios');
/**
* Start chromedriver and waits for it to become available before the tests start.
* Call this on wdio.confg `onPrepare`, passing `this` (the wdio config)
*/
function start(config) {
const pollUrl = `http://${config.host || 'localhost'}:${config.port || 4444}${config.path || '/wd/hub'}/status`;
@thom-nic
thom-nic / redux-async-actions.js
Created April 13, 2016 16:59
re: "Two Weird tricks with Redux" by @jlongster
/*
* Re: http://jlongster.com/Two-Weird-Tricks-with-Redux specifically James' comment on having to wait on an action:
*
* redux-thunk returns whatever value is returned by my action. In this case I'm using axios so it already returns a promise.
* So if I want to do something after an async action completes (without having to go through the redux store that gets
* updated by some sort of ACTION_DONE state) I can just `.then()` on the promise returned by my action creator.
*
* Example follows:
*/
@thom-nic
thom-nic / npm ls tree
Created December 19, 2015 02:54
react dependencies
├── axios@0.7.0
├─┬ babel@5.8.34
│ ├─┬ commander@2.9.0
│ │ └── graceful-readlink@1.0.1
│ ├── convert-source-map@1.1.2
│ ├── fs-readdir-recursive@0.1.2
│ ├─┬ glob@5.0.15
│ │ ├─┬ inflight@1.0.4
│ │ │ └── wrappy@1.0.1
│ │ └── once@1.3.3
@thom-nic
thom-nic / jasmine.matcher.toBeInstanceOf.js
Last active December 4, 2015 19:29 — forked from heat/jasmine.matcher.toBeInstanceOf.js
Jasmine Matcher instanceof for Jasmine 2.3 & ES6
/* eslint-env jasmine */
beforeEach(function() {
jasmine.addMatchers({
toBeInstanceOf: (util, customEqualityTesters) => {
return {
compare: (actual, expected) => {
const pass = (actual instanceof expected);
return {
pass,
message: `Expected ${actual} to ${pass ? 'not' : ''} be instance of ${expected}`,
@thom-nic
thom-nic / chunked_transfer_decoder.rb
Last active February 5, 2020 15:23
Rack middleware to decode chunked transfer HTTP request
#require 'rack/request'
# Rack middleware to decode a `Transfer-Encoding: chunked` HTTP request.
#
# USAGE NOTE:
#
# Some HTTP servers (Webrick and Unicorn/Rabinbows/Zbatery) already decode the
# chunked stream, but they leave the 'Transfer-Encoding' header and don't bother
# to add a 'Content-Length' header, which causes rails ActionDispatch::Request
# to not parse the whole request body.
@thom-nic
thom-nic / osx-for-hackers.sh
Last active August 12, 2019 12:23 — forked from brandonb927/osx-for-hackers.sh
OSX environment setup
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@thom-nic
thom-nic / bashup.sh
Created September 26, 2014 00:50
Mac bash upgrade to mitigate the Shellshock exploit
# shellshock upgrade & patch for Mac OSX
# OSX ships with a horribly old version of bash (3.2) which is vulnerable to
# the Shellshock exploit (CVE-2014-6271)
# We use homebrew to get a recent version of bash, then symlink it to
# /bin/bash and /bin/sh (because sh is really bash)
#
# Use this to see if you're vulnerable
# env X="() { :;} ; echo vulnerable" /bin/bash -c "echo testing"
brew update && brew install bash