Skip to content

Instantly share code, notes, and snippets.

View lxcodes's full-sized avatar

Alexander lxcodes

  • fh group
  • Erie, PA
View GitHub Profile
@lxcodes
lxcodes / gist:1010361
Created June 6, 2011 14:26
JavaScript TriggerEvent
Element.prototype.triggerEvent = function(eventName)
{
if (document.createEvent)
{
var evt = document.createEvent('HTMLEvents');
evt.initEvent(eventName, true, true);
return this.dispatchEvent(evt);
}
if (this.fireEvent)
return this.fireEvent('on' + eventName);
@lxcodes
lxcodes / gist:1010364
Created June 6, 2011 14:27
Set Cursor at the End of a ContentEditable
function setEndOfContenteditable(contentEditableElement)
{
var range,selection;
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
<div id="confirmed">
<h4>People who have already confirmed:</h4>
<div class="hSeparator"><!--[ie]--></div>
<table>
<%= @registerees.each do |r| %>
<tr>
<td><%= r[:fullName] %></td><td><%= r[:title]+' : '+r[:company] %></td><td><%= r[:city]+', ' r[:country]%></td>
</tr>
<% end %>
</table>
get '/Registration' do
protected!
@registerees = User.all(:isRegistered => true)
erb :registration
end
@lxcodes
lxcodes / gist:1037818
Created June 21, 2011 13:07
Password Reset
def password_reset
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;
new_pass = (0..20).map{ o[rand(o.length)] }.join;
self.update(:shahash => User.encrypt(new_pass))
return self.new_pass
end
@lxcodes
lxcodes / gist:1041594
Created June 23, 2011 00:03
User Model
class User
include DataMapper::Resource
timestamps :at
property :id, Serial
property :first_name, String, :required => true
property :last_name, String, :required => true
property :company, String
property :title, String
property :city, String
@lxcodes
lxcodes / gist:1041599
Created June 23, 2011 00:05
DataMapper Error On Update
DataObjects::DataError at /register
Out of range value for column 'mobile_number' at row 1
Ruby /usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb: in execute_non_query, line 194
Web POST lordevents.com.dev/register
Traceback (innermost first)
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb: in execute_non_query
connection.create_command(statement).execute_non_query(*bind_values)...
@lxcodes
lxcodes / gist:1041698
Created June 23, 2011 01:23
Ajax Post -- Registration
<form id="registration" action="/register" method="post" accept-charset="utf-8">
<table>
<tr>
<td><input type="text" name="first_name" value="" id="first_name" class="validate[required]"><br /><label for="first_name"><%= t[:forms][:firstName] %></label></td>
<td><input type="text" name="last_name" value="" id="last_name" class="validate[required]"><br /><label for="last_name"><%= t[:forms][:lastName] %></label></td>
</tr>
<tr>
<td><input type="text" name="company" value="" id="company" class="validate[required]"><br /><label for="company"><%= t[:forms][:company] %></label></td>
<td><input type="text" name="title" value="" id="title" class="validate[required]"><br /><label for="title"><%= t[:forms][:title] %></label></td>
</tr>
@lxcodes
lxcodes / Error
Created June 23, 2011 20:45
Validation Helper
ArgumentError at /faca-sua-insricao
invalid byte sequence in US-ASCII
file: utils.rb location: gsub line: 153
sinatra.error
#<NoMethodError: undefined method `errors' for nil:NilClass>
@lxcodes
lxcodes / app.rb
Created June 26, 2011 21:46
Sinatra Load Routes
# encoding: utf-8
class app < Sinatra::Application
Dir.glob('./routes/*').each { |r| require File.expand_path(File.join(File.dirname(__FILE__), r)) }
Dir.glob('./models/*').each { |r| require File.expand_path(File.join(File.dirname(__FILE__), r)) }
end