Skip to content

Instantly share code, notes, and snippets.

View alanshaw's full-sized avatar
🌶️
https://storacha.network

ash alanshaw

🌶️
https://storacha.network
View GitHub Profile
@alanshaw
alanshaw / upstart-to-systemd.md
Created November 24, 2016 13:08
upstart -> systemd

upstart -> systemd

I can recommend having a quick read through this: https://wiki.ubuntu.com/SystemdForUpstartUsers

Instead of putting your upstart config in /etc/init you put it in /etc/systemd/system and it has a different format. Systemd configs are called "units" and (for us) look like:

[Unit]
Description=Job that runs the {{service}} service
@alanshaw
alanshaw / instructions.md
Created December 1, 2016 17:09
Using react-native-config-node with jest and other test runners

I’ve figured out how to use react-native-config-node with other test runners (I'm using jest) that might be a bit simpler and more generic than the method described in the README:

I installed the two modules:

npm install react-native-config-node babel-plugin-import-rename --save-dev

...and added the following config to my .babelrc:

@alanshaw
alanshaw / rm-node_modules.sh
Created December 6, 2016 16:13
Remove node_modules
# list individual size
find . -name node_modules -maxdepth 3 -exec du -hs {} \;
# calc total size
find . -name node_modules -maxdepth 3 | du -hs
# remove
find . -name node_modules -maxdepth 3 -exec rm -rf {} \;
@alanshaw
alanshaw / recurse.js
Created February 7, 2017 14:00
Retry in watt, each retry adds a new stack frame
const watt = require("watt")
const send = watt(function* (next) {
try {
// oh noes, an err occurred
throw new Error('Unexpected things')
} catch (err) {
// Wait for a bit before retry
yield setTimeout(next)
return send()
@alanshaw
alanshaw / git-serve.md
Created April 25, 2017 10:10
git server

You can set an alias to spin up a git server so you can share what you're working on over a local network:

git config --global alias.serve '!server(){ git daemon --verbose --export-all --base-path=. --reuseaddr $@; }; server'

Now you can do git serve --port=9999 and somebody else can git pull git://YOUR-IP:9999/ to get a copy of your code.

@alanshaw
alanshaw / contactsText-in-ellipsis.md
Created July 17, 2017 14:41
Selenium containsText within ellipsis

For some reason in nightwatch assert.containsText and getText return an empty string for elements who's text content is hidden in ellipsis.

Here's a workaround:

const sel = '[data-id=foo]'

// Often hidden in ellipsis - workaround get via textContent instead getText
// https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5773
this.getAttribute(sel, 'textContent', ({ value }) => {
# Create a patch file for the last 3 commits
git format-patch -3
# Apply patch file
git apply [filename]
@alanshaw
alanshaw / mes.md
Last active July 20, 2017 12:33
Nes + minimongo

Mes

Ties Nes + minimongo together for gloryful reactive apps.

Server

// opts are Nes server.subscription options
server.mes.subscription('/item/{_id}', opts, (reply) => {
@alanshaw
alanshaw / getElementsState.js
Created July 21, 2017 16:38
Nightwatch commands for getting state of multiple elements
// Get state for multiple elements
// getState is passed an element and should return a promise that gets some state
// e.g. http://nightwatchjs.org/api#elementIdText
// Callback will be called with an array of the state values once they're all resolved
exports.command = function getElementsState (selector, getState, callback) {
this.elements('css selector', selector, function (elements) {
const values = elements.value.map(getState)
Promise.all(values).then(callback)
})
return this
@alanshaw
alanshaw / revert-master-to-upstream.sh
Last active October 3, 2017 12:47
How to revert Master branch to upstream
# https://stackoverflow.com/questions/8134960/how-to-revert-master-branch-to-upstream
git remote update
# the double hyphen ensures that upstream/master is
# considered as a revision and not confused as a path
git reset --hard upstream/master --
git push origin +master