Skip to content

Instantly share code, notes, and snippets.

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 }
@cyx
cyx / gist:219813
Created October 27, 2009 18:46 — forked from tpitale/gist:162954
#! /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
#!/usr/bin/env zsh
function resolve_symlink() {
local result=`readlink $1`
[ -z $result ] && echo $1 || $0 $result
}
function expand_path() {
cd -qP $1
pwd
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
@cyx
cyx / zuc.rb
Created August 17, 2011 20:05 — forked from vangberg/zuc.rb
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
@cyx
cyx / tpl.rb
Created August 18, 2011 04:30 — forked from tizoc/tpl.rb
# -*- 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
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]
@cyx
cyx / dbtasks.rb
Created August 25, 2011 15:02 — forked from tizoc/dbtasks.rb
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
@cyx
cyx / example.html
Created September 22, 2011 06:07 — forked from joelnet/example.html
Unobtrusive Knockout support library for jQuery
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}}
@cyx
cyx / xhr.rb
Created October 30, 2011 08:28 — forked from lucasmazza/xhr.rb
Using xhr with rspec + rack/test
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