Skip to content

Instantly share code, notes, and snippets.

@qerub
qerub / lifx-sunrise-simulator.rb
Last active Sep 9, 2020
LIFX Sunrise Simulator
View lifx-sunrise-simulator.rb
require "lifx" # http://www.rubydoc.info/gems/lifx
def calculate_color(i) # 0 <= i <= 1
h = [40 * 2 * i, 40].min # will be 40 (yellow) at i=1/2 and stay there
s = 1.0 - [(i - 0.5) * 2, 0].max # will be 1 until i=1/2 and then go down to 0
b = i
LIFX::Color.hsbk(h, s, b, LIFX::Color::KELVIN_MIN)
end
duration = 10 * 60 # seconds
@qerub
qerub / spiped-ssh.plist
Created Dec 19, 2013
Piping sshd through spiped running as an OS X launch daemon
View spiped-ssh.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>spiped-ssh</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/spiped</string>
<string>-d</string>
@qerub
qerub / vm_sync_shutdown.rb
Last active Jan 18, 2020
Script to shutdown a libvirt VM/domain and wait for completion
View vm_sync_shutdown.rb
#!/usr/bin/env ruby
require "libvirt"
def vm_sync_shutdown(name)
conn = Libvirt::open("qemu:///system")
dom = conn.lookup_domain_by_name(name)
# TODO: Use dom.state instead of dom.info.state when it gets available
@qerub
qerub / httpsExchange.ts
Created Dec 18, 2016
[TypeScript] Dependency-free Promise-based Node.js HTTP client
View httpsExchange.ts
// Based on https://www.tomas-dvorak.cz/posts/nodejs-request-without-dependencies/
import * as https from "https";
async function httpsExchange(requestOptions: https.RequestOptions): Promise<string> {
return new Promise<string>((resolve, reject) => {
const request = https.request(requestOptions, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error("Non-2xx status code: " + response.statusCode));
}
@qerub
qerub / HttpsFilter.java
Last active Feb 27, 2018
Servlet filter for forcing HTTPS when behind a SSL termination proxy that sends X-Forwarded-Proto
View HttpsFilter.java
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import static java.lang.String.format;
public class HttpsFilter implements Filter {
@qerub
qerub / lifx.yaml
Created Jun 25, 2016
First stab at a Swagger/OpenAPI specification for the LIFX API
View lifx.yaml
swagger: "2.0"
info:
title: LIFX HTTP Remote Control API
version: v1
description: https://api.developer.lifx.com/
host: api.lifx.com
basePath: /v1
schemes:
- https
produces:
@qerub
qerub / svn-diff-color.sh
Created May 8, 2011
Wrapper for svn diff that sets --diff-cmd=colordiff
View svn-diff-color.sh
#!/bin/sh
# http://colordiff.sourceforge.net/
if tty -s; then
exec svn diff --diff-cmd=colordiff "$@" | less -R
else
exec svn diff --diff-cmd=colordiff "$@"
fi
@qerub
qerub / gist:96104c9844aa399b679e
Created Jul 28, 2014
Integrating Thrift's JSON serializer with Jackson
View gist:96104c9844aa399b679e
class ThriftSerializer extends JsonSerializer<TBase> {
@Override
public void serialize(TBase value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
try {
TProtocolFactory f = new TSimpleJSONProtocol.Factory();
String s = new TSerializer(f).toString(value);
jgen.writeRawValue(s);
}
catch (TException e) {
throw new IOException(e);
@qerub
qerub / index.md
Last active Nov 6, 2016
Useful Docker commands
View index.md

How to remove dangling/untagged images

docker images -q -f dangling=true | xargs docker rmi

How to remove stopped/exited containers

docker ps -q -f status=exited | xargs docker rm
@qerub
qerub / properties.xml
Created Jun 25, 2016
Good starter properties for Java 8 and Maven
View properties.xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
You can’t perform that action at this time.