Skip to content

Instantly share code, notes, and snippets.

View superp's full-sized avatar

Pavlo Haleta superp

View GitHub Profile
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6eAVWnVEHuxEzepqKoKx33UNlFwsuT3fA1Vz8NO50MSTrB22vxGroGpemnBpunFSWfkum2zbbW7mCFabMEhugILuBCJWpWmPt+bqCnM/Ze7Hu71+mPsI+Sb+Mz1NNbstrMwaXSJsh3D/pbE5lO8Hvgt6bJjsBNA73k/ZsBeRvOJAiAQ2tep1/KHU/Uccq04jrKARmkrCUAHSKFC8K7uzUbagtPWJI6du/1V3nU/CalFM43Yqk28aClw6V68BzrGITHG5qQLBex79jHTncXfA2xQ6tFD7fK2bNZ2wBwM0wWnr7dKUTogAzzlFaRMu0FU6qICwYC3cJFCXdhmVN3dWtQ== superp@superp-hp
@superp
superp / gist:847323
Created February 28, 2011 13:39
rails 2 routes redirect
#routes.rb
map.articles '/articles', :controller => 'posts', :action=>'index'
map.posts '/posts', :controller => 'posts', :action=>'redirect'
map.resources :posts
#posts_controller.rb
def redirect
redirect_to articles_path, :status => 301
end
@superp
superp / gist:886862
Created March 25, 2011 13:56
overwrite update_with_password
# in User model
def update_with_password(params={})
unless params.key?(:current_password)
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
update_attributes(params)
# initializers/omniauth.rb
TestStream::Application.config.middleware.use OmniAuth::Builder do
provider :facebook, '...', '...', {:scope => 'publish_stream,offline_access,email'}
provider :twitter, '...', '...'
end
@superp
superp / gist:888384
Created March 26, 2011 15:38
Publish stream in Facebook & Twitter with OmniAuth
# models/person.rb
serialize :auth_hash, Hash
def facebook
@fb_user ||= FbGraph::User.me(user_attributes[:token])
end
def twitter
@tw_user ||= prepare_access_token(user_attributes[:token], user_attributes[:secret])
end
@superp
superp / Ruby.rb
Created July 6, 2011 13:57
Group by example in MongoMapper
class Tweet
include MongoMapper::Document
key :id_str, String
key :from_user_id, Integer
belongs_to :track_item
def self.grouped_by(column, options = {})
map_function = "function() { emit( this.#{column}, 1); }"
@superp
superp / .gitignore
Created December 27, 2011 11:08
Default gitignore file for Rails projects
.bundle/
.svn/
config/*.yml
config/*.conf
config/logrotate-config
config/nginx-config
config/nginx-config-vhost
db/schema.rb
db/sphinx/
log/
@superp
superp / gist:1523718
Created December 27, 2011 13:52
Sunrise CRM scaffold template
gem("mysql2")
gem("devise")
gem("sunrise-cms", :path => '/var/www/gems/cms/sunrise')
gem("therubyracer", :group => 'development')
gem("mongrel", :version => "1.2.0.pre2", :group => 'development')
gem("rspec-rails", :version => "~> 2.7.0", :group => 'test')
gem("database_cleaner", :version => "~> 0.7.0", :group => 'test')
gem("factory_girl_rails", :version => "~> 1.4.0", :group => 'test')
gem("fuubar", :group => 'test')
@superp
superp / gist:8472479
Created January 17, 2014 12:14
Update cms gem in all projects
#!/bin/bash
# Settings
APP_ROOT="/Volumes/Data/superp/www/fodojo/writers_cms/"
PULSAR_ROOT="/Volumes/Data/superp/www/fodojo/pulsar"
APPS=(...)
APPS_COUNT=${#APPS[*]}
BUNDLE_CMD="bundle update writers_cms"
GIT_COMMIT_CMD="git commit -am 'update-cms'"
@superp
superp / Switcher.js
Created April 16, 2014 06:41
jQuery Switcher
var $, Switcher;
$ = jQuery;
$.fn.extend({
switcher: function(options) {
return $(this).each(function(input_field) {
var switcher;
switcher = $(this).data("switcher");
if (switcher == null) {