Skip to content

Instantly share code, notes, and snippets.

@qerub
qerub / index.md
Last active November 21, 2021 20:02
Useful macOS commands

How to list non-Apple kernel extensions

kextstat | egrep -v '\bcom.apple.'

How to restart the computer without having to manually unlock FileVault

sudo fdesetup authrestart
@qerub
qerub / httpsExchange.ts
Created December 18, 2016 00:24
[TypeScript] Dependency-free Promise-based Node.js HTTP client
// 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 / lifx.yaml
Created June 25, 2016 23:00
First stab at a Swagger/OpenAPI specification for the LIFX API
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 / properties.xml
Created June 25, 2016 22:01
Good starter properties for Java 8 and Maven
<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>
@qerub
qerub / lifx-http-api.clj
Last active April 3, 2016 11:06
[Clojure] Interacting with LIFX's HTTP API using schemas
;; https://github.com/plumatic/schema
;; https://github.com/dakrone/clj-http
;; http://api.developer.lifx.com/docs/set-state
(ns lifx-http-api
(:require [schema.core :as s]
[clj-http.client :as http]))
(def ^:dynamic *base-url* "https://api.lifx.com/v1/lights")
(def ^:dynamic *auth-token* "<get yours at https://cloud.lifx.com/settings>")
@qerub
qerub / Optionals.java
Last active August 29, 2015 14:08
Java 8: The Missing Parts, Chapter 1: Optionals.java
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
public class Optionals {
@qerub
qerub / fancy-defn.clj
Last active August 29, 2015 14:07
[Clojure] fancy-defn: Proof of concept of schema.core/defn augmented with automatically generated clojure.core.typed annotations via circle.schema-typer
(ns fancy-defn
(:require [schema.core :as s]
[clojure.core.typed :as t]
[circle.schema-typer :as st]))
;; Schemas created with s/defn end up using this.
(defmethod st/convert schema.core.One [schema]
(assert (= false (:optional? schema))) ;; No support for optional arguments yet.
(st/convert (:schema schema)))
@qerub
qerub / gist:96104c9844aa399b679e
Created July 28, 2014 13:24
Integrating Thrift's JSON serializer with Jackson
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 / cwd.sh
Last active August 29, 2015 14:02
Bash script to exec program in given working directory
#!/bin/bash
# Usage: cwd.sh /app /usr/bin/python example.py
cd $1 && exec "${@:2}"
@qerub
qerub / index.md
Last active November 6, 2016 19:17
Useful Docker commands

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