Skip to content

Instantly share code, notes, and snippets.

View dobesv's full-sized avatar

Dobes Vandermeer dobesv

View GitHub Profile
@dobesv
dobesv / less-rhino-1.1.4.js
Created September 17, 2011 13:28
Rhino compatible version of Less 1.1.4 (LESS is a CSS preprocessor, see https://github.com/cloudhead/less.js)
//
// LESS - Leaner CSS v1.1.4
// http://lesscss.org
//
// Copyright (c) 2009-2011, Alexis Sellier
// Licensed under the Apache 2.0 License.
//
//
// Stub out `require` in rhino
@dobesv
dobesv / test.html
Created September 17, 2011 14:02
Some whitespace relating testing with jadejs
<div class="test"><!-- Adding text using | results in a newline AFTER (not before) each line-->foo
bar
baz
</div>
<div class="test"><!--I thought I could use extra | lines to insert additional whitespace but
this currently outputs | characters into the result.
-->|
foo
|
@dobesv
dobesv / purejsbug.html
Created October 25, 2011 05:17
Example of an issue in the purejs templating engine where a css class that is modified by the directives cannot be used in selector matching
<html>
<head>
<title>Test</title>
</head>
<body>
<div id='container'>
<div class='foo'>
<div class='bar'>
bla
</div>
@dobesv
dobesv / digestFile.js
Created January 3, 2012 08:41
Sample connect/express middleware to add a digest to all file uploads. Useful for change detection, that kind of thing. Also an example of calculating a hash (SHA1 or MD5) on a file.
var crypto = require('crypto'),
fs = require('fs');
/**
* Calculate the digest of a given file as a hex string.
*
* @param filename Name of the file to read
* @param {String} [algo='sha1'] Hash algorithm (e.g. 'md5' or 'sha1')
* @param {function(Exception,String) cb Callback which is invoked with (err,hash)
*/
@dobesv
dobesv / combinejs.js
Created January 21, 2012 11:06
Combine, minify, and compress javascript files. Supports "watching" the files for automatic updates
#!node
var fs = require('fs'),
path = require('path'),
gzip = require('./gzip');
function process(fileBody, options, cb) {
if(typeof(fileBody) === 'object') {
options = fileBody;
fileBody = undefined;
cb = options;
@dobesv
dobesv / connect-intercept.js
Created January 23, 2012 05:52
Function to intercept the response from the next() call.
var events = require('events');
/**
* When operating as a middleware our "origin" server is the next handler in the chain. This
* patches the given response object so that when the next handler writes to it we treat that
* as a response from the origin server.
*
* This replaces the writeHead, setHeader, removeHeader, write and end methods
* on the given response so that it can store the response in the cache and returns
* an object that be used to listen for the next() handler writing data and to send
@dobesv
dobesv / CoroutineDslPlugin.fan
Created March 2, 2012 16:19
Changes I made to the Fantom compiler module to make it easier to create my DSL
using compiler
class CoroutineDslPlugin : DslPlugin
{
new make(Compiler c) : super(c) {}
override Expr compile(DslExpr dsl)
{
src := dsl.src
loc := dsl.srcLoc
@dobesv
dobesv / MmapBuf.fan
Created March 8, 2012 02:19
Add Buf subclass supporting any kind of java.nio.ByteBuffer (not just MmapByteBuffer)
package fan.sys;
import java.nio.MappedByteBuffer;
public class MmapBuf extends NioBuf {
MmapBuf(File file, MappedByteBuffer mmap) {
super(mmap);
this.file = file;
this.mmap = mmap;
@dobesv
dobesv / NioBuf.patch
Created March 9, 2012 04:31
NioBuf as a patch
diff --git a/src/sys/fan/Buf.fan b/src/sys/fan/Buf.fan
--- a/src/sys/fan/Buf.fan
+++ b/src/sys/fan/Buf.fan
@@ -605,10 +605,19 @@
}
**************************************************************************
+** NioBuf
+**************************************************************************
+
@dobesv
dobesv / CallResolver-unknown-type.patch
Created March 9, 2012 04:54
Handle unknown type during ResolveCall
diff -r 7b06445b390c src/compiler/fan/util/CallResolver.fan
--- a/src/compiler/fan/util/CallResolver.fan Thu Mar 08 16:54:10 2012 -0500
+++ b/src/compiler/fan/util/CallResolver.fan Fri Mar 09 12:53:30 2012 +0800
@@ -71,6 +71,12 @@
ffiCoercion
return result
}
+ catch(UnknownTypeErr err)
+ {
+ expr.ctype = ns.error