Skip to content

Instantly share code, notes, and snippets.

@nikgraf
nikgraf / destructuring+defaults.js
Last active December 10, 2015 16:36
I'm a big fan of the destructuring assignment syntax in combination with setting default values in JavaScript ❤️
export default ({options = {}}) => {
const {
min = Number.MAX_SAFE_INTEGER,
max = Number.MIN_SAFE_INTEGER,
step = 1,
} = options;
return `Range between ${min} and ${max} with a step of ${step}`;
};
"use strict";
import React, {Component} from 'react';
import calcContentHeight from './dom-textarea-measure';
class AutogrowingTextarea extends Component {
constructor(props) {
this.props = props;
this.state = {};
this.textareaProps = sanitizeChildProps(props);
@nikgraf
nikgraf / autocomplete.dart
Created April 12, 2014 20:16
Web UI Autocomplete in Blossom
import 'dart:async';
import 'dart:html';
import 'package:web_ui/web_ui.dart';
import 'package:escape_handler/escape_handler.dart';
class State {
static const ACTIVE = const State._(0);
static const INACTIVE = const State._(1);
import 'dart:async';
import 'package:polymer/polymer.dart';
import 'package:observe/observe.dart';
class CountdownClock extends CustomElement with ObservableMixin {
static final oneSecond = new Duration(seconds: 1);
@observable var timeLeft = new Duration(seconds: 72);
/*
import 'package:mdv/mdv.dart' as mdv;
void main() {
mdv.initialize();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="import" href="countdown_clock.html">
</head>
<body>
<h1>Alarm</h1>
<div is="countdown-clock"></div>
<script type="application/dart" src="alarm.dart"></script>
void main() {
}
@nikgraf
nikgraf / run_dartium.dart
Created July 12, 2013 23:45
A small script to start Dartium with type checks and asserts enabled on OSX. To run it you need the Dart editor and added the `dart` command to $PATH
#!/usr/bin/env dart
import 'dart:io';
import 'dart:async';
main() {
// find and run Dartium with type checks and asserts enabled
var whichDart = Process.run('which', ['dart']);
whichDart.then((command) {
var dartiumExecutable = new Path(command.stdout).join(new Path('../../../chromium/Chromium.app/Contents/MacOS/Chromium'));
<x-secret placeholder="Choose a Password"></x-secret>
library cookie;
import 'dart:html';
/*
* dart document.cookie lib
*
* ported from
* http://www.quirksmode.org/js/cookies.html
*