Skip to content

Instantly share code, notes, and snippets.

@mansam
mansam / mounting-a-file.md
Last active Jan 16, 2020
Mounting a Secret into a Directory that Already Contains Files on an Image You Don't Control
View mounting-a-file.md

Mounting a Secret into a Directory that Already Contains Files on an Image You Don't Control

In some situations you may want to mount a value from a Secret or ConfigMap as a file in a directory which contains files you'd rather not overwrite. For this, you can use a subPath when defining the volume mount. Lets assume we have a secret my-secret which contains a key ca_bundle.pem.

volumes:
- name: my-secret-volume
 secret:
View keyword_shortcode.php
<?php
function keyword_shortcode($atts, $content = null) {
$custom_factions = array("Chapter", "Legion", "Regiment", "Craftworld", "Masque", "Clan", "Order", "Sept", "Hive Fleet", "Dynasty", "Kabal", "Haemonculus Coven", "Wych Cult", "Ordo");
if (!empty($content)) {
$titlecased_content = ucwords(strtolower($content));
if (in_array($titlecased_content, $custom_factions)) {
return '<span style="font-variant: small-caps; font-weight: bold;">&lt;' . $titlecased_content . '&gt;</span>';
} else {
return '<span style="font-variant: small-caps; font-weight: bold;">' . $titlecased_content . '</span>';
}
View gist:4e8cca8ae3f8b187a039
>>> def by_id(id, **kwargs):
... print(id, kwargs)
...
>>> by_id({'id': 1, 'foobaz': 2, 'bazfoo': 3})
{'foobaz': 2, 'bazfoo': 3, 'id': 1} {}
>>> by_id(**{'id': 1, 'foobaz': 2, 'bazfoo': 3})
1 {'foobaz': 2, 'bazfoo': 3}
>>> by_id(1, **{'id': 1, 'foobaz': 2, 'bazfoo': 3})
View api.py
import uuid
import wtforms_json
from sqlalchemy import not_
from sqlalchemy.dialects.postgresql import UUID
from wtforms import Form
from wtforms.fields import FormField, FieldList
from wtforms.validators import Length
from flask import current_app as app
from flask import request, json, jsonify, abort
View gist:eaadef37ea340e35df33
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
View each.py
def test_each_validator(self):
passes = {
"foo": [1, 2, 3, 4, 5, 6],
"bar": [{"qux": 1}, {"qux": 2}]
}
fails = {
"foo": [1, 2, 3, 4, 5, 11],
"bar": [{"qux": 3}, {"qux": 4, "zot": 5}]
}
validation = {
View gist:10024559

FRIDAY Apr. 11

  • All Your Ducks In A Row: Data Structures in the Standard Library and Beyond
  • Creating Bomb-Proof Data Importers
  • Cache me if you can: memcached, caching patterns and best practices
  • Python Scraping Showdown: A performance and accuracy review of top scraping libraries
  • The Birth & Death of JavaScript
  • Twisted Mixing
  • What Is Async, How Does It Work, And When Should I Use It?
  • Castle Anthrax: Dungeon Generation Techniques
  • Building and breaking a Python sandbox
@mansam
mansam / gist:9332445
Created Mar 3, 2014
Audio device detection w/ pyaudio
View gist:9332445
# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 006: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub
Bus 001 Device 009: ID 1130:f211 Tenx Technology, Inc. TP6911 Audio Headset
# cat d.py
import pyaudio
@mansam
mansam / xrandr_example.txt
Created Feb 5, 2014
Example of configuring dual-head with xrandr.
View xrandr_example.txt
# first, get the names of your displays:
$ xrandr
LVDS-1 connected 1366x768....
# modes...
HDMI-0 connected ...
# modes...
VGA0 connected...
# modes...
# LVDS is your laptop display.