Skip to content

Instantly share code, notes, and snippets.

View coderoshi's full-sized avatar

Eric Redmond coderoshi

View GitHub Profile
@coderoshi
coderoshi / mongohq.php
Created February 20, 2012 20:04 — forked from lhitchon/gist:1424751
MongoHQ PHP Connection
<!-- PHP Mongo Docs: http://php.net/manual/en/class.mongodb.php -->
<html>
<body>
<h1>MongoHQ Test</h1>
<?php
try {
// connect to MongoHQ assuming your MONGOHQ_URL environment
// variable contains the connection string
$connection_url = getenv("MONGOHQ_URL");
@coderoshi
coderoshi / mongohq.rb
Created February 21, 2012 00:20
MongoHQ Ruby Connection
# gem install mongo bson_ext json
require 'rubygems' # if less than Ruby 1.9
require 'mongo'
require 'uri'
require 'json'
def get_connection
return @db_connection if @db_connection
db = URI.parse(ENV['MONGOHQ_URL'])
db_name = db.path.gsub(/^\//, '')
@coderoshi
coderoshi / mongohq.js
Created February 21, 2012 01:52
MongoHQ NodeJS Connection
// npm install mongodb
var mongodb = require('mongodb');
var url = require('url');
var log = console.log;
var connectionUri = url.parse(process.env.MONGOHQ_URL);
var dbName = connectionUri.pathname.replace(/^\//, '');
mongodb.Db.connect(process.env.MONGOHQ_URL, function(error, client) {
if (error) throw error;
@coderoshi
coderoshi / mongohq.coffee
Created February 21, 2012 02:02
MongoHQ NodeJS Connection (Coffee)
# npm install mongodb
mongodb = require 'mongodb'
url = require 'url'
log = console.log
connection_uri = url.parse(process.env.MONGOHQ_URL)
db_name = connection_uri.pathname.replace(/^\//, '')
mongodb.Db.connect process.env.MONGOHQ_URL, (error, client)->
throw error if error
@coderoshi
coderoshi / neo4js.coffee
Created March 19, 2012 17:25
Neo4j REST NodeJS CoffeeScript
neo4j = require('./caching_client').createClient
port: process.env.NEO4J_PORT
host: process.env.NEO4J_HOST
username : process.env.NEO4J_LOGIN
password : process.env.NEO4J_PASSWORD
neo4j.runCypher 'START x = node(0) RETURN x', (err, output, res)->
if err
console.log err.message
else
@coderoshi
coderoshi / cors.coffee
Created April 25, 2012 17:18
CORS NodeJS Middleware
exports.cors = (req, res)->
origin = (req.headers.origin || "*")
if req.method.toUpperCase() == 'OPTIONS'
res.writeHead 200,
'Access-Control-Allow-Origin': origin
'Access-Control-Allow-Credentials': true
'Access-Control-Allow-Methods': '*'
'Access-Control-Allow-Headers': 'Accept, Authorization, Cache-Control, Content-Type, Origin, Referer, User-Agent, X-CSRF-Token'
'Content-Type': 'text/plain'
'Server': 'jsonapi'
@coderoshi
coderoshi / bracket.coffee
Created May 18, 2012 23:29
Challonge Hubot plugin
# Usage: (bracket followed by a comma-separated list of names)
# hubot bracket Joe, Fred, Tony, Eddy
https = require('https')
# uses challonge to create a bracket with the given names
module.exports = (robot) ->
robot.respond /bracket\s+(.+?)$/i, (msg) ->
names = msg.match[1]
return unless names
@coderoshi
coderoshi / cashcat.coffee
Created May 24, 2012 00:21
Ca$hcat Hubot plugin
# Cashcatme. Just like pug bombing, but with flava
#
# cashcat me - Receive a cashcat
# cashcat bomb N - get N cashcats
module.exports = (robot) ->
robot.respond /cashcat me/i, (msg) ->
msg.http("http://cashcatme.heroku.com/bomb?count=1")
.get() (err, res, body) ->
msg.send JSON.parse(body).cats
@coderoshi
coderoshi / Gemfile
Created May 24, 2012 16:55
A Sinatra example to turn any site into a JSON service
source :rubygems
gem 'sinatra'
gem 'httparty'
gem 'nokogiri'
@coderoshi
coderoshi / config.rb
Created August 21, 2012 17:47
Register FML in Middleman
# Register the FML plugin to middleman
module Middleman::Renderers::FAQML
def registered(app)
begin
require "faqml"
app.before_configuration { template_extensions :fml => :html }
::FAQML::Engine.set_default_options(
:buffer => '@_out_buf',
:generator => ::Temple::Generators::StringBuffer
)