Skip to content

Instantly share code, notes, and snippets.

View mschwartz's full-sized avatar

Michael Schwartz mschwartz

  • Southwestern USA
View GitHub Profile
@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' }
],
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',

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 / 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) {
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; }
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
title = 'hello'
color = req.data.color ? 'red'
"""
<html>
<head>
<title>#{title}</title>
</head>
<body>
<h1 style="color: #{color}">Have another cuppa joe!</h1>
</body>
// 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)