Skip to content

Instantly share code, notes, and snippets.

@altercation
altercation / dispreset.sh
Created May 18, 2022 16:58
Display Reset Script for macOS
#!/bin/sh
# dispreset:
# When called reset displays to last known arrangement using displayplacer
# if called within a timeout period (30 seconds), swap position.
# This is to work around the fact that in certain multimonitor configurations
# macOS fails to properly ID the displays using serial numbers pulled in via
# EDID and so loses track about which monitor is left/right positioned.
@nosmokingpistol
nosmokingpistol / Swagger Setup for Embedded Jetty Server.md
Last active November 8, 2023 11:13
Setup Swagger with an embedded Jetty Server

Swagger Setup for Embedded Jetty Server

In setting up a Jetty server with Jersey servlets, you may choose to use an embedded Jetty server setup. (See here for how to setup an embedded Jetty server). In this gist, we'll go through how to setup Swagger for this setup. I am using Swagger 1.5, Maven 3.3.3, Jersey 1.8, and Jetty 7.3. Make sure you add all dependencies to your pom.xml.

In the Swagger Core setup, the current official recommendations involve an Application class, or a web.xml, neither of which are used in an embedded Jetty server setup. To add Swagger to your embedded Jetty Server, you must do 3 things:

  1. Add the package scanning packages to your servlets which will serve your REST API.
  2. Add the Swagger package scanning servlet.
  3. P
@JakeWharton
JakeWharton / Oauth1SigningInterceptor.java
Last active November 27, 2023 10:04
An OkHttp interceptor which does OAuth1 signing. Requires Guava and Java 8, although those dependencies wouldn't be too hard to break if you didn't have them.
/*
* Copyright (C) 2015 Jake Wharton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@jayeb
jayeb / gist:c63b5f15bbd224e52b25
Created October 1, 2014 18:24
Google Play Music: Jump to random album
(function() {
var w = window,
getRandomAlbum = function() {
var albums, r, rAlbum;
if (w.location.hash == '#/albums') {
albums = document.querySelectorAll('div[data-type="album"]');
r = Math.random();
rAlbum = albums[Math.floor(r * albums.length)];
w.removeEventListener('hashchange', getRandomAlbum, false);
w.location.hash = '/album/' + rAlbum.dataset.id;
@edehde
edehde / README.md
Last active June 3, 2019 15:59
enables brew install maven30
@johnlcox
johnlcox / Preconditions.cs
Created February 25, 2013 19:34
C# Preconditions
public class Preconditions
{
/// <summary>
/// Ensures that an object reference passed as a parameter to the calling method is not null.
/// </summary>
/// <param name="reference">an object reference</param>
/// <param name="errorMessage">the exception message to use if the check fails</param>
/// <returns>the non-null reference that was validated</returns>
/// <exception cref="NullReferenceException">if reference is null</exception>
public static T CheckNotNull<T>(T reference, string errorMessage)
@valotas
valotas / tomcat.sh
Created May 31, 2011 07:11
Tomcat init.d script
#!/bin/bash
#
# tomcat7 This shell script takes care of starting and stopping Tomcat
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network $syslog
# Required-Stop: $network $syslog