Skip to content

Instantly share code, notes, and snippets.

View simianhacker's full-sized avatar

Chris Cowan simianhacker

View GitHub Profile
@simianhacker
simianhacker / require.snippet
Created August 24, 2013 02:14
This snippet will convert `req` to `var SomeName = require('some_name');`
snippet req "Require a module where it converts CamelCase to underscore (camel_case)" !b
var ${1:name} = require(${2:'${3:${1/(^[A-Z])|([A-Z])/(?2:_\l$2:\l$1)/g}}'});
endsnippet
@simianhacker
simianhacker / index.js
Last active December 17, 2015 13:59
Just testing Jaws to see what happens when you hit it with 100 concurrent connections without warming the cache.
siege -b -c 100 http://localhost:4444/cache-this
@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)
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 / 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);
}
@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 / 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")
<?php
$query = "select * from example_table where user_id = ?"
$values = array($_SESSION['user_id']);
$results = select($query,$values);
?>
<?php
require_once 'PHPUnit/Framework.php';
class Describe_Something_Awesome extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->something = "Awesome!";
}
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