Sunday, 11 August 2013

better git log in ~/.gitconfig

[alias]
l = log --date-order --date=iso --graph --full-history --all --pretty=format:'%x08%x09%C(red)%h %C(cyan)%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08 %C(bold blue)%aN%C(reset)%C(bold yellow)%d %C(reset)%s'
view raw gitconfig hosted with ❤ by GitHub

Tuesday, 6 August 2013

Load jquery dynamicly

if (typeof jQuery == 'undefined') {
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
// callback function provided as param
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
};
};
head.appendChild(script);
};
getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js', function() {
console.log("done")
});
} else {
alert("Could not load jQuery!")
};

Monday, 5 August 2013

remove all .DS_Store from git

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch

Rails console tips

app.project_path(Project.first)
=> "/projects/130349783-with-attachments"
>> app.class
=> ActionDispatch::Integration::Session
>> app.get "/735644780/projects/605816632-bcx.atom"
=> 200
>> app.response.body
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feed xml:lang=\"en-US\" ...
>> Project.instance_method(:trash).source_location
=> ["/Users/qrush/37s/apps/bcx/app/models/project.rb", 90]
>> app.method(:get).source_location
=> ["/Users/qrush/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/bundler/gems/rails-7d95b814583b/actionpack/lib/action_dispatch/testing/integration.rb", 32]
#http://37signals.com/svn/posts/3176-three-quick-rails-console-tips

Sunday, 4 August 2013

rails require local

gem "mygem", :path => "/Users/ioannis/Development/mygem/pkg/"

javascript objects keys and values

data = {one:1, two:2, three:3};
for(var key in data) {
console.log(data[key])
console.log(key)
}

Friday, 2 August 2013

device redirect back when user login

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def after_sign_in_path_for(resource)
sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http')
if request.referer == sign_in_url
super
else
stored_location_for(resource) || request.referer || root_path
end
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

rails and unicorn on localhost

#-------------------------------------------------
#Gem file
#-------------------------------------------------
gem 'unicorn'
#-------------------------------------------------
#Procfile in root directory (for heroku):
#-------------------------------------------------
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
#-------------------------------------------------
#./config/unicorn.rb file
#-------------------------------------------------
worker_processes 1
timeout 30
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
#make alias in ~/.profile start the server
# alias rails_u="unicorn_rails --config-file config/unicorn.rb -p 3000"
#I, [2013-08-02T21:54:02.553577 #57526] INFO -- : Refreshing Gem list
#I, [2013-08-02T21:54:10.570714 #57526] INFO -- : listening on addr=0.0.0.0:3000 fd=9
#I, [2013-08-02T21:54:10.617927 #57526] INFO -- : master process ready
#I, [2013-08-02T21:54:10.627250 #57538] INFO -- : worker=0 ready
view raw gistfile1.rb hosted with ❤ by GitHub

The UNIX Philosophy Mike Gancarz:

The UNIX Philosophy Mike Gancarz:
In 1994 Mike Gancarz (a member of the team that designed the X Window System), drew on his own experience with Unix, as well as discussions with fellow programmers and people in other fields who depended on Unix, to produce The UNIX Philosophy which sums it up in 9 paramount precepts:
Small is beautiful.
Make each program do one thing well.
Build a prototype as soon as possible.
Choose portability over efficiency.
Store data in flat text files.
Use software leverage to your advantage.
Use shell scripts to increase leverage and portability.
Avoid captive user interfaces.
Make every program a filter.
view raw gistfile1.txt hosted with ❤ by GitHub

Thursday, 1 August 2013

skip_before_filter :verify_authenticity_token

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
module Api
module V1
class AppsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:update_attr]
respond_to :json