Skip to content

Instantly share code, notes, and snippets.

View ThomasLocke's full-sized avatar

Thomas Løcke ThomasLocke

View GitHub Profile
@ThomasLocke
ThomasLocke / gist:b6104c4955d12cfe9038
Created July 26, 2014 06:51
Google Cloud Datastore Dart example
import 'dart:convert';
import 'configuration.dart';
import 'package:google_oauth2_client/google_oauth2_console.dart';
import 'package:google_datastore_v1beta2_api/datastore_v1beta2_api_client.dart' as client;
import 'package:google_datastore_v1beta2_api/datastore_v1beta2_api_console.dart' as console;
/**
* Search for args[0] ID in datastore. Add new entity if search fails to locate
@ThomasLocke
ThomasLocke / gist:8d8454175947c07db3f0
Created July 26, 2014 07:30
P12 to PEM conversion
$ openssl pkcs12 -in <P12 key> -nocerts -passin pass:notasecret -nodes -out <PEM key>
@ThomasLocke
ThomasLocke / gist:169a4d3026840465d78f
Created July 26, 2014 07:34
Google Cloud Datastore Dart example, entity data
final Map<String, client.Property> person =
{'name' : new client.Property.fromJson({'stringValue' : 'Thomas Løcke'}),
'website' : new client.Property.fromJson({'stringValue' : 'http://google.com/+ThomasLøcke'}),
'timestamp' : new client.Property.fromJson({'dateTimeValue' : timestamp})};
@ThomasLocke
ThomasLocke / gist:2225a652504c1c55f32f
Created July 26, 2014 13:21
Google Cloud Datastore Dart example, configuration
library configuration;
import 'dart:io';
import 'package:google_datastore_v1beta2_api/datastore_v1beta2_api_console.dart';
class Config {
static String get privateKey => new File('privatekey.pem').readAsStringSync();
static const String projectId = 'project-id';
static const String projectNumber = 'project-number';
@ThomasLocke
ThomasLocke / gist:876a4ae65c1eed9e2bdc
Created August 8, 2014 09:13
Google Cloud Datastore Dart example, getDatastore()
console.Datastore getDatastore() {
final ComputeOAuth2Console oauthClient =
new ComputeOAuth2Console(Config.projectNumber,
privateKey : Config.privateKey,
iss : Config.serviceEmail,
scopes : Config.scopes);
return new console.Datastore(oauthClient)
..makeAuthRequests = true;
}
@ThomasLocke
ThomasLocke / gist:669091ec56b315e44856
Created August 8, 2014 09:16
Google Cloud Datastore Dart example, getDatastore() GCE
console.Datastore getDatastore() {
final ComputeOAuth2Console oauthClient =
new ComputeOAuth2Console(Config.projectNumber);
return new console.Datastore(oauthClient)
..makeAuthRequests = true;
}
@ThomasLocke
ThomasLocke / gist:ec0c23bca4b48718782f
Created September 27, 2014 15:29
shelftest.main()
import 'dart:io';
import '../lib/routes.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_exception_response/exception_response.dart';
void main() {
final shelf.Handler handler = const shelf.Pipeline()
@ThomasLocke
ThomasLocke / gist:d10a26d2fe953d5f8f01
Created September 27, 2014 15:36
shelftest.pubspec.yaml
name: shelfTest
description: Just testing Shelf
dependencies:
junitconfiguration: any
shelf: any
shelf_exception_response: any
shelf_route: any
@ThomasLocke
ThomasLocke / gist:c8c0e44eaac371051aff
Created September 28, 2014 16:09
shelftest.routes.dart
library shelftest.routes;
import 'handlers.dart' as handler;
import 'package:shelf_route/shelf_route.dart';
Router routes = new Router()
..get('/user/{userid}', handler.getUser)
..put('/user/{userid}/name', handler.setUserName);
@ThomasLocke
ThomasLocke / gist:0ac5dca046c00ce25f49
Created September 29, 2014 14:00
shelftest.handlers.dart
library shelftest.handlers;
import 'dart:async';
import 'dart:convert';
import 'dart:io' show HttpHeaders;
import 'database.dart';
import 'user.dart';
import 'package:shelf_exception_response/exception.dart';