void main() {
Options opts = new Options();
for (String arg in opts.arguments) {
print(arg);
}
}
Let us play:$ dart opts.dart a a
$ dart opts.dart a b c d a b c dNothing to add, I think, except check the source.
Comments on Google+.
a weblog about programming and open source, mostly.
void main() {
Options opts = new Options();
for (String arg in opts.arguments) {
print(arg);
}
}
Let us play:$ dart opts.dart a a
$ dart opts.dart a b c d a b c dNothing to add, I think, except check the source.
String authEndpoint = 'https://accounts.google.com/o/oauth2/auth?';
String generateAuthUri(String client_id, String redirect_uri, String scope) {
List<List<String>> params = [
['client_id', client_id],
['redirect_uri', redirect_uri],
['scope', scope],
['response_type', 'token'],
['approval_prompt', 'force']
];
return authEndpoint + generateQueryString(params);
}
// Hopefully, this will one day be handled in a library
String generateQueryString(List<List<String>> params) {
List<String> parts = new List<String>();
for (List<String> part in params) {
String k = encodeComponent(part[0]);
String v = encodeComponent(part[1]);
parts.add(Strings.join([k, v], '='));
}
return Strings.join(parts, '&');
}
// Taken from Uri.dart
String encodeComponent(String component) {
if (component == null) return component;
return component.replaceAll(':', '%3A')
.replaceAll('/', '%2F')
.replaceAll('?', '%3F')
.replaceAll('=', '%3D')
.replaceAll('&', '%26')
.replaceAll(' ', '%20');
}
void redirectAuth(String uri) {
window.open(uri, 'authwin', 'width=600,height=400');
}
Very simple, but the key will be how we handle the redirect back to us in the next stage.
String extractToken() {
// eww
return window.location.hash.split('&')[0].split('=')[1];
}
void sendTokenAndClose(String token) {
window.opener.postMessage(token, '*');
window.close();
}
Which needs to be caught by the parent window by registering an event handler for the message event:
window.on.message.add(tokenReceived, false);
void tokenReceived(MessageEvent e) {
// the token is in e.data
}
We are now ready to use our token to make API calls, probably using JSONP which is the topic of another blog post, but you can see an idea on how to do it here in the Dart mailing list.
void main() {
Process p = new Process('/bin/ls', ['/']);
p.start();
StringInputStream stdoutStream = new StringInputStream(p.stdout);
print(stdoutStream.read());
p.close();
}
Notes:
void main() {
File f = new File('my_filename.txt');
FileInputStream fileStream = f.openInputStream();
StringInputStream stringStream = new StringInputStream(fileStream);
print(stringStream.read());
fileStream.close();
}
class Banana {
String getColor() {
return "yellow";
}
}
class Banana {
int age;
}
class Banana {
int age, length, width, ends = 2;
}
class Banana {
int age;
Banana(this.age);
}
class Banana {
Banana._internal();
factory Banana() {
return new Banana._internal();
}
}
You are viewing a mobilized version of this site...
View original page here