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 ApplicationHelper | |
# Your own stuff | |
def ajax_actions opts = {} | |
container = opts.delete(:container) || "actions_container" | |
actions_selector = opts.delete(:actions_selector) || "td.actions a" | |
raise ArgumentError.new("Please specify a container element identifier") if container.empty? or container.nil? | |
raise ArgumentError.new("The action links selector cannot be empty") if actions_selector.empty? or actions_selector.nil? | |
html = %[<div id="#{container}"></div>\n] | |
html << javascript_tag(%[ |
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 bash | |
echo "Creating and downloading live database image..." | |
ssh username@server.com 'mysqldump -u username -ppassword dbname | bzip2 > image.sql.bz' | |
scp username@server.com:./image.sql.bz ~/Desktop/ | |
ssh username@server.com 'rm -rf image.sql.bz' | |
echo "Done. Importing database..." | |
bunzip2 ~/Desktop/image.sql.bz | |
mysql -u username local_dbname < ~/Desktop/image.sql | |
rm -rf ~/Desktop/image.sql | |
echo "Done. Database update complete." |
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
# sudo gem install mechanize ratom --no-ri --no-rdoc | |
%W{rubygems mechanize atom/pub net/http}.each { |r| require r } | |
module Wordpress | |
# A proof of concept class, displaying how to manage a WP blog through ruby | |
class Blog | |
attr_accessor :agent, :blog_uri, :username, :password, :logged_in | |
def initialize blog_uri, username, password | |
@username = username | |
@password = password | |
@blog_uri = blog_uri.gsub(/\/$/,"") # remove last slash if given |
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
<?php | |
class Phrase { | |
public static function to_link($content){ | |
$phrases = DbFinder::from("Phrase")->find(); # This was for a symfony site | |
foreach ($phrases as $p) { # Interestingly, foreach is much faster than a for loop | |
$text = preg_quote($p->getText()); # Sanitize the text | |
$content = preg_replace("/(?!=(?:<a [^>]*>))({$text})(?!(?:<\/a>))/si","<a href=\"{$p->getUrl()}\">\\1</a>",$content,1); | |
} | |
return $content; | |
} |
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
Dir[File.join(%w[test fixtures files *.xml])].each do |file| | |
xml = File.read(file) | |
matches = xml.scan("\n") | |
if !matches or matches.size < 3 | |
puts "#{file}: Not enough line brakes, adding them now..." | |
File.open(file,"w") do |f| | |
f.puts(xml.gsub(/(<[^\/]*>)/,"\n\\1")) | |
end | |
end | |
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
require "net/http" | |
module Net | |
class HTTP | |
alias :old_connect :connect | |
def connect | |
D "opening connection to #{conn_address()}..." | |
begin # HACK START | |
s = timeout(@open_timeout) do | |
TCPSocket.open(conn_address(), conn_port(), App.available_ip_addresses.rand) | |
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
require "uri" | |
require "active_support" | |
# Get auth token from Googles | |
auth_uri = "https://www.google.com/accounts/ClientLogin" | |
params = { | |
"accountType" => "HOSTED_OR_GOOGLE", | |
"Email" => "yer_gmail", | |
"Passwd" => "yer_gpass", | |
"source" => "organization-appname-version", |
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
el: | |
i18n: | |
transliterate: | |
rule: | |
α: a | |
ά: a | |
Α: a | |
Ά: a | |
β: v | |
Β: v |
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
# Single edit line#20 | |
begin | |
require "active_support" | |
rescue LoadError | |
require "rubygems" | |
require "active_support" | |
end | |
module PermalinkFu |
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
%W[rubygems anemone].each {|r| require r} | |
site_root = "http://www.whatever.org/" | |
# Create the root folder | |
folder = URI.parse(site_root).host | |
FileUtils.mkdir_p(File.join(".",folder)) | |
Anemone.crawl(site_root) do |anemone| | |
anemone.on_every_page do |page| |
OlderNewer