Skip to content

Instantly share code, notes, and snippets.

class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@xarimanx
xarimanx / hide.js
Created December 18, 2013 06:09
Use jQuery to hide a DIV when the user clicks outside of it
$(document).mouseup(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
@xarimanx
xarimanx / deploy.rb
Created September 27, 2013 06:57 — forked from ryancheung/deploy.rb
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "[email protected]:ryancheung/blog.git"
set :scm, :git
@xarimanx
xarimanx / antiIe.txt
Created August 30, 2013 11:02
antiIE
<!--[if IE]>
<meta http-equiv="refresh" content="0;url=http://www.google.com/chrome/" />
<![endif]-->
/[if IE]
<meta http-equiv="refresh" content="0;url=http://www.google.com/chrome/" />
@xarimanx
xarimanx / upload_file_by_curl.txt
Created August 19, 2013 13:23
Upload file by curl
curl [url] -F '[param_name]=@[file_path];type=[mime-type]' -F '[other_params](optional)'
{
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"use_simple_full_screen": false,
@xarimanx
xarimanx / youtube-img.txt
Created August 5, 2013 07:48
Youtube thumbnail images
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to this:
@xarimanx
xarimanx / pub_sub.js
Created July 26, 2013 07:31
Pub/sub js plugin
/*
jQuery pub/sub plugin by Peter Higgins ([email protected])
Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
http://dojofoundation.org/license for more information.
*/
@xarimanx
xarimanx / data_attr_options.rb
Created July 4, 2013 14:48
generate options with custom data attrs
def options_from_collection_for_select_with_data(collection, value_method, text_method, selected = nil, data = {})
options = collection.map do |element|
[element.send(text_method), element.send(value_method), data.map do |k, v|
{"data-#{k}" => element.send(v)}
end
].flatten
end
selected, disabled = extract_selected_and_disabled(selected)
select_deselect = {}
select_deselect[:selected] = extract_values_from_collection(collection, value_method, selected)