Skip to content

Instantly share code, notes, and snippets.

View stackmagic's full-sized avatar

Patrick Huber stackmagic

  • Zurich, Switzerland
View GitHub Profile
import paho.mqtt.client as paho
import RPi.GPIO as GPIO
import json, time
# device credentials
device_id = '<DEVICE_ID>' # * set your device id (will be the MQTT client username)
device_secret = '<DEVICE_SECRET>' # * set your device secret (will be the MQTT client password)
random_client_id = '<CLIENT_ID>' # * set a random client_id (max 23 char)
# -------------- #
@stackmagic
stackmagic / test.sh
Created January 27, 2015 12:26
Always test your pupper modules
#!/bin/bash
#DEBUG="--verbose --debug"
hash puppet 2>/dev/null || { echo >&2 "Please install puppet"; exit 2; }
[ -z "$(facter | grep fqdn)" ] && { echo >&2 "Your machine has no FQDN (according to facter), some tests may fail or print warnings"; sleep 5; }
for dir in $(find . -type d -name tests); do
for file in $(find ${dir} -name '*.pp'); do
echo ">>> TESTING ${file}"
puppet apply ${DEBUG} --modulepath modules --noop "${file}" || { echo ">>> ERROR" ; HAS_FAILURES="true" ; }
@stackmagic
stackmagic / fix.sh
Created January 27, 2015 12:25
Debian file permissions fubar fix
# most basic permission fixes
chmod 1777 /tmp
chown root:root /tmp
chown -R man:root /var/cache/man
# reinstall some core tools
aptitude reinstall bash
aptitude reinstall man-db manpages
aptitude reinstall dpkg apt aptitude-common apt-listchanges apt-utils aptitude debconf
@stackmagic
stackmagic / jolokia.sh
Created January 27, 2015 12:24
dump everything jolokia offers
for name in $(curl --silent http://dwtest:10002/search/*:* | python -m json.tool | grep '"value":' -A9999 | tail -n +2 | head -n -2 | sed 's/ /%20/g' | cut -d'"' -f2);
do curl --silent "http://dwtest:10002/read/$name" | python -m json.tool;
done
@stackmagic
stackmagic / build.gradle
Created January 27, 2015 12:22
Reusing gradle repository definitions. Don't repeat yourself
// add your repositories here
buildscript {
repositories {
mavenLocal()
jcenter()
maven {
credentials {
username 'user'
password 'pass'
@stackmagic
stackmagic / custombuild.sh
Created January 27, 2015 12:12
building custom libs and uploading them to java with sometimes necessary pom.xml manipulations
#!/bin/bash
set -e
##
## SETUP
##
VERSION="4.2.${BUILD_NUMBER}.yourorg"
REPO="https://yourorg.com/nexus/content/repositories/yourorg"
// buildscript is necessary so shadow is available within this build script.
// we use it to package shadow with our own plugins so the user only needs
// to add one dependency, because the plugins themself use shadow too.
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
@stackmagic
stackmagic / gist:6d2bfb876209bb1e3eb3
Created September 24, 2014 10:55
JavaExec bootstrapClasspath issue
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
configurations {
bootClassPath
package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
# oneliner
for file in $(egrep -r "part1\.[a-Z]+\.part2" . | cut -d: -f1 | sort -u); do echo $file; awk '!(/part1/ && /part2/) { print $0 }' $file > tmp && mv tmp $file; done
# the same a little nicer
for file in $(egrep -r "part1\.[a-Z]+\.part2" . | cut -d: -f1 | sort -u); do
echo $file
awk '!(/part1/ && /part2/) { print $0 }' $file > tmp && mv tmp $file
done