Skip to content

Instantly share code, notes, and snippets.

@lrhn
lrhn / main.dart
Last active August 29, 2015 14:17
Function asCoRoutine(Iterable iterable) {
var iterator = iterable.iterator;
return () => (iterator..moveNext()).current;
}
Iterable<int> generator() sync* {
int i = 0;
while (true) {
yield i++;
}
@lrhn
lrhn / IncrementSelection.py
Last active June 25, 2016 21:41
Sublime plugin for incrementing and decrementing numbers in selections.
import sublime, sublime_plugin, re
def updateSelection(command, edit, delta, preserveLength):
rd = re.compile(r'\d+')
value = -delta
originalLength = 1
if (delta < 0):
value = len(command.view.sel()) * -delta
selCountLength = 1;
selectionCount = len(command.view.sel())
#! /usr/bin/perl
my $rev = $ARGV[0] || "HEAD";
my $log=`git log -n1 $rev`;
my $revision;
if ($log =~ m{git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@(\d+)}) {
$revision = $1;
} else {
# Commit 9ba7eef1c492 is r45832.
@lrhn
lrhn / AlignCommand.py
Last active November 30, 2016 13:59
Align selections in Sublime
import sublime, sublime_plugin
class AlignLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
def alignLeft(string, length):
return string.ljust(length)
alignSelections(self.view, edit, alignLeft)
class AlignRightSmartCommand(sublime_plugin.TextCommand):
def run(self, edit):
@lrhn
lrhn / refduri.dart
Created June 29, 2016 08:56
Reference implementation of URI reference resolution.
import "dart:convert" show JSON; // just for string prettification.
Uri resolve(Uri base, Uri ref) {
var scheme;
var userInfo;
var host;
var port;
var path;
var query;
var fragment;
@lrhn
lrhn / Assert Initializer Design Document.md
Last active August 24, 2016 14:28
Dart Assert in Initializer List - Design Document

Asserts in Initializer List

Lasse Nielsen (@lrhn)

Status: Experimental

(See: http://github.com/dart-lang/sdk/issues/24841, http://github.com/dart-lang/sdk/issues/27141)

In some cases, you want to validate your inputs before creating an instance, even in a const constructor. To allow that, we plan to test the possibility of allowing assert statements in the initializer list of a generative constructor.

We will start by implementing it in the VM behind a flag, with at least syntax support from the analyzer and possibly the formatter.

List<int> daysToYearMonthDay(int days) {
// Use 1st of March year -99 as base.
// This keeps the leap day of year 0, 400, ... in the first
// century, but place the Feb 29 day of the century at the very end.
days += 306 + 365 * 99 + 24;
const daysIn4Centuries = 365 * 400 + 97;
// Multiply by 4, then divide by days in 400 years. This is basically
// the same as dividing by 365.2425 * 100 - the average number of days
// in a century, but using only integer division.
@lrhn
lrhn / RotateSelection.py
Created November 30, 2016 13:58
Sublime commands to rotate the contents of selections.
import sublime
import sublime_plugin
# Rotate contents of selections forwards.
class RotateSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
prevText = view.substr(view.sel()[-1])
for selection in view.sel():
text = view.substr(selection);
@lrhn
lrhn / ascii
Created January 27, 2017 08:35
ASCII helper script - converts arguments to ASCII codes
#! /usr/bin/perl
my $format = "%2.2X";
if ($ARGV[0] eq "-l") {
$format = "%2.2x";
shift @ARGV;
}
if ($#ARGV >= 0) {
my @hex = ();
for $a (@ARGV) {
for $c ( split("", $a) ) {
import "dart:io";
bool verbose = false;
bool dryRun = false;
main(List<String> args) {
int unchanged = 0;
for(var path in args) {
if (path == "-v") {
verbose = true;
continue;