Skip to content

Instantly share code, notes, and snippets.

Thorsten Ball mrnugget

Block or report user

Report or block mrnugget

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1364674
$(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")
}
View gist:1364971
$(function() {
$(".session li.file").each(function() {
$(this).click(function() {
$(this).toggleClass("file-active");
$(this).children(".file-info").toggleClass("hidden");
});
});
});
View gist:1438953
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
View gist:1443098
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
View gist:1443133
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
View gist:1447507
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
View gist:1455161
module Archive
class Directory
attr_accessor :directory
def initialize(dir)
@directory = dir
@sessions = []
end
View gist:1478279
## 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
View gist:1478496
require 'spec_helper'
describe SessionsController do
render_views
#
#
#
describe "GET 'new'" do
it "should be successful" do
get :new
View gist:1510383
#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
You can’t perform that action at this time.