code
stringlengths
1
1.73M
language
stringclasses
1 value
require "net/http" module Ankoder # This class is used to request the _ankoderapi_session service. # # Browser::get '/video', session # Browser::post '/download', {:url => 'http://host.com/video.avi'}, session # Browser::put '/video/54000', {:name => 'new title'}, session # Browser::delete '/video/...
Ruby
module Ankoder class JobFailed < RuntimeError; end class Job < Base # Encode the given video into the given format # # Video_ID is the video id that get from Ankoder::Download # Profile_ID is selected from the list of Ankoder::Profile.find(:all) # # Job.create(:original_file_id => ...
Ruby
class String # convert "undercore_string" in "UnderscoreString" # # Method from Rails def camelize self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end end module Ankoder module CoreExtension module HashExtension # Replace "-" by "_" in all keys of the hash def un...
Ruby
module Ankoder # to get the list of the supported profile # # Profile.find(:all) # class Profile < Base end end
Ruby
module Ankoder # You can connect to the _ankoderapi_session service permanently # # Base::establish_connection! :login => "login", :password => "password" # # You can access all the resources and manipulate the objects like in ActiveRecord # # v = Video.find(15).update_attributes :name => "My edited ti...
Ruby
module Ankoder # to get the list of the upload api url # # Upload.find(:all) # class Upload < Base end end
Ruby
module Ankoder # Authenticate to the ankoder service # # user = Auth.create("login", "password") # user.account # # If you want to recover a session: # # user = Auth.recover(session_id) # user.account # # The initialize and create methods can take blocks. # # Auth.create("login", "passwor...
Ruby
require File.dirname(__FILE__) + '/test_helper.rb' class TestAnkoder < Test::Unit::TestCase def setup end def test_truth assert true end end
Ruby
require 'test/unit' require File.dirname(__FILE__) + '/../lib/ankoder'
Ruby
# Include hook code here require 'ankoder_on_rails'
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the ankoder_on_rails plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the ankoder_on_ra...
Ruby
# desc "Explaining what the task does" # task :ankoder_on_rails do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
require "xmlsimple" require "cgi" module Ankoder OUT_FORMAT = "xml" unless const_defined? :OUT_FORMAT RESOURCES = %w{job profile download video account upload} unless const_defined? :RESOURCES DEFAULT_EXPIRY = 300 unless const_defined? :DEFAULT_EXPIRY # These are error codes you receive if you use ping opt...
Ruby
require 'hmac' require 'hmac-sha1' module Ankoder # Get a video from Ankoder # # Videos.find(video_id) # class Video < Base def self.url_for(video_id, expires_in = nil) message = {:access_key => Configuration::access_key, :expires => expires(expires_in)}.to_json encoded_message = Base64.encod...
Ruby
module Ankoder class DownloadFailed < RuntimeError; end class Download < Base # Download file from the given URL # Download.create('url' => 'http://host.com/file.avi', :postback_url => 'http://your_own_host.com/postback/download') # # the return result would be the Video record that you can s...
Ruby
module Ankoder #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 0 TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end end
Ruby
module Ankoder class Account < Base #:nodoc: def new_record? false end def update_attributes(attributes={}) attributes.delete "account" attributes.keys.each do |k| attributes.merge!("user[#{k.to_s}]" => attributes[k]) attributes.delete k end if Account.u...
Ruby
require "net/http" module Ankoder # This class is used to request the _ankoderapi_session service. # # Browser::get '/video', session # Browser::post '/download', {:url => 'http://host.com/video.avi'}, session # Browser::put '/video/54000', {:name => 'new title'}, session # Browser::delete '/video/...
Ruby
module Ankoder class JobFailed < RuntimeError; end class Job < Base # Encode the given video into the given format # # Video_ID is the video id that get from Ankoder::Download # Profile_ID is selected from the list of Ankoder::Profile.find(:all) # # Job.create(:original_file_id => ...
Ruby
class String # convert "undercore_string" in "UnderscoreString" # # Method from Rails def camelize self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end end module Ankoder module CoreExtension module HashExtension # Replace "-" by "_" in all keys of the hash def un...
Ruby
module Ankoder # to get the list of the supported profile # # Profile.find(:all) # class Profile < Base end end
Ruby
module Ankoder # You can connect to the _ankoderapi_session service permanently # # Base::establish_connection! :login => "login", :password => "password" # # You can access all the resources and manipulate the objects like in ActiveRecord # # v = Video.find(15).update_attributes :name => "My edited ti...
Ruby
module Ankoder # to get the list of the upload api url # # Upload.find(:all) # class Upload < Base end end
Ruby
module Ankoder # Authenticate to the ankoder service # # user = Auth.create("login", "password") # user.account # # If you want to recover a session: # # user = Auth.recover(session_id) # user.account # # The initialize and create methods can take blocks. # # Auth.create("login", "passwor...
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
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 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
#!/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
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'data_mapper', '~> 1.2' gem 'dm-postgres-adapter' gem 'google-api-client', '>= 0.4.3' group :development do gem 'dm-sqlite-adapter', '~> 1.2' gem 'do_sqlite3', '~> 0.10' 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 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
puts ("hellow") a = "a"; a = a + "a" print (a) for i in (1..500) a = a + i.to_s() end puts a[312] #puts a puts (0..10).collect{ |v| v ** 2 }.select{ rand(2).zero? }.map.with_index { |*v| v } require 'gtk2' class RubyApp < Gtk::Window def initialize super set_title "Center" signa...
Ruby
require 'tk' root = TkRoot.new { title 'Hello, World!'; padx 50; pady 15 } lab = TkLabel.new(root) do text 'Hello, World!' textvariable $k background 'red' pack { padx 10 ; pady 10; side 'left' } end TkLabel.bind('ButtonPress-1') { lab.configure('background', 'red'); lab.configure('text', 'newtext') } k='a...
Ruby
# 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 # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# 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 the webserver when you make code changes. config.ca...
Ruby
# 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 the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION ...
Ruby
Account::AccountConfiguration.set_config :email_from, 'support@annorate.com' Account::AccountConfiguration.set_config :admin_email, 'admin@annorate.com' Account::AccountConfiguration.set_config :app_url, 'http://www.annorate.com' Account::AccountConfiguration.set_config :app_name, 'Annorate' Account::AccountConfigurati...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end ...
Ruby
ActionController::Routing::Routes.draw do |map| # users map.connect 'users/annorations/:login', :controller => 'users', :action => 'annorations' map.connect 'users/:login', :controller => 'users', :action => 'show' map.connect 'annorations/anonymous', :controller => 'annorations', :action => 'anonymous' map...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper # create a thumbnail of the specified uri def OutputThumbNail(uri) begin '<img src="' + Page.cache_thumbnail(uri) + '" alt="Thumbnail image for ' + uri + '" />' # rescue # ...
Ruby
module DefaultHelper end
Ruby
module UsersHelper def edit_link(annoration_id, login) "[<a class=\"s-edit-link\" href=\"/annorations/edit/#{annoration_id}?redirect=/users/annorations/#{login}\">edit</a>]" if @authorized_to_edit end end
Ruby
module TagsHelper end
Ruby
module AnnorationsHelper def star(star_number, rating = 0, attributes ={}) rating = rating || 0 "<img id=\"star_#{star_number}\" src=\"/images/star_" + (star_number > rating ? "empty" : "filled") + "_big.gif\" onmouseover=\"overStar(#{star_number})\" onclick=\"clickStar(#{star_number})\" onmouseout=\"le...
Ruby
module PagesHelper end
Ruby
class UserNotify < ActionMailer::Base include Account::AccountNotify end
Ruby
require 'open-uri' require 'taggable' class Page < ActiveRecord::Base acts_as_taggable has_many :annorations ############################################### # virtual attribute for the thumbnail uri. def to_thumbnail_uri return Page.cache_thumbnail(self.to_uri) end #########...
Ruby
class User < ActiveRecord::Base include Account::AccountModel has_many :annorations ########################################################## # Gets tags applied by a user to an entry # def tags_for_page(page_id) tags = tag_list_for_page(page_id) tag_list = "" tags...
Ruby
class Tag < ActiveRecord::Base def self.cloud(tags, category_list) if tags and tags.length > 0 max = 0 min = tags[0].count.to_i tags.each do |tag| count = tag.count.to_i max = count if count > max min = count if count < min end d...
Ruby
class Annoration < ActiveRecord::Base belongs_to :user belongs_to :page ############################################### # virtual attribute for the uri def uri page.uri end def uri=(new_uri) @uri_errors = Array.new @uri_value = format_uri(@uri_errors, new_uri, 's...
Ruby
class DefaultController < ApplicationController # home page def index @pages = Page.top_rated_pages @tags = Page.top_tags respond_to do |format| format.html # index.rhtml format.xml { render :xml => @annorations.to_xml } end end def bookmarklet @page_title = "Get the Annora...
Ruby
class PagesController < ApplicationController layout 'default' # GET /pages # GET /pages.xml def index @pages = Page.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @pages.to_xml } end end ...
Ruby
class AnnorationsController < ApplicationController layout 'default' before_filter :login_required, :except => ['index', 'show', 'follow', 'browse', 'current', 'anonymous', 'create'] # GET /annorations # GET /annorations.xml def index @page_title = "Newest Annorations" ...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_annorate_s...
Ruby
class TagsController < ApplicationController layout 'default' # home page def pages @tags = Page.top_tags @search_tags = params[:tags] @pages = Page.pages_tagged(@search_tags) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @annorations.to_xml } e...
Ruby
class UsersController < ApplicationController include Account::AccountController layout 'default' before_filter :setup_user, :only =>[:new, :edit, :update, :destroy] ################################### # this method is called after a user successfully signs in def logged_in red...
Ruby
class SearchController < ApplicationController layout 'default' def initialize @results_limit = 50 end ######################################################### # Show search page if there is nothing specified to search for # or if there are searchable params search for th...
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.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
class AddTags < ActiveRecord::Migration def self.up create_table "tags", :force => true do |t| t.column "name", :string, :default => "", :null => false t.column "created_at", :datetime t.column "updated_at", :datetime end create_table "pages_tags", :id => false, :force =...
Ruby
class CreateAnnorations < ActiveRecord::Migration def self.up create_table :annorations do |t| t.column :user_id, :integer t.column :page_id, :integer t.column :title, :string t.column :comment, :text t.column :rating, :integer t.column :created_at, :datetime t.column :up...
Ruby
# file created by: rake db:sessions:create class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end add_index :sessions, :session_id end def self.down drop_t...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.column "login", :string, :limit => 80, :default => "", :null => false t.column "salted_password", :string, :limit => 40, :default => "", :null => false t.column "email", ...
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.column :first_annoration_id, :integer t.column :uri, :string t.column :average_rating, :integer t.column :total_comments, :integer t.column :total_ratings, :integer t.column :created_at, :datet...
Ruby
require 'active_support' require 'active_record' module ActiveRecord module Acts #:nodoc: module Taggable #:nodoc: def self.append_features(base) #:nodoc: super base.extend(ClassMethods) end def self.split_tag_names(tags, separator,normalizer) tag_...
Ruby
#!/opt/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/opt/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/opt/local/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo...
Ruby
#!/opt/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/opt/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/opt/local/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
#!/usr/bin/env ruby require 'rubygems' require 'xmpp4r/client' require 'xmpp4r/roster' require 'xmpp4r/version' Jabber::debug = true class Annei def connect begin jid = Jabber::JID::new('example@example.org/Bot') password = '' @connection = Jabber::Client::new(jid,true) @connection.on_exception { conn...
Ruby