Skip to content

Instantly share code, notes, and snippets.

View Pindar's full-sized avatar

Simon Dittlmann Pindar

View GitHub Profile
function levenshtein (s1, s2) {
// From: http://phpjs.org/functions
// + original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
// + bugfixed by: Onno Marsman
// + revised by: Andrea Giammarchi (http://webreflection.blogspot.com)
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + reimplemented by: Alexander M Beedie
// * example 1: levenshtein('Kevin van Zonneveld', 'Kevin van Sommeveld');
// * returns 1: 3
if (s1 == s2) {
@Pindar
Pindar / temp_aws_key.sh
Created March 5, 2014 16:29
extract temporary aws keys
#!/bin/bash
# requires http://stedolan.github.io/jq/
AWS_ROLE_NAME=`wget -O - -q 'http://169.254.169.254/latest/meta-data/iam/security-credentials/'`
wget -O mycreds -q "http://169.254.169.254/latest/meta-data/iam/security-credentials/$AWS_ROLE_NAME"
SECRET_KEY=`jq -r '.SecretAccessKey' <mycreds`
ACCESS_KEY=`jq -r '.AccessKeyId' <mycreds`
TOKEN=`jq -r '.Token' <mycreds`
cat >temp_credentials <<EOM
AWSAccessKeyId=$ACCESS_KEY
@Pindar
Pindar / coap-server.js
Created June 5, 2014 15:31
CoAP Observer Try
#!/usr/bin/env node
/*
HOW TO:
1) install required tools
- npm install coap --save
- npm install coap-cli -g
2) run the server: chmod +x coap-server.js && ./coap-server.js
3) observe a resource
- coap get -o coap://localhost/message
@Pindar
Pindar / convert-encoding.sh
Last active August 29, 2015 14:05
Convert encoding
for file in *.php do
iconv -f cp1252 -t utf8 "$file" > "$file.new" && mv -f "$file.new" "$file"
done
@Pindar
Pindar / Gruntfile-snippet.js
Created October 1, 2014 09:16
usage of download-github-release grunt plugin
grunt.initConfig({
'download-github-releases': {
user: 'GITHUB_USER',
repo: 'REPOSITORY',
tag: 'TAG_NAME',
token: process.env.GITHUB_RELEASE_ACCESS_TOKEN,
outputDir: 'DOWNLOAD_DIRECTORY'
},
mkdir: {
githubmodules: {
@Pindar
Pindar / gist:300d3424f05410ad7c04
Last active August 29, 2015 14:16
set-env.sh
#!/bin/bash
FILE=${1}
ENVIRONMENT=${2}
SERVICE_NAME=${3}
ETCD=${4:-"127.0.0.1:4001"}
if [[ $FILE == "" || $ENVIRONMENT == "" || SERVICE_NAME == "" ]]; then
@Pindar
Pindar / git.sh
Created July 28, 2015 09:07
git commands
# restore file
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
# stage files with review
git add -p .
@Pindar
Pindar / backup-folder.sh
Created January 9, 2016 16:51
Backup files through rsync
#!/bin/bash
rsync -arq --exclude='.DS_Store' --exclude='.wdmc' /DataVolume/shares/Public/Shared\ Pictures/ nas:/DataVolume/Backup/Pictures/
@Pindar
Pindar / README.md
Last active February 13, 2023 21:23 — forked from mill1000/README.md
Headless A2DP Audio Streaming on Raspbian Stretch

About

This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

Motivation

A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:

  • Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
  • Simple - This solution has few dependencies, readily available packages and minimal configuration.
  • Up to date

Prerequisites

#!/usr/bin/env python3
import os
from subprocess import check_output
from gpiozero import Button
from signal import pause
import time
def playPause():
os.system("mpc toggle")