Skip to content

Instantly share code, notes, and snippets.

$('id_of_form').observe('submit', function(e){
var form = e.element();
// stops it from submitting
Event.stop(e);
// use the form action, or a hardcoded URL
var url = form.action;
new Ajax.Request(url, {
parameters: form.serialize(),
~/Sites/fortaleza[master]$ git checkout vcgames-list-all-games-page
error: Untracked working tree file 'public/flash/games/vcgames/PinBall/PinBallLogo.swf' would be overwritten by merge.
~/Sites/fortaleza[master]$ rm public/flash/games/vcgames/PinBall/PinBallLogo.swf
~/Sites/fortaleza[master*]$ git checkout vcgames-list-all-games-page
Switched to branch 'vcgames-list-all-games-page'
~/Sites/fortaleza[vcgames-list-all-games-page]$ git rebase master
First, rewinding head to replay your work on top of it...
error: Untracked working tree file 'public/flash/games/vcgames/PinBall/PinballLogo.swf' would be overwritten by merge.
could not detach HEAD
~/Sites/fortaleza[vcgames-list-all-games-page]$ mv public/flash/games/vcgames/PinBall/PinBallLogo.swf public/flash/games/vcgames/PinBall/PinballLogo.swf
@rlivsey
rlivsey / Rake task to wipe CSS files generated by SASS
Created June 22, 2009 20:29
Rake task to wipe CSS files generated by SASS
namespace :mb do
namespace :sass do
desc "clear out all Sass generated stylesheets"
task :wipe => :merb_env do
template_location = Sass::Plugin.options[:template_location]
Dir.glob(File.join(template_location, "**", "*.sass")).entries.each do |file|
name = file.sub(template_location + "/", "")[0...-5]
css = Sass::Plugin.send(:css_filename, name)
@rlivsey
rlivsey / gist:135147
Created June 24, 2009 10:40
useless comments
# Setting play_mode equals params mode if it exists and is equals fun or real
play_mode = params[:mode] if params[:mode] and ['fun', 'real'].include? params[:mode]
# Setting play mode equals fun if user is not logged in
play_mode = 'fun' unless has_user_logged?
# Setting game_mode equals demoplay when play_mode equals fun
game_mode = play_mode == 'fun' ? 'demoplay' : ''
@rlivsey
rlivsey / post-receive
Created July 3, 2009 10:35
git post-receive hook to trigger different Hudson build based on the branch
#!/usr/bin/env ruby
while (input = STDIN.read) != ''
rev_old, rev_new, ref = input.split(" ")
url = nil
if ref == "refs/heads/master"
url = "http://172.23.0.150:8080/job/Project%20Master/build"
elsif ref == "refs/heads/other-branch"
url = "http://172.23.0.150:8080/job/Project%20Other/build"
irb(main):001:0> name = "réunion-journalière"
=> "r\303\251union-journali\303\250re"
irb(main):002:0> File.open(name, 'w'){|f| f.write 'x' }
=> 1
irb(main):003:0> exit
$ ls -al
> total 36
> drwxr-xr-x 2 rlivsey rlivsey 4096 Jul 3 22:00 .
> drwxrwxr-x 10 rlivsey rlivsey 4096 Jul 3 12:20 ..
@rlivsey
rlivsey / gist:140359
Created July 3, 2009 22:38
Simplified code to show what the issue was
# broked
def render_pdf(html, name)
in_file = "#{name}.xhtml"
out_file = "#{name}.pdf"
# if the file name contains accents, they are changed to '??'
File.open(in_file, 'w') do |f|
f.write html
end
# returns duplicates, essentially the same as the datamapper query
SELECT books.*
FROM books
INNER JOIN readers ON readers.book_id = books.id
WHERE readers.user_id = xxx OR books.private = FALSE
# gets rid of the duplicates because of the DISTINCT
SELECT DISTINCT books.*
FROM books
INNER JOIN readers ON readers.book_id = books.id
document.observe('dom:loaded', function(){
$$('select.changer').each(function(select){
select.observe('change', function(){
new Ajax.Updater('other_div', '/some/action', {
parameters: {selected: $F(select)}
});
});
});
});
document.observe('dom:loaded', function(){
$$('select.changer').each(function(select){
select.observe('change', function(){
new Ajax.Updater('other_div', '/some/action', {
parameters: {selected: $F(select)}
});
});
});
});