Skip to content

Instantly share code, notes, and snippets.

View serverwentdown's full-sized avatar

Ambrose Chua serverwentdown

View GitHub Profile
# ensure DBUS_SESSION_BUS_ADDRESS and DISPLAY is set
git commit -am "`rhythmbox-client --print-playing-format "%ta - %tt @ %te"`"
@serverwentdown
serverwentdown / slackbot.sh
Last active August 29, 2015 14:27
Sends messages as a slackbot
#!/bin/zsh
function json_escape(){
echo -n "$1" | python -c 'import json,sys; print json.dumps(sys.stdin.read())'
}
function json_escape_file() {
cat $1 | python -c 'import json,sys; print json.dumps(sys.stdin.read())'
}
SLACK_URL="https://hooks.slack.com/services/bla/bla/bla"
@serverwentdown
serverwentdown / wikisum.sh
Created August 10, 2015 15:56
Downloads the Wikipedia article and parses it for the first paragraph as a summary
#!/bin/zsh
SUMMARY=`curl -Ls "http://en.wikipedia.org/wiki/Special:Search?search=${*// /+}" | grep "<p>.*<\/p>" | head -n 1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | sed -E 's/\[[^>]{1,2}\]//g'`
echo -n $SUMMARY
if [ -n "$SUMMARY" ]; then echo; fi;
[ -n "$SUMMARY" ]
@serverwentdown
serverwentdown / updatebind.sh
Last active August 29, 2015 14:26
Random script to update bind
sed "s/^$SUB\t$RECORD\t.*/$SUB\t$RECORD\t$ADDRESS/g"
@serverwentdown
serverwentdown / autobars.html
Created June 5, 2015 07:11
Basic client-side handlebars templating.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/x-handlebars-template">
<ul>
{{#each items}}
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 1
@serverwentdown
serverwentdown / httpserver.ino
Created May 11, 2015 16:48
RN-XV webserver with WiFlyHQ modified from example sketch to not require physical modifications to a Arduino + Wireless SD + RN-XV setup. (i.e. no shorting pin 8&0 and 9&1)
/*
* WiFlyHQ Example httpserver.ino
*
* This sketch implements a simple Web server that waits for requests
* and serves up a small form asking for a username, then when the
* client posts that form the server sends a greeting page with the
* user's name and an analog reading.
*
* This sketch is released to the public domain.
*
from time import *
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD) # Use physical layout as reference pins
MATRIX = [[1, 2, 3, "A"],
[4, 5, 6, "B"],
[7, 8, 9, "C"],
["*", 0, "#", "D"]]
ROW = [13, 15, 19, 21]
from time import *
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD) # Use physical layout as reference pins
MATRIX = [[1, 2, 3, "A"],
[4, 5, 6, "B"],
[7, 8, 9, "C"],
["*", 0, "#", "D"]]
ROW = [13, 15, 19, 21]
@serverwentdown
serverwentdown / server.js
Created April 3, 2015 12:17
A tiny xip.io clone quickly written in node.js. Requires module dnsd. Sample site at .addr.eurica.eu.org. Report vulnaribilities if any! :-)
var dnsd = require('dnsd');
var server = dnsd.createServer(handler);
server.zone('addr.eurica.eu.org', 'eurica.eu.org', 'webmaster@eurica.eu.org', 'now', '2h', '30m', '2w', '10m');
server.listen(5354);
console.log("Server running at " + server.ip + ":" + server.port);
function handler(req, res) {
var question = res.question[0];
var hostname = question.name;