Skip to content

Instantly share code, notes, and snippets.

var bserver_lib_path = APP_PATH + '/var/bserver.js';
var age = Date.now() - (fs.existsSync(bserver_lib_path) && fs.statSync(bserver_lib_path).mtime.getTime());
var bserver = null;
if (age < 10000 ) bserver = require(bserver_lib_path);
else {
console.log("Reloading bserver.js from BSERVER server");
var file = fs.createWriteStream(bserver_lib_path);
var request = require('http').get(settings.bserver_server + "/bserver.js", function(response) {
response.pipe(file);
response.on('end', function() {
@evantahler
evantahler / game-actions.js
Created July 1, 2013 05:05
Creating the API for a tic-tac-toe game with AI
// actions/game.js
// A collection of tasks and helper methods to create a simpel tic-tac-toe game
// - single player
// - simple AI
// - each connection can only have one active game at a time
exports.gameCreate = {
name: "gameCreate",
description: "I create a new game for this connection",
#!/bin/sh
killall node
#NODE_ARGS="--prof --prof_lazy --log"
#NODE_ARGS="--prof --log"
#!/bin/sh
RC=1
@sallespromanager
sallespromanager / oauth2 client
Created December 7, 2012 14:47
oauth2 client to Oauth2orize server
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OAuth 2 User Agent Authentication Flow Demo</title>
<script type="text/javascript" charset="utf-8" src="js/bootstrap/jquery.js"></script>
<script type="text/javascript" charset="utf-8">
$(function () {
var extractToken = function(hash) {
@brianyang
brianyang / twitter-oauth.js
Created November 21, 2012 15:11 — forked from santosh79/twitter-oauth.js
Twitter OAuth with node-oauth for node.js+express
var express = require('express');
var sys = require('util');
var oauth = require('oauth');
var app = express.createServer();
var _twitterConsumerKey = process.env['TWITTER_CONSUMER_KEY'];
var _twitterConsumerSecret = process.env['TWITTER_CONSUMER_SECRET'];
console.log("_twitterConsumerKey: %s and _twitterConsumerSecret %s", process.env['TWITTER_CONSUMER_KEY'], process.env['TWITTER_CONSUMER_SECRET']);
@nhoizey
nhoizey / screenshots.js
Created November 12, 2012 17:07
Take screenshots at different viewport sizes using CasperJS
/*
* Takes provided URL passed as argument and make screenshots of this page with several viewport sizes.
* These viewport sizes are arbitrary, taken from iPhone & iPad specs, modify the array as needed
*
* Usage:
* $ casperjs screenshots.js http://example.com
*/
var casper = require("casper").create();
@pmanijak
pmanijak / index.html
Created September 2, 2012 06:42
Service example with AngularJS for sharing scope data between controllers
<!doctype html>
<html ng-app="project">
<head>
<title>Angular: Service example</title>
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<script>
var projectModule = angular.module('project',[]);
projectModule.factory('theService', function() {
return {
@possibilities
possibilities / meteor-async.md
Created August 23, 2012 22:53
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase:

anonymous
anonymous / gist:2387816
Created April 14, 2012 20:48
Example of using Meteor.methods() and Meteor.call()
if (Meteor.is_client) {
Template.hello.greeting = function () {
return "Welcome to XYZ.";
};
Template.hello.events = {
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
@zenlor
zenlor / app.js
Created February 14, 2012 11:09
daemonizing wrapper for node apps
var express = require('express')
, app = module.exports = express.createServer();
// you express app resides here ...