code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
puts File.read( File.dirname(__FILE__) + '/README' ) | Ruby |
module BatchedSqlFu
class Error < StandardError; end
def flush_batch_limit
@flush_batch_limit ||= 100
end
def reset_batch_sql_collection!
@batch_sql_collection = nil
end
def batch_sql_collection
@batch_sql_collection ||= BatchSqlCollection.new(flush_batch_limit, self)
end
end | Ruby |
module BatchedSqlFu
class BatchSqlCollection
INSERT_RE = /INSERT INTO (.?[a-zA-Z0-9\_]*.?)\s+(\([^\)]*\))\s+VALUES\s*/i
attr_reader :statements
delegate :size, :join, :to => :statements
def initialize(flush_batch_limit, connection)
@flush_batch_limit = flush_batch_limit
@connect... | Ruby |
module BatchedSqlFu
module ActiveRecord
class StatementInvalid < StandardError; end
module ClassMethods
def insert_by_batch(flush_every = 100)
connection.reset_batch_sql_collection!
alias_insert_sql_to_batched_version!
begin
yield
connection.batch_sql_col... | Ruby |
preferred_syntax = :scss
http_path = '/'
css_dir = 'build'
sass_dir = 'src/sass'
images_dir = 'build/images'
fonts_dir = 'build/fonts'
relative_assets = true
line_comments = true | 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 |
#!/usr/bin/env ruby
require 'nokogiri'
string_to_remove = ['pref_cat_themes',
'theme_settings',
'theme_settings_summary',
'theme_settings_help']
string_files = []
Dir.glob('res/values*').each do |d|
file = d << "/strings.xml"
string_files << file if Fil... | Ruby |
#!/usr/bin/env ruby
# encoding: utf-8
project = 'battery-indicator'
user = `cat ~/.netrc | awk '{print $4;}'`.strip
pass = `cat ~/.netrc | awk '{print $6;}'`.strip
version = `grep "android:versionName=" AndroidManifest.xml`.split('"')[1]
apk_location = "BatteryIndicatorPro-#{version}.apk"
system("cp bin/*-release.ap... | Ruby |
require 'RMagick'
class NumberImageGenerator
@@IMAGE_DIR = 'numbers-hdpi/'
def generate(text, fs=18)
#filename = "b" + sprintf("%03d", text) + ".png";
filename = "" + sprintf("%03d", text) + ".png";
font_size = fs;
height = 35;
width = 35;
image = Magick::Image.new(width, height) {self.ba... | Ruby |
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
# read in convert.xml to see which how to convert the string-arrays
# for each strings.xml in res/values res/values-?? res/values-??-*
# find the string-arrays that match the ones in convert.xml and for each
# remove opening and closing string-array tag
#... | Ruby |
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
LANGS_URI = 'http://ath.darshancomputing.com/bi/langs/'
langs = Net::HTTP.get(URI.parse(LANGS_URI)).split()
langs.each do |lang|
if lang.length == 2
dir = 'res/values-' << lang
else
dir = 'res/values-' << lang[0,2] << '-r' << lang[2,2]
end
if ! D... | 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.
# 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.
# 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.
Battleshiponline::Application.config.session_store :cookie_store, :key => '_battleshiponline_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the sessio... | Ruby |
# A Site key gives additional protection against a dictionary attack if your
# DB is ever compromised. With no site key, we store
# DB_password = hash(user_password, DB_user_salt)
# If your database were to be compromised you'd be vulnerable to a dictionary
# attack on all your stupid users' passwords. With a... | 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 |
Battleshiponline::Application.configure do
# Settings specified here will take precedence over those in config/environment.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 ... | Ruby |
Battleshiponline::Application.configure do
# Settings specified here will take precedence over those in config/environment.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 ... | Ruby |
Battleshiponline::Application.configure do
# Settings specified here will take precedence over those in config/environment.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 ... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Battleshiponline::Application.initialize!
| 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 Battleshiponline
class Application < Rails::Applicat... | Ruby |
Battleshiponline::Application.routes.draw do
get "message/send"
get "battle/list"
get "battle/join"
get "battle/index"
get "battle/step"
get "forum" => "forum#index"
get "forum/forum"
get "forum/topic"
post "forum/post"
resources :users do
member do
put :suspend
put :unsuspe... | Ruby |
module ApplicationHelper
end
| Ruby |
module UsersHelper
#
# Use this to wrap view elements that the user can't access.
# !! Note: this is an *interface*, not *security* feature !!
# You need to do all access control at the controller level.
#
# Example:
# <%= if_authorized?(:index, User) do link_to('List all users', users_path)... | Ruby |
module BattleHelper
def cell_link(body,x,y)
link_to body, :action => :step, :x=>x,:y=>y
end
end
| Ruby |
module SessionsHelper
end | Ruby |
module ForumHelper
end
| Ruby |
class Message < ActiveRecord::Base
belongs_to :from_user, :class_name => 'User', :foreign_key => :user_id
belongs_to :to_user, :class_name => 'User', :foreign_key => :to_user_id
end
| Ruby |
class Topic < ActiveRecord::Base
belongs_to :forum
belongs_to :user
has_many :replies
def last_reply
replies.last
end
end
| Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
include Authorization::StatefulRoles
set_table_name 'users'
has_many :out_messages, :class_name => 'Message', :dependent => :delete_all, :forei... | Ruby |
class Reply < ActiveRecord::Base
belongs_to :user
belongs_to :topic
end
| Ruby |
class Friend < ActiveRecord::Base
end
| Ruby |
class Forum < ActiveRecord::Base
has_many :topics
end
| Ruby |
class UserObserver < ActiveRecord::Observer
def after_create(user)
user.reload
UserMailer.signup_notification(user).deliver
end
def after_save(user)
user.reload
UserMailer.activation(user).deliver if user.recently_activated?
end
end
| Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
end
def create
logout_keeping_session!
u... | Ruby |
require "battle"
class BattleController < ApplicationController
@game_battles = {}
def list
@battles = []
@game_battles.each do |b|
@battles << { :user_name => b.user_name,
:wating_time => (Time.now.to_i - b.start_time),
:id => b.id }
end
render
en... | Ruby |
class ApplicationController < ActionController::Base
include ::AuthenticatedSystem
#protect_from_forgery
end
| Ruby |
class ForumController < ApplicationController
def index
@forums = Forum.all
end
def forum
@forum = Forum.find(params[:id])
@topics = @forum.topics
@new_topic = Topic.new
@new_topic.forum = @forum
@new_topic.user = current_user
end
def topic
@topic = Topic.find(params[:id])
@... | Ruby |
class UsersController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# Protect these actions behind an admin login
# before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
before_filter :find_us... | Ruby |
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@url = "http://127.0.0.1:3000/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject += 'Your account has ... | 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'
Battleshiponline::Application.load_tasks
| Ruby |
source 'http://rubygems.org'
gem 'rails', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql'
gem 'declarative_authorization'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# ... | Ruby |
class CreateFriends < ActiveRecord::Migration
def self.up
create_table :friends do |t|
t.integer :first_user_id
t.integer :second_user_id
t.timestamps
end
end
def self.down
drop_table :friends
end
end
| Ruby |
class CreateMessages < ActiveRecord::Migration
def self.up
create_table :messages do |t|
t.integer :user_id
t.integer :to_user_id
t.string :content
t.timestamps
end
end
def self.down
drop_table :messages
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users" do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100, :default => '', :null => true
t.column :email, :string, :limit => 1... | 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 |
require "ship"
module Game
# cell of game field
class Cell
def initialize(x,y)
@x,@y = x,y
@ship = nil
end
end
# main class for player battlefield
class Battlefield
def initialize(user,width=10,height=10)
@user = user
@ships = []
# initialize cel... | Ruby |
module Game
class Ship
def initialize(cells)
@cells = cells
end
end
end | Ruby |
module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_user with the user model if they're logged in.
def logged_in?
!!current_user
end
# Accesses the current user from the session.
# Future calls avoid the database because ni... | Ruby |
require "battlefield"
module Game
# Main game class
# Contains run-time information about running game
class Battle
def initialize
@id = 0
@field = []
9.times { @field << 0 }
@players = []
@starttime = Time.now.to_i
end
def user_name
if !@players.e... | Ruby |
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil
end
def authorize_as(user)
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAu... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Battleshiponline::Application
| 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 |
# $ext_path: This should be the path of where the ExtJS SDK is installed
# Generally this will be in a lib/extjs folder in your applications root
# <root>/lib/extjs
$ext_path = "../../"
# sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder
# Generally this will be in a resource... | Ruby |
# include the utils rb file which has extra functionality for the ext theme
dir = File.dirname(__FILE__)
require File.join(dir, 'lib', 'utils.rb')
# register ext4 as a compass framework
Compass::Frameworks.register 'ext4', dir | Ruby |
# $ext_path: This should be the path of where the ExtJS SDK is installed
# Generally this will be in a lib/extjs folder in your applications root
# <root>/lib/extjs
$ext_path = "../../lib/extjs"
# sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder
# Generally this will be in a... | Ruby |
module ExtJS4
module SassExtensions
module Functions
module Utils
def parsebox(list, n)
assert_type n, :Number
if !n.int?
raise ArgumentError.new("List index #{n} must be an integer")
elsif n.to_i < 1
raise ArgumentError.new("List index #{n} must... | 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.
# 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.
# 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.
Bauarbeiter::Application.config.session_store :cookie_store, :key => '_Bauarbeiter_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 |
# 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 |
Bauarbeiter::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 |
Bauarbeiter::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 |
Bauarbeiter::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 |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Bauarbeiter::Application.initialize!
| Ruby |
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
| 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 Bauarbeiter
class Application < Rails::Application
... | Ruby |
Bauarbeiter::Application.routes.draw do
resources :masterplans
resources :notes
match '/' => 'Events#index'
resources :event_types
resources :events
resources :comments
resources :grades
resources :walls
resources :chains
resources :workers
resources :routes
resources :bauarbeiters
... | Ruby |
module ApplicationHelper
def logo
@logo = image_tag("baustelle2.gif", :alt => "Bauarbeiter")
end
end
| Ruby |
module NotesHelper
end
| Ruby |
module EventsHelper
end
| Ruby |
module EventTypesHelper
end
| Ruby |
module RoutesHelper
require 'scrobbler'
require 'active_support/all'
def route_is_outdated (buildDate)
# How much days until a route is out of date?
outOfDate = 180
now = DateTime.now
diff = now - buildDate
diff.to_i > outOfDate
end
def display_redo_route(route)
if r... | Ruby |
module WorkersHelper
end
| Ruby |
module WallsHelper
end
| Ruby |
module BauarbeiterHelper
end
| Ruby |
module PrinterHelper
end
| Ruby |
module ChainsHelper
end
| Ruby |
module LoginHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module GradesHelper
end
| Ruby |
class Grade < ActiveRecord::Base
has_many :routes
def <=>(x)
self.to_i <=> x.to_i
end
def to_uiaa
self.grade.split("|")[0]
end
def to_f
self.grade.split("|")[1]
end
def to_us
self.grade.split("|")[2]
end
def to_i
self.id
end
end
| Ruby |
class Event < ActiveRecord::Base
has_and_belongs_to_many :eventtypes
has_and_belongs_to_many :routes
end
| Ruby |
class Wall < ActiveRecord::Base
has_many :chains
def to_s
self.number.to_s + " " + self.name
end
def <=>(x)
self.number <=> x.number
end
def to_link
"<a href=\"/walls/#{self.id}\">#{self.name}</a>"
end
end
| Ruby |
require "digest/sha2"
class Worker < ActiveRecord::Base
validates_uniqueness_of :name
validates_uniqueness_of :email
validates_presence_of :name
validates_presence_of :email
validates_presence_of :password
validates_presence_of :salt
has_and_belongs_to_many :routes
has_many :comments
def <=>(x)
... | Ruby |
class Chain < ActiveRecord::Base
has_many :routes
has_many :masterplans
belongs_to :wall
def <=>(x)
self.number <=> x.number
end
end
| Ruby |
class Eventtype < ActiveRecord::Base
has_and_belongs_to_many :events
end
| Ruby |
class Note < ActiveRecord::Base
end
| Ruby |
class Comment < ActiveRecord::Base
has_and_belongs_to_many :routes
belongs_to :worker
end
| Ruby |
class Color < ActiveRecord::Base
has_many :routes
def <=>(x)
self.name <=> x.name
end
end
| Ruby |
class Route < ActiveRecord::Base
has_and_belongs_to_many :workers
has_and_belongs_to_many :comments
has_and_belongs_to_many :events
belongs_to :chain
belongs_to :grade
belongs_to :color
validates_presence_of :name, :color_id, :grade_id, :chain, :build
validates_format_of :name, :with => /[\w\d\.\:\-... | Ruby |
class GradesController < ApplicationController
before_filter :isSchorsch, :except => [:index, :show]
# GET /grades
# GET /grades.xml
def index
@grades = Grade.all.sort
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @grades }
end
end
# GET /grades/... | Ruby |
class WallsController < ApplicationController
before_filter :isSchorsch, :except => [:show, :index]
# GET /walls
# GET /walls.xml
def index
@walls = Wall.all.sort
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @walls }
end
end
# GET /walls/1
# G... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.