Skip to content

Instantly share code, notes, and snippets.

import 'package:unittest/unittest.dart';
import '../bin/singleton_pattern.dart';
void main(){
test("'new' shouldn't be able to create a new instance of SingleObject", (){
expect(() => (new SingleObject()), throwsA(new isInstanceOf<NoSuchMethodError>()));
});
test("Should return and instance of SingleObject", (){
expect(() => SingleObject.getInstance(), returnsNormally);
class SingleObject{
static final SingleObject _instance = new SingleObject._internal();
static SingleObject getInstance(){
return _instance;
}
void showMessage(){
print("Hello World!");
}
void main() {
//Get the only object available
SingleObject object = SingleObject.getInstance();
// this would cause a compilation error
//SingleObject singleObject = new SingleObject();
//show the message
object.showMessage();
}
class Gists{
// instance variable for user
String user;
getGistsForUser(String user){
this.user = user;
var url = "https://api.github.com/users/${this.user}/gists";
http.get(url)
.then(_processResults)
.catchError(_handleError);
}
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:io';
class Gists{
// instance variable for user
String user;
getGistsForUser(String user){
this.user = user;
var url = "https://api.github.com/users/${this.user}/gists";
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:io';
import 'dart:async';
class Gists{
// instance variable for user
String user;
Future getGistsForUser(String user){
this.user = user;
import 'dart:async';
import 'package:http/http.dart' as http;
Future makeRequest(String url) => http.get(url)
.then((res) => res.body);
void main() {
makeRequest('http://www.google.com')
.then((value) => print(value))
import 'dart:io';
import 'dart:async';
Future createFile(String fileName, String text){
return new File(fileName).create()
.then((File file){
file.writeAsStringSync(text);
return 'the file has been created with "$text" as its content';
});
}
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
#google_map_search {
left: 450px;
top: 230px;
position: absolute;
@mplacona
mplacona / gist:6756660daaf33a71d87f
Last active August 29, 2015 14:19
Hack for /video page replay
function heartbeat(){
if(document.querySelector('.demo--completed') != null){
eventFire(document.querySelector('.demo__restart'),'click');
}
setTimeout(heartbeat,1000);
}
function eventFire(el, etype){
if (el.fireEvent) {