Skip to content

Instantly share code, notes, and snippets.

View montyr75's full-sized avatar

Monty Rasmussen montyr75

View GitHub Profile
@montyr75
montyr75 / gist:2078bdc941d22ab0d131
Created December 6, 2014 20:00
Dynamically create an HTML element from a String in Dart.
new Element.html("YOUR HTML STRING HERE");
// You may need to pass a NodeValidator to get everything to render, like:
NodeValidator nodeValidator = new NodeValidatorBuilder()
..allowTextElements();
// ..allowHtml5()
// ..allowElement('Button', attributes: ['ng-disabled']);
new Element.html("YOUR HTML STRING HERE", validator: nodeValidator);
@montyr75
montyr75 / gist:7628003
Last active December 29, 2015 06:19
Synchronously get a line of user input from the command line console (stdin). Using synchronous I/O in the console can greatly simplify your program.
import "dart:io";
void main() {
// get user input using synchronous I/O
String input = stdin.readLineSync();
// get user input and convert to lowercase
String inputLC = stdin.readLineSync().toLowerCase();
print(input);
@montyr75
montyr75 / gist:7632735
Created November 24, 2013 21:39
Dart factorial function.
int factorial(int number) {
int factorialRange(int bottom, int top) {
if (top == bottom) {
return bottom;
}
return top * factorialRange(bottom, top - 1);
}
return factorialRange(1, number);
@montyr75
montyr75 / gist:8248296
Last active January 2, 2016 04:09
Prevent the user from dragging images on the page.
/* specific way */
img {
-moz-user-drag: -moz-none;
-webkit-user-drag: none;
user-drag: none;
}
/* "nuke 'em all" way */
img {
pointer-events: none;
@montyr75
montyr75 / gist:8248413
Last active January 2, 2016 04:09
Prevent the user from selecting text on the page.
.user-select-none {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@montyr75
montyr75 / gist:8283038
Created January 6, 2014 13:42
Change text selection colors in a browser with CSS.
/* Chrome */
::-webkit-selection {
background-color: #FF68B0;
color: #FFF;
}
/* Firefox */
::-moz-selection {
background-color: #FF68B0;
color: #FFF;
@montyr75
montyr75 / wait_for_config.dart
Last active June 9, 2016 16:13
Angular service that acquires information asynchronously, but has dependents waiting for that info. (Pattern)
class ConfigService {
var _config;
Completer _waitForConfig = new Completer();
ConfigService() {
doHttpCall().then((result) {
_config = result;
_waitForConfig.complete(_config);
}
@montyr75
montyr75 / download_string.dart
Last active June 17, 2016 17:05
Automatically send a string in the form of a downloaded file to a browser client using new HTML5 anchor attributes.
void downloadFileToClient(String filename, String text) {
AnchorElement tempLink = document.createElement('a');
tempLink
..attributes['href'] = 'data:text/plain;charset=utf-8,${Uri.encodeComponent(text)}'
..attributes['download'] = filename
..click();
}
@montyr75
montyr75 / empty.dart
Last active September 27, 2016 15:57
An empty place to start.
We couldn’t find that file to show.
@montyr75
montyr75 / safe_inner_html.dart
Last active May 31, 2018 18:46
Angular 2 directive to safely inject HTML.
import 'dart:html' show Element, NodeTreeSanitizer;
import 'package:angular2/core.dart'
show Directive, Input, OnChanges, SimpleChange;
@Directive(selector: '[safeInnerHtml]')
class SafeInnerHtml implements OnChanges {
Element _el;
SafeInnerHtml(this._el);