source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/traverse_spiral_matrix.rb
Ruby
mit
88
master
1,065
# Traverse 2D Array in a spiral # Set 4 variables to define the outer bounds # of the matrix - left, right, top, bottom # Set a direction: 0 -> left to right, 1 -> top to bottom, # 2 -> right to left, 3 -> bottom to top # At each iteration check which direction is set and # iterate through those values in the matrix # ...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/binary_search_tree_from_array.rb
Ruby
mit
88
master
275
def create_binary_tree(arr, arr_start, arr_end) return if arr_start > arr_end mid = arr_start + arr_end / 2 root = Node.new(arr[mid]) root.left = create_binary_tree(arr, arr_start, mid - 1) root.right = create_binary_tree(arr, mid + 1, arr_end) root end
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/binary_tree_to_linked_list.rb
Ruby
mit
88
master
738
# Given a binary tree, convert it to a doubly linked list without creating new nodes. # # Definition for a binary tree node. # class TreeNode # attr_accessor :val, :left, :right # def initialize(val) # @val = val # @left, @right = nil, nil # end # end # @param {TreeNode} root # @return {Str...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/first_bad_version.rb
Ruby
mit
88
master
1,211
# You are a product manager and currently leading a team to develop a new product. # Unfortunately, the latest version of your product fails the quality check. # Since each version is developed based on the previous version, # all the versions after a bad version are also bad. # # Suppose you have n versions [1, 2, ......
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/loop_detection.rb
Ruby
mit
88
master
1,380
# CtCI 6th Edition Problem 2.8 # Loop Detection: Given a circular linked list, implement an algorithm that returns the node at the # beginning of the loop. # DEFINITION # Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node, so # as to make a loop in the linked list. # ...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/find_linked_list_cycle.rb
Ruby
mit
88
master
369
def find_linked_list_cycle(list) return false unless list slow = list.head fast = list.head while fast && !fast.next.nil? slow = slow.next fast = fast.next.next if slow == fast break end end return false if fast.nil? || fast.next.nil? until slow == fast slow = head slow = ...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/path_between_two_nodes.rb
Ruby
mit
88
master
660
# needs refactoring class BFS def initialize(graph, s) @graph = graph @s = s @visited = [@s] @edge_to = {} end def bfs(target) return true if target == @s queue = [@s] while queue.length > 0 node = queue.shift @graph[node].each do |child_node| return true i...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/palindrome.rb
Ruby
mit
88
master
2,107
# CtCI 6th Edition Problem 2.6 # Palindrome: Implement a function to check if a linked list is a palindrome. class Node attr_accessor :data, :next, :prev def initialize(data) @data = data @next = nil @prev = nil end def to_a @next.nil? ? [data] : [data] + @next.to_a end end class LinkedLis...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/tree_breadth_first_search.rb
Ruby
mit
88
master
355
def bfs_tree(node) queue = [node] while queue.size != 0 n = queue.shift puts n.value n.children.each do |child| queue.push(child) end end end def bfs_binary_tree(node) queue = [node] while queue.size != 0 n = queue.shift puts n.value queue.push(n.left) if n.left queue....
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/count_primes.rb
Ruby
mit
88
master
334
# Count the number of prime numbers less than a non-negative number, n. # # @param {Integer} number # @return {Integer} def count_primes(n) primes = [nil, nil, *2..n] (0..Math.sqrt(n)).each do |i| (i**2..n).step(i) { |composite_number| primes[composite_number] = nil } unless primes[i].nil? end primes.comp...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/palindrome_linked_list.rb
Ruby
mit
88
master
1,528
# Refactor/rewrite this file class Node attr_accessor :value, :next def initialize(val, next_in_line) @value = val @next = next_in_line end end class LinkedList attr_accessor :head def initialize(val) @head = Node.new(val, nil) end def add(value) # Traverse to the end of the list ...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/root_to_leaf_paths.rb
Ruby
mit
88
master
589
# Given a binary tree, return all root-to-leaf paths. # # Definition for a binary tree node. # class TreeNode # attr_accessor :val, :left, :right # def initialize(val) # @val = val # @left, @right = nil, nil # end # end # @param {TreeNode} root # @return {String[]} def root_to_leaf_paths(r...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/pascals_triangle.rb
Ruby
mit
88
master
333
# @param {Integer} num_rows # @return {Integer[][]} # 1 # 1 1 # 1 2 1 # 1 3 3 1 def pascals_triangle(num_rows) rows = [[1], [1, 1]] while rows.count < num_rows new_row = [1] rows.last.each_cons(2) { |first, second| new_row << first + second } new_row << 1 rows << new_row end rows[0...n...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/missing_number.rb
Ruby
mit
88
master
315
# Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. # # @param {Integer[]} numbers # @return {Integer} def missing_number(numbers) last = -1 numbers.each do |number| return number - 1 unless number - 1 == last last = number end end
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/rotate_array.rb
Ruby
mit
88
master
260
def rotate_array(arr, n) reverse(reverse(arr[0...n]) + reverse(arr[n..arr.length - 1])) end def reverse(arr) i = 0 j = arr.length - 1 while i < j temp = arr[i] arr[i] = arr[j] arr[j] = temp i += 1 j -= 1 end arr end
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/two_sum.rb
Ruby
mit
88
master
428
# Given an integer x and a sorted array a of N distinct integers, # design a linear-time algorithm to determine if there exists # two distinct indices i and j such that arr[i] + arr[j] == x # @param {Array[]} arr # @return {Boolean} def two_sum(numbers, sum) possible_integers = Set.new numbers.each do |number| ...
github
Dbz/Algorithms
https://github.com/Dbz/Algorithms
algorithms/intersection.rb
Ruby
mit
88
master
1,520
# CtCI 6th Edition Problem 2.7 # Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the intersecting # node. Note that the intersection is defined based on reference, not value. That is, if the kth # node of the first linked list is the exact same node (by reference) as the jth ...
github
german/redis_orm
https://github.com/german/redis_orm
Rakefile
Ruby
mit
88
master
726
require 'rubygems' require 'rake' require 'rake/testtask' =begin require 'echoe' Echoe.new('redis_orm', '0.7') do |p| p.description = "ORM for Redis (advanced key-value storage) with ActiveRecord API" p.url = "https://github.com/german/redis_orm" p.author = "Dmitrii Samoilov" p.email ...
github
german/redis_orm
https://github.com/german/redis_orm
redis_orm.gemspec
Ruby
mit
88
master
1,501
Gem::Specification.new do |s| s.name = "redis_orm" s.version = "0.9" s.authors = ["Dmitrii Samoilov"] s.date = "2024-07-19" s.description = "ORM for Redis (advanced key-value storage) with ActiveRecord API" s.email = "germaninthetown@gmail.com" s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "T...
github
german/redis_orm
https://github.com/german/redis_orm
spec/association_indices_spec.rb
Ruby
mit
88
master
9,546
require 'spec_helper' describe "check indices for associations" do before(:each) do @article = Article.new :title => "DHH drops OpenID on 37signals" @article.save expect(@article).to be expect(@article.title).to eq("DHH drops OpenID on 37signals") @comment1 = Comment.new :body => "test" @co...
github
german/redis_orm
https://github.com/german/redis_orm
spec/spec_helper.rb
Ruby
mit
88
master
724
require 'rails/all' require 'rspec' require_relative '../lib/redis_orm' $: << File.dirname(File.expand_path(__FILE__)) + '/../lib/' module RedisOrmRails class Application < ::Rails::Application end end require 'rspec/rails' require 'ammeter/init' Dir.glob(['spec/classes/*.rb', 'spec/modules/*.rb']).each do |kla...
github
german/redis_orm
https://github.com/german/redis_orm
spec/polymorphic_spec.rb
Ruby
mit
88
master
2,099
require 'spec_helper' describe "check polymorphic property" do it "should provide proper associations and save records correctly for has_one/belongs_to polymorphic" do book = Book.new title: "Permutation City", price: 1529 book.save giftcard = Giftcard.create title: "Happy New Year!" ci1 = CatalogI...
github
german/redis_orm
https://github.com/german/redis_orm
spec/uuid_as_id_spec.rb
Ruby
mit
88
master
4,707
require 'spec_helper' describe "check basic functionality" do it "test_simple_creation" do UuidUser.count.should == 0 user = UuidUser.new :name => "german" user.save user.should be user.id.should be user.id.should_not == 1 user.id.length.should == 32 # b57525b09a69012e8fbe001d61192...
github
german/redis_orm
https://github.com/german/redis_orm
spec/expire_records_spec.rb
Ruby
mit
88
master
3,578
require 'spec_helper' describe "expire record after specified time" do it "should create a record and then delete if *expire* method is specified in appropriate class" do euser = ExpireUser.create :name => "Ghost rider" $redis.ttl(euser.__redis_record_key).should be > 9.minutes.from_now.to_i $redis.ttl(e...
github
german/redis_orm
https://github.com/german/redis_orm
spec/associations_spec.rb
Ruby
mit
88
master
9,038
require 'spec_helper' describe "check associations" do before(:each) do @article = Article.new :title => "DHH drops OpenID on 37signals" @article.save @article.should be @article.title.should == "DHH drops OpenID on 37signals" @comment1 = Comment.new :body => "test" @comment1.save @comm...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/cutout.rb
Ruby
mit
88
master
442
class Cutout < RedisOrm::Base property :filename, String before_create :increase_revisions before_destroy :decrease_revisions def increase_revisions ca = CutoutAggregator.last ca.update_attribute(:revision, ca.revision + 1) if ca end def decrease_revisions ca = CutoutAggregator.first if c...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/uuid_default_user.rb
Ruby
mit
88
master
375
class UuidDefaultUser < RedisOrm::Base use_uuid_as_id property :name, String, :default => "german" property :age, Integer, :default => 26 property :wage, Float, :default => 256.25 property :male, RedisOrm::Boolean, :default => true property :admin, RedisOrm::Boolean, :default => false property :crea...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/user.rb
Ruby
mit
88
master
1,016
class User < RedisOrm::Base property :name, String property :first_name, String property :last_name, String property :karma, Integer, default: 1000 property :age, Integer property :wage, Float property :male, RedisOrm::Boolean property :created_at, DateTime property :modified_at, DateTime propert...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/uuid_user.rb
Ruby
mit
88
master
272
class UuidUser < RedisOrm::Base use_uuid_as_id property :name, String property :age, Integer property :wage, Float property :male, RedisOrm::Boolean property :created_at, DateTime property :modified_at, DateTime has_many :users, :as => :friends end
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/sortable_user.rb
Ruby
mit
88
master
338
class SortableUser < RedisOrm::Base property :name, String, sortable: true property :age, Integer, sortable: true, default: 26.0 property :wage, Float, sortable: true, default: 20_000 property :address, String, default: "Singa_poor" property :test_type_cast, RedisOrm::Boolean, default: false index :age ...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/default_user.rb
Ruby
mit
88
master
336
class DefaultUser < RedisOrm::Base property :name, String, default: "german" property :age, Integer, default: 26 property :wage, Float, default: 256.25 property :male, RedisOrm::Boolean, default: true property :admin, RedisOrm::Boolean, default: false property :created_at, DateTime property :modified_a...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/article_with_comments.rb
Ruby
mit
88
master
203
class ArticleWithComments < RedisOrm::Base property :title, String property :comments, Array property :rates, Hash, default: {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0} has_many :categories end
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/custom_user.rb
Ruby
mit
88
master
227
class CustomUser < RedisOrm::Base property :first_name, String property :last_name, String index :first_name, :unique => false index :last_name, :unique => false index [:first_name, :last_name], :unique => true end
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/comment.rb
Ruby
mit
88
master
550
class Comment < RedisOrm::Base property :body, String property :text, String property :moderated, RedisOrm::Boolean, :default => false index :moderated belongs_to :user belongs_to :article has_many :comments, :as => :replies belongs_to :comment, :as => :reply_to before_save :trim_whitespaces aft...
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/expire_user_with_predicate.rb
Ruby
mit
88
master
283
class ExpireUserWithPredicate < RedisOrm::Base property :name, String property :persist, RedisOrm::Boolean, :default => false expire 10.minutes.from_now, :if => Proc.new {|r| !r.persist?} has_many :articles has_one :profile def persist? !!self.persist end end
github
german/redis_orm
https://github.com/german/redis_orm
spec/classes/photo.rb
Ruby
mit
88
master
506
class Photo < RedisOrm::Base property :image, String property :image_type, String property :checked, RedisOrm::Boolean, :default => false index :checked property :inverted, RedisOrm::Boolean, :default => true index :inverted index :image index [:image, :image_type] belongs_to :album belo...
github
german/redis_orm
https://github.com/german/redis_orm
spec/generators/model_generator_spec.rb
Ruby
mit
88
master
692
require 'spec_helper' require 'rails/generators/redis_orm/model/model_generator' describe RedisOrm::Generators::ModelGenerator do destination File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'tmp')) before do prepare_destination run_generator args end subj...
github
german/redis_orm
https://github.com/german/redis_orm
spec/modules/has_many_model_within_module.rb
Ruby
mit
88
master
268
module HasManyModelWithinModule class SpecialComment < RedisOrm::Base property :body, String, :default => "test" belongs_to :brochure, :as => :book end class Brochure < RedisOrm::Base property :title, String has_many :special_comments end end
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/atomicity_spec.rb
Ruby
mit
88
master
1,033
require 'spec_helper.rb' describe "check atomicity" do let(:init_value) { 1 } let(:number_of_threads) { 100 } it "should properly increment property's value" do article = Article.create({title: "Simple test atomicity with multiple threads", karma: init_value}) threads = [] number_of_threads.tim...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/expire_records_spec.rb
Ruby
mit
88
master
3,581
require 'spec_helper.rb' describe "expire record after specified time" do it "should create a record and then delete if *expire* method is specified in appropriate class" do euser = ExpireUser.create :name => "Ghost rider" $redis.ttl(euser.__redis_record_key).should be > 9.minutes.from_now.to_i $redis.tt...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/changes_array_spec.rb
Ruby
mit
88
master
769
require 'spec_helper.rb' describe "check associations" do it "should return correct _changes array" do user = User.new name: "german" # expect(user.name_changed?).to be_falsey expect(user.name_change).to eq([nil, "german"]) user.save expect(user.name_change).to eq(nil) user.name = "...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/validations_spec.rb
Ruby
mit
88
master
554
require 'spec_helper.rb' describe "check associations" do it "should validate presence if image in photo" do p = Photo.new expect(p.save).to be_falsey expect(p.errors).to be expect(p.errors[:image]).to include("can't be blank") p.image = "test" expect(p.save).to be_falsey expect(p.errors...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/uuid_as_id_spec.rb
Ruby
mit
88
master
4,511
require 'spec_helper.rb' describe "check basic functionality" do it "test_simple_creation" do UuidUser.count.should == 0 user = UuidUser.new :name => "german" user.save user.should be user.id.should be user.id.should_not == 1 user.id.length.should == 32 # b57525b09a69012e8fbe001d61...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/sortable_spec.rb
Ruby
mit
88
master
6,655
require 'spec_helper.rb' describe "test options" do before(:each) do @dan = SortableUser.create name: "Daniel", age: 26, wage: 40000.0, address: "Bellevue" @abe = SortableUser.create name: "Abe", age: 30, wage: 100000.0, address: "Bellevue" @michael = SortableUser.create name: "Michael", age: 25, wage: 6...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/has_one_has_many_spec.rb
Ruby
mit
88
master
1,120
require 'spec_helper.rb' describe "check associations" do it "should save associations properly" do @profile = Profile.new @profile.name = "my profile" @profile.save @profile.should be @profile.name.should == "my profile" @location1 = Location.new @location1.coordinates = "44.343456345 ...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/callbacks_spec.rb
Ruby
mit
88
master
1,290
require 'spec_helper.rb' describe "check callbacks" do it "should fire after_create/after_destroy callbacks" do user = User.create(first_name: "Robert", last_name: "Pirsig") expect($redis.zrank("users:sorted_by_rating", user.id)).to eq(0) comment = Comment.create :text => "First!" user.comments << c...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/exceptions_spec.rb
Ruby
mit
88
master
1,686
require 'spec_helper.rb' describe "exceptions test" do it "should raise an exception if association is provided with improper class" do expect(User.count).to eq(0) user = User.new name: "german", age: 26 user.save expect(user).to be expect(user.name).to eq('german') expect(User.count).to eq...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/association_indices_spec.rb
Ruby
mit
88
master
9,046
require 'spec_helper' describe "check indices for associations" do before(:each) do @article = Article.new :title => "DHH drops OpenID on 37signals" @article.save @article.should be @article.title.should == "DHH drops OpenID on 37signals" @comment1 = Comment.new :body => "test" @comment1.sa...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/dynamic_finders_spec.rb
Ruby
mit
88
master
1,856
require 'spec_helper.rb' describe "check associations" do class DynamicFinderUser < RedisOrm::Base property :first_name, String property :last_name, String index :first_name, :unique => true index :last_name, :unique => true index [:first_name, :last_name], :unique => false end it "should ...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/indices_spec.rb
Ruby
mit
88
master
2,274
require 'spec_helper.rb' describe "check indices" do it "should change index accordingly to the changes in the model" do user = User.new :first_name => "Robert", :last_name => "Pirsig" user.save u = User.find_by_first_name("Robert") u.id.should == user.id u = User.find_by_first_name_and_last_na...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/basic_functionality_spec.rb
Ruby
mit
88
master
5,194
require 'spec_helper.rb' describe "check basic functionality" do it "should have 3 models in descendants" do RedisOrm::Base.descendants.should include(User, DefaultUser, TimeStamp) RedisOrm::Base.descendants.should_not include(EmptyPerson) end it "should return the same user" do user = User.new na...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/options_spec.rb
Ruby
mit
88
master
9,230
require 'spec_helper.rb' describe "test options" do before(:each) do @album = Album.new @album.title = "my 1st album" @album.save @album.should be @album.title.should == "my 1st album" @photo1 = Photo.new :image => "facepalm.jpg", :image_type => "jpg", :checked => true @photo1.save ...
github
german/redis_orm
https://github.com/german/redis_orm
spec/models/associations_spec.rb
Ruby
mit
88
master
9,028
require 'spec_helper.rb' describe "check associations" do before(:each) do @article = Article.new :title => "DHH drops OpenID on 37signals" @article.save @article.should be @article.title.should == "DHH drops OpenID on 37signals" @comment1 = Comment.new :body => "test" @comment1.save @c...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm.rb
Ruby
mit
88
master
397
require 'active_model' require 'redis' require 'uuid' require_relative 'redis_orm/associations/belongs_to' require_relative 'redis_orm/associations/has_many_helper' require_relative 'redis_orm/associations/has_many_proxy' require_relative 'redis_orm/associations/has_many' require_relative 'redis_orm/associations/has_on...
github
german/redis_orm
https://github.com/german/redis_orm
lib/rails/generators/redis_orm/model/model_generator.rb
Ruby
mit
88
master
553
require 'rails/generators' require 'rails/generators/named_base' module RedisOrm module Generators class ModelGenerator < ::Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) desc "Creates a RedisOrm model" argument :attributes, type: :array, default: [], banne...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/redis_orm.rb
Ruby
mit
88
master
34,992
require 'active_support/inflector/inflections' require 'active_support/inflector/transliterate' require 'active_support/inflector/methods' require 'active_support/inflections' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/time/acts_like' require 'active_support/core_ext/time/cal...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/utils.rb
Ruby
mit
88
master
293
module RedisOrm module Utils def calculate_key_for_zset(string) return 0.0 if string.nil? sum = "" string.codepoints.each do |codepoint| sum += ("%05i" % codepoint.to_s) # 5 because 65536 => 2 bytes UTF-8 end "0.#{sum}".to_f end end end
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/associations/has_one.rb
Ruby
mit
88
master
4,525
module RedisOrm module Associations module HasOne # user.avatars => user:1:avatars => [1, 22, 234] => Avatar.find([1, 22, 234]) # *options* is a hash and can hold: # *:as* key # *:dependant* key: either *destroy* or *nullify* (default) def has_one(foreign_model, options = {}) ...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/associations/has_many.rb
Ruby
mit
88
master
4,307
module RedisOrm module Associations module HasMany # user.avatars => user:1:avatars => [1, 22, 234] => Avatar.find([1, 22, 234]) # options # *:dependant* key: either *destroy* or *nullify* (default) def has_many(foreign_models, options = {}) class_associations = class_variable_ge...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/associations/belongs_to.rb
Ruby
mit
88
master
5,752
module RedisOrm module Associations module BelongsTo # class Avatar < RedisOrm::Base # belongs_to :user # end # # class User < RedisOrm::Base # has_many :avatars # end # # avatar.user => avatar:234:user => 1 => User.find(1) def belongs_to(foreign_m...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/associations/has_many_helper.rb
Ruby
mit
88
master
778
module RedisOrm module Associations module HasManyHelper private def save_index_for_associated_record(index, record, index_prefix) index_name = if index.name.is_a?(Array) # TODO sort alphabetically index.name.inject(index_prefix) do |sum, index_part| sum += [index_part,...
github
german/redis_orm
https://github.com/german/redis_orm
lib/redis_orm/associations/has_many_proxy.rb
Ruby
mit
88
master
7,371
module RedisOrm module Associations class HasManyProxy include HasManyHelper def initialize(receiver_model_name, reciever_id, foreign_models, options) @records = [] @reciever_model_name = receiver_model_name.to_s.downcase @reciever_id = reciever_id @foreign_model...
github
german/redis_orm
https://github.com/german/redis_orm
benchmarks/sortable_benchmark.rb
Ruby
mit
88
master
1,583
require File.expand_path(File.dirname(__FILE__) + '/../lib/redis_orm') require 'benchmark' class User < RedisOrm::Base property :name, String property :age, Integer property :wage, Float index :name index :age end class SortableUser < RedisOrm::Base property :name, String, :sortable => true property ...
github
amiika/ziffers
https://github.com/amiika/ziffers
ziffers.rb
Ruby
mit
88
master
64,871
require_relative "load_libs.rb" require_relative "./lib/enumerables.rb" require_relative "./lib/monkeypatches.rb" require_relative "./lib/parser/zgrammar.rb" require_relative "./lib/ziffarray.rb" require_relative "./lib/ziffhash.rb" require_relative "./lib/common.rb" require_relative "./lib/generators.rb" require_relat...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/monkeypatches.rb
Ruby
mit
88
master
3,311
module RangeZiffers include SonicPi::Lang::WesternTheory def to_z self.to_a.map {|degree| get_ziff(degree) } end end Range.include RangeZiffers module NoteHelper include SonicPi::Lang::WesternTheory def to_h (note_info self).to_h end end Integer.include NoteHelper class SonicPi::Scale def self...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/pc_sets.rb
Ruby
mit
88
master
58,080
module Ziffers def forte(n) if n.is_a?(String) r = FORTE.key(n) elsif n.is_a?(Integer) r = FORTE.keys[n] elsif n.is_a?(Array) r = n.sort r = FORTE[r] r = "No forte name for: "+n.to_s if !r end r ? r : [] end # From http //www.stephenandrewtaylor.net/setfinder/ind...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/ziffarray.rb
Ruby
mit
88
master
18,680
require_relative "./generators.rb" require_relative "./defaults.rb" ''' # For testing and debugging load "~/ziffers/lib/generators.rb" load "~/ziffers/lib/defaults.rb" ''' module Ziffers class ZiffArray < Array include Comparable include Ziffers::Generators include Ziffers::Defaults # Endless list ...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/common.rb
Ruby
mit
88
master
6,549
module Ziffers module Common include Ziffers::Defaults @@degree_based = false def set_degree_based(degrees=!@@degree_based) @@degree_based = degrees end def get_note_from_dgr(dgr, zkey, zscale, oct=0, add=0) ziff = get_ziff(dgr,zkey,zscale,oct,add) ziff[:note] end...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/generators.rb
Ruby
mit
88
master
8,608
require_relative "./defaults.rb" ''' # For testing and debugging load "~/ziffers/lib/defaults.rb" ''' module Ziffers module Generators include Ziffers::Defaults def ints_to_lengths(val,map=nil) val.map {|n| int_to_length(n,map) } end # Creates tone matrix from the given row. Given row should be in a...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/defaults.rb
Ruby
mit
88
master
5,132
module Ziffers module Defaults def int_to_length(val,map=nil) if map map[val%map.length] else # ['e','q','q.','h','h.','w','w.','d','d.','l'] # 0.125, 0.25, 0.375, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0 k = @@rhythm_keys[val%@@rhythm_keys.length] @@default_durs[k.t...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/enumerables.rb
Ruby
mit
88
master
16,691
module Ziffers module Enumerables def create_ruleset(n) rules = Hash.new return rules if n > 255 binary = "%08b" % n 8.times do |i| key = "%03b" % i rules[key] = binary[7-i].to_i end return rules end def mutate(gen, rules) next_gen = [] rul...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/ziffhash.rb
Ruby
mit
88
master
14,539
module Ziffers class ZiffHash < Hash def eql?(other_hash) @@set_keys.filter {|key| self[key] == other_hash[key]} == @@set_keys end # TODO: Add other keys to hash? def hash self[:pc].hash end # Pitch class number def pc return self.pcs if self[:hpc...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/parser/scala.rb
Ruby
mit
88
master
809
require "prime" def cents_to_semitones(cents) """Tranform cents to semitones""" cents = [0.0] + cents unless cents[0] == 0.0 semitone_scale = [] cents.each_with_index do |cent, i| break if i == cents.length - 1 semitone_interval = (cents[i + 1] - cent) / 100.0 semitone_scale << semitone_interval ...
github
amiika/ziffers
https://github.com/amiika/ziffers
lib/parser/zgrammar.rb
Ruby
mit
88
master
11,168
require "treetop" require_relative "../defaults.rb" require_relative "./scala.rb" ''' # For testing and debugging load "~/ziffers/lib/defaults.rb" ''' module Ziffers module Grammar include SonicPi include SonicPi::Lang::WesternTheory include Ziffers::Defaults Treetop.load(File.expand_path(File.join...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/play_tests.rb
Ruby
mit
88
master
5,983
load "~/ziffers/ziffers.rb" use_synth :piano Ziffers.debug use_bpm 400 def testzplay # Test octaves zplay "e __6 _0 _1 _2 _3 _4 _5 _6 0 1 2 3 4 5 6 ^0 ^1 ^2 ^3 ^4 ^5 ^6 ^^0" # Test degrees zplay "e E T 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -T -E" # frere jacques zplay "[:q 0 1 2 0:] [:q 2 3 ...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/play_loop_tests.rb
Ruby
mit
88
master
346
def loop_tests z1 "0", stop: 1 z2 ->(){rrand_i(1,4)}, stop: 1 z3 (0..Float::INFINITY).lazy.collect{|n|n.to_s(2).split('').count('1')%7}, rhythm:spread(7,9), stop: 1 z4 pi.take(1), scale: :kumoi, synth: :tb303, rhythm: 0.125, cutoff: tweak(:sine,60,100,10).reflect, stop: 1 z5 "q0", rules: {"q"=>"e", "e"=>"q"},...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/run_wiki_tests.rb
Ruby
mit
88
master
14,483
load "~/ziffers/ziffers.rb" Ziffers.debug def test_melody # Note lengths a = zparse "|q 4 2 4 2 |q 4 5 4 2 |q 3 1 3 1 |q 3 4 3 1 |q 4 2 4 2 |q 4 5 4 2 | w4 |q 4 3 2 1 | w0 |" assert_equal(a.pcs,[4, 2, 4, 2, 4, 5, 4, 2, 3, 1, 3, 1, 3, 4, 3, 1, 4, 2, 4, 2, 4, 5, 4, 2, 4, 4, 3, 2, 1, 0]) # Decimal notation a...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/run_wiki_tests_2.rb
Ruby
mit
88
master
5,611
def test_chords # Chords a = zparse "[: i vi v :]" # Play chords as a sequence using default chord length of 1 assert_equal(a.pcs,[[0, 2, 4], [5, 0, 2], [4, 6, 1], [0, 2, 4], [5, 0, 2], [4, 6, 1]]) a = zparse "q [: iv 1 2 3 iii 2 3 4 ii 4 3 2 i 1 2 3 :]", chord_duration: 0 # Play chord simultaniously with the m...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/run_wiki_test_generative.rb
Ruby
mit
88
master
13,174
load "~/ziffers/ziffers.rb" Ziffers.debug def test_generative # Generative syntax with_random_seed 2353 do a = zparse "[: q ? ? ? 0 ? ? ? (1,2) [6,7] (1,2) [6,7] (1,2) [6,7] (1,2) [6 3,[7 2,8 3,9 3,11 3]] :]" assert_equal(a.notes.length,32) a = zparse "([1,4,5,3],[(6,7),(6,[8,10,11]),(6,[9,10,39])])"...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/run_tests.rb
Ruby
mit
88
master
13,303
load "~/ziffers/ziffers.rb" #Ziffers.debug def test1 # Test different timing notations m1 = zparse("[: q. 0 0 | q0 e1 q.2 |q2 e1 q2 e3| h.4 | 0.125 7 7 7 4 4 4 2 2 2 0 0 0| q4 e3 q2 e1 | h.0 :]") print m1 m1_s = m1.durations m1_n = m1.notes m1_n_assert = [0.375, 0.375, 0.25, 0.125, 0.375, 0.25, 0.125, 0...
github
amiika/ziffers
https://github.com/amiika/ziffers
test/run_wiki_test_multi.rb
Ruby
mit
88
master
2,518
load "~/ziffers/ziffers.rb" Ziffers.debug def test_play # Multistaff a = parse_rows " / synth: :pretty_bell [:q 2 2 2 4 q. 4 e 3 h 2 q 2 1 2 4 q. 2 e 1 h 0 :] [: 4 e 5 4 3 2 h 3 e 4 3 2 1 h 2 e 3 2 1 0 q. 1 e _ 4 h 4 q ^ 0 1 2 3 h 2 1 :] [: q 0 0 _ 6 6 ^ 1 _ 6 h ^ 0 q 0 _ 6 ^ 0 0 0 _ 6 h ^ 0 :] [: q 0 e 2 1...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/pitch_helper.rb
Ruby
mit
88
master
1,177
require "~/ziffers/ziffers.rb" # Have a perfect pitch? Find out! # This pling plong tool can also help you to: # Relate sound to numbers or note names # Relate note names to pcs # Configuration pitch_key = :C # Choose key C-B pitch_scale = :chromatic # Scale :chromatic, :major, :minor, :major_pentatonic, :minor_penta...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/fibonacci_chords.rb
Ruby
mit
88
master
288
load "~/ziffers/ziffers.rb" # Good 'old' way to use enumerations def fibonacci Enumerator.new do |y| a = b = 1 while true y << a a, b = b, a + b end end end enum = fibonacci live_loop :fibonacci_chords do zplay enum, duration: 0.5, parse_chord: true end
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/avril14th.rb
Ruby
mit
88
master
2,261
load "~/ziffers/ziffers.rb" # Avril 14th by Aphex Twin # Created automatically from MIDI file using: https://github.com/amiika/ziffers-musescore ziff " / synth: :piano, sustain: 2.0, decay: 0.6 | [: q ^ 2 _ 5 ^ 0 e r s 0 | sq. 5 e 5 ^ 4 3 2 0 :] | [: q ^^ 2 _ 5 ^ 0 e r s 0 | \ | sw ^ 5 :] | [: q. 2 s 2 sq. 4 e ...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/solfeggio.rb
Ruby
mit
88
master
325
# Simple example inspired by Arvo Pärt's Solfeggio Ziffers.set_default_opts(synth: :hollow, sustain: 1.5) z1 "0 r r r r 5 r r r r 4 r r r r 2 r r r 6" z2 "r 1 r r r r 6 r r r r r r r 1 r 3 r r r", octave: -1 z3 "r r 2 r 4 r r r 2 r r 5 r 0 r r r 4 r r", octave: -2 z4 "r r r 3 r r r 1 r 3 r r 6 r r r r r 5 r", octave:...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/royal_theme_loop.rb
Ruby
mit
88
master
322
load "~/ziffers/ziffers.rb" use_bpm 140 royal_theme = zparse "h 0 2 | 4 5 | #-1 q r 4 | h #3 3 | #2 b2 | q 2 1 b1 0 | q #-1 e #-2 #-3 q 0 3 | h 2 1 | w 0 |", scale: :minor z0 royal_theme, synth: :piano z1 royal_theme, phase: 0.15, synth: :kalimba z2 royal_theme, phase: 0.25, synth: :piano, octave: -1: :fm, octave: -...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/ievan_polka.rb
Ruby
mit
88
master
429
load "~/ziffers/ziffers.rb" use_bpm 300 ievanpolka = \ "[:q 0 e 0 0 q 0 1 | q 2 0 0 2 | <(q1 _ 6 6 ^1 |q2 0 h0) (q. 4 e3 q 2 1|q 2 0 h0)> :]"\ "[:q 4 e 4 4 q 3 2 | q 1 _ 6 6 ^1 | <(q3 e3 3 q2 1|q2 0 0 2) (q3 e 3 3 q 2 1|q 2 0 h0)> :]" n = zparse ievanpolka, key:"g", scale:"minor" notes = zparams(n, :note) du...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/musical_dice_game_piece.rb
Ruby
mit
88
master
7,869
load "~/ziffers/ziffers.rb" # Musical dice game: https://opus-infinity.org/dice_games/mozart_waltz/ # Still work in progress use_bpm 100 use_synth :piano use_random_seed 52335 tremble = [ "e ^ 3 1 4 ", "e , 5 s #3 4 6 ^ 4 ", "e ^ 4 0 2 ", "e ^ 4 q 1 ", "q ,46^14 e r ", "e , 4 ^ 0 2 ", "s ^ 2 0 2 4 ^^ 0 ^ 4 ", "q ^ 0...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/moonlight_loop.rb
Ruby
mit
88
master
289
load "~/ziffers/ziffers.rb" use_synth :piano use_bpm 100 zloop :moonlight, "h 07 [: (-3 0 2) :4] -16 [: (-3 0 2) :4] -25 [: (-2 0 2) :] -43 [: (-2 b1 3) :] -34 (-3 #-1 3) (-3 0 2) -34 (-3 0 #1) (-4 -1 1)", key: :cs4, scale: :minor, release: 4, sustain: 3, decay: 1, chord_key: :cs2
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/ziffers_with_define.rb
Ruby
mit
88
master
207
load "~/ziffers/ziffers.rb" define :foo do zplay "s123" end define :bar do |v=nil| zplay v ? v.to_s : "s531" end zplay "q F B F e B B B", F: :foo, B: :bar zplay "e:foo:bar(342) n:bar(012) :bar(438)"
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/keyboard_input.rb
Ruby
mit
88
master
363
require "~/ziffers/ziffers.rb" # Play ziffers using keyboard # On windows: https://in-thread.sonic-pi.net/t/connecting-sonic-pi-to-virtual-midi-piano-keyboard-on-windows-10/176 live_loop :midi_piano do use_real_time note, velocity = sync "/midi/loopmidi_port/0/1/note_on" print note zmidi note, {sample: :ambi_...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/simple_cycles.rb
Ruby
mit
88
master
214
load "~/ziffers/ziffers.rb" z1 "q 1 2 3 4", key: :g, seed: 1, cycle: [ { at: 2, offset: ->(i){i%10}, inverse: true }, { at: 4, first: 2, retrograde: 2, inverse: -1 }, { at: 8, from: 6, to: 7, inverse: 3 } ]
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/solfeggio_2.rb
Ruby
mit
88
master
315
Ziffers.set_default_opts(synth: :hollow, sustain: 3.0, duration: 0.5, scale: :minor) z1 "^0 r ^2 r r r r r r", rotate: 1, store: true z2 " r _1 r r r _6 r r _0", rotate: 1, store: true z3 " r r __3 r _5 r __0 r __2", rotate: 1, store: true z4 " r r r 4 r r r 1 r", rotate: 1, store: true
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/musical_dice_game.rb
Ruby
mit
88
master
5,750
load "~/ziffers/ziffers.rb" # Musical dice game: https://en.wikipedia.org/wiki/Musikalisches_W%C3%BCrfelspiel # Very random version of musical dice game use_bpm 100 use_synth :piano use_random_seed 987654365787 tremble = ["e 3 1 4", "e _5 s _#3 _4 _6 4", "e 4 0 2", "e 4 q 1", "q _4_614 e r", "e _4 0 2", "s 2 0 2 4 ...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/markov_chain.rb
Ruby
mit
88
master
1,325
load "~/ziffers/ziffers.rb" use_bpm 90 barrios = "| s 0 _4 #4 1 4 _4 0 _4 #4 1 4 _4 | s _6 _4 #4 1 4 _4 _6 _4 #4 1 4 _4 | s 1 _4 4 _6 3 _6 1 _4 4 _6 3 _4 | \ | s _0 _4 3 0 #1 _4 _0 _4 3 0 #1 _4 | s _#5 _4 3 0 #1 _4 _#5 _4 3 0 #1 _4 | s _5 _#3 #1 0 1 _#3 _5 _#3 #1 0 1 _#3 | \ | s _#4 _3 #1 0 1 _3 _#4 _3 #1 0 1 _3 ...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/solfeggio_3.rb
Ruby
mit
88
master
371
use_bpm 60 melody = zparse "0..6" octaves = [0,-2,1,-1,2,0,1] # Deal melody to 5 parts (Like dealing cards) parts = melody.deal 5 12.times do melody.length.times do |i| parts.each_with_index do |z,j| zplay z[i], octave: octaves[i+j], synth: :hollow, sustain: 6.0, decay: 4.0, duration: rrand(0.5,1.5) if z...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/canone.rb
Ruby
mit
88
master
445
load "~/ziffers/ziffers.rb" use_bpm 120 a = zparse "| q. _ 0 e 0 q 1 e 2 2 | C q _ 3 3 2 e 2 2 | q _ 1 h 4 q 3 | e r s _ 4 3 e 2 s 3 2 h 1 | q. _ 0 e 0 q 1 e 2 2 | w _ 3 |", C: {cue: :foo } b = "| q. _ 0 e 0 q 1 e 2 2 | q _ 3 3 2 e 2 2 | q _ 1 h 4 q 3 | e r s _ 4 3 e 2 s 3 2 h 1 | w _ 3 |" z1 a, synth: :pia...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/not_tested/ziffers_keyboard.rb
Ruby
mit
88
master
2,400
require "~/ziffers/ziffers.rb" # Ziffers keyboard - Always on key & scale # These settings work with VMPK defaults using "QWERTYUIOP"-keys to play use_bpm 60 use_synth :beep startNote = 60 # Change this to start degrees from other key. Q-button using VMPK. playKey = :c playScale = :mixolydian metronome = true waitBea...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/not_tested/kircher/test_kircher.rb
Ruby
mit
88
master
425
load "~/ziffers/examples/kircher.rb" use_bpm 100 r = 1 use_synth :hollow use_synth_defaults release: 2.0 live_loop :kircher do r = rand_i(2) rp = rand_i(2) print r m = get_cardset(3)[:cards][r][:p][rp] rh = get_cardset(4)[:cards][r][:r][rp] zthread m[1], rhythm: rh[1].map{|v|v/4} zthread m[2], rhythm:...
github
amiika/ziffers
https://github.com/amiika/ziffers
examples/not_tested/kircher/kircher.rb
Ruby
mit
88
master
28,217
module Ziffers module Common def get_cardset(n) @@cardsets[n] end @@cardsets = [ { :title => 'euripedeaea (class I fronts)', :recommendedModes => [1,2,3,4], :meter => '4/4', # Note lengths indicate metrical beats per note. You may randomly choose any one of these. # # A negative value on the first note indicates ...