Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
$(function() {
$(".session li.file").each(function() {
elem = $(this).children(".file-info");
$(this).click(function() {
if($(this).hasClass("file-active"))
{
$(this).removeClass("file-active")
} else {
$(this).addClass("file-active")
}
$(function() {
$(".session li.file").each(function() {
$(this).click(function() {
$(this).toggleClass("file-active");
$(this).children(".file-info").toggleClass("hidden");
});
});
});
class Song < ActiveRecord::Base
belongs_to :session
validates :file_name, :presence => true
validate :file_name_has_to_be_audio
def file_name_has_to_be_audio
unless ['mp3', 'MP3', 'flac', 'FLAC', 'wav', 'WAV'].include? file_name.split(".").last
errors.add(:file_name, "has to be mp3/flac/wav file")
end
@mrnugget
mrnugget / gist:1443098
Created December 7, 2011 14:54
No return
ruby-1.9.2-p290 :021 > def f_in_d(dir)
ruby-1.9.2-p290 :022?> d = Dir.new(dir)
ruby-1.9.2-p290 :023?> audio_files = Array.new
ruby-1.9.2-p290 :024?> d.entries.each do |f|
ruby-1.9.2-p290 :025 > if File.directory?(f) && f != "." && f != ".."
ruby-1.9.2-p290 :026?> audio_files.push(Dir.glob("#{dir}/#{f}/*.{mp3,flac,wav}"))
ruby-1.9.2-p290 :027?> end
ruby-1.9.2-p290 :028?> end
ruby-1.9.2-p290 :029?> return audio_files
ruby-1.9.2-p290 :030?> end
ruby-1.9.2-p290 :001 > dir = "/media/james/howling_vibes/aufnahmen/"
=> "/media/james/howling_vibes/aufnahmen/"
ruby-1.9.2-p290 :002 > d = Dir.new(dir)
=> #<Dir:/media/james/howling_vibes/aufnahmen/>
ruby-1.9.2-p290 :003 > audio_files = []
=> []
ruby-1.9.2-p290 :004 > d.entries.each do |f|
ruby-1.9.2-p290 :005 > if File.directory?(f) && f != "." && f != ".."
ruby-1.9.2-p290 :006?> audio_files.push(Dir.glob("#{dir}/#{f}/*.{mp3,flac,wav}"))
ruby-1.9.2-p290 :007?> end
Failures:
1) Archive::ArchiveDirectory should initalize
Failure/Error: ArchiveDirectory.new(dir).directory.should == dir
NameError:
uninitialized constant ArchiveDirectory
# ./spec/lib/archive_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.31153 seconds
1 example, 1 failure
module Archive
class Directory
attr_accessor :directory
def initialize(dir)
@directory = dir
@sessions = []
end
## sessions_controller.rb ##
def new
@title = "Add session"
archive = Archive::Directory.new(Rails.root.join("spec/fixtures/archive"))
@new_files = files_in_archive_not_in_db(archive)
end
private
require 'spec_helper'
describe SessionsController do
render_views
#
#
#
describe "GET 'new'" do
it "should be successful" do
get :new
#session_spec.rb
it "should show songs in the right order" do
song1 = @session.songs.create(:file_name => "03.testing.mp3")
song2 = @session.songs.create(:file_name => "01.testing.mp3")
@session.songs.should == [song2, song1]
end
#session.rb