Skip to content

Instantly share code, notes, and snippets.


Alexander lxcodes

View GitHub Profile
lxcodes / gist:1010361
Created Jun 6, 2011
JavaScript TriggerEvent
View gist:1010361
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 / gist:1010364
Created Jun 6, 2011
Set Cursor at the End of a ContentEditable
View gist:1010364
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
View gist:1029881
<div id="confirmed">
<h4>People who have already confirmed:</h4>
<div class="hSeparator"><!--[ie]--></div>
<%= @registerees.each do |r| %>
<td><%= r[:fullName] %></td><td><%= r[:title]+' : '+r[:company] %></td><td><%= r[:city]+', ' r[:country]%></td>
<% end %>
View events.rb
get '/Registration' do
@registerees = User.all(:isRegistered => true)
erb :registration
View gist:1037818
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
View gist:1041594
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 / gist:1041599
Created Jun 23, 2011
DataMapper Error On Update
View gist:1041599
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
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
lxcodes / gist:1041698
Created Jun 23, 2011
Ajax Post -- Registration
View gist:1041698
<form id="registration" action="/register" method="post" accept-charset="utf-8">
<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>
<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>
lxcodes / Error
Created Jun 23, 2011
Validation Helper
View Error
ArgumentError at /faca-sua-insricao
invalid byte sequence in US-ASCII
file: utils.rb location: gsub line: 153
#<NoMethodError: undefined method `errors' for nil:NilClass>
lxcodes / app.rb
Created Jun 26, 2011
Sinatra Load Routes
View app.rb
# 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)) }
You can’t perform that action at this time.