Skip to content

Instantly share code, notes, and snippets.

View ae6rt's full-sized avatar

Mark Petrovich ae6rt

  • Petaluma, CA
View GitHub Profile
@ae6rt
ae6rt / server.py
Created December 11, 2013 14:18
Python Bottle REST reference app. Place latest version of bottle.py in the working directory.
from bottle import Bottle, run, request, response, abort, static_file,debug
import os
import json
app = Bottle()
prefix = "./albums"
@app.get('/')
var uuids = angular.module('uuids', []);
uuids.factory("rfc4122", function () {
return {
newuuid: function () {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
@ae6rt
ae6rt / AngularJS-apply.scope
Last active August 30, 2018 22:37
An AngularJS websocket service that updates a controller scope variable
var app = angular.module('app', []);
app.controller('controller', function ($scope, websocketService) {
$scope.msg = "...";
websocketService.start("ws://localhost:8080/events", function (evt) {
var obj = JSON.parse(evt.data);
$scope.$apply(function () {
$scope.msg = obj.message
});
@ae6rt
ae6rt / gist:7035322
Created October 18, 2013 01:56
How to parse a Spring beans file using JDOM2
private void run(File srcDir) throws IOException, JDOMException {
List<String> mapperClassNames = new ArrayList<String>();
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new FileReader(new File(srcDir, "src/main/resources/dataAccessContext.xml")));
Element rootElement = document.getRootElement();
Namespace namespace = Namespace.getNamespace("http://www.springframework.org/schema/beans");
List<Element> beans = rootElement.getChildren("bean", namespace);
for (Element e : beans) {
List<Element> property = e.getChildren("property", namespace);
@ae6rt
ae6rt / gist:7000490
Created October 15, 2013 23:53
Grouping dependencies in Gradle
Group dependencies in Gradle:
ext.libraries = [
logging: [
"ch.qos.logback:logback-classic:${versions.logback}",
"org.slf4j:log4j-over-slf4j:${versions.slf4j}",
"org.slf4j:jul-to-slf4j:${versions.slf4j}"
]
]
@ae6rt
ae6rt / gist:6951063
Created October 12, 2013 15:13
gradle xml-apis version conflict
07:20:25.162 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration jdom:jdom:1.0(runtime).
07:20:25.162 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration xerces:xmlParserAPIs:2.6.2(runtime).
07:20:25.163 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] version for xerces:xmlParserAPIs:2.6.2(runtime) is not selected. ignoring.
07:20:25.163 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration xerces:xercesImpl:2.6.2(runtime).
07:20:25.164 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] version for xerces:xercesImpl:2.6.2(runtime) is not selected. ignoring.
07:20:25.164 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration xom:xom:1.0b3(runtime).
07:20:25.165 [DEBUG] [org.gradle.api
@ae6rt
ae6rt / gist:6407227
Created September 1, 2013 20:48
Bash error trapping example
#!/bin/sh
set -e
set -u
cleanup() {
rm -f -P ${DOWNLOAD_FILE} ${DECRYPTED_FILE} ${DECRYPTED_FILE}.gpg
}
trap cleanup ERR
@ae6rt
ae6rt / gist:6395540
Last active December 22, 2015 01:19
Simple Amazon S3 file transfer using boto library
#!/usr/bin/python
'''
The AWS IAM user needs these permissions. Note these permissions
are set on the user, not the bucket.
{
"Version": "2012-10-17",
"Statement": [
{
@ae6rt
ae6rt / gist:6330516
Last active December 21, 2015 15:59
Deploy Maven artifacts to Amazon S3. Reference: https://github.com/SpringSource/aws-maven
The POM of the app that would publish artifacts would look like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.petrovic</groupId>
<artifactId>maven-s3-lab</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@ae6rt
ae6rt / gist:6241247
Created August 15, 2013 14:26
Gradle build config for publishing artifact with source code to a Maven repository.
apply plugin: 'java'
apply plugin: 'maven-publish'
group = "org.petrovic"
version = "0.2"
ext.versions = [
logback: "1.0.13",
junit: "4.11",
hamcrest: "1.3"