Skip to content

Instantly share code, notes, and snippets.

case class Context(local: Boolean)
trait FileSource {
def readFile(location: String): String
def writeFile(location: String, content: String): Unit
}
object FileSource {
def apply(context: Context): FileSource {
if (context.local) new LocalFileSource(context) else new ExternalFileSource(context)
}
def walk[T](caseClass: T): Iterator[String] = caseClass match {
case string: String => Iterator(string)
case product: Product => product.productIterator.flatMap(walk)
case _ => Iterator()
}
if (walk(config).contains(null)) {
throw new Exception("Case class structure has null")
}
case class Color(value: String, name: String)
<script>
define('compare', () => ({
isEqual(sub1, sub2) {
return sub1 + sub2
},
@jonvuri
jonvuri / es-class-properties.js
Created February 16, 2016 20:43
Demonstration of ES class properties proposal applied to Polymer elements (Transpiled output from Babel 6.5.2 including http://babeljs.io/docs/plugins/syntax-class-properties/)
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var MyElement = function MyElement() {
_classCallCheck(this, MyElement);
this.is = 'my-element';
this.properties = {
@jonvuri
jonvuri / es-class-properties.js
Last active February 16, 2016 20:48
Demonstration of ES class properties proposal applied to Polymer elements
// Currently fails in Polymer
class MyElement {
is = 'my-element'
properties = {
greeting: {
type: String,
@jonvuri
jonvuri / interfaced-el.html
Created February 5, 2016 18:44
Polymer interfacing idea
<dom-module id="interfaced-el">
<template>
</template>
<script>
Polymer({
is: 'interfaced-el',
Polymer.Collection._parseKey (polymer.0.js:3753)
Polymer.Collection.setItem (polymer.0.js:3759)
Polymer.Base._addFeature.set (polymer.0.js:2001)
(anonymous function) (polymer.0.js:1494)
Polymer.Base._addFeature._notifyListener (polymer.0.js:1923)
Polymer.Base._addFeature.fire (polymer.0.js:1288)
Polymer.Bind._modelApi._notifyChange (polymer.0.js:1359)
Polymer.Base.extend._notifyEffect (polymer.0.js:1530)
(anonymous function) (polymer.0.js:1393)
Polymer.Bind._modelApi._effectEffects (polymer.0.js:1390)
- Gigabyte G1
- Pros
- Best look for my build (Air)
- Most well-regarded binning
- Cons
- Some cards have coil whine issues
- Zotac AMP! Extreme
- Pros
- Largest heatsink, most effective cooling (Air)
- Ships with highest clock
@jonvuri
jonvuri / gist:cf6118f784bb115f6846
Created July 17, 2015 17:38
Plain text error handler for Jetty
context.setErrorHandler(new ErrorHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
baseRequest.setHandled(true);
String method = request.getMethod();
if (!method.equals(HttpMethod.GET) && !method.equals(HttpMethod.POST) && !method.equals(HttpMethod.HEAD)) {
return;
}
response.setContentType(MimeTypes.Type.TEXT_PLAIN_8859_1.toString());
response.setHeader(HttpHeader.CACHE_CONTROL.toString(), "must-revalidate,no-cache,no-store");