Skip to content

Instantly share code, notes, and snippets.

@nysalor
nysalor / _store_upload.rb
Created March 5, 2012 04:40
rails3 drag'n drop upload store method
# forked from http://kray.jp/blog/rails3-fileupload/
def _store_upload(file)
if request.xhr?
if request.body.size == request.headers['CONTENT_LENGTH'].to_i
file_data = request.body.read
file_name = file
end
else
if file.instance_of?(File)
file_data = file.read
@nysalor
nysalor / getposition.js.coffee
Created January 15, 2012 08:41
gmaps4rails:getposition and replace markers
@get_current_position = () =>
navigator.geolocation.getCurrentPosition @nearby_places, @failed_alert
@nearby_places = (position) =>
res = $.getJSON "/places/nearby.json", { lat: position.coords.latitude, long: position.coords.longitude },
(json) ->
Gmaps.map.replaceMarkers json
@failed_alert = () =>
alert "failed to get current position."
@nysalor
nysalor / bit_ly.rb
Created January 14, 2012 07:18
bit.ly url shorter
require 'rubygems'
require 'net/http'
Net::HTTP.version_1_2
require 'json'
class BitLy
def initialize(params={})
@base_query = "version=2.0.1&login=#{params[:id]}&apiKey=#{params[:api_key]}"
end