code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/bin/env ruby require 'socket' require 'ipaddr' port = 5350 print "Listening for NAT-PMP public IP changes:\n" socket = UDPSocket.new socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true) socket.bind("224.0.0.1",port) addr = '0.0.0...
Ruby
#!/usr/bin/env ruby require 'socket' require 'ipaddr' port = 5350 # A compatible NAT gateway MUST generate a response with the following # format: # # 0 1 2 3 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 # +-+-+-+-+-+-+-+-+-+-+-+-+...
Ruby
#!/usr/bin/env ruby require 'socket' require 'ipaddr' port = 5350 print "Listening for NAT-PMP public IP changes:\n" socket = UDPSocket.new while true do begin # socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) # socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true) socket...
Ruby
require 'rake/clean' CLEAN.include('dist/kmltree.css', 'dist/kmltree.min.js', 'dist/kmltree.js', 'dist/images', 'src/_sprites.sass', 'sprites-url') CLOBBER.include('compiler') SRC = FileList[ 'src/kmltreeManager.js', 'src/base64.js', 'src/tmpl.js', 'src/kmldom.js', 'src/URI.js', 'src/kmltree.js', 'src/googleLayers.js...
Ruby
module ItemHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper include TagsHelper def logged_in? return @session[:user_id] ? true : false end def paginate_number(number, current, order = nil) i = 0 result = "" return '<span class="current">1</sp...
Ruby
module AccountHelper end
Ruby
# this model expects a certain database layout and its based on the name/login pattern. class User < ActiveRecord::Base has_many :gifts def self.get(openid_url) find_first(["openid_url = ?", openid_url]) end protected validates_uniqueness_of :openid_url, :on => :create validates_presence_of :o...
Ruby
class Event < ActiveRecord::Base end
Ruby
class Gift < ActiveRecord::Base acts_as_taggable belongs_to :age belongs_to :event belongs_to :item belongs_to :user end
Ruby
class Genre < ActiveRecord::Base belongs_to :items end
Ruby
class Type < ActiveRecord::Base has_many :items end
Ruby
class Age < ActiveRecord::Base end
Ruby
class Item < ActiveRecord::Base has_many :gifts belongs_to :type belongs_to :genre end
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 => '_10pockets_...
Ruby
require "pathname" require "cgi" # load the openid library begin require "rubygems" require_gem "ruby-openid", ">= 2.0.3" rescue LoadError require "openid" end class AccountController < ApplicationController layout 'default' def index @pages, @items = paginate(:item, :per_page => 2, :order_by => 'gift...
Ruby
class ItemController < ApplicationController layout 'default', :except => :search def vote @item = Item.find params[:id] @productname = @item.name end def age return render unless params[:id] gifts = Gift.find :all, :conditions => ['age_id = ?', params[:id]] @pages, @items = paginate(...
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
class ItemAddCount < ActiveRecord::Migration def self.up add_column :items, :gift_counts, :integer, :default => 0 end def self.down remve_column :items, :gift_counts, :integer end end
Ruby
class CreateAges < ActiveRecord::Migration def self.up create_table :ages do |t| t.column :name, :string end [_("Birth"), _("3 Months"), _("3 to 6 Months"), _("6 to 9 Months"), _("9 to 12 Months"), _("12 to 18 Months"), _("18 to 24 Months"), _("2 years old"), _("3 years old"), _("4 years old"), _("5...
Ruby
class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| t.column :name, :text t.column :code, :string t.column :price, :integer, :default => 0 t.column :caption, :text t.column :url, :text t.column :affiliateurl, :text t.column :imageflag, :inte...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :openid_url, :string end end def self.down drop_table :users end end
Ruby
class ItemAddCreatedAt < ActiveRecord::Migration def self.up add_column :items, :created_at, :timestamp add_column :items, :updated_at, :timestamp end def self.down remove_column :items, :created_at remove_column :items, :updated_at end end
Ruby
class ItemAddType < ActiveRecord::Migration def self.up add_column :items, :type_id, :integer, :default => 0 rename_column :items, :genreid, :genre_id end def self.down rename_column :items, :genre_id, :genreid remove_column :items, :type_id end end
Ruby
class GiftAddGender < ActiveRecord::Migration def self.up add_column :gifts, :gender, :integer end def self.down remove_column :gifts, :gender end end
Ruby
class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.column :name, :string end [_("Birth celebration"), _("Congratulation on inside"), _("Return to Birth celebration"), _("Birth day"), _("Christmas"), _("Entrance celebration"), _("3 years Festival"), _("5 years Fest...
Ruby
class CreateGenres < ActiveRecord::Migration def self.up create_table :genres do |t| t.column :name, :string end ["Book", "Music", "CE", "Kitchen", "DVD", "Video", "Software", "Video Games", "Toy", "Sports", "Health and Beauty", "Watch", "Baby Product", "Apparel"].each do |n| Genre.create :nam...
Ruby
class ActsAsTaggableMigration < ActiveRecord::Migration def self.up create_table :tags do |t| t.column :name, :string end create_table :taggings do |t| t.column :tag_id, :integer t.column :taggable_id, :integer # You should make sure that the column created is...
Ruby
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 add_index :sessions, :updated_at end def self.down drop_table :sess...
Ruby
class CreateGifts < ActiveRecord::Migration def self.up create_table :gifts do |t| t.column :user_id, :integer, :default => 0 t.column :comment, :string t.column :item_id, :integer, :default => 0 t.column :created_at, :timestamp t.column :updated_at, :timestamp t.column :age_id...
Ruby
class CreateTypes < ActiveRecord::Migration def self.up create_table :types do |t| t.column :name, :string end ["rakuten", "amazon"].each do |n| Type.create :name => n end end def self.down drop_table :types end end
Ruby
# Use this migration to create the tables for the ActiveRecord store class AddOpenIdStoreToDb < ActiveRecord::Migration def self.up create_table "open_id_associations", :force => true do |t| t.column "server_url", :binary t.column "handle", :string t.column "secret", :binary t.column "issu...
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/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/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/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/plugin'
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/about'
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/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/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/runner'
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/console'
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/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/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/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
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 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
# 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
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # Sa...
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
# 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
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) unless defined?(Rails::Initializer) if File.directory?("#{RAILS_ROOT}/vendor/rails") require "#{RAILS_ROOT}/vendor/rails/railties/lib/init...
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
require 'gettext/utils' task :updatepo do GetText.update_pofiles("10pockets", Dir.glob("{app,config,components,lib}/**/*.{rb,rhtml,rjs}"), "10pockets 0.0.1" ) end task :makemo do GetText.create_mofiles(true, "po", "locale") end
Ruby
require 'rexml/document' require 'cgi' require 'open-uri' module RakutenWebService DEVELOPER_ID = "[your developer id]" module GenreSearch class URL_Builder attr_accessor :affiliateId, :callBack, :genreid, :genrepath attr_accessor :base, :developerId, :operation, :version def initialize(devel...
Ruby
require_dependency "user" module OpenidLoginSystem protected # overwrite this if you want to restrict access to only a few actions # or if you want to check if the user has the correct rights # example: # # # only allow nonbobs # def authorize?(user) # user.login != "bob" # end def a...
Ruby
#!/usr/bin/env ruby require 'rubygems' require 'rexml/document' require "rexml/streamlistener" include REXML class Parser attr_reader :tags include StreamListener def initialize @tags = [] end def tag_start(element, attributes) @parse = true if element == 'mnem' end def text(text) @ta...
Ruby
# Iterates all instructions and displays write-access to code, i.e. finds self-modifying code # Also tries to apply the changes statically to aid further analyzation # Changed addresses will be remembered here in order to reanalyze them later changes = [] $api.traverseCode do |inst| for op in inst.getDestOpe...
Ruby
# Calculate a mnemonic histogram histogram = Hash.new(0) total = 0 $api.traverseCode do |inst| mnem = inst.getMnemonic.to_s histogram[mnem] += 1 total += 1 end histogram.sort_by {|mnem, count| count}.reverse_each do |a| puts "%10s: %5d (%.2f%%)" % [a[0], a[1], a[1] / total.to_f * 100] ...
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 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
Reported by [email protected], Mar 11, 2011 I found the need to have a nice start / stop / restart wrapper for shellinabox, and a quick way to add new configurations and URLS. Attached is a file that does just that. It is ruby based, and expects a conf directory in the shellinthebox home directory. All file(s) plac...
Ruby
#!/usr/bin/ruby #=============================================================================== # # FILE: siab.rb # # USAGE: ruby siab.rb [start|stop|restar|help] # # DESCRIPTION: a ShellInAbox control script and configuration system reader. # To auto-configure a shellinabox service creat...
Ruby
$LOAD_PATH << "#{File.dirname(__FILE__)}" relative_assets = true images_dir = "assets/images"
Ruby
$LOAD_PATH << "#{File.dirname(__FILE__)}" relative_assets = true images_dir = "assets/images" css_dir = "assets/css" fonts_dir = "assets/css/font" Compass::Frameworks.register("sassy-math", :path => "#{File.dirname(__FILE__)}/..") # Sassy math Functions module Sass::Script::Functions # Exponents def exponent(ba...
Ruby
$LOAD_PATH << "#{File.dirname(__FILE__)}" relative_assets = true images_dir = "assets/images" css_dir = "assets/css" fonts_dir = "assets/css/font" Compass::Frameworks.register("sassy-math", :path => "#{File.dirname(__FILE__)}/..") # Sassy math Functions module Sass::Script::Functions # Exponents def exponent(ba...
Ruby
module Blueprint # Strips out most whitespace and can return a hash or string of parsed data class CSSParser attr_accessor :namespace attr_reader :css_output, :raw_data # ==== Options # * <tt>css_string</tt> String of CSS data # * <tt>options</tt> # * <tt>:namespace</tt> -- Namespace to...
Ruby
require "yaml" require "optparse" module Blueprint class Compressor TEST_FILES = ["index.html", "parts/elements.html", "parts/forms.html", "parts/grid.html", "parts/sample.html"] attr_accessor :namespace, :custom_css, :custom_layout, :se...
Ruby
module Blueprint # Validates generated CSS against the W3 using Java class Validator attr_reader :error_count def initialize @error_count = 0 end # Validates all three CSS files def validate java_path = `which java`.rstrip raise "You do not have a Java installed, but it is re...
Ruby
module Blueprint # parses a hash of key/value pairs, key being output CSS selectors, value # being a list of CSS selectors to draw from class SemanticClassNames attr_accessor :class_assignments attr_reader :namespace, :source_file # ==== Options # * <tt>options</tt> # * <tt>:namespace</tt...
Ruby
module Blueprint class GridBuilder attr_reader :column_width, :gutter_width, :output_path, :able_to_generate # ==== Options # * <tt>options</tt> # * <tt>:column_width</tt> -- Width (in pixels) of current grid column # * <tt>:gutter_width</tt> -- Width (in pixels) of current grid gutter # ...
Ruby
require 'erb' module Blueprint # Generates a custom grid file, using ERB to evaluate custom settings class CustomLayout # path to ERB file used for CSS template CSS_ERB_FILE = File.join(Blueprint::LIB_PATH, 'grid.css.erb') attr_writer :column_count, :column_width, :gutter_width, :input_padding, ...
Ruby
require "rubygems" begin require "bundler" Bundler.require(:default) rescue LoadError puts "Bundler is required to run the compression script\n\n" puts " gem install bundler" exit(1) rescue Bundler::GemNotFound puts "You need to bundle in order to run the compression script\n\n" puts " bundle insta...
Ruby
class String # see if string has any content def blank?; self.length.zero?; end # strip space after :, remove newlines, replace multiple spaces with only one space, remove comments def strip_space! replace self.gsub(/:\s*/, ":").gsub(/\n/, "").gsub(/\s+/, " ").gsub(/(\/\*).*?(\*\/)/, "") end # remove ...
Ruby
module Blueprint class Namespace # Read html to string, remove namespace if any, # set the new namespace, and update the test file. def initialize(path, namespace) html = File.path_to_string(path) remove_current_namespace(html) add_namespace(html, namespace) File.string_to_file(ht...
Ruby
#!/usr/bin/env ruby require File.join(File.dirname(__FILE__), "blueprint", "blueprint") # **Basic # # Calling this file by itself will pull files from blueprint/src and # concatenate them into three files; ie.css, print.css, and screen.css. # # ruby compress.rb # # However, argument variables can be set to c...
Ruby
#!/usr/bin/env ruby require File.join(File.dirname(__FILE__), "blueprint", "blueprint") # **Basic # # Calling this file by itself will pull files from blueprint/src and # concatenate them into three files; ie.css, print.css, and screen.css. # # ruby compress.rb # # However, argument variables can be set to c...
Ruby
#!/usr/bin/env ruby require "blueprint/blueprint" require "blueprint/validator" # This script will validate the core Blueprint files. # # The files are not completely valid. This has to do # with a small number of CSS hacks needed to ensure # consistent rendering across browsers. # # To add your own CSS files for val...
Ruby
#!/usr/bin/env ruby require "blueprint/blueprint" require "blueprint/validator" # This script will validate the core Blueprint files. # # The files are not completely valid. This has to do # with a small number of CSS hacks needed to ensure # consistent rendering across browsers. # # To add your own CSS files for val...
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
require "facebooker/delayed_user_action"
Ruby
# These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
Ruby