Skip to content

Instantly share code, notes, and snippets.

View montyr75's full-sized avatar

Monty Rasmussen montyr75

View GitHub Profile
@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:7632761
Created November 24, 2013 21:43
A Dart function that returns a List of all possible permutations of a given string.
List<String> findAllPermutations(String source) {
List allPermutations = [];
void permutate(List list, int cursor) {
// when the cursor gets this far, we've found one permutation, so save it
if (cursor == list.length) {
allPermutations.add(list);
return;
}
@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 / 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:09b5dc9a20ba01955872
Last active January 5, 2023 02:55
Find the last day of the current month with Dart's DateTime class.
final now = DateTime.now();
final lastDayOfMonth = DateTime(now.year, now.month + 1, 0);
print("${lastDayOfMonth.month}/${lastDayOfMonth.day}");
@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 / 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);
}