Skip to content

Instantly share code, notes, and snippets.

View Achillefs's full-sized avatar

Achilles Charmpilas Achillefs

  • Athens, GR
View GitHub Profile
<?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;
}
# 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
#!/usr/bin/env bash
echo "Creating and downloading live database image..."
ssh [email protected] 'mysqldump -u username -ppassword dbname | bzip2 > image.sql.bz'
scp [email protected]:./image.sql.bz ~/Desktop/
ssh [email protected] '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."
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(%[