Skip to content

Instantly share code, notes, and snippets.

@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
@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 / _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 / create_uploader.js.coffee
Created March 5, 2012 04:41
fileuploader initialize script
# initializer for fileuploader.js(http://github.com/valums/file-uploader)
@create_uploader = (upload_action, complete_action, token) =>
uploader = new qq.FileUploader {
element: document.getElementById('upload'),
action: upload_action,
debug: false,
params: {
authenticity_token: token
},
onComplete: () =>
@nysalor
nysalor / deploy_assets.rb
Created March 5, 2012 05:38
deploy settings for remote precompile
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
@nysalor
nysalor / staging.rb
Created March 8, 2012 09:35
capistrano multistage deploy_to
set :rails_env, 'staging'
set :branch, 'trunk'
set :deploy_to, "/var/www/#{application}-#{rails_env}"
role :web, "staging-server"
role :app, "staging-server"
role :db, "staging-server", :primary => true
@nysalor
nysalor / staging.rb
Created March 8, 2012 09:36
capistrano multistage deploy_to(fixed)
set(:deploy_to) { "/var/www/#{application}-#{rails_env}" }
set(:releases_path) { File.join(deploy_to, version_dir) }
set(:shared_path) { File.join(deploy_to, shared_dir) }
set(:current_path) { File.join(deploy_to, current_dir) }
set(:release_path) { File.join(releases_path, release_name) }
# unicornを使っているなら以下も
set(:unicorn_config) { "#{current_path}/config/unicorn.rb" }
set(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
--- a/src/nsterm.m 2012-03-20 12:48:57.000000000 +0900
+++ b/src/nsterm.m 2012-03-20 13:22:16.000000000 +0900
@@ -4708,9 +4708,7 @@
if (NS_KEYLOG)
NSLog (@"firstRectForCharRange request");
- if (NILP (Feval (Fcons (intern ("ns-in-echo-area"), Qnil))))
- win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
- else if (WINDOWP (echo_area_window))
+ if (WINDOWP (echo_area_window))
@nysalor
nysalor / styles.css.erb
Created April 4, 2012 08:58
stylesheet with asset pipiline (erb)
.bgimage {
background: #fffff url("<%= asset_path 'css/background.png' %>") repeat-x;
}
@nysalor
nysalor / styles.css.scss
Created April 4, 2012 09:00
stylesheet with asset pipiline (scss)
.bgimage {
background: #fffff url(asset-path('css/background.png', image)) repeat-x;
}