Skip to content

Instantly share code, notes, and snippets.

View git-push.zsh
gp() {
current_branch=$(git rev-parse --abbrev-ref HEAD)
if echo "$current_branch" | grep -qE '^(master|main|devel)$'; then
read "answer?You're about to push to a MAIN branch, are you sure? [y/N] "
if ! echo "$answer" | grep -qE '^y'; then
echo "aborting..."
return
fi
fi
git push origin HEAD
View kubernetes_pod_status_from_spec.rb
def pod_status_from_spec(spec)
# translated from: https://github.com/kubernetes/kubernetes/blob/a9f6b93b62a98598913180c640ab044c85a6718b/pkg/printers/internalversion/printers.go#L695-L781
# related issue: https://github.com/kubernetes/kubernetes/issues/22839
metadata = spec.fetch("metadata")
pod_status = spec.fetch("status")
reason = pod_status.fetch("phase")
restarts = 0
if pod_status["reason"]
# unsure about this, the go code is opaque
View form4.py
class PirateForm(ModelForm):
class Meta:
model = Pirate
fields = ("name", "is_captain")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cleanup_missing_keys(kwargs.get("data"))
def cleanup_missing_keys(self, data):
View form3.html
{% if user.name == "Alice" %}
<input type=hidden name=is_captain value=false>
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
{% else %}
{{ object.is_captain|yesno:"Yes,No" }} <i>(must be admin to edit)</i>
{% endif %}
View form_condition.html
...
{% if form.can_edit_captain_field() %}
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
{% else %}
...
View form_with_comment.html
{# Keep this condition in sync with PirateForm #}
{% if user.name == "Alice" %}
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
{% else %}
View form1.html
<p>
{{ form.name.errors }}
<label for=id_name>Name:</label>
{{ form.name }}
</p>
<p>
{{ form.is_captain.errors }}
<label for=id_is_captain>Is Captain?:</label>
{% if user.name == "Alice" %}
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
View form0.html
<p>
{{ form.name.errors }}
<label for=id_name>Name:</label>
{{ form.name }}
</p>
<p>
{{ form.is_captain.errors }}
<label for=id_is_captain>Is Captain?:</label>
{% if user %}
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
View form0.py
class PirateForm(ModelForm):
class Meta:
model = Pirate
fields = ("name", "is_captain")
def __init__(self, *args, **kwargs):
user = kwargs.pop("user", None)
super().__init__(*args, **kwargs)
if not user:
@jbbarth
jbbarth / changelog_writer.py
Last active Jan 12, 2017
Usage: ./changelog_writer.py <new_tag> [from_tag]
View changelog_writer.py
#!/usr/bin/env python
import os
import re
import subprocess
import sys
CHANGELOG_FILE = "HISTORY.rst"