Skip to content

Instantly share code, notes, and snippets.

View simianhacker's full-sized avatar

Chris Cowan simianhacker

View GitHub Profile
--[[
VPLanguage = lua
VPScriptMenuTitle = GitHub Commit
VPEndConfig
]]
-- we assume git is located in /opt/local/bin/git
posix.chdir(document:fileName())
-- add new files
class Application < Merb::Controller
before :check_remember_me
def check_remember_me
unless session.authenticated?
if cookies[:auth_token]
if user = User.first(:auth_token=>cookies[:auth_token])
if user.valid_token?
session.user = user
end
describe "Facebook Connect Authentication" do
it "should create a new user in the system when the Facebook Connect cookies are set" do
response = request(url(:home), :cookie=>facebook_cookies)
user = User.first(:facebook_id=>facebook_params[:user])
user.should_not be_nil
user.should be_valid
end
end
<?php
require_once 'PHPUnit/Framework.php';
class Describe_Something_Awesome extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->something = "Awesome!";
}
<?php
$query = "select * from example_table where user_id = ?"
$values = array($_SESSION['user_id']);
$results = select($query,$values);
?>
@simianhacker
simianhacker / Example.coffee
Created May 4, 2012 17:30
Example option object argument of for Class
class MyClass
constructor: (options) ->
# stuff here
myObject = new MyClass(bar: "foo", foo: "bar")
@simianhacker
simianhacker / gist:3308895
Created August 9, 2012 23:11
Upstart template for Node.js
description "Node server for #{application} (#{node_env})"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
script
exec sudo -u nobody sh -c "NODE_ENV=#{node_env} #{path_to_node} #{script_name}"
end script
@simianhacker
simianhacker / gist:3493548
Created August 27, 2012 23:57
Example MySQL API-ish Request
var mysql = some_function_to_create_a_mysql_connection();
app.get('/foo', function (req, res) {
mysql.query('SELECT * FROM example', function (err, results) {
if(err) {
res.send(400);
}
res.send(results, 200);
}
var configuration = {
domain: 'localhost',
port: 3000,
keys: require('./keys.js')
}
var express = require('express');
var app = express();
app.listen(configuration.port);
var passport = require('passport');
@simianhacker
simianhacker / json_path.sql
Last active May 13, 2019 17:40
Here is a set of functions for working with a PostgreSQL+JSON+PLV8 database.
-- Function: json_path(json, text)
-- DROP FUNCTION json_path(json, text);
CREATE OR REPLACE FUNCTION json_path(data json, path text)
RETURNS text AS
$BODY$
/* JSONPath 0.8.0 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)