Skip to content

Instantly share code, notes, and snippets.

View cuu508's full-sized avatar

Pēteris Caune cuu508

View GitHub Profile
@cuu508
cuu508 / androidicon.py
Created April 27, 2011 19:28
GIMP plugin for applying Android menu icon style
#!/usr/bin/env python
# GIMP plugin for applying Android menu icon style
# For batch processing, use it like this:
# gimp -i --batch-interpreter=python-fu-eval -b 'pdb.python_fu_androidicon_batch(None, None, "/path/to/pictures/*.svg", "/path/to/res");pdb.gimp_quit(1)'
from gimpfu import *
import glob
import os
import shutil
@cuu508
cuu508 / ExpandablePanel.java
Created April 28, 2011 23:37
Expandable Panel Android widget -- WIP
package com.example.myapp.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
from collections import*
from re import*
Phrase=type("",(str,),{"word_count":lambda o:Counter(findall("\w+",o.lower()))})
def deploy():
""" Checks out code, prepares venv, runs management commands,
updates supervisor and nginx configuration. """
now = datetime.datetime.today()
now_string = now.strftime("%Y%m%d-%H%M%S")
project_dir = "/home/hc/webapps/hc-%s" % now_string
venv_dir = os.path.join(project_dir, "venv")
svn_url = "https://github.com/healthchecks/healthchecks/trunk"
location ~ ^/(\w\w\w\w\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w\w\w\w\w\w\w\w\w)/?$ {
add_header Content-Type text/plain;
postgres_pass database;
postgres_output value;
postgres_escape $ip $remote_addr;
postgres_escape $agent =$http_user_agent;
postgres_escape $body =$request_body;
def switch(tag, project_dir):
# Supervisor
supervisor_conf_path = "/etc/supervisor/conf.d/hc_%s.conf" % tag
upload_template("supervisor/hc.conf.tmpl",
supervisor_conf_path,
context=locals(),
backup=False,
use_sudo=True)
upload_template("supervisor/hc_sendalerts.conf.tmpl",
<!-- Template emails/report-body-text.html -->
Hello,
This is a monthly report sent by healthchecks.io.
{% include "emails/summary-text.html %}
Cheers,
The healthchecks.io Team
class IncludeNode(Node):
context_key = '__include_context'
# ... constructor etc. ...
def render(self, context):
try:
# ... template gets rendered here ...
except Exception as e:
if context.template.engine.debug:
@cuu508
cuu508 / checkloadavg.sh
Last active September 26, 2018 08:06
Report load average to Healthchecks.io. If it's above the configured threshold, use the "/fail" endpoint
# Run this from cron every minute:
# * * * * * checkloadavg.sh
CODE=ca75b1df-4f4e-4711-8dc0-f21eeb4b0dac
AVG=$(cat /proc/loadavg | cut -d " " -f 1)
THRESHOLD=0.5
if (( $(echo "$AVG > $THRESHOLD" | bc -l) )); then
curl --retry 3 -d "Load average: $AVG" -X POST https://hc-ping.com/$CODE/fail
else
@cuu508
cuu508 / coverage_but_not_quite.py
Created April 15, 2021 11:10
Detect which lines can be removed from a .py file without breaking tests
import subprocess
path = "hc/api/views.py"
test_cmd = "python manage.py test --keepdb --parallel=8 -v 0"
original = open(path, "r").read()
report = open("report-%s.txt" % path.replace("/", "."), "w")
lines = original.split("\n")
for idx in range(0, len(lines)):