This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeController < ApplicationController | |
def index | |
if (@target_url = params["url"]) && !@target_url.blank? | |
@target_url = @target_url =~ %r{^http://} ? @target_url : "http://#{@target_url}" | |
filter_if_length_less_than = 40 | |
@page = open(@target_url).read | |
doc = Nokogiri::HTML.parse(@page) | |
content = doc.search("h1,p,.comment") | |
content = content.reject { |node| node.text.gsub(/\W/,'').strip.length < filter_if_length_less_than } | |
content = content.reject { |node| (%w[noscript li] & node.ancestors.map { |e| e.name }).length > 0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/mongodb/bin | |
DAEMON=/opt/mongodb/bin/mongod | |
PIDFILE=/var/log/mongodb/mongodb.pid | |
LOGFILE=/var/log/mongodb/mongod.log | |
NAME=mongodb | |
DESC=mongodb | |
test -x $DAEMON || exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
function resolve_symlink() { | |
local result=`readlink $1` | |
[ -z $result ] && echo $1 || $0 $result | |
} | |
function expand_path() { | |
cd -qP $1 | |
pwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def daemonize(name = File.basename($0), options = {}) | |
pid_path = options[:pid_path] || File.expand_path("tmp/pids/#{name}.pid") | |
# If the pid file exists, check that the process is actually still running. | |
begin | |
if File.exists?(pid_path) && Process.kill(0, File.read(pid_path).to_i) | |
$stderr.puts "Already running." | |
exit 1 | |
end | |
rescue Errno::ESRCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def path matcher | |
lambda {|req| | |
return unless match = req.env["PATH_INFO"].match(/^\/(#{matcher})(\/|$)/) | |
path = match.captures[0] | |
req.env["SCRIPT_NAME"] += "/#{path}" | |
req.env["PATH_INFO"] = "/#{match.post_match}" | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
module Tpl | |
def self.new_proc(template, variables = []) | |
render_definition = "Proc.new do |__v, __o|\n __v ||= {}; __o ||= ''\n" | |
compile(template, variables, render_definition) | |
render_definition << "__o\nend" | |
eval(render_definition) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mote(template, params = {}) | |
variables = mote_process_variables(mote_cache, template, params) | |
mote_cache[template] ||= Mote.parse(template, self, variables) | |
mote_cache[template][params] | |
end | |
def mote_file(filename, params = {}) | |
variables = mote_process_variables(mote_files, filename, params) | |
mote_files[filename] ||= Mote.parse(File.read(filename), self, variables) | |
mote_files[filename][params] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "migrate", "Runs Sequel migrations" | |
def migrate(version=nil, database_url=DATABASE_URL) | |
require 'sequel' | |
Sequel.extension :migration | |
db = Sequel.connect(database_url, :test => true) | |
puts 'Running migrations...' | |
Sequel::Migrator.apply(db, 'db/migrate', version && version.to_i) | |
dump_schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Choose a ticket class: <select id="tickets"></select> | |
<p id="ticketOutput"></p> | |
<script id="ticketTemplate" type="text/x-jquery-tmpl"> | |
{{if chosenTicket}} | |
You have chosen <b>${ chosenTicket().name }</b> | |
($${ chosenTicket().price }) | |
<button data-bind="click: resetTicket">Clear</button> | |
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module XhrHelpers | |
def xhr(path, params = {}) | |
verb = params.delete(:as) || :get | |
send(verb,path, params, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest") | |
end | |
alias_method :ajax, :xhr | |
end | |
RSpec.configuration.include XhrHelpers, :type => :controller |
OlderNewer