Skip to content

Instantly share code, notes, and snippets.

@salbito
salbito / person.rb
Created January 18, 2010 14:41 — forked from Mikr0Tik/person.rb
class Person < ActiveRecord::Base
before_update :before_update_changes
attr_accessor :update_changes
def before_update_changes
@update_changes = changes
end
end
def getUriQuery(url)
dots = url.scan(/\./)
dotsSize = dots.size
httpRegex = '(?![https?:\/\/])'
minimumUriRegex = '([^.]+\.[^.]+\...|[^.]+\.[^.]+)$' # Credit to @blaines
dotsSize -= 1
appendableRegex = '[^.]+\.'*dotsSize
customUriRegex = minimumUriRegex.insert(18, appendableRegex).insert(1, appendableRegex)
fullUriRegex = httpRegex + customUriRegex
uriToQuery = url.slice(Regexp.new(fullUriRegex))
search.html.erb
<%= form_tag(:action => "search") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:wth) %>
<%= submit_tag("Search") %>
<% end %>
--
Answers new method
def new
@survey = Survey.find(params[:survey_id])
@questions = @survey.questions.all
@answers = @questions.map{|q| q.answers.build}
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @answer }
end
def new
@questions = Question.find_all_by_survey_id(params[:survey_id])
@answers = @questions.map{|q| q.answers.build}
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @answer }
end
end
@salbito
salbito / gist:713858
Created November 24, 2010 15:54
Dynamic Activerelation queries based on attr_accessible
def index
@details = Details.where(["id != ?", 0])
@detail_params = Details.attr_accessible.to_a
for detail_param in @detail_params
if params[detail_param]
@details = @details.where(["#{detail_param} = ?", params[detail_param.intern]])
end
end
@user_ids = @details.select(:user_id).map{|d| d.user_id}
@users = User.find(@user_ids)
SIGN UP
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"password_confirmation\":\"12345678\", \"password\":\"12345678\", \"email\":\"[email protected]\"}}" \
http://your_server.com/users
SIGN IN
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"remember_me\":\"0\", \"password\":\"12345678\", \"email\":\"[email protected]\"}}" \
http://your_server.com/users/sign_in
@salbito
salbito / gist:1165174
Created August 23, 2011 13:52 — forked from powmedia/gist:1081802
Backbone.sync for Titanium
//Customise Backbone.sync to work with Titanium rather than jQuery
Backbone.sync = (function() {
var methodMap = {
'create': 'POST',
'read' : 'GET',
'update': 'PUT',
'delete': 'DELETE'
};
var xhr = Ti.Network.createHTTPClient({ timeout: 5000 });
@salbito
salbito / dabblet.css
Created November 26, 2012 03:05 — forked from chriscoyier/dabblet.css
Triangle with Shadow
/*
Triangle with Shadow
*/
.triangle-with-shadow {
width: 50px;
height: 200px;
position: relative;
overflow: hidden;
box-shadow: 0 16px 10px -17px rgba(0,0,0,0.5);
export default TechStackCheckboxes extend Component {
createTechStackCheckboxes() {
// starts with unchecked box
const isAllChecked = false;
// map out techStackItems and crate input boxes for each item
return this.props.techStackItems.map((item) => (
<div key={item}>
<input
key={item}