Skip to content

Instantly share code, notes, and snippets.

View jdavisclark's full-sized avatar

Davis Clark jdavisclark

View GitHub Profile
@jdavisclark
jdavisclark / main.go
Last active February 11, 2023 06:02
IOC with a localised container
package main
import (
"errors"
"fmt"
"os"
"reflect"
)
type Writer interface {
@jdavisclark
jdavisclark / gist:08c7b286a4aad7873b2819a864c74583
Last active April 9, 2018 13:58
my made up app def language
- endpoint
for: movies
that: persists new records
for model: movie
backed by: postgres
cached by: redis
- endpoint
for: movies
that: retrieves records
@jdavisclark
jdavisclark / gist:42c181e93f822a4f0c5a797c5bba6d3d
Last active April 1, 2016 15:02
azure management list registered container items
GET https://management.azure.com/subscriptions/SUBSCRIPTION_ID_REDACTED/resourceGroups/RESOURCE_GROUP_REDACTED/providers/Microsoft.Backup/BackupVault/VAULT_REDACTED/items?api-version=2014-09-01
@jdavisclark
jdavisclark / gist:07d3155c5e121bda8f8b
Created June 30, 2015 19:55
fix all orphaned users
SET NOCOUNT ON
USE AdventureWorks
GO
DECLARE @loop INT
DECLARE @USER sysname
IF OBJECT_ID('tempdb..#Orphaned') IS NOT NULL
BEGIN
DROP TABLE #orphaned
END
@jdavisclark
jdavisclark / debugWebserver.js
Last active August 29, 2015 14:20
basic console echoing debug server with built in localtunnel. need to install localtunnel
// if you want to specify a custom localtunnel subomain, just throw it in an additional argument eg: node debugWebserver.js mysubdomain
var util = require("util");
var lt = require("localtunnel");
var http = require('http');
http.createServer(function (req, res) {
console.log(req.method + " " + req.url)
req.on("data", function(chunk) {
console.log("Body: " + chunk)
@jdavisclark
jdavisclark / gist:67df901f71d96b7649b4
Created January 10, 2015 17:59
simple script to push the latest github repo tag to a geckoboard text widget
#!/bin/bash
## This script requires jq (http://stedolan.github.io/jq/) and curl
TAGSRESPONSE=`curl --silent -X GET -u YOURKEY:x-oauth-basic https://api.github.com/repos/yourUser/yourRepo/tags`
TAG=`echo $TAGSRESPONSE | /usr/local/bin/jq '.[] | .name' | sort --reverse | head -1 | tr -d '"'`
APIBODY=`echo "{ \"api_key\": \"yourKey\",\"data\": {\"item\": [{\"text\": \"${TAG}\",\"type\": 2}]}}"`
echo $APIBODY > /tmp/apiBody.json
curl --silent -d @/tmp/apiBody.json -X POST -H "Content-Type: application/json" 'https://push.geckoboard.com/v1/send/yourBoardId'
@jdavisclark
jdavisclark / gist:9115898
Created February 20, 2014 15:13
project relative require
module.exports = function(projectRoot) {
var nodeRequire = require;
var path = nodeRequire("path");
// normalize the project root path
projectRoot = path.normalize(projectRoot);
if(projectRoot[projectRoot.length -1] !== "/") {
projectRoot += "/";
}
var util = require('./util');
module.exports = function(jsgiReq) {
return Object.create(jsgiReq, {
isXMLHttpRequest: getter(function() {
return !util.no(this.headers['x-requested-with']);
}),
_paramGroups: {
routeParams: {
@jdavisclark
jdavisclark / gist:8918442
Created February 10, 2014 16:00
iis rewrite rule: rewrite portions of the authority/domain-name to the path
<rewrite>
<rules>
<rule name="thing" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*?)\.(.*?)\..*" />
</conditions>
<action type="Redirect" url="https://www.google.com?sub={C:1}&amp;asdf={C:2}&amp;path={R:0}" />
</rule>
</rules>
var bogart = require('bogart');
var router = bogart.router();
router.get('/', function(req) {
return bogart.file('index.html');
});
var app = bogart.app();
app.use(bogart.batteries);
app.use(router);