Skip to content

Instantly share code, notes, and snippets.

View TexRx's full-sized avatar
🏠
Working from home

Bobbie Tables TexRx

🏠
Working from home
View GitHub Profile
@TexRx
TexRx / app.js
Created March 19, 2012 18:32 — forked from pixelhandler/app.js
Develop a RESTful API Using Node.js With Express and Mongoose - See: http://pixelhandler.com/blog/2012/02/09/develop-a-restful-api-using-node-js-with-express-and-mongoose/
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');
@TexRx
TexRx / gist:2221053
Created March 27, 2012 22:35 — forked from shripadk/gist:652819
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
@TexRx
TexRx / gist:2772809
Created May 23, 2012 01:54 — forked from karlseguin/gist:2724327
Collects all the IDs and classes from a given element down (like document.body)
function scan(parent) {
var found = {classes: {}, ids: []};
var unexamined = [parent];
while (unexamined.length > 0) {
parent = unexamined.pop();
var nodeLength = parent.childNodes.length;
for(var i = 0; i < nodeLength; ++i) {
node = parent.childNodes[i];
if (node.nodeType != 1) { continue; }
@TexRx
TexRx / gist:2772814
Created May 23, 2012 01:55 — forked from karlseguin/gist:2462535
extensions to HTMLDocument for setting up click and keypress events
//Helper extension for setting up document.on('click') and document.on('keypress') if escape...
//I think it's pretty stupid code, inspired by having eaten absolutely too much, watcha gonna do.
//usage:
// document.on('escape', hide);
// document.on('click', hide);
(function(){
var events = {'escape': [], 'click': [], 'enter': []};
@TexRx
TexRx / gist:2772817
Created May 23, 2012 01:56 — forked from karlseguin/gist:1876859
sublime text 2 script to save to remove server
#variation of http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ that adds creating new folders remotely.
import sublime_plugin, os
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
remote = { "/Users/leto/work/project": ["/usr/bin/scp", None, "user@server", "root_remote_path_like ~/project/", None] }
for dirname, target in remote.iteritems():
if view.file_name().startswith( dirname ):
@TexRx
TexRx / gist:2772820
Created May 23, 2012 01:56 — forked from karlseguin/gist:1694156
style override I use for duckduckgo.com
body{background:#fff;font-family:'Verdana';font-size:16px;}
#header{background-image:nome;background:#f0f0f0;border-bottom:1px solid #ddd;height:45px}
#header_logo, #keyboard_shortcuts{display:none !important;}
#search_form{border:none;margin-top:4px}
#search_form_input{border:solid #ccc;border-width:1px 0 1px 1px}
#search_form_input_clear{border:solid #ccc;border-width:1px 0}
#header_button_menu_wrapper{position:absolute;top:3px;right:20px;}
#header_button{background:none;border:none}
#header_button_menu_wrapper a.header_button_menu_item{color:#555;font-size:90%;text-shadow:none;background:none;text-transform: lowercase}
#zero_click_abstract, #zero_click_abstract_top, .results_zero_click, .results_zero_click_more{border:none;}
@TexRx
TexRx / gist:2772822
Created May 23, 2012 01:57 — forked from karlseguin/gist:1336377
C# pool creator
public class Pool<T>
{
private readonly int _count;
private readonly Queue<T> _pool;
private readonly Func<Pool<T>, T> _create;
private readonly object _lock = new object();
public Pool(int count, Func<Pool<T>, T> create)
{
_count = count;
@TexRx
TexRx / gist:2772825
Created May 23, 2012 01:58 — forked from karlseguin/gist:1327266
Nodejs and MongoDB, A Beginner’s Approach - Mirror

this is a mirror of http://blog.ksetyadi.com/2011/10/nodejs-and-mongodb-a-beginners-approach/

This is not a book and I didn’t try to sell a book to you.

The term “A Beginner’s Approach” reflects my self when finding a hard way out to connect Nodejs to MongoDB. There are lots of libraries available to use when connecting Nodejs to MongoDB. If you were trying to make your feet wet, and that’s what I’m doing until today, you probably want to try this approach. I can’t promise anything but at least, you will not get a headache.

First, read about Nodejs. After that, MongoDB. If you’re already familiar with it, skip it and install both on your system. There maybe vary depending on your system. If you use Mac and Homebrew (or MacPorts), you’re lucky. Just do this:

$ brew install node
// account.js
var Store = new (require('./store').Store)('accounts', {'_id': 'id', 's': 'secret'}, function(){return new Account();});
var Account = function Account() {
this.id = this.secret = null;
};
Account.findById = function(id, callback) {
Store.findOne({'_id': Store.idFromString(id)}, function(err, result) {
if (err) { callback(err); }
@TexRx
TexRx / gist:2772832
Created May 23, 2012 02:00 — forked from karlseguin/gist:852817
simulate typing into an input
function simType(input, value)
{
var characters = value.split('');
var i = 0;
var id = setInterval(function()
{
input.value += characters[i++];
if (i == characters.length) { clearInterval(id); }
}, 75);
};