Skip to content

Instantly share code, notes, and snippets.

View jsumners's full-sized avatar

James Sumners jsumners

View GitHub Profile
@jsumners
jsumners / app.js
Created May 22, 2015 19:56
A simple usage of Mongoose and its promise API
'use strict';
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test2');
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function dbOpenCB(callback) {
console.log('open callback called');
});
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/"
>
<channel>
@jsumners
jsumners / pdns_control.py
Created August 20, 2015 19:18
Ansible modules for PowerDNS's authoritative and recursive control utilities
#!/usr/bin/python
DOCUMENTATION = '''
---
module: pdns_control
author: "James Sumners"
short_description: Issue pdns_control commands
requirements: [ pdns_control ]
description:
- Issue PowerDNS authoritative server pdns_control commands
options:
# Let's return to screen
set-option -g prefix C-a
unbind-key C-b
# more intuitive keybindings for splitting
unbind %
bind h split-window -v
unbind '"'
bind v split-window -h
@jsumners
jsumners / write_png_from_clipboard.as
Created April 4, 2012 19:11
Do you have a screenshot in your OS X clipboard? Write it to a PNG!
set d to the clipboard as «class PNGf»
set fid to open for access "/tmp/screenshot.png" with write permission
write d to fid
close access fid
-- http://www.michael-hogg.co.uk/applescript.php
-- helped me figure this one out
@jsumners
jsumners / NSData+Base64.h
Created September 10, 2012 18:52 — forked from Abizern/NSData+Base64.h
A category on NSData for coding and encoding Base64
//
// NSData+Base64.h
// base64
//
// Created by Matt Gallagher on 2009/06/03.
// Copyright 2009 Matt Gallagher. All rights reserved.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software. Permission is granted to anyone to
@jsumners
jsumners / NSDictionary+JBSObjectForPath.h
Created October 9, 2012 17:38
A category for retrieving objects from nested NSDictionaries
#import <Foundation/Foundation.h>
@interface NSDictionary (JBSObjectForPath)
/**
Returns the object from a nested `NSDictionary` at the given path, with path
components separated by a "/". For example, if you have the following
dictionary:
~~~~
{"foo":{"bar":"foobar"}}
@jsumners
jsumners / UIColor+JBSUtilities.m
Created October 9, 2012 20:47
Screw all of the bullshit llvm warnings in UIColor-Utilities
#import <UIKit/UIKit.h>
@interface UIColor (JBSUtilities)
/**
Give it a hex string, e.g. "#FFEEDD" or "FFEEDD", get back the UIColor
representation.
@param stringToConvert A NSASCIIStringEncoding hex string.
@return The UIColor represented by the hex string.
@jsumners
jsumners / UIApplication+iPhoneVersion.h
Created November 2, 2012 18:38
A category on UIApplication for determining the iPhone device
#import <UIKit/UIKit.h>
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
/**
Provides a few methods to determine what sort of device the application is
running on. Specifically, the methods make it easy to determine what sort of
iPhone resolution is available: `[[UIApplication sharedApplication] isIphone3]`
*/
@jsumners
jsumners / data.bin
Last active November 1, 2015 16:37