Skip to content

Instantly share code, notes, and snippets.

@unixcharles
unixcharles / backbone.iframe.sync.js
Created October 11, 2011 14:14
Backbone.sync implementation that use iframe + multipart/form-data
(function () {
Backbone.syncWithoutUpload = Backbone.sync
Backbone.syncWithUpload = function(method, model, options) {
// Create iframe
var iframe_id = 'file_upload_iframe_' + Date.now()
, iframe = jQuery('<iframe id="' + iframe_id + '" name="' + iframe_id + '" ></iframe>').hide()
// Create an hidden form
var authToken = jQuery('meta[name=csrf-token]').attr('content')
, authParam = jQuery('meta[name=csrf-param]').attr('content')
@unixcharles
unixcharles / Ohhh noes.txt
Created September 19, 2011 14:20
OSX libxml2 error fix
Look like brew libxml2 and the one bundled with osx are fighting
/Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle: dlsym(0x7ffb44ee7880, Init_libxml_ruby): symbol not found - /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle (LoadError)
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml.rb:9
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.1
@unixcharles
unixcharles / log_sql.rb
Created May 18, 2011 09:57
Query report
# initializer, run dev or test with LOG_SQL=true to log SQL
connection = ActiveRecord::Base.connection
class << connection
alias :original_exec :execute
def execute(sql, *name)
# try to log sql command but ignore any errors that occur in this block
# we log before executing, in case the execution raises an error
begin
file = File.open(RAILS_ROOT + "/log/queries.sql",'a'){|f| f.puts sql}
rescue Exception => e
@unixcharles
unixcharles / nginx.conf
Last active January 18, 2024 12:21
nginx config for http/https proxy to localhost:3000
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
@unixcharles
unixcharles / fix_permission.rb
Created October 19, 2010 13:03
Fix permission issue on Amazon S3. Restore to default paperclip setting
BUCKET = "teambox-assets"
# require 'aws/s3'
AWS::S3::Base.establish_connection!(:access_key_id => YOUR_ACCESS_KEY, :secret_access_key => YOUR_SECRET_KEY )
include AWS::S3
def set_public(key, bucket)
policy = S3Object.acl(key, bucket)
policy.grants << ACL::Grant.grant(:public_read)
$ git push heroku master
Counting objects: 1852, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (486/486), done.
Writing objects: 100% (1614/1614), 446.30 KiB, done.
Total 1614 (delta 1175), reused 1531 (delta 1113)
-----> Heroku receiving push
-----> Rails app detected
-----> Detected use of caches_page

User can generate url/key for project when they have the right to comment:

teambox.com/hooks/:key

Each key tie to project and user

@hook = Hook.find_by_key(params[:key])

Optional params

Here is the complete workflow
$ git clone git@github.com:unixcharles/refinerycms.git && cd refinerycms
Create a new branch
$ git checkout -b bugfixes
... some change, few days and a few commits later... I can also push the work-in-process-branch change to github if I plan to work on a different computer or share idea
When I'm done I do:
charles@Charles ~/Documents/Rails $ git clone git://github.com/resolve/refinerycms.git refinery_test
Initialized empty Git repository in /Users/charles/Documents/Rails/refinery_test/.git/
remote: Counting objects: 13618, done.
remote: Compressing objects: 100% (6686/6686), done.
remote: Total 13618 (delta 5655), reused 12987 (delta 5282)
Receiving objects: 100% (13618/13618), 9.76 MiB | 864 KiB/s, done.
Resolving deltas: 100% (5655/5655), done.
charles@Charles ~/Documents/Rails $ cd refinery_test
charles@Charles ~/Documents/Rails/refinery_test $ mate .
charles@Charles ~/Documents/Rails/refinery_test $ rake db:setup
Charles:refinery_test charles$ rake db:setup
(in /Users/charles/Documents/Rails/refinery_test)
/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
[BUG] cross-thread violation on rb_gc()
(null)
Abort trap
Charles:refinery_test charles$ rm -rf ./vendor/plugins/slim_scrooge
Charles:refinery_test charles$ rake db:setup
(in /Users/charles/Documents/Rails/refinery_test)