Skip to content

Instantly share code, notes, and snippets.

View seansawyer's full-sized avatar

Sean Sawyer seansawyer

View GitHub Profile
@seansawyer
seansawyer / socket_lock.php
Last active August 29, 2015 14:20
Interprocess locking in PHP with Unix domain sockets
<?php
/**
* Try to acquire an arbitrarily-named lock by binding a Unix
* (family AF_UNIX) datagram (type SOCK_DGRAM) socket to an
* abstract address corresponding to the lock name. On success,
* the bound socket resource is returned (or null, on
* failure). You may either call unlock() with that resource to
* release the lock explicitly, or rely on the operating system
* to clean up the socket when the process exits.
@seansawyer
seansawyer / hex_to_bit_varying.sql
Last active February 2, 2017 09:40
PL/pgSQL function to convert a hexadecimal string to a bit varying
DROP FUNCTION IF EXISTS hex_to_bit_varying(hex_string text);
CREATE FUNCTION hex_to_bit_varying(hex_string text) RETURNS bit varying AS $$
DECLARE
bytes bytea = decode(hex_string, 'hex');
n int = length(bytes) * 8 - 1;
bits bit varying := B''::bit varying;
BEGIN
-- RAISE NOTICE 'bytes=%, n=%', bytes, n;
-- RAISE NOTICE 'bits=%', bits;
FOR i IN 0 .. n BY 8 LOOP
@seansawyer
seansawyer / ocvpn
Created April 17, 2015 19:08
OpenConnect VPN script
#!/bin/sh
#
# Originally part of vpnc source code:
# © 2005-2012 Maurice Massar, Jörg Mayer, Antonio Borneo et al.
# © 2009-2012 David Woodhouse <dwmw2@infradead.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@seansawyer
seansawyer / README.md
Last active August 25, 2022 14:49
Managing OpenStack instances with Ansible through an SSH bastion host

Managing OpenStack instances with Ansible through an SSH bastion host

I'm be using DreamCompute as my OpenStack provider, but there are dozens to choose from. I assume you already have Ansible and the OpenStack CLI tools installed.

Motivation

With the proliferation of OpenStack public clouds offering free and intro tiers, it's becoming very easy to effectively run a simple application for free or nearly free. Also with the emergence of Ansible, you don't need to learn and deploy complicated tools to do configuration management.

@seansawyer
seansawyer / ThriftIdl.scala
Last active August 29, 2015 14:16
Parboiled parser definition for Thrift IDL
package com.rsglab.chimpquery.consumer.thrift
import org.parboiled.scala._
/**
* Parboiled parser definition for Thrift IDL
* @see https://thrift.apache.org/docs/idl
*/
class ThriftIdl extends Parser {
/**
@seansawyer
seansawyer / vim-eclim-scala.md
Last active May 26, 2021 02:58
Vim + Eclim for Scala development

Vim + Eclim + Scala

WARNING! Do not install anything from update sites before installing Eclim! This is because Eclim determines available project natures (android, scala, etc) by trying to discover them at install time. If they are installed on a per-user basis, it won't find them. If you're installing Eclim for use with an existing Eclipse install

You're also better off not to install any plugins via your package manager. Eclim will give you the option to install plugins associated with each project nature from its install wizard.

Install Eclipse Luna. On Arch Linux, it's available in extra.

pacman -Sy eclipse

Can I make a game in a Gist?

I'll write the world in YAML first, and write the code to stitch it together last.

Maybe I can use Mermaid to draw the map.

@seansawyer
seansawyer / response.json
Last active August 29, 2015 14:08
Response format for post creation
{
"cloned": true,
"content": "---\nlayout: post\ntitle: \"Welcome to the Dirty\"\ndate: 2014-11-08 13:27:37\n\n# user-defined metadata\nimage:\n url: http://instagram.com/p/tO77AKB5QU/\n numdogs: 2\n numgirls: 1\n names:\n - Rebel\n - Dirty\n - Dog\n---\n\n\n## Dirty's Staff\n\nThere are {{page.image.numdogs}} dogs and {{page.image.numgirls}} babe work at Dirty's.\n\nTheir names are:\n{% for names in page.image.names %}\n* {{names}}\n{% endfor %}\n\n### Company Photo\n\n{% assign url={{page.image.url}} %}\n{% include embedly.html url=url %}\n",
"front_matter_json": {
"date": "Sat, 08 Nov 2014 13:27:37 GMT",
"image": {
"names": [
"Rebel",
"Dirty",
"Dog"
@seansawyer
seansawyer / gist:88a16373a3d2c2a939b1
Last active September 21, 2015 22:11
Vagrant + Ansible crash course

Install Virtualbox, Vagrant and Ansible.

Create a new directory for your first Vagrant VM. In that directory, create a Vagrantfile using vagrant init, and enable the Ansible provisioner by adding the following.

config.vm.provision "ansible" do |ansible|
  ansible.playbook = "playbook.yml"
end

Now you can create an Ansible playbook named playbook.yml file in the same directory as your Vagrantfile, and vagrant provision will run it. Here's an easy one to start with that will update NSS and add the EPEL and IUS repositories.