Skip to content

Instantly share code, notes, and snippets.

View bensie's full-sized avatar

James Miller bensie

View GitHub Profile
require "json"
module ApiMacros
def json(content)
JSON.pretty_generate content
end
def decode_json(content)
JSON.parse content, symbolize_names: true
@bensie
bensie / api.rb
Created March 11, 2014 04:20
Accept multipart upload with Sinatra
post "/shots" do
if params[:photo] && params[:photo].is_a?(Hash)
class UploadedFile < OpenStruct; end
paperclip = UploadedFile.new(
tempfile: params[:photo][:tempfile],
path: params[:photo][:tempfile].path,
original_filename: params[:photo][:filename],
content_type: params[:photo][:type],
head: params[:photo][:head]
)
@bensie
bensie / gist:e9b5cd8a16fe1d40210f
Created August 6, 2014 15:35
Install ElasticSearch
sudo apt-get install openjdk-7-jre-headless -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.2.deb
sudo dpkg -i elasticsearch-1.2.2.deb
sudo service elasticsearch start

Keybase proof

I hereby claim:

  • I am bensie on github.
  • I am bensie (https://keybase.io/bensie) on keybase.
  • I have a public key whose fingerprint is B720 6EF1 71C0 466C 38BF 65AC C5AB 1889 61E6 14A1

To claim this, I am signing this object:

@bensie
bensie / uploader.go
Created January 7, 2015 19:34
Quick and dirty golang file uploader
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func uploadHandler(w http.ResponseWriter, r *http.Request) {
@bensie
bensie / routes.rb
Last active August 29, 2015 14:18
Rails Authentication
Rails.application.routes.draw do
scope module: "api" do
constraints subdomain: "api" do
match "/", to: "root#options", via: [:options]
match "*unmatched", to: "root#options", via: [:options]
resource :me, only: [:show, :update], controller: "me"
post "/me/access_tokens", to: "access_tokens#create"
delete "/me/access_tokens", to: "access_tokens#destroy"
@bensie
bensie / Mod-Rails on Ubuntu
Created October 16, 2008 19:42
Step by step commands for getting mod_rails installed on Ubuntu
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo apt-get install build-essential
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby1.8 ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient16-dev libmysqlclient16 libnet-daemon-perl libopenssl-ruby libopenssl-ruby1.8 libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client mysql-client-5.1 mysql-common mysql-server mysql-server-5.1 rdoc1.8 ri1.8 ruby1.8 ruby1.8-dev zlib1g-dev
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
function validateField(fieldId, alertMessage) {
if (document.getElementById(fieldId).value == "") {
alert(alertMessage);
document.getElementById(fieldId).focus();
return false;
} else {
return true;
}
}
require 'httpclient'
module EnomApi
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def manage_with_enom
send :include, InstanceMethods
end
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base