Skip to content

Instantly share code, notes, and snippets.

View ThomasLocke's full-sized avatar

Thomas Løcke ThomasLocke

  • Loecke K/S
  • Denmark
View GitHub Profile
@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: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: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: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: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: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:8157769
Created December 28, 2013 09:40
Trying to harden client.getUrl() in Dart, so it never crashes my HTTP server and never completes with an error.
Future getTag() {
final Completer c = new Completer();
final HttpClient client = new HttpClient();
client.getUrl(Uri.parse(tagUrl))
.then((HttpClientRequest request) {
return request.close();
})
.catchError((e) {
// If the tagUrl server is down, we catch and log it here.
@ThomasLocke
ThomasLocke / gist:7582314
Created November 21, 2013 14:21
How to access Google Drive from Dart.
// Add google_drive_v2_api to pubspec.yaml
import "package:google_oauth2_client/google_oauth2_console.dart" as oauth;
import "package:google_drive_v2_api/drive_v2_api_console.dart" as drivelib;
const _IDENTIFIER = "<YOUR CLIENT ID>";
const _SECRET = "<YOUR CLIENT SECRET>";
const _SCOPES = const ["https://www.googleapis.com/auth/drive.file"];
void main() {
@ThomasLocke
ThomasLocke / gist:6650607
Created September 21, 2013 13:28
Dead simple HTTP server in Dart - snippet 1
import 'dart:async';
import 'dart:io';
import 'package:route/server.dart';
import 'package:route/url_pattern.dart';
final Map<String, UrlPattern> Urls = {'/' : new UrlPattern('/'),
'ninja' : new UrlPattern('/ninja'),
'pirate' : new UrlPattern('/pirate'),
'samurai' : new UrlPattern('/samurai')};
@ThomasLocke
ThomasLocke / gist:6568446
Created September 15, 2013 06:18
Using the Ada Web Server (AWS), part 2 -snippet 11
function Hello_World_Template
(Request : in AWS.Status.Data)
return AWS.Response.Data
is (AWS.Response.File (AWS.MIME.Text_Plain,
"templates/hello_world.tmpl"));