Skip to content

Instantly share code, notes, and snippets.

View johnnypez's full-sized avatar
🏠
Working from home

John Butler johnnypez

🏠
Working from home
  • StitcherAds
  • Ireland
View GitHub Profile
@johnnypez
johnnypez / git-panic-moonwalk.md
Last active June 8, 2018 10:04
Panic Moonwalk

git panic-moonwalk

When you need to get yourself out of an uncomfortable situation...

panic moonwalk

[alias]
  panic-moonwalk = reset --hard
 # back away!
@johnnypez
johnnypez / readme.md
Last active July 21, 2017 21:12
Creating and ECS Optimised AMI with Instance Storage

Launch an instance storage backed ec2 instance with the default ECS Optimized AMI (c3.* or m3.* family) Map /dev/xvdcz to ephemeral0

SSH into it

# stop docker processes
docker ps -q | xargs docker stop

# stop docker
@johnnypez
johnnypez / gist:7757df654a3672310f37
Created January 20, 2016 20:24 — forked from acgourley/gist:9a11ffedd44c414fb4b8
Knex / MySQL Timeout Issue Postmortem

For several weeks our production deployment (Express, Bookshelf/Knex -> MySQL) was randomly having queries fail resulting in 500 errors and server crashes.

The first issue is that the Knex library was using Pool2 slightly incorrectly, and when a ETIMEDOUT error occurred, it tried to release the pooled connection twice. This would create an exception which would crash express (unless you have a top level error handler defined in your express setup)

In this issue (myndzi/pool2#12 (comment)) filed on pool2 by the author of knex (tgriesser) the author of pool2 (myndzi) points out the error handling issue and created a fork of knex with the fix git+https://github.com/myndzi/knex#double-release

After installing the fix on my server, whenever ETIMEDOUT occured an error would be generated in the expected part of the code so that I could decide to retry the query or fail gracefully. Removing the ETIMEDOUT entirely would be

@johnnypez
johnnypez / component.coffee
Last active August 29, 2015 14:10
This is a trivial example of how we connect stores with react components. I'd love to hear any thoughts or feedback on how we handle store versioning, listening etc.
define (require) ->
FooStore = require './foo_store'
ListeningMixin = require './listening_mixin'
_getStateFromStores = ->
ver: FooStore.ver()
foo: FooStore.foo()
React.createClass
mixins: [ListeningMixin]
@johnnypez
johnnypez / react_lifecycle.sublime-completions
Created November 19, 2014 14:27
Lifecycle method completions for ReactJS + Coffeescript
{
"scope": "source.coffee",
"completions":
[
{ "trigger": "propTypes", "contents": "propTypes: {}" },
{ "trigger": "mixins", "contents": "mixins: [$1]" },
{ "trigger": "statics", "contents": "statics: {}" },
{ "trigger": "displayName", "contents": "displayName: '$1'" },
{ "trigger": "getInitialState", "contents": "getInitialState: ->" },
@johnnypez
johnnypez / devops
Created September 20, 2013 15:05
opens random devops reaction for your enjoyment :)
#!/usr/bin/env ruby
require 'open-uri'
require 'rexml/document'
feed = open("http://devopsreactions.tumblr.com/api/read?num=50").read
doc = REXML::Document.new feed
posts = []
REXML::XPath.each doc, '//post' do |node|
posts << node.attributes["url"]
end
@johnnypez
johnnypez / release_name.rb
Created August 21, 2013 14:31
generate an ubuntu style release name
#! /usr/bin/env ruby
require 'yaml'
data = YAML.load(DATA)
adjective = data["adjectives"].sample
animal = data["animals"].select {|a| a.match(/^#{adjective[0]}/)}.sample
puts "#{adjective} #{animal}"
__END__
---
adjectives:
- adorable
@johnnypez
johnnypez / sync_locales
Created August 19, 2013 20:21
syncs keys from en.yml to other exisiting locale files
#!/usr/bin/env ruby
require 'yaml'
require 'active_support'
RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
files = Dir.glob("#{RAILS_ROOT}/config/locales/*.yml")
locales = files.map{|f| File.basename(f, '.yml')}
def flat_hash(hash, k = nil)
@johnnypez
johnnypez / jquery-rails-ajax-events.md
Last active December 17, 2015 08:49
jquery-rails ajax events

# rails:attachBindings

fired when jquery-rails starts attaching bindings to links, forms etc.

# confirm

gives you the opprotunity to skip a confirm dialog by returning a falsy value

# confirm:complete

@johnnypez
johnnypez / .profile
Created April 24, 2013 09:02
shows cwd / user / git branch info in bash prompt
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
function get_git_color() {
isred=`git status -s 2> /dev/null | egrep "^.[^? ]" | wc | awk '{print $1}'`
isorange=`git status -s 2> /dev/null | egrep "^[^? ]" | wc | awk '{print $1}'`