Skip to content

Instantly share code, notes, and snippets.

@bengosney
bengosney / batstat
Created December 8, 2013 20:15
Small script the gives you the battery percentage and colours it green when charging and red when discharging. Returns nothing if battery is 100%. I use it in my bash prompt and set the percentage a little lower.
#!/bin/bash
max_bat=`cat /sys/class/power_supply/BAT0/charge_full`
cur_bat=`cat /sys/class/power_supply/BAT0/charge_now`
per_bat=`echo "scale=0; $cur_bat*100/$max_bat" | bc`
status=`cat /sys/class/power_supply/BAT0/status | grep Discharging`
if [ $per_bat -le 100 ]; then
echo -ne "$(tput sgr0)"

Keybase proof

I hereby claim:

  • I am bengosney on github.
  • I am 00dog (https://keybase.io/00dog) on keybase.
  • I have a public key whose fingerprint is 5DCA 60FD DC95 174F FAB7 E08E 9059 AFB5 FD42 59E8

To claim this, I am signing this object:

Turn it pinkish
gatttool -b D0:39:72:C8:40:F0 --char-write-req -a 0x0043 -n 56ff5e5300f0aa
Warm
56000000ff0faa
56000000860faa
BB - brightness of warm
Colour
56 RR GG BB 00f0aa
@bengosney
bengosney / gist:06b611c051c0f3e6d8837c9adbd553b9
Created April 8, 2016 10:27
Ansible timezone for CentOS
---
- name: Check current timezone
shell: "timedatectl | gawk -F'[: ]+' ' $2 ~ /Timezone/ {print $3}'"
register: current_zone
changed_when: False
- name: Set UTC timezone
file: src=/usr/share/zoneinfo/{{ timezone }} dest=/etc/localtime state=link force=yes
when: current_zone.stdout != '{{ timezone }}'
@bengosney
bengosney / click_email_type.py
Created March 15, 2017 17:17
Email validator type for the click package http://click.pocoo.org/6/
import re
class EmailParamType(click.ParamType):
name = 'email'
email_re = re.compile(r"[^@]+@[^@]+\.[^@]+")
def convert(self, value, param, ctx):
if self.email_re.match(value):
return value
else:
@bengosney
bengosney / node-mkdirp.js
Last active January 12, 2018 15:50
`mkdir -p` for node, will create all missing directories. Please don't install a full blown npm package for 19 lines of code!
// Copyright 2018 Ben Gosney - MIT licence - https://opensource.org/licenses/MIT
const fs = require('fs');
const mkdirp = (full_path) => {
while (!fs.existsSync(full_path)) { // loop untill the full path excists
let part_path = full_path;
while(!fs.existsSync(part_path)) { // this will be true after we find a dir we can make then loop and start again
try {
@bengosney
bengosney / commit-msg
Created August 15, 2019 09:51 — forked from romellem/commit-msg
Git hook - Post-commit spell check (using `aspell`)
#!/bin/bash
ASPELL=$(which aspell)
if [ $? -ne 0 ]; then
echo "Aspell not installed - unable to check spelling" >&2
exit
else
WORDS=$($ASPELL --mode=email --add-email-quote='#' list < "$1" | sort -u)
fi
if [ -n "$WORDS" ]; then
printf "\e[1;33m Possible spelling errors found in commit message:\n\e[0m\e[0;31m%s\n\e[0m\e[1;33m Use git commit --amend to change the message.\e[0m\n\n" "$WORDS" >&2
@bengosney
bengosney / Makefile
Last active May 3, 2021 13:17
serve current dir over https
.PHONY := serv, cleancd
.DEFAULT_GOAL := serv
SCRIPTFILE=simple-https-server.py
CERT=server.pem
IP=$(shell hostname -I | cut -f 1 -d " ")
DIR=$(shell pwd)
$(SCRIPTFILE):
@echo "" > $@
@bengosney
bengosney / Makefile
Last active June 23, 2023 08:01
Python Makefile
.PHONY: help clean test install all init dev
.DEFAULT_GOAL := install
.PRECIOUS: requirements.%.in
HOOKS=$(.git/hooks/pre-commit)
REQS=$(wildcard requirements.*.txt)
PYTHON_VERSION:=$(shell python --version | cut -d " " -f 2)
PIP_PATH:=.direnv/python-$(PYTHON_VERSION)/bin/pip
WHEEL_PATH:=.direnv/python-$(PYTHON_VERSION)/bin/wheel
@bengosney
bengosney / horizontal-scroll-shadow.scss
Created January 6, 2022 15:53
Add horizontal scroll shadow to an element
$size: 15px;
$background: white;
background-image:
linear-gradient(to right, $background, $background),
linear-gradient(to right, $background, $background),
radial-gradient(ellipse closest-side, rgba(0,0,0,.25) 0%,rgba(0,0,0,0) 100%),
radial-gradient(ellipse closest-side, rgba(0,0,0,.25) 0%,rgba(0,0,0,0) 100%);
background-position: left center, right center, -($size / 2) center, right (-($size / 2)) center;
background-repeat: no-repeat;
background-color: $background;