Skip to content

Instantly share code, notes, and snippets.

View mschwartz's full-sized avatar

Michael Schwartz mschwartz

  • Southwestern USA
View GitHub Profile
// ctest.coffee
res.write '<pre>'
res.write 'hello, world\n'
res.write Util.print_r req
outputs in the browser:
hello, world
(object) :
[init] : (function)
title = 'hello'
color = req.data.color ? 'red'
"""
<html>
<head>
<title>#{title}</title>
</head>
<body>
<h1 style="color: #{color}">Have another cuppa joe!</h1>
</body>
var smarty_cache = {}
function getCachedSmarty(key) {
// (key is whatever you use to lookup in the DB)
var template = smarty_cache[key];
if (!template) {
template = SQL.getDataRow(query_to_get_template);
var compiled = smart.compile(template);
template = {
template: template,
compiled: compiled
var console = require('console');
function handlerMaker(obj) {
return {
// Fundamental traps
getOwnPropertyDescriptor: function(name) {
console.log('getOwnPropertyDescriptor ' + name);
var desc = Object.getOwnPropertyDescriptor(obj, name);
// a trapping proxy's properties must always be configurable
if (desc !== undefined) { desc.configurable = true; }
@mschwartz
mschwartz / gist:2785580
Created May 25, 2012 03:25
Filesystem by Proxy in SilkJS
var fs = require('builtin/fs'),
console = require('console');
function DirectoryProxy(path) {
return Proxy.create({
get: function(receiver, name) {
return fs.readFile(path + '/' + name);
},
set: function(receiver, name, value) {

NodeJS v0.8.0

mschwartz@mschwartz:~/src/bench$ cat node.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
mschwartz@mschwartz:~/src/bench$ node node.js 
@mschwartz
mschwartz / example.jst
Last active December 22, 2015 02:39
SilkJS forms and Schema work together
<html>
<head>
</head>
<body>
<%
if (req.data.button) {
console.dir(req.data);
var example = {};
req.data.each(function(value, key) {
if (key.substr(0, 6) === 'field_') {
Schema.add({
name: 'Content',
fields: [
{ name: 'contentId', type: 'int', autoIncrement: true, defaultValue: 0 },
{ name: 'seoFriendly', type: 'varchar', size: 255 },
{ name: 'title', type: 'varchar', size: 255, defaultValue: 'Untitled' },
{ name: 'description', type: 'varchar', size: 255, defaultValue: 'No description' },
{ name: 'body', type: 'longtext' }
],
primaryKey: 'contentId',
@mschwartz
mschwartz / gist:6405201
Last active December 22, 2015 02:39
Not shared content
Schema.add({
name: 'Content',
fields: [
{ name: 'contentId', type: 'int', autoIncrement: true, defaultValue: 0 },
{ name: 'churchId', type: 'int' },
{ name: 'seoFriendly', type: 'varchar', size: 255 },
{ name: 'title', type: 'varchar', size: 255, defaultValue: 'Untitled' },
{ name: 'description', type: 'varchar', size: 255, defaultValue: 'No description' },
{ name: 'body', type: 'longtext' }
],
var myObject = {
"foo": true,
"author": "simon",
"env": 123
}
var myProxy = new JavaAdapter(org.mozilla.javascript.NativeObject, {
// The "start" argument is here for setters and getters living
// on a prototype, so they know what to use as "this"-object.
put: function(name, start, value) {