Skip to content

Instantly share code, notes, and snippets.

@seansullivan
seansullivan / gist:7835884
Created December 7, 2013 00:58
node.js middleware to write raw request body to log file.
var fs = require('fs');
app.use(function(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
@seansullivan
seansullivan / gist:7818128
Created December 6, 2013 03:33
S3 ACL public for all files
{
"Version": "2008-10-17",
"Id": "b2cc31d0-cc91-4285-a658-473099d2c867",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
@seansullivan
seansullivan / chrome_to_md.sh
Last active December 28, 2015 21:39
Shell script for creating Markdown file from currently active tab and highlighted text in Google Chrome. Intent is to power a Jekyll <http://jekyllrb.com/> blog to replace my old Posterous site. Forked from Jekyll Bookmarklet <http://jonathanbuys.com/04-05-2011/Jekyll_Bookmarklet.html>
#!/bin/bash
TITLE=`osascript -e 'tell application "Google Chrome" \
to return title of active tab of front window'`
URL=`osascript -e 'tell application "Google Chrome" \
to return URL of active tab of front window'`
TEXT=`osascript -e 'tell application "Google Chrome" \
to execute the active tab of front window \
@seansullivan
seansullivan / call_command.py
Created September 9, 2013 18:25
Python call_command for calling command line in script.
def call_command(command):
process = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return process.communicate()
# Ex usage: call_command("sudo mount {dev} {mnt}".format(dev=device_path, mnt=mount_path))
@seansullivan
seansullivan / s3-deploy
Created August 26, 2013 19:26
Deploy local folder to s3 bucket using s3cmd.
#!/bin/bash
s3cmd sync --delete-removed ./mybucket-local/ s3://mybucket.com
s3cmd setacl --acl-public --recursive s3://mybucket.com
server {
listen 80;
server_name myblog.com;
root /var/www/wp-blog;
## This should be in your http block and if it is, it's not needed here.
index index.html index.php;
location = /favicon.ico {
@seansullivan
seansullivan / gist:4507044
Last active December 10, 2015 23:08
Cross Domain Headers for CompoundJS
#CORS middleware
allowCrossDomain = (req, res, next) ->
res.header 'Access-Control-Allow-Origin', '*'
res.header 'Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'
res.header 'Access-Control-Allow-Headers', 'Content-Type, X-Requested-With'
next()
# Cut off OPTIONS requests and just send true as response
handleOptionsMethod = (req, res, next) ->
return res.send(200) if req.method == 'OPTIONS'
@seansullivan
seansullivan / gist:3244870
Created August 3, 2012 05:50
Set up navigation inside view controller
// Note-- @interface ContainingViewController : UIViewController <UINavigationControllerDelegate, UITabBarControllerDelegate>
-(void) setUpNav {
// create tab bar controller and array to hold the view controllers
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController.view setFrame:CGRectMake(0, 0, 300, 100)];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1];
UIViewController *view1 = [[UIViewController alloc] init];
var FeedCat = function () {
this.cat = 'Garfield';
this.feed = function (scope_) {
var scope = scope_;
var feedIt = function (food) {
scope.doFeed(food);
}
#!/bin/bash
declare -A hosts
hosts[site1]=200
hosts[site2]=201
default=${hosts[site1]}
if [ $1 ]
then