Skip to content

Instantly share code, notes, and snippets.

@stanpalatnik
stanpalatnik / gist:1967577
Created March 3, 2012 19:08
Index source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{+title}7th-Degree{/title}</title>
<script type="text/javascript" src='/javascripts/utils.js'></script>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
{+http_header/}
</head>
<body>
<div id="wrapper">
@stanpalatnik
stanpalatnik / app.js
Created March 3, 2012 21:28
Setting up Dust.js
// Module dependencies.
var express = require('express')
, routes = require('./routes')
, http = require('http')
, fs = require('fs')
, path = require('path')
, cons = require('consolidate')
var app = express();
{?username}
{username}
{:else}
Please Log-In!
@stanpalatnik
stanpalatnik / index.html
Created March 3, 2012 22:40
Dust.js Client side
<html>
<head>
<script src="dust-full-0.3.0.min.js"></script>
<script type="text/javascript">
//example showing client-side compiling and rendering
var compiled = dust.compile("Hello {name}!", "index");
dust.loadSource(compiled);
dust.render("index", {name: "David"}, function(err, out) {
if(err!= null)
@stanpalatnik
stanpalatnik / index.html
Created March 3, 2012 22:56
Dust.js Client side
<html>
<head>
<script src="dust-full-0.3.0.min.js"></script>
<script type="text/javascript">
//example showing client-side compiling and rendering
var compiled = dust.compile("Hello {name}!", "index");
dust.loadSource(compiled);
dust.render("index", {name: "David"}, function(err, out) {
if(err != null)
@stanpalatnik
stanpalatnik / gist:2287475
Created April 2, 2012 21:49
csrf example
<form id="form" name="form" method="post" action="/signin">
<h1>Sign-in form</h1>
<div><label>Username
</label>
<input type="text" name="user[username]" class="required" id="username"/></div>
<div>
<input type="password" name="user[password]" class="required" id="password"/></div>
detach { //this creates a new actor
completeWith { //we use a completeWith directive which respones with whatever we output at the end of the code block
var person = new Person();
person.address = getAddress(address['latitude'], address['longitude']).then((result) => person.address = result)
person.save
"saved!"
}
}
@tailrec
def extractor[T](resultSet: ResultSet,
result: scala.collection.mutable.Builder[T, Vector[T]] = Vector.newBuilder[T])( process: ResultSet => T ): Vector[T] = {
if (!resultSet.next) result.result()
else {
val value = process(resultSet)
extractor(resultSet, result += value)(process)
}
}
import DbWrapper._
import scala.util.{Failure, Success, Try}
class Auctioneer {
/**
*
* @param item
* @return Boolean Whether or not the auction was successfully started
*/
def startAuction(item: Item): Boolean = {
import scala.annotation.tailrec
import scala.collection.mutable
object Euler02 extends App {
@tailrec
def fib(num: Int, prev: Int, result: mutable.Builder[Int, Vector[Int]] = Vector.newBuilder[Int]): Vector[Int] = {
num match {
case 0 => result.result()
case x if x > 4000000 => result.result()