code
stringlengths
1
1.73M
language
stringclasses
1 value
# This class find dates in a text. require 'date' class DateFinder DATE_REGEXP = [/((19|20)[0-9]{2}[- \/.](0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01]))/] def self.find(text) dates = [] DATE_REGEXP.each do |regexp| text.scan(regexp).each { |date| dates << DateTime.parse(date[0]) } end ...
Ruby
# ultimately shall check that all client are compatible with what expects the launcher require 'test/unit' class TC_MyTest < Test::Unit::TestCase # def setup # end # def teardown # end def test_fail assert(false, 'Assertion was false.') end end
Ruby
require 'socket' require 'timeout' class TCPClient def initialize(ip,port) @t = nil @ip = ip @port = port end def connect begin timeout(10) do @t = TCPSocket.new(@ip, @port) end rescue @t = nil raise end end def disconne...
Ruby
class AntClientList attr_reader :list def initialize @list = Hash.new end def add(c) @list[c.id] = c end def remove_id(id) @list.delete(id) end def get_id(id) @list[id] end end class AntClient attr_accessor :id, :type, :name, :versi...
Ruby
require "opengl" require "glut" require "tgcc.rb" require "GLUtils.rb" class Graphic_renderer COULEURS=[[ 1.0, 0.0, 0.0, 0.0 ],[ 0.0, 1.0, 0.0, 0.0 ],[ 0.0, 0.0, 1.0, 0.0 ]] def pputs(x,y=1) if @debug==nil @debug=1 end if y>=@debug puts x $stdout.flush end end def init_m...
Ruby
#module Utils class String; def ord; self[0]; end; def last; self[self.length-1].to_s; end; def removelast; if (self.length>1); self[0..self.length-2]; else; return ""; end; end; def ischar;s=self.to_i;(s>="a".ord && s<="z".ord) || (s>="A".ord && s<="Z".ord) ? true : false; end; end class Fixnum; def...
Ruby
require 'socket' require "TCPClient.rb" require "AntClient.rb" require "Utils.rb" require "Map.rb" class GuiClient attr_accessor :map def initialize(ip,port) @version = "0.5" @progname = "GUI" puts "GUI - Ant Battle GUI"+@version puts " Esc to close" puts " Connecting to #{ip}:#{po...
Ruby
require 'tgc.rb' require 'tgcc.rb' class Helper def Helper.showHelp puts "Usage: ruby maingui.rb host port\n\n" puts "Example:\n" puts " ruby maingui.rb localhost 5000\n" puts " ruby maingui.rb 82.238.147.130 80\n" end end if ARGV.length < 2 Helper.showHelp puts "...
Ruby
require '../lib/TCPClient' require '../lib/Map' require '../lib/Utils' require '../lib/AntClient' class GuiClient < TCPClient attr_reader :brains, :map def initialize(ip,port) super(ip,port) @progversion = "0.1" @progname = "Launcher" @freetext = "Ant Battle Viewer" @brains = [] @map ...
Ruby
#!/usr/bin/env ruby require 'gui' require 'gui_client' class AboutBox < Gtk::Dialog def initialize super("About", nil, Gtk::Dialog::MODAL, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK]) message = "Ant Battle Viewer.\nThat's all folks." hbox = Gt...
Ruby
#!/usr/bin/env ruby # # This file is gererated by ruby-glade-create-template 1.1.4. # require 'libglade2' class GuiGlade include GetText attr :glade def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE) bindtextdomain(domain, localedir, nil, "UTF-8") @glade = ...
Ruby
#!/usr/bin/env ruby require 'gui' require 'gui_client' class AboutBox < Gtk::Dialog def initialize super("About", nil, Gtk::Dialog::MODAL, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK]) message = "Ant Battle Viewer.\nThat's all folks." hbox = Gt...
Ruby
#!/usr/bin/env ruby # # This file is gererated by ruby-glade-create-template 1.1.4. # require 'libglade2' class GuiGlade include GetText attr :glade def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE) bindtextdomain(domain, localedir, nil, "UTF-8") @glade = ...
Ruby
#!/usr/bin/env ruby # set default values ip = "127.0.0.1" port = 5000 brain = 'random' i = 0 # parse command line while true arg = ARGV[i] break if arg == nil com = arg.split('=') case com[0].upcase when 'S' case com[1] when 'P' # public server ip = "82....
Ruby
class Colony attr_reader :progversion, :progname, :freetext def init @progversion = "0.2" @progname = "Straight" end def play @map.allies_each(@id) { |ant| raise "play: having a dead ant" if(ant.life==0) # going straight to the ennemy x,y = ...
Ruby
class Colony attr_reader :progversion, :progname, :freetext def init @progversion = "0.5" @progname = "ABCDE" @freetext = "Ant Battle Client Developper Example" end def play @map.allies_each(@id) { |ant| #raise "play: having a dead ant" if(ant.life==0) ...
Ruby
#!/usr/bin/env ruby # set default values ip = "127.0.0.1" port = 5000 brain = 'random' i = 0 # parse command line while true arg = ARGV[i] break if arg == nil com = arg.split('=') case com[0].upcase when 'S' case com[1] when 'P' # public server ip = "82....
Ruby
# this file defines brain and ants goals # modify this configuration file to modify the client behaviour # TODO: use State Design Pattern (The State Design Pattern is a fully encapsulated, self-modifying Strategy Design Pattern) require 'Map' require 'Pathfinding' #require 'enum' KILL = 1 # top level goal PROTECT...
Ruby
require 'Utils' require 'goals' class Colony def init @progversion = "0.1" @progname = "Submarine Prick" @freetext = "Find the anagram :)" @goals = [] end def play set_goals @map.allies_each(@id) { |a| puts "each: #{a}" arr = ...
Ruby
require 'Minimax' require 'Map' require 'Utils' class Map # yield every successor state and the action that leads to the state def each_successor # a successor (state) is the result of each ant actions # since each ant has 84 possible moves (without counting attack combinaisons), ...
Ruby
# Written in Ruby from scratch by Mickael, so it might not be as good as you expect :) # References: # http://en.wikipedia.org/wiki/A-star_search_algorithm # http://www.policyalmanac.org/games/aStarTutorial.htm # http://theory.stanford.edu/~amitp/GameProgramming/ # this file contains a method for cli...
Ruby
# Ant Battle GUI Toolkit require 'gtk2' require 'thread' class GuiTk def initialize(map) @map = map Gtk.init window = Gtk::Window.new window.resize(505,505) window.title = 'Ant Battle Viewer' window.signal_connect("destroy") { Gtk.main_quit } @da = Gtk::D...
Ruby
require 'socket' require 'timeout' class TCPClient def initialize(ip,port) @t = nil @ip = ip @port = port end def connect begin timeout(2) do @t = TCPSocket.new(@ip, @port) end rescue @t = nil raise end end def disconnect @t.close...
Ruby
#require 'Utils' #========================================= class MapObject attr_accessor :x, :y, :object_type, :object_id def initialize @x = @y = 0 end def to_s "type#{object_type},id#{object_id}(#{x},#{y})" end end #========================================= class Res...
Ruby
class AntClientList attr_reader :list def initialize @list = Hash.new end def add(c) @list[c.id] = c end def remove_id(id) @list.delete(id) end def get_id(id) @list[id] end end class AntClient attr_accessor :id, :type, :name, :versi...
Ruby
require 'Utils' INFINITY = 1.0 / 0.0 # Takes a state iterator and the maximum search depth and returns # the best possible value and the best operation to execute. # # A state should implement # * #each_successor (yield every successor state and the action that leads to the state) # * #value (the heuristic t...
Ruby
require 'TCPClient' require 'Utils' require 'AntClient' require 'Map' require 'timeout' #begin #require 'guitk' #$hasgtk = true #rescue $hasgtk = false #end class Colony attr_reader :progversion, :progname, :freetext def initialize(ip,port) @id = -1 @opp = -1 @client_list = AntClientL...
Ruby
class String; def ord; self[0]; end; def last; self[self.length-1].to_s; end; def removelast; if (self.length>1); self[0..self.length-2]; else; return ""; end; end; def ischar;s=self.to_i;(s>="a".ord && s<="z".ord) || (s>="A".ord && s<="Z".ord) ? true : false; end; end class Fixnum; def last...
Ruby
require 'sinatra/activerecord/rake' require './main'
Ruby
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
Ruby
class CreateUsers < ActiveRecord::Migration def up create_table :users do |t| t.string :profile_id t.string :email t.string :refresh_token end add_index :users, :profile_id end def down drop_table :users end end
Ruby
# Copyright (C) 2012 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writ...
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
Ruby
class CreateAppPermissions < ActiveRecord::Migration def self.up create_table :app_permissions do |t| t.references :app t.references :permission t.timestamps end add_index :app_permissions, :app_id add_index :app_permissions, :permission_id end def self.down drop_table :ap...
Ruby
class CreateTargets < ActiveRecord::Migration def self.up create_table :targets do |t| t.string :name t.timestamps end add_index :targets, :name, :unique => true end def self.down drop_table :targets end end
Ruby
class CreateVisuals < ActiveRecord::Migration def self.up create_table :visuals do |t| t.references :app t.timestamps end add_index :visuals, :app_id end def self.down drop_table :visuals end end
Ruby
class CreatePermissions < ActiveRecord::Migration def self.up create_table :permissions do |t| t.string :name t.timestamps end add_index :permissions, :name, :unique => true end def self.down drop_table :permissions end end
Ruby
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.integer :rating t.string :creationTime t.string :authorName t.string :text t.string :authorId t.references :app t.timestamps end add_index :comments, :app_id add_index ...
Ruby
class CreateRatings < ActiveRecord::Migration def self.up create_table :ratings do |t| t.string :rating t.integer :ratingCount t.integer :downloadCount t.string :downloadCountText t.references :app t.timestamps end add_index :ratings, :app_id, :unique => true end ...
Ruby
class AddAttachmentImageToVisual < ActiveRecord::Migration def self.up add_column :visuals, :image_file_name, :string add_column :visuals, :image_content_type, :string add_column :visuals, :image_file_size, :integer add_column :visuals, :image_updated_at, :datetime end def self.down remove_co...
Ruby
class CreateVestalVersions < ActiveRecord::Migration def self.up create_table :versions do |t| t.belongs_to :versioned, :polymorphic => true t.belongs_to :user, :polymorphic => true t.string :user_name t.text :modifications t.integer :number t.integer :reverted_from t...
Ruby
class CreateAppTargets < ActiveRecord::Migration def self.up create_table :app_targets do |t| t.references :app t.references :target t.timestamps end add_index :app_targets, :app_id add_index :app_targets, :target_id end def self.down drop_table :app_targets end end
Ruby
class CreateApps < ActiveRecord::Migration def self.up create_table :apps do |t| t.string :creator t.string :packageName t.string :title t.text :description t.string :appId t.string :category t.text :recentChanges t.string :email t.string :phone t.string...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'mysql2' gem 'paperclip' gem 'will_paginate' gem 'vestal_versions', :git => 'git://github.com/adamcooper/vestal_versions' # Use unicorn as the web server # gem 'unicorn' # D...
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
module ApplicationHelper end
Ruby
module VisualsHelper end
Ruby
module AppPermissionHelper end
Ruby
module AppTargetHelper end
Ruby
module PermissionsHelper end
Ruby
module AppsHelper end
Ruby
module CommentsHelper end
Ruby
class Visual < ActiveRecord::Base belongs_to :app has_attached_file :image, :url => "/:attachment/:id/:style/:basename.:extension", :path => ":rails_root/public/:attachment/:id/:style/:basename.:extension" validates_attachment_presence :image validates_attachment_co...
Ruby
class AppPermission < ActiveRecord::Base belongs_to :app belongs_to :permission end
Ruby
class Target < ActiveRecord::Base has_many :app_targets has_many :apps, :through => :app_targets end
Ruby
class Rating < ActiveRecord::Base versioned belongs_to :app end
Ruby
class Comment < ActiveRecord::Base belongs_to :app end
Ruby
class Permission < ActiveRecord::Base validates_uniqueness_of :name validates_presence_of :name has_many :app_permissions has_many :apps, :through => :app_permissions end
Ruby
class App < ActiveRecord::Base validates_uniqueness_of :packageName has_one :rating, :dependent => :destroy has_many :visuals, :dependent => :destroy has_many :comments, :dependent => :destroy has_many :app_targets has_many :targets, :through => :app_targets has_many :app_permissions has_many :...
Ruby
class AppTarget < ActiveRecord::Base belongs_to :app belongs_to :target end
Ruby
class Record attr_accessor :id, :exists end
Ruby
class ApplicationController < ActionController::Base # protect_from_forgery end
Ruby
class AppTargetsController < ApplicationController # POST /app_targets.xml # POST /app_targets.json def create @app_target = AppTarget.new(params[:app_target]) respond_to do |format| if @app_target.save format.xml { render :xml => @app_target, :status => :created, :location => @app_targ...
Ruby
class CommentsController < ApplicationController # POST /comments.xml # POST /comments.json def create @app = App.find(params[:app_id]) @comment = @app.comments.new(params[:comment]) respond_to do |format| if @comment.save format.xml { render :xml => @comment, :status => :...
Ruby
class PermissionsController < ApplicationController # POST /permission.xml # POST /permission.json def create @permission = Permission.new(:name => params[:permission]) respond_to do |format| if @permission.save format.xml { render :xml => @permission, :status => :created, :location => @...
Ruby
class AppsController < ApplicationController # GET /apps # GET /apps.xml # GET /apps.json def index @apps = App.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @apps } format.json { render :json => @apps } end end # GET /apps/1 ...
Ruby
class VisualsController < ApplicationController # POST /visuals def create @app = App.find(params[:app_id]) @visual = @app.visuals.new(:image => params[:image]) respond_to do |format| if @visual.save format.html { render :json => @visual, :status => :created} else ...
Ruby
class AppPermissionsController < ApplicationController # POST /app_permissions/update_permissions.xml # POST /app_permissions/update_permissions.json def update_permissions app = App.find(params[:app_id]) app.permission_ids = params[:permissions] respond_to do |format| if app.save! ...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', ...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
VestalVersions.configure do |config| # Place any global options here. For example, in order to specify your own version model to use # throughout the application, simply specify: # # config.class_name = "MyCustomVersion" # # Any options passed to the "versioned" method in the model itself will override this...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. Marketplace::Application.config.session_store :cookie_store, :key => '_Marketplace_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table wi...
Ruby
Marketplace::Application.routes.draw do root :to => "apps#index" resources :apps do collection do post 'exists', 'ids' end resources :visuals do collection do post 'exists' end end end resources :app_targets do collection do post 'exists' end end ...
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. gemfile = File.expand_path('../../Gemfile', __FILE__) begin ENV['BUNDLE_GEMFILE'] = gemfile require 'bundler' Bundler.setup rescue Bundler::GemNotFound => e STDERR.puts e.message STDERR.puts "Try running `bundle install`." exit! end if File.exist?(gem...
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Marketplace class Application < Rails::Application ...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Marketplace::Application.initialize!
Ruby
Marketplace::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turne...
Ruby
Marketplace::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the w...
Ruby
Marketplace::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the t...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Marketplace::Application
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) require 'rake' Marketplace::Application.load_tasks
Ruby
# Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = "/" css_dir = "theme/css" sass_dir = "theme/scss" images_dir = "images" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): output_style = :co...
Ruby
#!/usr/bin/ruby # Copyright 2013 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required ...
Ruby
# Copyright 2013 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable la...
Ruby
require 'google/api_client' require 'google/api_client/client_secrets' require 'json' require 'launchy' require 'thin' RESPONSE_HTML = <<stop <html> <head> <title>OAuth 2 Flow Complete</title> </head> <body> You have successfully completed the OAuth 2 flow. Please close this browser window and return to ...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' require 'logger' require 'oauth/oauth_util' require 'sqlite3' require 'thread' require 'trollop' YOUTUBE_API_READONLY_SCOPE = 'https://www.googleapis.com/auth/youtube.readonly' YOUTUBE_ANALYTICS_API_SCOPE = 'https://www.googleapis.com/auth/yt-analytics.re...
Ruby
#!/usr/bin/ruby require 'benchmark' Benchmark.bm do |x| [1, 2, 5, 10, 20].each do |thread_count| x.report("#{thread_count} threads:") do system('./analyticsdump.rb', '--threads', thread_count.to_s) end sleep(60) end end
Ruby
require 'google/api_client' require 'google/api_client/client_secrets' require 'json' require 'launchy' require 'thin' RESPONSE_HTML = <<stop <html> <head> <title>OAuth 2 Flow Complete</title> </head> <body> You have successfully completed the OAuth 2 flow. Please close this browser window and return to ...
Ruby
#!/usr/bin/ruby # Copyright 2011 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required ...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' # oauth/oauth_util is not part of the official Ruby client library. # Get it at http://samples.google-api-ruby-client.googlecode.com/git/oauth/oauth_util.rb require 'oauth/oauth_util' require 'trollop' # This code assumes that there's a client_secrets.j...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' # oauth/oauth_util is not part of the official Ruby client library. # Get it at http://samples.google-api-ruby-client.googlecode.com/git/oauth/oauth_util.rb require 'oauth/oauth_util' # A limited OAuth 2 access scope that allows for read-only access. YO...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' # oauth/oauth_util is not part of the official Ruby client library. # Get it at http://samples.google-api-ruby-client.googlecode.com/git/oauth/oauth_util.rb require 'oauth/oauth_util' require 'trollop' # An OAuth 2 access scope that allows for full read...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' require 'trollop' # Set DEVELOPER_KEY to the "API key" value from the "Access" tab of the # Google APIs Console <http://code.google.com/apis/console#access> # Please ensure that you have enabled the YouTube Data API for your project. DEVELOPER_KEY = "REP...
Ruby
require 'google/api_client' require 'google/api_client/client_secrets' require 'json' require 'launchy' require 'thin' RESPONSE_HTML = <<stop <html> <head> <title>OAuth 2 Flow Complete</title> </head> <body> You have successfully completed the OAuth 2 flow. Please close this browser window and return to ...
Ruby
NOT READY YET #!/usr/bin/ruby require 'rubygems' require 'google/api_client' require 'oauth/oauth_util' client = Google::APIClient.new youtube = client.discovered_api('youtube', 'v3alpha') auth_util = CommandLineOAuthHelper.new('https://www.googleapis.com/auth/youtube') client.authorization = auth_util.authorize() ...
Ruby
#!/usr/bin/ruby require 'rubygems' require 'google/api_client' # oauth/oauth_util is not part of the official Ruby client library. # Get it at http://samples.google-api-ruby-client.googlecode.com/git/oauth/oauth_util.rb require 'oauth/oauth_util' # An OAuth 2 access scope that allows for full read/write access. YOU...
Ruby