Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / play.yml
Created July 23, 2017 23:00
Ansible to run code only on a single manager node
- hosts: server_swarm
tasks:
- command: "docker info --format '{%raw%}{{json .Swarm.ControlAvailable}}'{%endraw%}"
register: result
become: true
- debug: msg='Deploy on this host'
when: result.stdout == 'true'
run_once: true
@toast38coza
toast38coza / create-secret.sh
Last active July 23, 2017 23:30
Secrets with docker-compose
echo "This is a secret" | docker secret create my_secret_data -
@toast38coza
toast38coza / http_status.py
Last active April 2, 2018 11:13
HTTP status codes as a dict. Source: https://httpstatuses.com/
STATUS_CODES = {
100: "100 Continue",
101: "101 Switching Protocols",
102: "102 Processing",
200: "200 OK",
201: "201 Created",
202: "202 Accepted",
203: "203 Non-authoritative Information",
204: "204 No Content",
FROM python:3.4
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
@toast38coza
toast38coza / what.three.words.py
Created March 16, 2017 15:57
Playing around with What.Three.Words in python
# pip install what3words
# setup:
api_key = environ['W3W_API_KEY']
w3w = what3words.Geocoder(api_key)
# forward: 3 words to address:
In [18]: w3w.forward(addr='prom.cape.pump')
Out[18]:
@toast38coza
toast38coza / vuex_persist.js
Created January 18, 2017 13:20
Dump the entire vuex store to localStorage and retrieve it again.
// key to use for get/set state:
export const LOCALSTORAGE_KEY = '..'
// as an action:
export const PERSIST_ACTION = ({ rootState }) => {
let stateAsString = JSON.stringify(rootState)
window.localStorage.setItem(LOCALSTORAGE_KEY, stateAsString)
}
// restore a cached vuex store:
@toast38coza
toast38coza / App.vue
Last active January 13, 2017 07:06
Quickstart Framework7-vue setup for a typical VueJS webpack project
<template>
<!-- App -->
<div id="app">
<!-- Statusbar -->
<f7-statusbar></f7-statusbar>
<!-- Left Panel -->
<f7-panel left reveal layout="dark">
<f7-view id="left-panel-view" navbar-through :dynamic-navbar="true">
@toast38coza
toast38coza / getting_your_token.sh
Last active November 11, 2016 12:20
Using the Google natural language API with python
# install gcoud SDK https://cloud.google.com/sdk/downloads
gcloud auth activate-service-account --key-file=/path/to/project/application-key.json
gcloud auth print-access-token
@toast38coza
toast38coza / README.md
Created September 14, 2016 09:38
vuex-counter-plain-old-javascript

A Simple Vuex example in old-skool JavaScript

Because learning all the things: new framework (Vue), new Architecture (Flux), new JavaScript (ES6), new build tools (Browserify, WebPack) all in one can be a little daunting ...

I've kept the below example as simple and bare-bones as possible. One html file with everything you need. You can simply open index.html in your favorite browser to see it in action.

Or, if you want to run it with a server:

@toast38coza
toast38coza / README.md
Last active November 4, 2019 08:26
Take a large file and cache it in memcached

Installation

pip install -r requirements.txt

Run

python chunker.py